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>
This commit is contained in:
Dirk Hohndel 2016-01-08 23:18:41 -08:00
parent 038cfcba91
commit b1f90b6aa0
5 changed files with 50 additions and 2 deletions

View file

@ -91,6 +91,7 @@ MobileComponents.Page {
iconName: "trash-empty" iconName: "trash-empty"
onTriggered: { onTriggered: {
print("delete this!") print("delete this!")
manager.deleteGpsFix(when)
} }
}, },
Action { Action {

View file

@ -528,6 +528,13 @@ void QMLManager::clearGpsData()
populateGpsData(); populateGpsData();
} }
void QMLManager::deleteGpsFix(quint64 when)
{
locationProvider->deleteGpsFix(when);
populateGpsData();
}
QString QMLManager::logText() const QString QMLManager::logText() const
{ {
QString logText = m_logText + QString("\nNumer of GPS fixes: %1").arg(locationProvider->getGpsNum()); QString logText = m_logText + QString("\nNumer of GPS fixes: %1").arg(locationProvider->getGpsNum());

View file

@ -85,6 +85,7 @@ public slots:
QString getNumber(QString diveId); QString getNumber(QString diveId);
QString getDate(QString diveId); QString getDate(QString diveId);
QString getCurrentPosition(); QString getCurrentPosition();
void deleteGpsFix(quint64 when);
private: private:
QString m_cloudUserName; QString m_cloudUserName;

View file

@ -327,6 +327,11 @@ void GpsLocation::applyLocations()
mark_divelist_changed(true); 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 > GpsLocation::currentGPSInfo() const
{ {
QVector<gpsTracker> trackers; QVector<gpsTracker> trackers;
@ -348,9 +353,43 @@ QVector< gpsTracker > GpsLocation::currentGPSInfo() const
gt.name = geoSettings->value(QString("gpsFix%1_name").arg(i)).toString(); gt.name = geoSettings->value(QString("gpsFix%1_name").arg(i)).toString();
trackers.append(gt); trackers.append(gt);
} }
std::sort(trackers.begin(), trackers.end(), timeCompare);
return trackers; 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() void GpsLocation::clearGpsData()
{ {
geoSettings->clear(); geoSettings->clear();

View file

@ -12,7 +12,7 @@
struct gpsTracker { struct gpsTracker {
degrees_t latitude; degrees_t latitude;
degrees_t longitude; degrees_t longitude;
time_t when; quint64 when;
QString name; QString name;
}; };
@ -52,7 +52,7 @@ public slots:
void postError(QNetworkReply::NetworkError error); void postError(QNetworkReply::NetworkError error);
void getUseridError(QNetworkReply::NetworkError error); void getUseridError(QNetworkReply::NetworkError error);
void clearGpsData(); void clearGpsData();
void deleteGpsFix(quint64 when);
}; };
#endif // GPSLOCATION_H #endif // GPSLOCATION_H