[PATCH] Only auto-complete gps information when empty.

Linus Torvalds torvalds at linux-foundation.org
Mon Nov 11 15:52:06 UTC 2013


ACK. Looks great. I didn't test it (horrible internet, reading email on my
phone, not computer), but I assume you did..

Dirk, take this one, not mine.

     Linus
On Nov 12, 2013 8:21 AM, "Michael Andreen" <harv at ruin.nu> wrote:

Previously gps information was always overwritten, unless the user had
modified it in the current editing session. This causes problem with
some use cases, like when coordinates are provided before the location
name by the companion app.

Now gps information is only overwritten when it is:
  - Empty
  - Auto-completed in the current editing session. (When the user hits
    accept it is considered hand-edited.)

Signed-off-by: Michael Andreen <harv at ruin.nu>
---
Maybe something like this? Only minimal testing done.

 qt-ui/maintab.cpp | 14 +++++++++++---
 qt-ui/maintab.h   |  1 +
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index 0c0d99a..246b1fb 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -286,7 +286,7 @@ void MainTab::updateDiveInfo(int dive)
        UPDATE_TEMP(d, airtemp);
        UPDATE_TEMP(d, watertemp);
        if (d) {
-               ui.coordinates->setText(printGPSCoords(d->latitude.udeg,
d->longitude.udeg));
+               updateGpsCoordinates(d);
                ui.dateTimeEdit->setDateTime(QDateTime::fromTime_t(d->when
- gettimezoneoffset()));
                if (mainWindow() &&
mainWindow()->dive_list()->selectedTrips.count() == 1) {
                        // only use trip relevant fields
@@ -449,7 +449,7 @@ void MainTab::acceptChanges()
        } else {
                struct dive *curr = current_dive;
                //Reset coordinates field, in case it contains garbage.
-
ui.coordinates->setText(printGPSCoords(current_dive->latitude.udeg,
current_dive->longitude.udeg));
+               updateGpsCoordinates(curr);
                if (notesBackup[curr].buddy != ui.buddy->text() ||
                        notesBackup[curr].suit != ui.suit->text() ||
                        notesBackup[curr].notes != ui.notes->toPlainText()
||
@@ -555,7 +555,6 @@ void MainTab::rejectChanges()
                struct dive *curr = current_dive;
                ui.notes->setText(notesBackup[curr].notes );
                ui.location->setText(notesBackup[curr].location);
-               ui.coordinates->setText(notesBackup[curr].coordinates);
                ui.buddy->setText(notesBackup[curr].buddy);
                ui.suit->setText(notesBackup[curr].suit);
                ui.divemaster->setText(notesBackup[curr].divemaster);
@@ -593,6 +592,7 @@ void MainTab::rejectChanges()
                                mydive->weightsystem[i] =
notesBackup[mydive].weightsystem[i];
                        }
                }
+               updateGpsCoordinates(curr);
                if (selected_dive >= 0) {
                        multiEditEquipmentPlaceholder =
*get_dive(selected_dive);

cylindersModel->setDive(&multiEditEquipmentPlaceholder);
@@ -706,6 +706,7 @@ void MainTab::on_location_textChanged(const QString&
text)
                                    (dive->latitude.udeg ||
dive->longitude.udeg)) {
                                        EDIT_SELECTED_DIVES(
mydive->latitude = dive->latitude );
                                        EDIT_SELECTED_DIVES(
mydive->longitude = dive->longitude );
+                                       //Don't use updateGpsCoordinates()
since we don't want to set modified state yet

ui.coordinates->setText(printGPSCoords(dive->latitude.udeg,
dive->longitude.udeg));
                                        markChangedWidget(ui.coordinates);
                                        break;
@@ -803,3 +804,10 @@ QString MainTab::printGPSCoords(int lat, int lon)
                       lonh.toLocal8Bit().data(), londeg, UTF8_DEGREE,
ilonmin / 1000000, (ilonmin % 1000000) / 10);
        return result;
 }
+
+void MainTab::updateGpsCoordinates(const struct dive *dive)
+{
+       ui.coordinates->setText(printGPSCoords(dive->latitude.udeg,
dive->longitude.udeg));
+       ui.coordinates->setModified(dive->latitude.udeg ||
dive->longitude.udeg);
+
+}
diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h
index 341a282..5a9e2ef 100644
--- a/qt-ui/maintab.h
+++ b/qt-ui/maintab.h
@@ -99,6 +99,7 @@ private:
        void resetPallete();
        void saveTags();
        QString printGPSCoords(int lat, int lon);
+       void updateGpsCoordinates(const struct dive *dive);
 };

 #endif
--
1.8.3.2
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.hohndel.org/pipermail/subsurface/attachments/20131112/a5940063/attachment.html>


More information about the subsurface mailing list