diff options
author | Salvador Cuñat <salvador.cunat@gmail.com> | 2017-12-02 11:28:00 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-12-10 11:38:19 -0800 |
commit | 2182167b533b4c71dc64747d4d761cd780cfbde2 (patch) | |
tree | b870cbd93b38751534d5923d45272a290fc83a86 /desktop-widgets | |
parent | 6f42ab46da1b5956ad15859c1c2f5829e1af2013 (diff) | |
download | subsurface-2182167b533b4c71dc64747d4d761cd780cfbde2.tar.gz |
applying gps fixes: group repetitive code under a macro
Title is self explanatory.
[Dirk Hohndel: small edits to remove typo / improve readability]
Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'desktop-widgets')
-rw-r--r-- | desktop-widgets/subsurfacewebservices.cpp | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/desktop-widgets/subsurfacewebservices.cpp b/desktop-widgets/subsurfacewebservices.cpp index 0537723b8..b11a910f1 100644 --- a/desktop-widgets/subsurfacewebservices.cpp +++ b/desktop-widgets/subsurfacewebservices.cpp @@ -55,6 +55,13 @@ static void copy_gps_location(struct dive *from, struct dive *to) } #define SAME_GROUP 6 * 3600 // six hours +#define SET_LOCATION(_dive, _gpsfix, _mark) \ +{ \ + copy_gps_location(_gpsfix, _dive); \ + changed ++; \ + tracer = _mark; \ +} + //TODO: C Code. static functions are not good if we plan to have a test for them. static bool merge_locations_into_dives(void) { @@ -79,9 +86,7 @@ static bool merge_locations_into_dives(void) if (time_during_dive_with_offset(dive, gpsfix->when, 0)) { if (verbose) qDebug() << "gpsfix is during the dive, pick that one"; - copy_gps_location(gpsfix, dive); - changed++; - tracer = j; + SET_LOCATION(dive, gpsfix, j); break; } else { /* @@ -101,25 +106,19 @@ static bool merge_locations_into_dives(void) } else if (gpsfix->when > dive_endtime(dive)) { if (verbose) qDebug() << "which is even later after the end of the dive, so pick the previous one"; - copy_gps_location(gpsfix, dive); - changed++; - tracer = j; + SET_LOCATION(dive, gpsfix, j); break; } else { /* ok, gpsfix is before, nextgpsfix is after */ if (dive->when - gpsfix->when <= nextgpsfix->when - dive_endtime(dive)) { if (verbose) qDebug() << "pick the one before as it's closer to the start"; - copy_gps_location(gpsfix, dive); - changed++; - tracer = j; + SET_LOCATION(dive, gpsfix, j); break; } else { if (verbose) qDebug() << "pick the one after as it's closer to the start"; - copy_gps_location(nextgpsfix, dive); - changed++; - tracer = j + 1; + SET_LOCATION(dive, nextgpsfix, j + 1); break; } } @@ -129,9 +128,7 @@ static bool merge_locations_into_dives(void) } else { if (verbose) qDebug() << "which seems to be the best one for this dive, so pick it"; - copy_gps_location(gpsfix, dive); - changed++; - tracer = j; + SET_LOCATION(dive, gpsfix, j); break; } } |