summaryrefslogtreecommitdiffstats
path: root/qt-ui/maintab.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2015-07-13 15:38:46 -0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-07-13 15:44:16 -0700
commit1a68e7985b1aad038b0a0d337ab5d606aa43f64c (patch)
tree118cd533723ed026234587655239a78b0019c808 /qt-ui/maintab.cpp
parentc658f2878b540407a65af8c57b3e1bb3cc7c78c4 (diff)
downloadsubsurface-1a68e7985b1aad038b0a0d337ab5d606aa43f64c.tar.gz
Move code that handles location to a sane place
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/maintab.cpp')
-rw-r--r--qt-ui/maintab.cpp70
1 files changed, 18 insertions, 52 deletions
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index c68138fae..66e42e3c4 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)