[2014-07-09 08:39:58 -0700] Dirk Hohndel:
> While this is one possible way to do this, it violates our design logic.
> Now people can disagree with that logic, but here is how things are
> suppsoed to work:
> 
> if you edit multiple dives, one of them is displayed (the current_dive).
> When you change a value on that dive, it is modified in all selected dives
> that previously had the same value.

Okay. How about this patch, then?

It only modifies GPS coordinates when both mydive->location and
mydive->coordinates have the same value as for the current_dive.

Cheers.

-- 
Gaetan
>From 8fbb1c189f2acbb904eb30a8432a92d3d3325696 Mon Sep 17 00:00:00 2001
From: Gaetan Bisson <[email protected]>
Date: Wed, 9 Jul 2014 06:32: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 a little more
straightforward.

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 | 78 ++++++++++++++++++++++---------------------------------
 qt-ui/maintab.h   |  1 +
 2 files changed, 32 insertions(+), 47 deletions(-)

diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index 477cd22..1220fb3 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,19 @@ 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) {
-			MODIFY_SELECTED_DIVES(gpsHasChanged(mydive, cd, ui.coordinates->text(), 0));
-		}
-		if (!same_string(displayed_dive.location, cd->location)) {
+		if (displayed_dive.latitude.udeg != cd->latitude.udeg ||
+		    displayed_dive.longitude.udeg != cd->longitude.udeg)
+			MODIFY_SELECTED_DIVES(
+				if (same_string(mydive->location, cd->location) &&
+				    mydive->latitude.udeg == cd->latitude.udeg &&
+				    mydive->longitude.udeg == cd->longitude.udeg)
+					gpsHasChanged(mydive, cd, ui.coordinates->text(), 0);
+			);
+		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 +988,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

Reply via email to