aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-11-16 15:04:36 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-03-09 12:41:57 -0700
commit8f043138ba34946b477e615a6506067b8cb93c77 (patch)
tree833a6e9fce1abb8430232d00b2120d2b1fb934e2 /core
parentca911e6916a5598c7558cabc2f695fceee3d5143 (diff)
downloadsubsurface-8f043138ba34946b477e615a6506067b8cb93c77.tar.gz
GPS fixes: collect fixes first, apply later
Make the application of the GPS fixes in two runs: first collect dives and fixes, then apply the fixes. This will simplify turning the application of GPS fixes into an undo-command. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core')
-rw-r--r--core/gpslocation.cpp47
-rw-r--r--core/gpslocation.h6
2 files changed, 29 insertions, 24 deletions
diff --git a/core/gpslocation.cpp b/core/gpslocation.cpp
index 257764a05..da96928ea 100644
--- a/core/gpslocation.cpp
+++ b/core/gpslocation.cpp
@@ -211,34 +211,23 @@ int GpsLocation::getGpsNum() const
return m_trackers.count();
}
-static void copy_gps_location(struct gpsTracker &gps, struct dive *d)
-{
- struct dive_site *ds = d->dive_site;
- if (!ds) {
- ds = create_dive_site(qPrintable(gps.name), &dive_site_table);
- add_dive_to_dive_site(d, ds);
- }
- ds->location = gps.location;
-}
-
#define SAME_GROUP 6 * 3600 /* six hours */
-#define SET_LOCATION(_dive, _gpsfix, _mark) \
-{ \
- copy_gps_location(_gpsfix, _dive); \
- invalidate_dive_cache(_dive); \
- changed++; \
- last = _mark; \
+#define ADD_LOCATION(_dive, _gpsfix, _mark) \
+{ \
+ fixes.push_back( { _dive, _gpsfix.location, _gpsfix.name } ); \
+ last = _mark; \
}
int GpsLocation::applyLocations()
{
int i;
- int changed = 0;
int last = 0;
int cnt = m_trackers.count();
if (cnt == 0)
return false;
+ std::vector<DiveAndLocation> fixes;
+
// create a table with the GPS information
QList<struct gpsTracker> gpsTable = m_trackers.values();
@@ -261,7 +250,7 @@ int GpsLocation::applyLocations()
if (time_during_dive_with_offset(d, gpsTable[j].when, 0)) {
if (verbose)
qDebug() << "gpsFix is during the dive, pick that one";
- SET_LOCATION(d, gpsTable[j], j);
+ ADD_LOCATION(d, gpsTable[j], j);
break;
} else {
/*
@@ -280,19 +269,19 @@ int GpsLocation::applyLocations()
} else if (gpsTable[j].when > dive_endtime(d)) {
if (verbose)
qDebug() << "which is even later after the end of the dive, so pick the previous one";
- SET_LOCATION(d, gpsTable[j], j);
+ ADD_LOCATION(d, gpsTable[j], j);
break;
} else {
/* ok, gpsFix is before, nextgpsFix is after */
if (d->when - gpsTable[j].when <= gpsTable[j+1].when - dive_endtime(d)) {
if (verbose)
qDebug() << "pick the one before as it's closer to the start";
- SET_LOCATION(d, gpsTable[j], j);
+ ADD_LOCATION(d, gpsTable[j], j);
break;
} else {
if (verbose)
qDebug() << "pick the one after as it's closer to the start";
- SET_LOCATION(d, gpsTable[j + 1], j + 1);
+ ADD_LOCATION(d, gpsTable[j + 1], j + 1);
break;
}
}
@@ -302,7 +291,7 @@ int GpsLocation::applyLocations()
} else {
if (verbose)
qDebug() << "which seems to be the best one for this dive, so pick it";
- SET_LOCATION(d, gpsTable[j], j);
+ ADD_LOCATION(d, gpsTable[j], j);
break;
}
}
@@ -318,9 +307,19 @@ int GpsLocation::applyLocations()
}
}
- if (changed > 0)
+
+ for (DiveAndLocation &dl: fixes) {
+ struct dive_site *ds = dl.d->dive_site;
+ if (!ds) {
+ ds = create_dive_site(qPrintable(dl.name), &dive_site_table);
+ add_dive_to_dive_site(dl.d, ds);
+ invalidate_dive_cache(dl.d);
+ }
+ ds->location = dl.location;
+ }
+ if (!fixes.empty())
mark_divelist_changed(true);
- return changed;
+ return !fixes.empty();
}
QMap<qint64, gpsTracker> GpsLocation::currentGPSInfo() const
diff --git a/core/gpslocation.h b/core/gpslocation.h
index 0a333947b..88fdb813c 100644
--- a/core/gpslocation.h
+++ b/core/gpslocation.h
@@ -20,6 +20,12 @@ struct gpsTracker {
int idx;
};
+struct DiveAndLocation {
+ struct dive *d;
+ location_t location;
+ QString name;
+};
+
class GpsLocation : public QObject {
Q_OBJECT
public: