From 76e5c5ac671fdeb29cf667d478a27757054d67cb Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Thu, 11 Oct 2018 07:53:21 +0200 Subject: 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 --- desktop-widgets/modeldelegates.cpp | 12 +++++++----- 1 file 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)"); -- cgit v1.2.3-70-g09d2