mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
6a70793ba8
commit
fb06d27593
2 changed files with 17 additions and 17 deletions
|
@ -10,8 +10,8 @@
|
||||||
GpsLocation::GpsLocation(QObject *parent)
|
GpsLocation::GpsLocation(QObject *parent)
|
||||||
{
|
{
|
||||||
// create a QSettings object that's separate from the main application settings
|
// create a QSettings object that's separate from the main application settings
|
||||||
QSettings *geoSettings = new QSettings(QSettings::NativeFormat, QSettings::UserScope,
|
geoSettings = new QSettings(QSettings::NativeFormat, QSettings::UserScope,
|
||||||
QString("org.subsurfacedivelog"), QString("subsurfacelocation"), this);
|
QString("org.subsurfacedivelog"), QString("subsurfacelocation"), this);
|
||||||
gpsSource = QGeoPositionInfoSource::createDefaultSource(parent);
|
gpsSource = QGeoPositionInfoSource::createDefaultSource(parent);
|
||||||
if (gpsSource != 0) {
|
if (gpsSource != 0) {
|
||||||
QString msg = QString("have position source %1").arg(gpsSource->sourceName());
|
QString msg = QString("have position source %1").arg(gpsSource->sourceName());
|
||||||
|
@ -47,19 +47,19 @@ void GpsLocation::newPosition(QGeoPositionInfo pos)
|
||||||
QGeoCoordinate lastCoord;
|
QGeoCoordinate lastCoord;
|
||||||
QString msg("received new position %1");
|
QString msg("received new position %1");
|
||||||
status(qPrintable(msg.arg(pos.coordinate().toString())));
|
status(qPrintable(msg.arg(pos.coordinate().toString())));
|
||||||
int nr = geoSettings.value("count", 0).toInt();
|
int nr = geoSettings->value("count", 0).toInt();
|
||||||
if (nr) {
|
if (nr) {
|
||||||
lastCoord.setLatitude(geoSettings.value(QString("gpsFix%1_lat").arg(nr)).toInt() / 1000000.0);
|
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);
|
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();
|
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 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) {
|
if (!nr || pos.timestamp().toTime_t() > lastTime + MINTIME || lastCoord.distanceTo(pos.coordinate()) > MINDIST) {
|
||||||
geoSettings.setValue("count", nr + 1);
|
geoSettings->setValue("count", nr + 1);
|
||||||
geoSettings.setValue(QString("gpsFix%1_time").arg(nr), pos.timestamp().toTime_t());
|
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_lat").arg(nr), rint(pos.coordinate().latitude() * 1000000));
|
||||||
geoSettings.setValue(QString("gpsFix%1_lon").arg(nr), rint(pos.coordinate().longitude() * 1000000));
|
geoSettings->setValue(QString("gpsFix%1_lon").arg(nr), rint(pos.coordinate().longitude() * 1000000));
|
||||||
geoSettings.sync();
|
geoSettings->sync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ void GpsLocation::status(QString msg)
|
||||||
|
|
||||||
int GpsLocation::getGpsNum() const
|
int GpsLocation::getGpsNum() const
|
||||||
{
|
{
|
||||||
return geoSettings.value("count", 0).toInt();
|
return geoSettings->value("count", 0).toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct gpsTracker {
|
struct gpsTracker {
|
||||||
|
@ -98,16 +98,16 @@ bool GpsLocation::applyLocations()
|
||||||
int i;
|
int i;
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
int last = 0;
|
int last = 0;
|
||||||
int cnt = geoSettings.value("count", 0).toInt();
|
int cnt = geoSettings->value("count", 0).toInt();
|
||||||
if (cnt == 0)
|
if (cnt == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// create a table with the GPS information
|
// create a table with the GPS information
|
||||||
struct gpsTracker *gpsTable = (struct gpsTracker *)calloc(cnt, sizeof(struct gpsTracker));
|
struct gpsTracker *gpsTable = (struct gpsTracker *)calloc(cnt, sizeof(struct gpsTracker));
|
||||||
for (int i = 0; i < cnt; i++) {
|
for (int i = 0; i < cnt; i++) {
|
||||||
gpsTable[i].latitude.udeg = geoSettings.value(QString("gpsFix%1_lat").arg(i)).toInt();
|
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].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].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
|
// now walk the dive table and see if we can fill in missing gps data
|
||||||
|
|
|
@ -20,7 +20,7 @@ private:
|
||||||
QGeoPositionInfo lastPos;
|
QGeoPositionInfo lastPos;
|
||||||
QGeoPositionInfoSource *gpsSource;
|
QGeoPositionInfoSource *gpsSource;
|
||||||
void status(QString msg);
|
void status(QString msg);
|
||||||
QSettings geoSettings;
|
QSettings *geoSettings;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue