diff --git a/commands/command_divesite.cpp b/commands/command_divesite.cpp index 1188e9f81..45eb29e3a 100644 --- a/commands/command_divesite.cpp +++ b/commands/command_divesite.cpp @@ -281,7 +281,7 @@ bool EditDiveSiteLocation::workToBeDone() bool old_ok = has_location(&ds->location); if (ok != old_ok) return true; - return ok && !same_location(&value, &ds->location); + return ok && value != ds->location; } void EditDiveSiteLocation::redo() diff --git a/core/divesite.cpp b/core/divesite.cpp index 2b2a5b448..a767d6e5c 100644 --- a/core/divesite.cpp +++ b/core/divesite.cpp @@ -57,7 +57,7 @@ struct dive_site *get_dive_site_by_gps(const location_t *loc, struct dive_site_t int i; struct dive_site *ds; for_each_dive_site (i, ds, ds_table) { - if (same_location(loc, &ds->location)) + if (*loc == ds->location) return ds; } return NULL; @@ -71,7 +71,7 @@ struct dive_site *get_dive_site_by_gps_and_name(const std::string &name, const l int i; struct dive_site *ds; for_each_dive_site (i, ds, ds_table) { - if (same_location(loc, &ds->location) && ds->name == name) + if (*loc == ds->location && ds->name == name) return ds; } return NULL; @@ -273,7 +273,7 @@ static void merge_string(std::string &a, const std::string &b) static bool same_dive_site(const struct dive_site *a, const struct dive_site *b) { return a->name == b->name - && same_location(&a->location, &b->location) + && a->location == b->location && a->description == b->description && a->notes == b->notes; } diff --git a/core/load-git.cpp b/core/load-git.cpp index d4a42e447..43f8b7521 100644 --- a/core/load-git.cpp +++ b/core/load-git.cpp @@ -180,7 +180,7 @@ static void parse_dive_gps(char *line, struct git_parser_state *state) ds = create_dive_site_with_gps(std::string(), &location, state->log->sites); add_dive_to_dive_site(state->active_dive, ds); } else { - if (dive_site_has_gps_location(ds) && !same_location(&ds->location, &location)) { + if (dive_site_has_gps_location(ds) && ds->location != location) { std::string coords = printGPSCoordsC(&location); // we have a dive site that already has GPS coordinates // note 1: there will be much less copying once the core diff --git a/core/parse-xml.cpp b/core/parse-xml.cpp index 3b29b182e..bc826fc3a 100644 --- a/core/parse-xml.cpp +++ b/core/parse-xml.cpp @@ -1209,7 +1209,7 @@ static void gps_in_dive(const char *buffer, struct dive *dive, struct parser_sta add_dive_to_dive_site(dive, ds); } else { if (dive_site_has_gps_location(ds) && - has_location(&location) && !same_location(&ds->location, &location)) { + has_location(&location) && ds->location != location) { // Houston, we have a problem report_info("dive site uuid in dive, but gps location (%10.6f/%10.6f) different from dive location (%10.6f/%10.6f)", ds->location.lat.udeg / 1000000.0, ds->location.lon.udeg / 1000000.0, diff --git a/core/qthelper.cpp b/core/qthelper.cpp index 96b7d2dff..c0f9a5052 100644 --- a/core/qthelper.cpp +++ b/core/qthelper.cpp @@ -268,31 +268,6 @@ bool parseGpsText(const QString &gps_text, double *latitude, double *longitude) pos == normalized.size(); } -#if 0 // we'll need something like this for the dive site management, eventually -bool gpsHasChanged(struct dive *dive, struct dive *master, const QString &gps_text, bool *parsed_out) -{ - location_t location; - bool ignore; - bool *parsed = parsed_out ?: &ignore; - *parsed = true; - - /* if we have a master and the dive's gps address is different from it, - * don't change the dive */ - if (master && !same_location(&master->location, &dive->location)) - return false; - - if (!(*parsed = parseGpsText(gps_text, location))) - return false; - - /* if dive gps didn't change, nothing changed */ - if (same_location(&dive->location, location)) - return false; - /* ok, update the dive and mark things changed */ - dive->location = location; - return true; -} -#endif - static xmlDocPtr get_stylesheet_doc(const xmlChar *uri, xmlDictPtr, int, void *, xsltLoadType) { std::string filename = std::string(":/xslt/") + (const char *)uri; diff --git a/core/units.h b/core/units.h index f74d2d54d..1b176f455 100644 --- a/core/units.h +++ b/core/units.h @@ -138,9 +138,14 @@ static inline bool has_location(const location_t *loc) return loc->lat.udeg || loc->lon.udeg; } -static inline bool same_location(const location_t *a, const location_t *b) +static inline bool operator==(const location_t &a, const location_t &b) { - return (a->lat.udeg == b->lat.udeg) && (a->lon.udeg == b->lon.udeg); + return (a.lat.udeg == b.lat.udeg) && (a.lon.udeg == b.lon.udeg); +} + +static inline bool operator!=(const location_t &a, const location_t &b) +{ + return !(a == b); } static inline location_t create_location(double lat, double lon) diff --git a/desktop-widgets/modeldelegates.cpp b/desktop-widgets/modeldelegates.cpp index 933480715..e0fe81027 100644 --- a/desktop-widgets/modeldelegates.cpp +++ b/desktop-widgets/modeldelegates.cpp @@ -475,7 +475,7 @@ void LocationFilterDelegate::paint(QPainter *painter, const QStyleOptionViewItem if (dive_site_has_gps_location(ds) && currentDiveHasGPS) { // so we are showing a completion and both the current dive site and the completion // have a GPS fix... so let's show the distance - if (same_location(&ds->location, ¤tLocation)) { + if (ds->location == currentLocation) { bottomText += tr(" (same GPS fix)"); } else { int distanceMeters = get_distance(&ds->location, ¤tLocation); diff --git a/qt-models/divelocationmodel.cpp b/qt-models/divelocationmodel.cpp index 17e40b250..5fbf48f7d 100644 --- a/qt-models/divelocationmodel.cpp +++ b/qt-models/divelocationmodel.cpp @@ -294,7 +294,7 @@ bool GPSLocationInformationModel::filterAcceptsRow(int sourceRow, const QModelIn if (!ds || ds == ignoreDs || ds == RECENTLY_ADDED_DIVESITE || !has_location(&ds->location)) return false; - return distance <= 0 ? same_location(&ds->location, &location) + return distance <= 0 ? ds->location == location : (int64_t)get_distance(&ds->location, &location) * 1000 <= distance; // We need 64 bit to represent distances in mm }