From c7e1c40b0e9ff1c9152f06b7f1c134f232297fe7 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Thu, 25 Apr 2019 00:26:48 +0200 Subject: Dive site: sort by distance to current dive When presenting the list of dive sites on the dive-info tab, sort the dive sites by distance to the current dive. The idea is that when the user wants to select a dive site, close dive sites should be prioritized. The location of the dive is determined with the dive_get_gps_location() function introduced in the previous commit. This actual GPS data get precedence over the currently set dive site for that dive. On change of dive, the current location is updated in the DiveLocationFilterProxyModel so that a potentially expensive search for GPS data is not repeated for every comparison. Signed-off-by: Berthold Stoeger --- desktop-widgets/tab-widgets/maintab.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'desktop-widgets/tab-widgets') diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index 0638fbded..e70e79ce2 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -391,15 +391,14 @@ void MainTab::updateDateTime(struct dive *d) void MainTab::updateDiveSite(struct dive *d) { struct dive_site *ds = d->dive_site; + ui.location->setCurrentDiveSite(d); if (ds) { - ui.location->setCurrentDiveSite(ds); ui.locationTags->setText(constructLocationTags(&ds->taxonomy, true)); if (ui.locationTags->text().isEmpty() && has_location(&ds->location)) ui.locationTags->setText(printGPSCoords(&ds->location)); ui.editDiveSiteButton->setEnabled(true); } else { - ui.location->clear(); ui.locationTags->clear(); ui.editDiveSiteButton->setEnabled(false); } @@ -601,9 +600,7 @@ void MainTab::reload() void MainTab::refreshDisplayedDiveSite() { - struct dive_site *ds = get_dive_site_for_dive(current_dive); - if (ds) - ui.location->setCurrentDiveSite(ds); + ui.location->setCurrentDiveSite(current_dive); } void MainTab::acceptChanges() -- cgit v1.2.3-70-g09d2