diff options
-rw-r--r-- | desktop-widgets/locationinformation.cpp | 30 | ||||
-rw-r--r-- | desktop-widgets/locationinformation.h | 2 |
2 files changed, 31 insertions, 1 deletions
diff --git a/desktop-widgets/locationinformation.cpp b/desktop-widgets/locationinformation.cpp index 5844d43ed..c9d11b5ee 100644 --- a/desktop-widgets/locationinformation.cpp +++ b/desktop-widgets/locationinformation.cpp @@ -6,6 +6,7 @@ #include "desktop-widgets/divelistview.h" #include "core/qthelper.h" #include "desktop-widgets/mapwidget.h" +#include "core/color.h" #include "core/divefilter.h" #include "core/divesitehelpers.h" #include "desktop-widgets/modeldelegates.h" @@ -87,6 +88,17 @@ void LocationInformationWidget::mergeSelectedDiveSites() Command::mergeDiveSites(diveSite, selected_dive_sites); } +// If we can't parse the coordinates, inform the user with a visual clue +void LocationInformationWidget::coordinatesSetWarning(bool warn) +{ + QPalette palette; + if (warn) { + palette.setColor(QPalette::Base, REDORANGE1_MED_TRANS); + palette.setColor(QPalette::Text, WHITE1); + } + ui.diveSiteCoordinates->setPalette(palette); +} + void LocationInformationWidget::updateLabels() { if (!diveSite) { @@ -114,6 +126,7 @@ void LocationInformationWidget::updateLabels() ui.diveSiteCoordinates->setText(printGPSCoords(&diveSite->location)); else ui.diveSiteCoordinates->clear(); + coordinatesSetWarning(false); ui.locationTags->setText(constructLocationTags(&diveSite->taxonomy, false)); } @@ -156,6 +169,7 @@ void LocationInformationWidget::diveSiteChanged(struct dive_site *ds, int field) enableLocationButtons(false); ui.diveSiteCoordinates->clear(); } + coordinatesSetWarning(false); return; default: return; @@ -169,6 +183,7 @@ void LocationInformationWidget::clearLabels() ui.diveSiteDescription->clear(); ui.diveSiteNotes->clear(); ui.diveSiteCoordinates->clear(); + coordinatesSetWarning(false); ui.locationTags->clear(); } @@ -176,11 +191,19 @@ void LocationInformationWidget::clearLabels() static location_t parseGpsText(const QString &text) { double lat, lon; - if (parseGpsText(text, &lat, &lon)) + if (parseGpsText(text.trimmed(), &lat, &lon)) return create_location(lat, lon); return zero_location; } +// Check if GPS text is parseable +static bool validateGpsText(const QString &textIn) +{ + double lat, lon; + QString text = textIn.trimmed(); + return text.isEmpty() || parseGpsText(text.trimmed(), &lat, &lon); +} + void LocationInformationWidget::diveSiteDeleted(struct dive_site *ds, int) { // If the currently edited dive site was removed under our feet, close the widget. @@ -248,6 +271,11 @@ void LocationInformationWidget::on_diveSiteCoordinates_editingFinished() Command::editDiveSiteLocation(diveSite, parseGpsText(ui.diveSiteCoordinates->text())); } +void LocationInformationWidget::on_diveSiteCoordinates_textEdited(const QString &s) +{ + coordinatesSetWarning(!validateGpsText(s)); +} + void LocationInformationWidget::on_diveSiteCountry_editingFinished() { if (diveSite) diff --git a/desktop-widgets/locationinformation.h b/desktop-widgets/locationinformation.h index a936269e6..bed267dc2 100644 --- a/desktop-widgets/locationinformation.h +++ b/desktop-widgets/locationinformation.h @@ -27,6 +27,7 @@ public slots: void acceptChanges(); void on_diveSiteCountry_editingFinished(); void on_diveSiteCoordinates_editingFinished(); + void on_diveSiteCoordinates_textEdited(const QString &s); void on_diveSiteDescription_editingFinished(); void on_diveSiteName_editingFinished(); void on_diveSiteNotes_editingFinished(); @@ -42,6 +43,7 @@ private slots: private: void keyPressEvent(QKeyEvent *e) override; void clearLabels(); + void coordinatesSetWarning(bool warn); GPSLocationInformationModel filter_model; dive_site *diveSite; int64_t closeDistance; // Distance of "close" dive sites in mm |