mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Map: show multiple selected dive sites
If multiple dives are selected, highlight all corresponding sites. For that, replace the MapLocationModel::m_selectedDs pointer by a QVector<>. Fill the vector in MapLocationModel::reload() and add a isSelected() member function. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
446dfed6e7
commit
a35d1bd0e7
3 changed files with 23 additions and 18 deletions
|
@ -56,17 +56,17 @@ Item {
|
||||||
anchorPoint.x: 0
|
anchorPoint.x: 0
|
||||||
anchorPoint.y: mapItemImage.height
|
anchorPoint.y: mapItemImage.height
|
||||||
coordinate: model.coordinate
|
coordinate: model.coordinate
|
||||||
z: mapHelper.model.selectedDs === model.divesite ? mapHelper.model.count - 1 : 0
|
z: mapHelper.model.isSelected(model.divesite) ? mapHelper.model.count - 1 : 0
|
||||||
sourceItem: Image {
|
sourceItem: Image {
|
||||||
id: mapItemImage
|
id: mapItemImage
|
||||||
source: "qrc:///dive-location-marker" + (mapHelper.model.selectedDs === model.divesite ? "-selected" : (mapHelper.editMode ? "-inactive" : "")) + "-icon"
|
source: "qrc:///dive-location-marker" + (mapHelper.model.isSelected(model.divesite) ? "-selected" : (mapHelper.editMode ? "-inactive" : "")) + "-icon"
|
||||||
SequentialAnimation {
|
SequentialAnimation {
|
||||||
id: mapItemImageAnimation
|
id: mapItemImageAnimation
|
||||||
PropertyAnimation { target: mapItemImage; property: "scale"; from: 1.0; to: 0.7; duration: 120 }
|
PropertyAnimation { target: mapItemImage; property: "scale"; from: 1.0; to: 0.7; duration: 120 }
|
||||||
PropertyAnimation { target: mapItemImage; property: "scale"; from: 0.7; to: 1.0; duration: 80 }
|
PropertyAnimation { target: mapItemImage; property: "scale"; from: 0.7; to: 1.0; duration: 80 }
|
||||||
}
|
}
|
||||||
MouseArea {
|
MouseArea {
|
||||||
drag.target: (mapHelper.editMode && mapHelper.model.selectedDs === model.divesite) ? mapItem : undefined
|
drag.target: (mapHelper.editMode && mapHelper.model.isSelected(model.divesite)) ? mapItem : undefined
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (!mapHelper.editMode)
|
if (!mapHelper.editMode)
|
||||||
|
@ -74,8 +74,8 @@ Item {
|
||||||
}
|
}
|
||||||
onDoubleClicked: map.doubleClickHandler(mapItem.coordinate)
|
onDoubleClicked: map.doubleClickHandler(mapItem.coordinate)
|
||||||
onReleased: {
|
onReleased: {
|
||||||
if (mapHelper.editMode && mapHelper.model.selectedDs === model.divesite) {
|
if (mapHelper.editMode && mapHelper.model.isSelected(model.divesite)) {
|
||||||
mapHelper.updateCurrentDiveSiteCoordinatesFromMap(mapHelper.model.selectedDs, mapItem.coordinate)
|
mapHelper.updateCurrentDiveSiteCoordinatesFromMap(model.divesite, mapItem.coordinate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ Item {
|
||||||
id: mapItemText
|
id: mapItemText
|
||||||
text: model.name
|
text: model.name
|
||||||
font.pointSize: 11.0
|
font.pointSize: 11.0
|
||||||
color: mapHelper.model.selectedDs === model.divesite ? "white" : "lightgrey"
|
color: mapHelper.model.isSelected(model.divesite) ? "white" : "lightgrey"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,8 +61,7 @@ QVariant MapLocation::divesiteVariant()
|
||||||
return QVariant::fromValue(m_ds);
|
return QVariant::fromValue(m_ds);
|
||||||
}
|
}
|
||||||
|
|
||||||
MapLocationModel::MapLocationModel(QObject *parent) : QAbstractListModel(parent),
|
MapLocationModel::MapLocationModel(QObject *parent) : QAbstractListModel(parent)
|
||||||
m_selectedDs(nullptr)
|
|
||||||
{
|
{
|
||||||
m_roles[MapLocation::Roles::RoleDivesite] = MapLocation::PROPERTY_NAME_DIVESITE;
|
m_roles[MapLocation::Roles::RoleDivesite] = MapLocation::PROPERTY_NAME_DIVESITE;
|
||||||
m_roles[MapLocation::Roles::RoleCoordinate] = MapLocation::PROPERTY_NAME_COORDINATE;
|
m_roles[MapLocation::Roles::RoleCoordinate] = MapLocation::PROPERTY_NAME_COORDINATE;
|
||||||
|
@ -120,6 +119,7 @@ void MapLocationModel::reload()
|
||||||
|
|
||||||
qDeleteAll(m_mapLocations);
|
qDeleteAll(m_mapLocations);
|
||||||
m_mapLocations.clear();
|
m_mapLocations.clear();
|
||||||
|
m_selectedDs.clear();
|
||||||
|
|
||||||
QMap<QString, MapLocation *> locationNameMap;
|
QMap<QString, MapLocation *> locationNameMap;
|
||||||
MapLocation *location;
|
MapLocation *location;
|
||||||
|
@ -140,7 +140,11 @@ void MapLocationModel::reload()
|
||||||
if (!diveSiteMode && dive->hidden_by_filter && dive != current_dive)
|
if (!diveSiteMode && dive->hidden_by_filter && dive != current_dive)
|
||||||
continue;
|
continue;
|
||||||
struct dive_site *ds = get_dive_site_for_dive(dive);
|
struct dive_site *ds = get_dive_site_for_dive(dive);
|
||||||
if (!dive_site_has_gps_location(ds) || locations.contains(ds))
|
if (!dive_site_has_gps_location(ds))
|
||||||
|
continue;
|
||||||
|
if (dive->selected && !m_selectedDs.contains(ds))
|
||||||
|
m_selectedDs.append(ds);
|
||||||
|
if (locations.contains(ds))
|
||||||
continue;
|
continue;
|
||||||
latitude = ds->location.lat.udeg * 0.000001;
|
latitude = ds->location.lat.udeg * 0.000001;
|
||||||
longitude = ds->location.lon.udeg * 0.000001;
|
longitude = ds->location.lon.udeg * 0.000001;
|
||||||
|
@ -165,15 +169,16 @@ void MapLocationModel::reload()
|
||||||
|
|
||||||
void MapLocationModel::setSelected(struct dive_site *ds, bool fromClick)
|
void MapLocationModel::setSelected(struct dive_site *ds, bool fromClick)
|
||||||
{
|
{
|
||||||
m_selectedDs = ds;
|
m_selectedDs.clear();
|
||||||
emit selectedDsChanged();
|
m_selectedDs.append(ds);
|
||||||
if (fromClick)
|
if (fromClick)
|
||||||
emit selectedLocationChanged(getMapLocation(m_selectedDs));
|
emit selectedLocationChanged(getMapLocation(ds));
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant MapLocationModel::selectedDs()
|
bool MapLocationModel::isSelected(const QVariant &dsVariant) const
|
||||||
{
|
{
|
||||||
return QVariant::fromValue(m_selectedDs);
|
dive_site *ds = dsVariant.value<dive_site *>();
|
||||||
|
return ds && m_selectedDs.contains(ds);
|
||||||
}
|
}
|
||||||
|
|
||||||
MapLocation *MapLocationModel::getMapLocation(const struct dive_site *ds)
|
MapLocation *MapLocationModel::getMapLocation(const struct dive_site *ds)
|
||||||
|
|
|
@ -50,7 +50,6 @@ class MapLocationModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(int count READ count NOTIFY countChanged)
|
Q_PROPERTY(int count READ count NOTIFY countChanged)
|
||||||
Q_PROPERTY(QVariant selectedDs READ selectedDs NOTIFY selectedDsChanged)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MapLocationModel(QObject *parent = NULL);
|
MapLocationModel(QObject *parent = NULL);
|
||||||
|
@ -65,7 +64,9 @@ public:
|
||||||
MapLocation *getMapLocation(const struct dive_site *ds);
|
MapLocation *getMapLocation(const struct dive_site *ds);
|
||||||
void updateMapLocationCoordinates(const struct dive_site *ds, QGeoCoordinate coord);
|
void updateMapLocationCoordinates(const struct dive_site *ds, QGeoCoordinate coord);
|
||||||
Q_INVOKABLE void setSelected(struct dive_site *ds, bool fromClick = true);
|
Q_INVOKABLE void setSelected(struct dive_site *ds, bool fromClick = true);
|
||||||
QVariant selectedDs();
|
// The dive site is passed as a QVariant, because a null-QVariant is not automatically
|
||||||
|
// transformed into a null pointer and warning messages are spewed onto the console.
|
||||||
|
Q_INVOKABLE bool isSelected(const QVariant &ds) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
@ -73,11 +74,10 @@ protected:
|
||||||
private:
|
private:
|
||||||
QVector<MapLocation *> m_mapLocations;
|
QVector<MapLocation *> m_mapLocations;
|
||||||
QHash<int, QByteArray> m_roles;
|
QHash<int, QByteArray> m_roles;
|
||||||
struct dive_site *m_selectedDs;
|
QVector<dive_site *> m_selectedDs;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void countChanged(int c);
|
void countChanged(int c);
|
||||||
void selectedDsChanged();
|
|
||||||
void selectedLocationChanged(MapLocation *);
|
void selectedLocationChanged(MapLocation *);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue