From 786f164046af5fdc6f676b8ae86928181f2d214c Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Tue, 6 Oct 2015 15:59:51 -0300 Subject: Be way more carefull when copying dive site I don't know how I was not shot regarding on how broken the old behavior was. The new behavior: 1 copy the old_dive_site on top of the current_dive_site only if the current_dive_site was actually a new uuid, created by that method. 2 if the current_dive_site is an existing one but it doesn't have gps coords, copy only the gps coords. This fixes existing dive sites copying notes and coordinates from the old_dive_site. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/maintab.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 6ab9a871c..d4483273e 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -834,23 +834,32 @@ uint32_t MainTab::updateDiveSite(uint32_t pickedUuid, int divenr) const uint32_t origUuid = cd->dive_site_uuid; struct dive_site *origDs = get_dive_site_by_uuid(origUuid); struct dive_site *newDs = NULL; + bool createdNewDive = false; if (pickedUuid == origUuid) return origUuid; if (pickedUuid == RECENTLY_ADDED_DIVESITE) { pickedUuid = create_dive_site(ui.location->text().isEmpty() ? qPrintable(tr("New dive site")) : qPrintable(ui.location->text()), displayed_dive.when); + createdNewDive = true; } newDs = get_dive_site_by_uuid(pickedUuid); // Copy everything from the displayed_dive_site, so we have the latitude, longitude, notes, etc. // The user *might* be using wrongly the 'choose dive site' just to edit the name of it, sigh. - if(origDs) { - copy_dive_site(origDs, newDs); - free(newDs->name); - newDs->name = copy_string(qPrintable(ui.location->text().constData())); - newDs->uuid = pickedUuid; + if (origDs) { + if(createdNewDive) { + copy_dive_site(origDs, newDs); + free(newDs->name); + newDs->name = copy_string(qPrintable(ui.location->text().constData())); + newDs->uuid = pickedUuid; + qDebug() << "Creating and copying dive site"; + } else if (newDs->latitude.udeg == 0 && newDs->longitude.udeg == 0) { + newDs->latitude.udeg = origDs->latitude.udeg; + newDs->longitude.udeg = origDs->longitude.udeg; + qDebug() << "Copying GPS information"; + } } if (origDs && pickedUuid != origDs->uuid && same_string(origDs->notes, "SubsurfaceWebservice")) { -- cgit v1.2.3-70-g09d2