Fixes for gps coordinates handling.

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@ruin.nu>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Michael Andreen 2013-09-19 18:37:44 +02:00 committed by Dirk Hohndel
parent 01408a429d
commit 583cea0e2c

View file

@ -134,7 +134,7 @@ void MainTab::enableEdition()
notesBackup[mydive].visibility = mydive->visibility; notesBackup[mydive].visibility = mydive->visibility;
notesBackup[mydive].latitude = mydive->latitude; notesBackup[mydive].latitude = mydive->latitude;
notesBackup[mydive].longitude = mydive->longitude; notesBackup[mydive].longitude = mydive->longitude;
notesBackup[mydive].coordinates = ui->location->text(); notesBackup[mydive].coordinates = ui->coordinates->text();
} }
editMode = DIVE; editMode = DIVE;
} }
@ -366,6 +366,11 @@ void MainTab::acceptChanges()
mark_divelist_changed(TRUE); mark_divelist_changed(TRUE);
} else { } else {
struct dive *curr = current_dive; 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() || if (notesBackup[curr].buddy != ui->buddy->text() ||
notesBackup[curr].suit != ui->suit->text() || notesBackup[curr].suit != ui->suit->text() ||
notesBackup[curr].notes != ui->notes->toPlainText() || notesBackup[curr].notes != ui->notes->toPlainText() ||
@ -388,6 +393,7 @@ void MainTab::acceptChanges()
ui->buddy->setPalette(p); ui->buddy->setPalette(p);
ui->notes->setPalette(p); ui->notes->setPalette(p);
ui->location->setPalette(p); ui->location->setPalette(p);
ui->coordinates->setPalette(p);
ui->divemaster->setPalette(p); ui->divemaster->setPalette(p);
ui->suit->setPalette(p); ui->suit->setPalette(p);
} }
@ -453,13 +459,14 @@ void MainTab::rejectChanges()
ui->buddy->setPalette(p); ui->buddy->setPalette(p);
ui->notes->setPalette(p); ui->notes->setPalette(p);
ui->location->setPalette(p); ui->location->setPalette(p);
ui->coordinates->setPalette(p);
ui->divemaster->setPalette(p); ui->divemaster->setPalette(p);
ui->suit->setPalette(p); ui->suit->setPalette(p);
editMode = NONE; editMode = NONE;
} }
#undef EDIT_TEXT2 #undef EDIT_TEXT2
#define EDIT_SELECTED_DIVES( WHAT ) \ #define EDIT_SELECTED_DIVES( WHAT ) do { \
if (editMode == NONE) \ if (editMode == NONE) \
return; \ return; \
\ \
@ -471,7 +478,8 @@ void MainTab::rejectChanges()
continue; \ continue; \
\ \
WHAT; \ WHAT; \
} } \
} while(0)
void markChangedWidget(QWidget *w){ void markChangedWidget(QWidget *w){
QPalette p; QPalette p;
@ -500,21 +508,26 @@ void MainTab::on_location_textChanged(const QString& text)
dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips.begin(); dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips.begin();
EDIT_TEXT(currentTrip->location, text); EDIT_TEXT(currentTrip->location, text);
} else if (editMode == DIVE){ } else if (editMode == DIVE){
struct dive* dive; if (!ui->coordinates->isModified() ||
int i = 0; ui->coordinates->text().trimmed().isEmpty()) {
for_each_dive(i, dive){ struct dive* dive;
QString location(dive->location); int i = 0;
if (location == text && for_each_dive(i, dive){
(dive->latitude.udeg || dive->longitude.udeg)){ QString location(dive->location);
EDIT_SELECTED_DIVES( mydive->latitude = dive->latitude ) if (location == text &&
EDIT_SELECTED_DIVES( mydive->longitude = dive->longitude ) (dive->latitude.udeg || dive->longitude.udeg)) {
char buffer[256]; EDIT_SELECTED_DIVES( mydive->latitude = dive->latitude );
print_gps_coordinates(buffer, sizeof buffer, dive->latitude.udeg, dive->longitude.udeg); EDIT_SELECTED_DIVES( mydive->longitude = dive->longitude );
ui->coordinates->setText(buffer); char buffer[256];
break; 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); markChangedWidget(ui->location);
@ -545,7 +558,15 @@ void MainTab::on_notes_textChanged()
void MainTab::on_coordinates_textChanged(const QString& text) void MainTab::on_coordinates_textChanged(const QString& text)
{ {
QByteArray textByteArray = text.toLocal8Bit(); 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) void MainTab::on_rating_valueChanged(int value)