diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2015-11-13 11:55:39 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-11-13 11:57:02 -0800 |
commit | fb06d2759311c04c78716be4325e4bc4fb3f04e3 (patch) | |
tree | d44170fed9c81001f3b282f25287c4025e9004e0 /qt-mobile | |
parent | 6a70793ba843549bd8e1921a91a3af0e10702405 (diff) | |
download | subsurface-fb06d2759311c04c78716be4325e4bc4fb3f04e3.tar.gz |
Location service: make persistant storage work correctly
Ouch that's an embarrassing bug. Oh well. Shift happens.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-mobile')
-rw-r--r-- | qt-mobile/gpslocation.cpp | 32 | ||||
-rw-r--r-- | qt-mobile/gpslocation.h | 2 |
2 files changed, 17 insertions, 17 deletions
diff --git a/qt-mobile/gpslocation.cpp b/qt-mobile/gpslocation.cpp index 35654b7ff..97602356f 100644 --- a/qt-mobile/gpslocation.cpp +++ b/qt-mobile/gpslocation.cpp @@ -10,8 +10,8 @@ GpsLocation::GpsLocation(QObject *parent) { // create a QSettings object that's separate from the main application settings - QSettings *geoSettings = new QSettings(QSettings::NativeFormat, QSettings::UserScope, - QString("org.subsurfacedivelog"), QString("subsurfacelocation"), this); + geoSettings = new QSettings(QSettings::NativeFormat, QSettings::UserScope, + QString("org.subsurfacedivelog"), QString("subsurfacelocation"), this); gpsSource = QGeoPositionInfoSource::createDefaultSource(parent); if (gpsSource != 0) { QString msg = QString("have position source %1").arg(gpsSource->sourceName()); @@ -47,19 +47,19 @@ void GpsLocation::newPosition(QGeoPositionInfo pos) QGeoCoordinate lastCoord; QString msg("received new position %1"); status(qPrintable(msg.arg(pos.coordinate().toString()))); - int nr = geoSettings.value("count", 0).toInt(); + int nr = geoSettings->value("count", 0).toInt(); if (nr) { - lastCoord.setLatitude(geoSettings.value(QString("gpsFix%1_lat").arg(nr)).toInt() / 1000000.0); - lastCoord.setLongitude(geoSettings.value(QString("gpsFix%1_lon").arg(nr)).toInt() / 1000000.0); - time_t lastTime = geoSettings.value(QString("gpsFix%1_time").arg(nr)).toULongLong(); + lastCoord.setLatitude(geoSettings->value(QString("gpsFix%1_lat").arg(nr)).toInt() / 1000000.0); + lastCoord.setLongitude(geoSettings->value(QString("gpsFix%1_lon").arg(nr)).toInt() / 1000000.0); + time_t lastTime = geoSettings->value(QString("gpsFix%1_time").arg(nr)).toULongLong(); } // if we have no record stored or if at least 10 minutes have passed or we moved at least 200m if (!nr || pos.timestamp().toTime_t() > lastTime + MINTIME || lastCoord.distanceTo(pos.coordinate()) > MINDIST) { - geoSettings.setValue("count", nr + 1); - geoSettings.setValue(QString("gpsFix%1_time").arg(nr), pos.timestamp().toTime_t()); - geoSettings.setValue(QString("gpsFix%1_lat").arg(nr), rint(pos.coordinate().latitude() * 1000000)); - geoSettings.setValue(QString("gpsFix%1_lon").arg(nr), rint(pos.coordinate().longitude() * 1000000)); - geoSettings.sync(); + geoSettings->setValue("count", nr + 1); + geoSettings->setValue(QString("gpsFix%1_time").arg(nr), pos.timestamp().toTime_t()); + geoSettings->setValue(QString("gpsFix%1_lat").arg(nr), rint(pos.coordinate().latitude() * 1000000)); + geoSettings->setValue(QString("gpsFix%1_lon").arg(nr), rint(pos.coordinate().longitude() * 1000000)); + geoSettings->sync(); } } @@ -76,7 +76,7 @@ void GpsLocation::status(QString msg) int GpsLocation::getGpsNum() const { - return geoSettings.value("count", 0).toInt(); + return geoSettings->value("count", 0).toInt(); } struct gpsTracker { @@ -98,16 +98,16 @@ bool GpsLocation::applyLocations() int i; bool changed = false; int last = 0; - int cnt = geoSettings.value("count", 0).toInt(); + int cnt = geoSettings->value("count", 0).toInt(); if (cnt == 0) return false; // create a table with the GPS information struct gpsTracker *gpsTable = (struct gpsTracker *)calloc(cnt, sizeof(struct gpsTracker)); for (int i = 0; i < cnt; i++) { - gpsTable[i].latitude.udeg = geoSettings.value(QString("gpsFix%1_lat").arg(i)).toInt(); - gpsTable[i].longitude.udeg = geoSettings.value(QString("gpsFix%1_lon").arg(i)).toInt(); - gpsTable[i].when = geoSettings.value(QString("gpsFix%1_time").arg(i)).toULongLong(); + gpsTable[i].latitude.udeg = geoSettings->value(QString("gpsFix%1_lat").arg(i)).toInt(); + gpsTable[i].longitude.udeg = geoSettings->value(QString("gpsFix%1_lon").arg(i)).toInt(); + gpsTable[i].when = geoSettings->value(QString("gpsFix%1_time").arg(i)).toULongLong(); } // now walk the dive table and see if we can fill in missing gps data diff --git a/qt-mobile/gpslocation.h b/qt-mobile/gpslocation.h index 044420d08..a279593d5 100644 --- a/qt-mobile/gpslocation.h +++ b/qt-mobile/gpslocation.h @@ -20,7 +20,7 @@ private: QGeoPositionInfo lastPos; QGeoPositionInfoSource *gpsSource; void status(QString msg); - QSettings geoSettings; + QSettings *geoSettings; signals: |