summaryrefslogtreecommitdiffstats
path: root/qt-models/divelocationmodel.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-10-08 19:01:45 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-10-11 16:25:32 -0700
commitf39596df0628c567f2ffd45cfa5fe809fbb7cf75 (patch)
treeb8ffa384adf6fb48e8238259edade9f64319e72d /qt-models/divelocationmodel.cpp
parentac02854a8aa98dcd6876c9249654ac9e1d949c92 (diff)
downloadsubsurface-f39596df0628c567f2ffd45cfa5fe809fbb7cf75.tar.gz
Map: remove access to displayed_dive_site in GPS-filter model
The location information shows a list of dive sites at the same location as the edited dive site. This was done by passing a function to an "SsrfSortFilterProxyModel". Unfortunately, the latter does only support function pointers without state and therefore had to access the global "displayed_dive_site" object. Replace the SsrfSortFilterProxyModel by a proper subclass of QSortFilterProxyModel that contains information on the position and id of the currently edited dive site. Update the filter model if the location of the dive site changes. This introduces a behavioral change: editing the GPS location will lead to an updated list. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models/divelocationmodel.cpp')
-rw-r--r--qt-models/divelocationmodel.cpp38
1 files changed, 26 insertions, 12 deletions
diff --git a/qt-models/divelocationmodel.cpp b/qt-models/divelocationmodel.cpp
index 4411f5d98..ca803f1cf 100644
--- a/qt-models/divelocationmodel.cpp
+++ b/qt-models/divelocationmodel.cpp
@@ -116,21 +116,35 @@ GeoReferencingOptionsModel::GeoReferencingOptionsModel(QObject *parent) : QStrin
setStringList(list);
}
-bool filter_same_gps_cb (QAbstractItemModel *model, int sourceRow, const QModelIndex& parent)
+bool GPSLocationInformationModel::filterAcceptsRow(int sourceRow, const QModelIndex &parent) const
{
- int ref_lat = displayed_dive_site.latitude.udeg;
- int ref_lon = displayed_dive_site.longitude.udeg;
- uint32_t ref_uuid = displayed_dive_site.uuid;
- QSortFilterProxyModel *self = (QSortFilterProxyModel*) model;
+ uint32_t uuid = sourceModel()->index(sourceRow, LocationInformationModel::UUID, parent).data().toUInt();
+ if (uuid == ignoreUuid || uuid == RECENTLY_ADDED_DIVESITE)
+ return false;
+ struct dive_site *ds = get_dive_site_by_uuid(uuid);
- uint32_t ds_uuid = self->sourceModel()->index(sourceRow, LocationInformationModel::UUID, parent).data().toUInt();
- struct dive_site *ds = get_dive_site_by_uuid(ds_uuid);
+ return ds && ds->latitude.udeg == latitude.udeg && ds->longitude.udeg == longitude.udeg;
+}
- if (!ds)
- return false;
+GPSLocationInformationModel::GPSLocationInformationModel(QObject *parent) : QSortFilterProxyModel(parent),
+ ignoreUuid(0),
+ latitude({ 0 }),
+ longitude({ 0 })
+{
+ setSourceModel(LocationInformationModel::instance());
+}
- if (ds->latitude.udeg == 0 || ds->longitude.udeg == 0)
- return false;
+void GPSLocationInformationModel::set(uint32_t ignoreUuidIn, degrees_t latitudeIn, degrees_t longitudeIn)
+{
+ ignoreUuid = ignoreUuidIn;
+ latitude = latitudeIn;
+ longitude = longitudeIn;
+ invalidate();
+}
- return ds->latitude.udeg == ref_lat && ds->longitude.udeg == ref_lon && ds->uuid != ref_uuid;
+void GPSLocationInformationModel::setCoordinates(degrees_t latitudeIn, degrees_t longitudeIn)
+{
+ latitude = latitudeIn;
+ longitude = longitudeIn;
+ invalidate();
}