diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2018-10-20 14:12:15 -0400 |
---|---|---|
committer | Lubomir I. Ivanov <neolit123@gmail.com> | 2018-10-21 19:55:09 +0300 |
commit | 28e3413ff66552f392fecee25068d634cdfe59fc (patch) | |
tree | 5fe303d1e7dc1c371e13b534b85c232e29aea884 /core/gpslocation.cpp | |
parent | c9869406301ff72f76b399097f0845fc1102ced1 (diff) | |
download | subsurface-28e3413ff66552f392fecee25068d634cdfe59fc.tar.gz |
Add 'location_t' data structure
Instead of having people treat latitude and longitude as separate
things, just add a 'location_t' data structure that contains both.
Almost all cases want to always act on them together.
This is really just prep-work for adding a few more locations that we
track: I want to add a entry/exit location to each dive (independent of
the dive site) because of how the Garmin Descent gives us the
information (and hopefully, some day, other dive computers too).
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'core/gpslocation.cpp')
-rw-r--r-- | core/gpslocation.cpp | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/core/gpslocation.cpp b/core/gpslocation.cpp index 54015837b..485cbac56 100644 --- a/core/gpslocation.cpp +++ b/core/gpslocation.cpp @@ -137,7 +137,7 @@ QString GpsLocation::currentPosition() if (delta < 300) { // we can simply use the last position that we tracked gpsTracker gt = m_trackers.last(); - QString gpsString = printGPSCoords(gt.latitude.udeg, gt.longitude.udeg); + QString gpsString = printGPSCoords(>.location); qDebug() << "returning last position" << gpsString; return gpsString; } else { @@ -159,8 +159,8 @@ void GpsLocation::newPosition(QGeoPositionInfo pos) int nr = m_trackers.count(); if (nr) { gpsTracker gt = m_trackers.last(); - lastCoord.setLatitude(gt.latitude.udeg / 1000000.0); - lastCoord.setLongitude(gt.longitude.udeg / 1000000.0); + lastCoord.setLatitude(gt.location.lat.udeg / 1000000.0); + lastCoord.setLongitude(gt.location.lon.udeg / 1000000.0); lastTime = gt.when; } // if we are waiting for a position update or @@ -176,8 +176,7 @@ void GpsLocation::newPosition(QGeoPositionInfo pos) gpsTracker gt; gt.when = pos.timestamp().toTime_t(); gt.when += gettimezoneoffset(gt.when); - gt.latitude.udeg = lrint(pos.coordinate().latitude() * 1000000); - gt.longitude.udeg = lrint(pos.coordinate().longitude() * 1000000); + gt.location = create_location(pos.coordinate().latitude(), pos.coordinate().longitude()); addFixToStorage(gt); gpsTracker gtNew = m_trackers.last(); qDebug() << "newest fix is now at" << QDateTime().fromMSecsSinceEpoch(gtNew.when - gettimezoneoffset(gtNew.when) * 1000).toString(); @@ -215,8 +214,7 @@ static void copy_gps_location(struct gpsTracker &gps, struct dive *d) d->dive_site_uuid = create_dive_site(qPrintable(gps.name), gps.when); ds = get_dive_site_by_uuid(d->dive_site_uuid); } - ds->latitude = gps.latitude; - ds->longitude = gps.longitude; + ds->location = gps.location; } #define SAME_GROUP 6 * 3600 /* six hours */ @@ -331,8 +329,8 @@ void GpsLocation::loadFromStorage() for (int i = 0; i < nr; i++) { struct gpsTracker gt; gt.when = geoSettings->value(QString("gpsFix%1_time").arg(i)).toLongLong(); - gt.latitude.udeg = geoSettings->value(QString("gpsFix%1_lat").arg(i)).toInt(); - gt.longitude.udeg = geoSettings->value(QString("gpsFix%1_lon").arg(i)).toInt(); + gt.location.lat.udeg = geoSettings->value(QString("gpsFix%1_lat").arg(i)).toInt(); + gt.location.lon.udeg = geoSettings->value(QString("gpsFix%1_lon").arg(i)).toInt(); gt.name = geoSettings->value(QString("gpsFix%1_name").arg(i)).toString(); gt.idx = i; m_trackers.insert(gt.when, gt); @@ -347,11 +345,10 @@ void GpsLocation::replaceFixToStorage(gpsTracker >) } gpsTracker replacedTracker = m_trackers.value(gt.when); geoSettings->setValue(QString("gpsFix%1_time").arg(replacedTracker.idx), gt.when); - geoSettings->setValue(QString("gpsFix%1_lat").arg(replacedTracker.idx), gt.latitude.udeg); - geoSettings->setValue(QString("gpsFix%1_lon").arg(replacedTracker.idx), gt.longitude.udeg); + geoSettings->setValue(QString("gpsFix%1_lat").arg(replacedTracker.idx), gt.location.lat.udeg); + geoSettings->setValue(QString("gpsFix%1_lon").arg(replacedTracker.idx), gt.location.lon.udeg); geoSettings->setValue(QString("gpsFix%1_name").arg(replacedTracker.idx), gt.name); - replacedTracker.latitude = gt.latitude; - replacedTracker.longitude = gt.longitude; + replacedTracker.location = gt.location; replacedTracker.name = gt.name; } @@ -360,8 +357,8 @@ void GpsLocation::addFixToStorage(gpsTracker >) int nr = m_trackers.count(); geoSettings->setValue("count", nr + 1); geoSettings->setValue(QString("gpsFix%1_time").arg(nr), gt.when); - geoSettings->setValue(QString("gpsFix%1_lat").arg(nr), gt.latitude.udeg); - geoSettings->setValue(QString("gpsFix%1_lon").arg(nr), gt.longitude.udeg); + geoSettings->setValue(QString("gpsFix%1_lat").arg(nr), gt.location.lat.udeg); + geoSettings->setValue(QString("gpsFix%1_lon").arg(nr), gt.location.lon.udeg); geoSettings->setValue(QString("gpsFix%1_name").arg(nr), gt.name); gt.idx = nr; geoSettings->sync(); @@ -389,8 +386,8 @@ void GpsLocation::deleteFixFromStorage(gpsTracker >) m_trackers.remove(movedTracker.when); m_trackers.insert(movedTracker.when, movedTracker); geoSettings->setValue(QString("gpsFix%1_time").arg(movedTracker.idx), when); - geoSettings->setValue(QString("gpsFix%1_lat").arg(movedTracker.idx), movedTracker.latitude.udeg); - geoSettings->setValue(QString("gpsFix%1_lon").arg(movedTracker.idx), movedTracker.longitude.udeg); + geoSettings->setValue(QString("gpsFix%1_lat").arg(movedTracker.idx), movedTracker.location.lat.udeg); + geoSettings->setValue(QString("gpsFix%1_lon").arg(movedTracker.idx), movedTracker.location.lon.udeg); geoSettings->setValue(QString("gpsFix%1_name").arg(movedTracker.idx), movedTracker.name); geoSettings->remove(QString("gpsFix%1_lat").arg(cnt - 1)); geoSettings->remove(QString("gpsFix%1_lon").arg(cnt - 1)); |