summaryrefslogtreecommitdiffstats
path: root/qt-models
diff options
context:
space:
mode:
Diffstat (limited to 'qt-models')
-rw-r--r--qt-models/divelocationmodel.cpp38
-rw-r--r--qt-models/divelocationmodel.h16
2 files changed, 39 insertions, 15 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();
}
diff --git a/qt-models/divelocationmodel.h b/qt-models/divelocationmodel.h
index 8dbc8f3e6..048b2c0a3 100644
--- a/qt-models/divelocationmodel.h
+++ b/qt-models/divelocationmodel.h
@@ -10,9 +10,6 @@
#define RECENTLY_ADDED_DIVESITE 1
-bool filter_same_gps_cb (QAbstractItemModel *m, int sourceRow, const QModelIndex& parent);
-
-
class LocationInformationModel : public QAbstractTableModel {
Q_OBJECT
public:
@@ -36,6 +33,19 @@ private:
QStringList locationNames;
};
+// To access only divesites at the given GPS coordinates with the exception of a given dive site
+class GPSLocationInformationModel : public QSortFilterProxyModel {
+Q_OBJECT
+private:
+ uint32_t ignoreUuid;
+ degrees_t latitude, longitude;
+ bool filterAcceptsRow(int sourceRow, const QModelIndex &source_parent) const override;
+public:
+ GPSLocationInformationModel(QObject *parent = nullptr);
+ void set(uint32_t ignoreUuid, degrees_t latitude, degrees_t longitude);
+ void setCoordinates(degrees_t latitude, degrees_t longitude);
+};
+
class GeoReferencingOptionsModel : public QStringListModel {
Q_OBJECT
public: