From 6a57ce5c6bfcd1787a4e57dc0b4e4ceea0743ec1 Mon Sep 17 00:00:00 2001 From: Gaetan Bisson Date: Thu, 3 Jul 2014 13:12:47 -1000 Subject: Autofill GPS coordinates for added dives. Prior to commit 95cb4e, when a new dive was added with the same location name as a previous dive, the GPS coordinates for that new dive would be automatically set to that of the matching previous dive. This restores this feature, by duplicating code further down qt-ui/maintab.cpp that handles the case where multiple dives are modified at once. Signed-off-by: Gaetan Bisson Signed-off-by: Dirk Hohndel --- qt-ui/maintab.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'qt-ui/maintab.cpp') diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 4495731be..68918e7ed 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -613,9 +613,27 @@ void MainTab::acceptChanges() hideMessage(); ui.equipmentTab->setEnabled(true); if (editMode == ADD) { - // we need to add the dive we just created to the dive list and select it. + // 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 -- cgit v1.2.3-70-g09d2