aboutsummaryrefslogtreecommitdiffstats
path: root/desktop-widgets
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-10-11 07:53:21 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-10-11 16:25:02 -0700
commit76e5c5ac671fdeb29cf667d478a27757054d67cb (patch)
tree2f5bfeb67a63ffc10019bf8a76fbd3540ae23ff4 /desktop-widgets
parentb426a7937edcf87ae07a20b542cbf578cf92d86a (diff)
downloadsubsurface-76e5c5ac671fdeb29cf667d478a27757054d67cb.tar.gz
Dive site: remove access to displayed dive site from LocationFilterDelegate
When editing a dive, in the location box a list of dive sites is shown containing the distance to the current dive site. This was implemented via the global displayed_dive_site object, which is set when switching between dives. This seems like an unnecessary indirection. Instead, use the current_dive macro. This is part of a series to refactor dive-site handling to use pointers instead of UUIDs and a general push to reduce global state. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets')
-rw-r--r--desktop-widgets/modeldelegates.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/desktop-widgets/modeldelegates.cpp b/desktop-widgets/modeldelegates.cpp
index 2772dbcdb..74a11adaf 100644
--- a/desktop-widgets/modeldelegates.cpp
+++ b/desktop-widgets/modeldelegates.cpp
@@ -455,6 +455,8 @@ void LocationFilterDelegate::paint(QPainter *painter, const QStyleOptionViewItem
struct dive_site *ds = get_dive_site_by_uuid(
index.model()->data(index.model()->index(index.row(),0)).toInt()
);
+ struct dive_site *currentDiveSite = current_dive ? get_dive_site_for_dive(current_dive) : nullptr;
+ bool currentDiveSiteHasGPS = currentDiveSite && dive_site_has_gps_location(currentDiveSite);
//Special case: do not show name, but instead, show
if (index.row() < 2) {
diveSiteName = index.data().toString();
@@ -482,14 +484,14 @@ void LocationFilterDelegate::paint(QPainter *painter, const QStyleOptionViewItem
free( (void*) gpsCoords);
}
- if (dive_site_has_gps_location(ds) && dive_site_has_gps_location(&displayed_dive_site)) {
+ if (dive_site_has_gps_location(ds) && currentDiveSiteHasGPS) {
// 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 (ds->latitude.udeg == displayed_dive_site.latitude.udeg &&
- ds->longitude.udeg == displayed_dive_site.longitude.udeg) {
+ if (ds->latitude.udeg == currentDiveSite->latitude.udeg &&
+ ds->longitude.udeg == currentDiveSite->longitude.udeg) {
bottomText += tr(" (same GPS fix)");
} else {
- int distanceMeters = get_distance(ds->latitude, ds->longitude, displayed_dive_site.latitude, displayed_dive_site.longitude);
+ int distanceMeters = get_distance(ds->latitude, ds->longitude, currentDiveSite->latitude, currentDiveSite->longitude);
QString distance = distance_string(distanceMeters);
int nr = nr_of_dives_at_dive_site(ds->uuid, false);
bottomText += tr(" (~%1 away").arg(distance);
@@ -497,7 +499,7 @@ void LocationFilterDelegate::paint(QPainter *painter, const QStyleOptionViewItem
}
}
if (bottomText.isEmpty()) {
- if (dive_site_has_gps_location(&displayed_dive_site))
+ if (currentDiveSiteHasGPS)
bottomText = tr("(no existing GPS data, add GPS fix from this dive)");
else
bottomText = tr("(no GPS data)");