diff options
-rw-r--r-- | qt-mobile/qml/GpsList.qml | 1 | ||||
-rw-r--r-- | qt-mobile/qmlmanager.cpp | 7 | ||||
-rw-r--r-- | qt-mobile/qmlmanager.h | 1 | ||||
-rw-r--r-- | subsurface-core/gpslocation.cpp | 39 | ||||
-rw-r--r-- | subsurface-core/gpslocation.h | 4 |
5 files changed, 50 insertions, 2 deletions
diff --git a/qt-mobile/qml/GpsList.qml b/qt-mobile/qml/GpsList.qml index 1e3242e6d..0ee654fc1 100644 --- a/qt-mobile/qml/GpsList.qml +++ b/qt-mobile/qml/GpsList.qml @@ -91,6 +91,7 @@ MobileComponents.Page { iconName: "trash-empty" onTriggered: { print("delete this!") + manager.deleteGpsFix(when) } }, Action { diff --git a/qt-mobile/qmlmanager.cpp b/qt-mobile/qmlmanager.cpp index 1d68dc3a7..df20de11d 100644 --- a/qt-mobile/qmlmanager.cpp +++ b/qt-mobile/qmlmanager.cpp @@ -528,6 +528,13 @@ void QMLManager::clearGpsData() populateGpsData(); } +void QMLManager::deleteGpsFix(quint64 when) +{ + locationProvider->deleteGpsFix(when); + populateGpsData(); +} + + QString QMLManager::logText() const { QString logText = m_logText + QString("\nNumer of GPS fixes: %1").arg(locationProvider->getGpsNum()); diff --git a/qt-mobile/qmlmanager.h b/qt-mobile/qmlmanager.h index ebc33abf9..05dae9925 100644 --- a/qt-mobile/qmlmanager.h +++ b/qt-mobile/qmlmanager.h @@ -85,6 +85,7 @@ public slots: QString getNumber(QString diveId); QString getDate(QString diveId); QString getCurrentPosition(); + void deleteGpsFix(quint64 when); private: QString m_cloudUserName; 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 |