[2014-07-08 11:15:25 -0700] Dirk Hohndel: > It might make sense to have it run when focus leaves the location field?
Here is a patch that does that. I have virtually no experience writing GUI code, though, so I won't be offended if you tell me editingFinished() was completely not where the code should have gone. (Or anything of the kind.) It works well enough for me, however; Miika, could you also test this patch in as various editing scenarios as you can, and see if it does what you'd expect? Cheers. -- Gaetan
>From 2c2d1501ab7524daad8f44c000541e5ddf91a338 Mon Sep 17 00:00:00 2001 From: Gaetan Bisson <[email protected]> Date: Tue, 8 Jul 2014 17:47:10 -1000 Subject: [PATCH] Complete GPS coordinates on location focusout. Introduce on_location_editingFinished() and move the GPS coordinates completion logic there. This simplifies acceptChanges(), but replaces the clever code for multidive completion by something much more straightforward: - The old code used to compare the locations from multiple sources (displayed_dive, current_dive, mydive, ui, etc.) to determine what subset of a multidive selection it should update with the automatic completion for GPS coordinates based on the newly entered location. - The new on_location_editingFinished() only works on displayed_dive, and whatever changes it makes to the coordinates field are then saved normally, as any other field would, regardless of whether a single or multiple dives are selected. I believe the simplicity and behavioral predictability of the new code is worth getting rid of the obscure magic of the old code for. That is perhaps debatable... Note the call to on_location_editingFinished() from acceptChanges(); without it, completion only happens *after* the dive has been saved. Signed-off-by: Gaetan Bisson <[email protected]> --- qt-ui/maintab.cpp | 71 ++++++++++++++++++++----------------------------------- qt-ui/maintab.h | 1 + 2 files changed, 26 insertions(+), 46 deletions(-) diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 477cd22..d073299 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -625,28 +625,11 @@ void MainTab::acceptChanges() tabBar()->setTabIcon(1, QIcon()); // Equipment hideMessage(); ui.equipmentTab->setEnabled(true); + on_location_editingFinished(); // complete coordinates *before* saving if (editMode == ADD) { // We need to add the dive we just created to the dive list and select it. - // And if we happen to have GPS data for the location entered, let's add those. // Easy, right? struct dive *added_dive = clone_dive(&displayed_dive); - if (!same_string(added_dive->location, "") && - ui.coordinates->text().trimmed().isEmpty()) { - struct dive *dive; - int i = 0; - for_each_dive (i, dive) { - QString location(dive->location); - if (location == ui.location->text() && - (dive->latitude.udeg || dive->longitude.udeg)) { - if (same_string(added_dive->location, dive->location)) { - added_dive->latitude = dive->latitude; - added_dive->longitude = dive->longitude; - } - MainWindow::instance()->globe()->reload(); - break; - } - } - } record_dive(added_dive); addedId = added_dive->id; // unselect everything as far as the UI is concerned - we'll fix that below @@ -687,38 +670,14 @@ void MainTab::acceptChanges() if (displayed_dive.watertemp.mkelvin != cd->watertemp.mkelvin) MODIFY_SELECTED_DIVES(EDIT_VALUE(watertemp.mkelvin)); if (displayed_dive.when != cd->when) { - time_t offset = current_dive->when - displayed_dive.when; + time_t offset = cd->when - displayed_dive.when; MODIFY_SELECTED_DIVES(mydive->when -= offset;); } - if (displayed_dive.latitude.udeg != current_dive->latitude.udeg || - displayed_dive.longitude.udeg != current_dive->longitude.udeg) { + if (displayed_dive.latitude.udeg != cd->latitude.udeg || + displayed_dive.longitude.udeg != cd->longitude.udeg) MODIFY_SELECTED_DIVES(gpsHasChanged(mydive, cd, ui.coordinates->text(), 0)); - } - if (!same_string(displayed_dive.location, cd->location)) { + if (!same_string(displayed_dive.location, cd->location)) MODIFY_SELECTED_DIVES(EDIT_TEXT(location)); - // if we have a location text and haven't edited the coordinates, try to fill the coordinates - // from the existing dives - if (!same_string(cd->location, "") && - (!ui.coordinates->isModified() || - ui.coordinates->text().trimmed().isEmpty())) { - struct dive *dive; - int i = 0; - for_each_dive (i, dive) { - QString location(dive->location); - if (location == ui.location->text() && - (dive->latitude.udeg || dive->longitude.udeg)) { - MODIFY_SELECTED_DIVES(if (same_string(mydive->location, dive->location)) { - mydive->latitude = dive->latitude; - mydive->longitude = dive->longitude; - }); - displayed_dive.latitude = dive->latitude; - displayed_dive.longitude = dive->longitude; - MainWindow::instance()->globe()->reload(); - break; - } - } - } - } if (tagsChanged(&displayed_dive, cd)) saveTags(); @@ -1024,6 +983,26 @@ void MainTab::on_location_textChanged(const QString &text) markChangedWidget(ui.location); } +// If we have GPS data for the location entered, add it. +void MainTab::on_location_editingFinished() +{ + if (!same_string(displayed_dive.location, "") && + ui.coordinates->text().trimmed().isEmpty()) { + struct dive *dive; + int i = 0; + for_each_dive (i, dive) { + if (same_string(displayed_dive.location, dive->location) && + (dive->latitude.udeg || dive->longitude.udeg)) { + displayed_dive.latitude = dive->latitude; + displayed_dive.longitude = dive->longitude; + MainWindow::instance()->globe()->reload(); + updateGpsCoordinates(&displayed_dive); + break; + } + } + } +} + void MainTab::on_suit_textChanged(const QString &text) { if (editMode == IGNORE) diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h index 3eb5596..476e451 100644 --- a/qt-ui/maintab.h +++ b/qt-ui/maintab.h @@ -60,6 +60,7 @@ slots: void acceptChanges(); void rejectChanges(); void on_location_textChanged(const QString &text); + void on_location_editingFinished(); void on_coordinates_textChanged(const QString &text); void on_divemaster_textChanged(); void on_buddy_textChanged(); -- 2.0.1
_______________________________________________ subsurface mailing list [email protected] http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface
