Hi,

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.

I only recently noticed that this behavior changed with 95cb4e: now the
GPS coordinates are left empty; is that on purpose? It was really quite
handy for people who regularly dive the same sites like me to have their
coordinates autofilled.

There have been significant changes to that part of the code since
95cb4e (early June), but I managed to replicate the old behavior with
the attached patch. It's probably suboptimal since it duplicates code
further down qt-ui/maintab.cpp that handles the case where multiple
dives are modified at once. However I'm not familiar enough with the
code base to know what the preferred way to implement this would be;
instead I'm just submitting this patch as an RFC / bug report...

Cheers.

-- 
Gaetan
>From 18074c1f41b2b655dd14028c9d02f2e6175f3517 Mon Sep 17 00:00:00 2001
From: Gaetan Bisson <[email protected]>
Date: Thu, 3 Jul 2014 13:12:47 -1000
Subject: [PATCH] Autofill GPS coordinates for added dives.

---
 qt-ui/maintab.cpp | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index 4495731..fda75e6 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -616,6 +616,25 @@ void MainTab::acceptChanges()
 		// we need to add the dive we just created to the dive list and select it.
 		// 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
-- 
2.0.1

_______________________________________________
subsurface mailing list
[email protected]
http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to