summaryrefslogtreecommitdiffstats
path: root/subsurface-core/gpslocation.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2016-01-08 23:18:41 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2016-01-08 23:18:41 -0800
commitb1f90b6aa0171cc5a5b7b5ff2f8dbc6236e23c4e (patch)
treef75d68234e4de76fcd8deaf9172f6516dbc951b0 /subsurface-core/gpslocation.cpp
parent038cfcba911f2ae0e22ef6138042a6154578723c (diff)
downloadsubsurface-b1f90b6aa0171cc5a5b7b5ff2f8dbc6236e23c4e.tar.gz
QML UI: partial, slow and incomplete implementation of delete GPS fix
This only deletes the fix on the mobile device, not on the server. And it is really really slow. Re-reading the data from the settings just isn't a smart way to do this. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'subsurface-core/gpslocation.cpp')
-rw-r--r--subsurface-core/gpslocation.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/subsurface-core/gpslocation.cpp b/subsurface-core/gpslocation.cpp
index 79fb9a088..f174c575b 100644
--- a/subsurface-core/gpslocation.cpp
+++ b/subsurface-core/gpslocation.cpp
@@ -327,6 +327,11 @@ void GpsLocation::applyLocations()
mark_divelist_changed(true);
}
+static int timeCompare(const gpsTracker &a, const gpsTracker &b)
+{
+ return a.when <= b.when;
+}
+
QVector< gpsTracker > GpsLocation::currentGPSInfo() const
{
QVector<gpsTracker> trackers;
@@ -348,9 +353,43 @@ QVector< gpsTracker > GpsLocation::currentGPSInfo() const
gt.name = geoSettings->value(QString("gpsFix%1_name").arg(i)).toString();
trackers.append(gt);
}
+ std::sort(trackers.begin(), trackers.end(), timeCompare);
return trackers;
}
+void GpsLocation::deleteGpsFix(quint64 when)
+{
+ int cnt = geoSettings->value("count", 0).toInt();
+ if (cnt == 0) {
+ qDebug() << "no gps fixes";
+ return;
+ }
+ bool found = false;
+ int i;
+ struct gpsTracker gt;
+ for (i = 0; i < cnt; i++) {
+ if (geoSettings->value(QString("gpsFix%1_time").arg(i)).toULongLong() == when) {
+ if (i < cnt - 1) {
+ geoSettings->setValue(QString("gpsFix%1_lat").arg(i), geoSettings->value(QString("gpsFix%1_lat").arg(cnt - 1)));
+ geoSettings->setValue(QString("gpsFix%1_lon").arg(i), geoSettings->value(QString("gpsFix%1_lon").arg(cnt - 1)));
+ geoSettings->setValue(QString("gpsFix%1_time").arg(i), geoSettings->value(QString("gpsFix%1_time").arg(cnt - 1)));
+ geoSettings->setValue(QString("gpsFix%1_name").arg(i), geoSettings->value(QString("gpsFix%1_name").arg(cnt - 1)));
+ }
+ found = true;
+ break;
+ }
+ }
+ if (found) {
+ geoSettings->remove(QString("gpsFix%1_lat").arg(cnt - 1));
+ geoSettings->remove(QString("gpsFix%1_lon").arg(cnt - 1));
+ geoSettings->remove(QString("gpsFix%1_time").arg(cnt - 1));
+ geoSettings->remove(QString("gpsFix%1_name").arg(cnt - 1));
+ cnt--;
+ geoSettings->setValue("count", cnt);
+ }
+ qDebug() << "found" << found << "at position" << i << "of" << cnt + 1;
+}
+
void GpsLocation::clearGpsData()
{
geoSettings->clear();