diff options
Diffstat (limited to 'subsurface-core')
-rw-r--r-- | subsurface-core/gpslocation.cpp | 39 | ||||
-rw-r--r-- | subsurface-core/gpslocation.h | 4 |
2 files changed, 41 insertions, 2 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(); diff --git a/subsurface-core/gpslocation.h b/subsurface-core/gpslocation.h index 4193be561..0c722a5f4 100644 --- a/subsurface-core/gpslocation.h +++ b/subsurface-core/gpslocation.h @@ -12,7 +12,7 @@ struct gpsTracker { degrees_t latitude; degrees_t longitude; - time_t when; + quint64 when; QString name; }; @@ -52,7 +52,7 @@ public slots: void postError(QNetworkReply::NetworkError error); void getUseridError(QNetworkReply::NetworkError error); void clearGpsData(); - + void deleteGpsFix(quint64 when); }; #endif // GPSLOCATION_H |