diff options
Diffstat (limited to 'qt-models')
-rw-r--r-- | qt-models/maplocationmodel.cpp | 21 | ||||
-rw-r--r-- | qt-models/maplocationmodel.h | 8 |
2 files changed, 17 insertions, 12 deletions
diff --git a/qt-models/maplocationmodel.cpp b/qt-models/maplocationmodel.cpp index 85c106ff1..90d7209f7 100644 --- a/qt-models/maplocationmodel.cpp +++ b/qt-models/maplocationmodel.cpp @@ -61,8 +61,7 @@ QVariant MapLocation::divesiteVariant() return QVariant::fromValue(m_ds); } -MapLocationModel::MapLocationModel(QObject *parent) : QAbstractListModel(parent), - m_selectedDs(nullptr) +MapLocationModel::MapLocationModel(QObject *parent) : QAbstractListModel(parent) { m_roles[MapLocation::Roles::RoleDivesite] = MapLocation::PROPERTY_NAME_DIVESITE; m_roles[MapLocation::Roles::RoleCoordinate] = MapLocation::PROPERTY_NAME_COORDINATE; @@ -120,6 +119,7 @@ void MapLocationModel::reload() qDeleteAll(m_mapLocations); m_mapLocations.clear(); + m_selectedDs.clear(); QMap<QString, MapLocation *> locationNameMap; MapLocation *location; @@ -140,7 +140,11 @@ void MapLocationModel::reload() if (!diveSiteMode && dive->hidden_by_filter && dive != current_dive) continue; 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; latitude = ds->location.lat.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) { - m_selectedDs = ds; - emit selectedDsChanged(); + m_selectedDs.clear(); + m_selectedDs.append(ds); 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) diff --git a/qt-models/maplocationmodel.h b/qt-models/maplocationmodel.h index 6c28c6c99..6f075cc84 100644 --- a/qt-models/maplocationmodel.h +++ b/qt-models/maplocationmodel.h @@ -50,7 +50,6 @@ class MapLocationModel : public QAbstractListModel { Q_OBJECT Q_PROPERTY(int count READ count NOTIFY countChanged) - Q_PROPERTY(QVariant selectedDs READ selectedDs NOTIFY selectedDsChanged) public: MapLocationModel(QObject *parent = NULL); @@ -65,7 +64,9 @@ public: MapLocation *getMapLocation(const struct dive_site *ds); void updateMapLocationCoordinates(const struct dive_site *ds, QGeoCoordinate coord); 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: QHash<int, QByteArray> roleNames() const override; @@ -73,11 +74,10 @@ protected: private: QVector<MapLocation *> m_mapLocations; QHash<int, QByteArray> m_roles; - struct dive_site *m_selectedDs; + QVector<dive_site *> m_selectedDs; signals: void countChanged(int c); - void selectedDsChanged(); void selectedLocationChanged(MapLocation *); }; |