mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Dive site: give visual clue for invalid coordinates
On the dive site edit screen, when the user enters invalid coordinates and saves, we treat this as "no location". This is rather unfriendly, therefore warn the user with a visual clue. This is performed by setting the background color of the widget to red. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
e5487f86a6
commit
cabaaa69db
2 changed files with 31 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue