summaryrefslogtreecommitdiffstats
path: root/qt-models/divelocationmodel.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-10-25 08:02:06 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-10-29 00:09:31 +0000
commitb9b1b3146b3a0a05efcb11c50a953f3e8f2e023c (patch)
treea40397ddd9d370deb5ae66920d0bf2e98bf27868 /qt-models/divelocationmodel.cpp
parent6f98dca26e342dff90c5dba81bf81cbeab5f6e63 (diff)
downloadsubsurface-b9b1b3146b3a0a05efcb11c50a953f3e8f2e023c.tar.gz
Dive site: remove UUIDs from LocationInformationModel
Replace UUIDs from LocationInformationModel and fix the fallout. Notably, replace the UUID "column" by a DIVESITE "column". Getting pointers through Qt's QVariant is horrible, we'll have to think about a better solution. RECENTLY_ADDED_DIVESITE now defines to a special pointer to struct dive_site (defined as ~0). This fixes an interesting logic bug: The old code checked the uuid of the LocationInformationModel (currUuid) for the value "1", which corresponded to RECENTLY_ADDED_DIVESITE. If equal, currType would be set to NEW_DIVE_SITE. Later, _currType_ was compared against _RECENTLY_ADDED_DIVESITE_. This would only work because NEW_DIVE_SITE and RECENTLY_ADDED_DIVESITE both were defined as 1. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models/divelocationmodel.cpp')
-rw-r--r--qt-models/divelocationmodel.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/qt-models/divelocationmodel.cpp b/qt-models/divelocationmodel.cpp
index c1a7308f4..18be89806 100644
--- a/qt-models/divelocationmodel.cpp
+++ b/qt-models/divelocationmodel.cpp
@@ -41,7 +41,7 @@ QVariant LocationInformationModel::getDiveSiteData(const struct dive_site *ds, i
case Qt::EditRole:
case Qt::DisplayRole :
switch(column) {
- case UUID: return ds->uuid;
+ case DIVESITE: return QVariant::fromValue<void*>((void *)ds); // Not nice: casting away const
case NAME: return ds->name;
case LATITUDE: return ds->location.lat.udeg;
case LONGITUDE: return ds->location.lon.udeg;
@@ -102,7 +102,8 @@ bool LocationInformationModel::removeRows(int row, int, const QModelIndex&)
return true;
}
-GeoReferencingOptionsModel *GeoReferencingOptionsModel::instance() {
+GeoReferencingOptionsModel *GeoReferencingOptionsModel::instance()
+{
static GeoReferencingOptionsModel *self = new GeoReferencingOptionsModel();
return self;
}
@@ -118,24 +119,23 @@ GeoReferencingOptionsModel::GeoReferencingOptionsModel(QObject *parent) : QStrin
bool GPSLocationInformationModel::filterAcceptsRow(int sourceRow, const QModelIndex &parent) const
{
- uint32_t uuid = sourceModel()->index(sourceRow, LocationInformationModel::UUID, parent).data().toUInt();
- if (uuid == ignoreUuid || uuid == RECENTLY_ADDED_DIVESITE)
+ struct dive_site *ds = (struct dive_site *)sourceModel()->index(sourceRow, LocationInformationModel::DIVESITE, parent).data().value<void *>();
+ if (ds == ignoreDs || ds == RECENTLY_ADDED_DIVESITE)
return false;
- struct dive_site *ds = get_dive_site_by_uuid(uuid);
return ds && same_location(&ds->location, &location);
}
GPSLocationInformationModel::GPSLocationInformationModel(QObject *parent) : QSortFilterProxyModel(parent),
- ignoreUuid(0),
+ ignoreDs(nullptr),
location({{0},{0}})
{
setSourceModel(LocationInformationModel::instance());
}
-void GPSLocationInformationModel::set(uint32_t ignoreUuidIn, const location_t &locationIn)
+void GPSLocationInformationModel::set(const struct dive_site *ignoreDsIn, const location_t &locationIn)
{
- ignoreUuid = ignoreUuidIn;
+ ignoreDs = ignoreDsIn;
location = locationIn;
invalidate();
}