mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 21:53:23 +00:00
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>
This commit is contained in:
parent
ca911e6916
commit
8f043138ba
2 changed files with 29 additions and 24 deletions
|
@ -211,34 +211,23 @@ int GpsLocation::getGpsNum() const
|
||||||
return m_trackers.count();
|
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 SAME_GROUP 6 * 3600 /* six hours */
|
||||||
#define SET_LOCATION(_dive, _gpsfix, _mark) \
|
#define ADD_LOCATION(_dive, _gpsfix, _mark) \
|
||||||
{ \
|
{ \
|
||||||
copy_gps_location(_gpsfix, _dive); \
|
fixes.push_back( { _dive, _gpsfix.location, _gpsfix.name } ); \
|
||||||
invalidate_dive_cache(_dive); \
|
last = _mark; \
|
||||||
changed++; \
|
|
||||||
last = _mark; \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int GpsLocation::applyLocations()
|
int GpsLocation::applyLocations()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int changed = 0;
|
|
||||||
int last = 0;
|
int last = 0;
|
||||||
int cnt = m_trackers.count();
|
int cnt = m_trackers.count();
|
||||||
if (cnt == 0)
|
if (cnt == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
std::vector<DiveAndLocation> fixes;
|
||||||
|
|
||||||
// create a table with the GPS information
|
// create a table with the GPS information
|
||||||
QList<struct gpsTracker> gpsTable = m_trackers.values();
|
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 (time_during_dive_with_offset(d, gpsTable[j].when, 0)) {
|
||||||
if (verbose)
|
if (verbose)
|
||||||
qDebug() << "gpsFix is during the dive, pick that one";
|
qDebug() << "gpsFix is during the dive, pick that one";
|
||||||
SET_LOCATION(d, gpsTable[j], j);
|
ADD_LOCATION(d, gpsTable[j], j);
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
|
@ -280,19 +269,19 @@ int GpsLocation::applyLocations()
|
||||||
} else if (gpsTable[j].when > dive_endtime(d)) {
|
} else if (gpsTable[j].when > dive_endtime(d)) {
|
||||||
if (verbose)
|
if (verbose)
|
||||||
qDebug() << "which is even later after the end of the dive, so pick the previous one";
|
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;
|
break;
|
||||||
} else {
|
} else {
|
||||||
/* ok, gpsFix is before, nextgpsFix is after */
|
/* ok, gpsFix is before, nextgpsFix is after */
|
||||||
if (d->when - gpsTable[j].when <= gpsTable[j+1].when - dive_endtime(d)) {
|
if (d->when - gpsTable[j].when <= gpsTable[j+1].when - dive_endtime(d)) {
|
||||||
if (verbose)
|
if (verbose)
|
||||||
qDebug() << "pick the one before as it's closer to the start";
|
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;
|
break;
|
||||||
} else {
|
} else {
|
||||||
if (verbose)
|
if (verbose)
|
||||||
qDebug() << "pick the one after as it's closer to the start";
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -302,7 +291,7 @@ int GpsLocation::applyLocations()
|
||||||
} else {
|
} else {
|
||||||
if (verbose)
|
if (verbose)
|
||||||
qDebug() << "which seems to be the best one for this dive, so pick it";
|
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;
|
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);
|
mark_divelist_changed(true);
|
||||||
return changed;
|
return !fixes.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<qint64, gpsTracker> GpsLocation::currentGPSInfo() const
|
QMap<qint64, gpsTracker> GpsLocation::currentGPSInfo() const
|
||||||
|
|
|
@ -20,6 +20,12 @@ struct gpsTracker {
|
||||||
int idx;
|
int idx;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct DiveAndLocation {
|
||||||
|
struct dive *d;
|
||||||
|
location_t location;
|
||||||
|
QString name;
|
||||||
|
};
|
||||||
|
|
||||||
class GpsLocation : public QObject {
|
class GpsLocation : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Add table
Reference in a new issue