Okay,
This *seems* to be working, I tested it quite a lot to make sure I didn't
broke anything very obvious:

change the name of a dive site to something that already exists, it will
use the first dive site with that name from the dive_site_table
change the name of a dive site to something that doesn't exists, it will
create a new one
click on the name of a dive site on the drop_down list, it will store the
dive_site_uuid to use as the dive's dive site


On Mon, Jul 13, 2015 at 3:22 PM, Tomaz Canabrava <[email protected]> wrote:

> Now it works.
> (I think there's something missing, will keep working here)
>
>
From 90d1bf9f0f3a23d385dfa9616d8d3dd047129d74 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Mon, 13 Jul 2015 15:38:46 -0300
Subject: [PATCH 4/4] Move code that handles Location to a sane place

Dark times are ahead upon us. So, This fixes a few thigns
related to Location Management, it is working :)

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/maintab.cpp | 70 ++++++++++++++-----------------------------------------
 qt-ui/maintab.h   |  2 +-
 2 files changed, 19 insertions(+), 53 deletions(-)

diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index c68138f..66e42e3 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -818,13 +818,24 @@ void MainTab::reload()
 		mydive->what = displayed_dive.what;  \
 	}
 
-void MainTab::updateDisplayedDiveDiveSite()
+void MainTab::updateDisplayedDiveSite()
 {
 	const QString new_name = ui.location->text();
 	const QString orig_name = displayed_dive_site.name;
 	const uint32_t orig_uuid = displayed_dive_site.uuid;
 	const uint32_t new_uuid = locationManagementEditHelper->diveSiteUuid();
 
+	qDebug() << "Updating Displayed Dive Site";
+	if(current_dive) {
+		struct dive_site *ds_from_dive = get_dive_site_by_uuid(current_dive->dive_site_uuid);
+		if (!dive_site_has_gps_location(ds_from_dive) &&
+			same_string(displayed_dive_site.notes, "SubsurfaceWebservice")) {
+			ds_from_dive->latitude = displayed_dive_site.latitude;
+			ds_from_dive->longitude = displayed_dive_site.longitude;
+			delete_dive_site(displayed_dive_site.uuid);
+		}
+	}
+
 	if(orig_uuid) {
 		if (new_uuid && orig_uuid != new_uuid) {
 			displayed_dive.dive_site_uuid = new_uuid;
@@ -835,7 +846,7 @@ void MainTab::updateDisplayedDiveDiveSite()
 		} else {
 			qDebug() << "Current divesite is the same as informed";
 		}
-	} else {
+	} else if (!orig_uuid) {
 		if (new_uuid) {
 			displayed_dive.dive_site_uuid = new_uuid;
 			copy_dive_site(get_dive_site_by_uuid(displayed_dive.dive_site_uuid), &displayed_dive_site);
@@ -854,6 +865,10 @@ void MainTab::acceptChanges()
 	struct dive *d;
 	bool do_replot = false;
 
+	if(ui.location->hasFocus()) {
+		this->setFocus();
+	}
+
 	acceptingEdit = true;
 	tabBar()->setTabIcon(0, QIcon()); // Notes
 	tabBar()->setTabIcon(1, QIcon()); // Equipment
@@ -866,7 +881,6 @@ void MainTab::acceptChanges()
 		struct dive *added_dive = clone_dive(&displayed_dive);
 		record_dive(added_dive);
 		addedId = added_dive->id;
-		updateDisplayedDiveDiveSite();
 		get_dive_by_uniq_id(added_dive->id)->dive_site_uuid = displayed_dive_site.uuid;
 
 		// unselect everything as far as the UI is concerned and select the new
@@ -925,7 +939,6 @@ void MainTab::acceptChanges()
 			MODIFY_SELECTED_DIVES(mydive->when -= offset;);
 		}
 
-		updateDisplayedDiveDiveSite();
 		if (displayed_dive.dive_site_uuid != cd->dive_site_uuid)
 			MODIFY_SELECTED_DIVES(EDIT_VALUE(dive_site_uuid));
 
@@ -1406,54 +1419,7 @@ void MainTab::on_location_editingFinished()
 		return;
 	}
 
-	QString currText = ui.location->text();
-
-	struct dive_site *ds;
-	int idx;
-	bool found = false;
-	for_each_dive_site (idx,ds) {
-		if (same_string(ds->name, qPrintable(currText))) {
-			found = true;
-			break;
-		}
-	}
-
-	if (!found) {
-		uint32_t uuid = create_dive_site(qPrintable(ui.location->text()));
-		ds = get_dive_site_by_uuid(uuid);
-		if (same_string(displayed_dive_site.notes, "SubsurfaceWebservice")) {
-			ds->latitude = displayed_dive_site.latitude;
-			ds->longitude = displayed_dive_site.longitude;
-			delete_dive_site(displayed_dive_site.uuid);
-		}
-		displayed_dive.dive_site_uuid = uuid;
-		copy_dive_site(get_dive_site_by_uuid(uuid), &displayed_dive_site);
-		markChangedWidget(ui.location);
-
-		LocationInformationModel::instance()->update();
-		emit diveSiteChanged(uuid);
-		return;
-	}
-
-	if (!get_dive_site(idx))
-		return;
-
-	if (current_dive) {
-		struct dive_site *ds_from_dive = get_dive_site_by_uuid(displayed_dive.dive_site_uuid);
-		if(ds_from_dive && ui.location->text() == ds_from_dive->name)
-			return;
-		ds_from_dive = get_dive_site(idx);
-		if (!dive_site_has_gps_location(ds_from_dive) &&
-		    same_string(displayed_dive_site.notes, "SubsurfaceWebservice")) {
-			ds_from_dive->latitude = displayed_dive_site.latitude;
-			ds_from_dive->longitude = displayed_dive_site.longitude;
-			delete_dive_site(displayed_dive_site.uuid);
-		}
-		displayed_dive.dive_site_uuid = ds_from_dive->uuid;
-		copy_dive_site(get_dive_site_by_uuid(ds_from_dive->uuid), &displayed_dive_site);
-		markChangedWidget(ui.location);
-		emit diveSiteChanged(ds_from_dive->uuid);
-	}
+	updateDisplayedDiveSite();
 }
 
 void MainTab::on_suit_textChanged(const QString &text)
diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h
index 6a6b9d1..1e3f950 100644
--- a/qt-ui/maintab.h
+++ b/qt-ui/maintab.h
@@ -123,7 +123,7 @@ private:
 	dive_trip_t displayedTrip;
 	bool acceptingEdit;
 	LocationManagementEditHelper *locationManagementEditHelper;
-	void updateDisplayedDiveDiveSite();
+	void updateDisplayedDiveSite();
 };
 
 #endif // MAINTAB_H
-- 
2.4.5

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

Reply via email to