summaryrefslogtreecommitdiffstats
path: root/qt-ui/maintab.cpp
diff options
context:
space:
mode:
authorGravatar Gaetan Bisson <bisson@archlinux.org>2014-07-09 06:35:27 -1000
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-07-09 09:40:44 -0700
commit35121e114730d4e03e922d66e69da8e56add9ed2 (patch)
treebf4a978cfae1c8dbdb8b3d651618979c501e45e8 /qt-ui/maintab.cpp
parenta2f47485d4fcaadb2cfedd8f5e60f8379f76f048 (diff)
downloadsubsurface-35121e114730d4e03e922d66e69da8e56add9ed2.tar.gz
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. [Dirk Hohndel: trivial merge, minor changes for consistency] Signed-off-by: Gaetan Bisson <bisson@archlinux.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/maintab.cpp')
-rw-r--r--qt-ui/maintab.cpp84
1 files changed, 32 insertions, 52 deletions
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index a55ddfd31..f84c63ec2 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,45 +670,22 @@ 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;
- }
- }
- }
- }
+
saveTags();
-#if 0 // with the new architecture this shouldn't be needed anymore
- if (editMode == MANUALLY_ADDED_DIVE) {
- DivePlannerPointsModel::instance()->copyCylinders(cd);
- } else
-#endif
if (editMode != ADD && cylindersModel->changed) {
mark_divelist_changed(true);
MODIFY_SELECTED_DIVES(
@@ -1002,6 +962,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)