[PATCH] Fixes for gps coordinates handling.
Michael Andreen
harv at ruin.nu
Wed Sep 18 12:07:44 UTC 2013
Reset coordinates properly when clicking undo.
When auto-completing location, only copy coordinates if they have not
been manually edited.
Set the background to red if the gps coordinates won't change, e.g.
there is a parse error, the change is too small or only whitespace
changes.
Signed-off-by: Michael Andreen <harv at ruin.nu>
---
This should fix both the undo bug and not overwriting manually edited coordinates. The red background for when gps_changed() returns FALSE is not optimal, but it's better than nothing.
qt-ui/maintab.cpp | 56 ++++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 39 insertions(+), 17 deletions(-)
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index cb61db8..c4aefd3 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -374,7 +374,7 @@ void MainTab::on_editAccept_clicked(bool edit)
notesBackup[mydive].visibility = mydive->visibility;
notesBackup[mydive].latitude = mydive->latitude;
notesBackup[mydive].longitude = mydive->longitude;
- notesBackup[mydive].coordinates = ui->location->text();
+ notesBackup[mydive].coordinates = ui->coordinates->text();
}
editMode = DIVE;
}
@@ -382,6 +382,7 @@ void MainTab::on_editAccept_clicked(bool edit)
ui->diveNotesMessage->animatedHide();
ui->editAccept->hide();
ui->editReset->hide();
+
/* now figure out if things have changed */
if (mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) {
if (notesBackup[NULL].notes != ui->notes->toPlainText() ||
@@ -389,6 +390,11 @@ void MainTab::on_editAccept_clicked(bool edit)
mark_divelist_changed(TRUE);
} else {
struct dive *curr = current_dive;
+ //Reset coordinates field, in case it contains garbage.
+ char buffer[256];
+ print_gps_coordinates(buffer, sizeof buffer
+ , current_dive->latitude.udeg, current_dive->longitude.udeg);
+ ui->coordinates->setText(buffer);
if (notesBackup[curr].buddy != ui->buddy->text() ||
notesBackup[curr].suit != ui->suit->text() ||
notesBackup[curr].notes != ui->notes->toPlainText() ||
@@ -411,6 +417,7 @@ void MainTab::on_editAccept_clicked(bool edit)
ui->buddy->setPalette(p);
ui->notes->setPalette(p);
ui->location->setPalette(p);
+ ui->coordinates->setPalette(p);
ui->divemaster->setPalette(p);
ui->suit->setPalette(p);
}
@@ -484,13 +491,14 @@ void MainTab::on_editReset_clicked()
ui->buddy->setPalette(p);
ui->notes->setPalette(p);
ui->location->setPalette(p);
+ ui->coordinates->setPalette(p);
ui->divemaster->setPalette(p);
ui->suit->setPalette(p);
editMode = NONE;
}
#undef EDIT_TEXT2
-#define EDIT_SELECTED_DIVES( WHAT ) \
+#define EDIT_SELECTED_DIVES( WHAT ) do { \
if (editMode == NONE) \
return; \
\
@@ -502,7 +510,8 @@ void MainTab::on_editReset_clicked()
continue; \
\
WHAT; \
- }
+ } \
+} while(0)
void markChangedWidget(QWidget *w){
QPalette p;
@@ -531,21 +540,26 @@ void MainTab::on_location_textChanged(const QString& text)
dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips.begin();
EDIT_TEXT(currentTrip->location, text);
} else if (editMode == DIVE){
- struct dive* dive;
- int i = 0;
- for_each_dive(i, dive){
- QString location(dive->location);
- if (location == text &&
- (dive->latitude.udeg || dive->longitude.udeg)){
- EDIT_SELECTED_DIVES( mydive->latitude = dive->latitude )
- EDIT_SELECTED_DIVES( mydive->longitude = dive->longitude )
- char buffer[256];
- print_gps_coordinates(buffer, sizeof buffer, dive->latitude.udeg, dive->longitude.udeg);
- ui->coordinates->setText(buffer);
- break;
+ if (!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 == text &&
+ (dive->latitude.udeg || dive->longitude.udeg)) {
+ EDIT_SELECTED_DIVES( mydive->latitude = dive->latitude );
+ EDIT_SELECTED_DIVES( mydive->longitude = dive->longitude );
+ char buffer[256];
+ print_gps_coordinates(buffer, sizeof buffer
+ , dive->latitude.udeg, dive->longitude.udeg);
+ ui->coordinates->setText(buffer);
+ markChangedWidget(ui->coordinates);
+ break;
+ }
}
}
- EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->location, text) )
+ EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->location, text) );
}
markChangedWidget(ui->location);
@@ -576,7 +590,15 @@ void MainTab::on_notes_textChanged()
void MainTab::on_coordinates_textChanged(const QString& text)
{
QByteArray textByteArray = text.toLocal8Bit();
- EDIT_SELECTED_DIVES(gps_changed(mydive, NULL, textByteArray.data()));
+ gboolean gpsChanged = FALSE;
+ EDIT_SELECTED_DIVES(gpsChanged |= gps_changed(mydive, NULL, textByteArray.data()));
+ if (gpsChanged) {
+ markChangedWidget(ui->coordinates);
+ } else {
+ QPalette p;
+ p.setBrush(QPalette::Base, QColor(Qt::red).lighter());
+ ui->coordinates->setPalette(p);
+ }
}
void MainTab::on_rating_valueChanged(int value)
--
1.8.1.5
More information about the subsurface
mailing list