From a084ea5b261b10d336f7a474a5b57705550d8825 Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Mon, 27 Nov 2017 00:26:46 +0200 Subject: locationinformation: don't update map location on typing Currently when the user is typing new coordinates the marker on the map changes location right away. Disable that and add a 'flag' button that should be pressed instead. Also make the coordinates update when pressing Enter or when the text field loses focus. Signed-off-by: Lubomir I. Ivanov --- desktop-widgets/locationInformation.ui | 31 +++++++++++++++++++++++-------- desktop-widgets/locationinformation.cpp | 27 +++++++++++++++++++++------ desktop-widgets/locationinformation.h | 2 ++ 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/desktop-widgets/locationInformation.ui b/desktop-widgets/locationInformation.ui index c15c713fd..24b7977e4 100644 --- a/desktop-widgets/locationInformation.ui +++ b/desktop-widgets/locationInformation.ui @@ -54,20 +54,20 @@ - + Qt::ClickFocus - + - + - + Reverse geo lookup @@ -81,7 +81,7 @@ - + @@ -91,7 +91,7 @@ - + Dive sites on same coordinates @@ -139,7 +139,7 @@ - + @@ -153,9 +153,23 @@ - + + + + + Update location on map + + + + + + + :/mapwidget-marker-selected:/mapwidget-marker-selected + + + @@ -170,6 +184,7 @@ diveSiteName diveSiteCountry diveSiteCoordinates + updateLocationButton geoCodeButton diveSiteDescription diveSiteNotes diff --git a/desktop-widgets/locationinformation.cpp b/desktop-widgets/locationinformation.cpp index ad00198b7..454c4c68f 100644 --- a/desktop-widgets/locationinformation.cpp +++ b/desktop-widgets/locationinformation.cpp @@ -38,6 +38,9 @@ LocationInformationWidget::LocationInformationWidget(QWidget *parent) : QGroupBo connect(ui.geoCodeButton, SIGNAL(clicked()), this, SLOT(reverseGeocode())); connect(this, SIGNAL(nameChanged(const QString &, const QString &)), LocationFilterModel::instance(), SLOT(changeName(const QString &, const QString &))); + connect(ui.updateLocationButton, SIGNAL(clicked()), this, SLOT(updateLocationOnMap())); + connect(ui.diveSiteCoordinates, SIGNAL(returnPressed()), this, SLOT(updateLocationOnMap())); + ui.diveSiteCoordinates->installEventFilter(this); SsrfSortFilterProxyModel *filter_model = new SsrfSortFilterProxyModel(this); filter_model->setSourceModel(LocationInformationModel::instance()); @@ -58,7 +61,7 @@ LocationInformationWidget::LocationInformationWidget(QWidget *parent) : QGroupBo MapWidget::instance(), &MapWidget::updateCurrentDiveSiteCoordinatesToMap); } -bool LocationInformationWidget::eventFilter(QObject *, QEvent *ev) +bool LocationInformationWidget::eventFilter(QObject *object, QEvent *ev) { if (ev->type() == QEvent::ContextMenu) { QContextMenuEvent *ctx = (QContextMenuEvent *)ev; @@ -66,10 +69,18 @@ bool LocationInformationWidget::eventFilter(QObject *, QEvent *ev) contextMenu.addAction(tr("Merge into current site"), this, SLOT(mergeSelectedDiveSites())); contextMenu.exec(ctx->globalPos()); return true; + } else if (ev->type() == QEvent::FocusOut && object == ui.diveSiteCoordinates) { + emit coordinatesChanged(); } return false; } +void LocationInformationWidget::enableLocationButtons(bool enable) +{ + ui.geoCodeButton->setEnabled(enable); + ui.updateLocationButton->setEnabled(enable); +} + void LocationInformationWidget::mergeSelectedDiveSites() { if (QMessageBox::warning(MainWindow::instance(), tr("Merging dive sites"), @@ -137,7 +148,7 @@ void LocationInformationWidget::updateGpsCoordinates() QString oldText = ui.diveSiteCoordinates->text(); const char *coords = printGPSCoords(displayed_dive_site.latitude.udeg, displayed_dive_site.longitude.udeg); ui.diveSiteCoordinates->setText(coords); - ui.geoCodeButton->setEnabled(dive_site_has_gps_location(&displayed_dive_site)); + enableLocationButtons(dive_site_has_gps_location(&displayed_dive_site)); free((void *)coords); if (oldText != ui.diveSiteCoordinates->text()) markChangedWidget(ui.diveSiteCoordinates); @@ -222,7 +233,7 @@ void LocationInformationWidget::showEvent(QShowEvent *ev) { if (displayed_dive_site.uuid) { updateLabels(); - ui.geoCodeButton->setEnabled(dive_site_has_gps_location(&displayed_dive_site)); + enableLocationButtons(dive_site_has_gps_location(&displayed_dive_site)); QSortFilterProxyModel *m = qobject_cast(ui.diveSiteListView->model()); emit startFilterDiveSite(displayed_dive_site.uuid); if (m) @@ -274,10 +285,9 @@ void LocationInformationWidget::on_diveSiteCoordinates_textChanged(const QString displayed_dive_site.latitude.udeg = lrint(latitude * 1000000); displayed_dive_site.longitude.udeg = lrint(longitude * 1000000); markChangedWidget(ui.diveSiteCoordinates); - emit coordinatesChanged(); - ui.geoCodeButton->setEnabled(latitude != 0 && longitude != 0); + enableLocationButtons(latitude != 0 && longitude != 0); } else { - ui.geoCodeButton->setEnabled(false); + enableLocationButtons(false); } } free((void *)coords); @@ -324,6 +334,11 @@ void LocationInformationWidget::reverseGeocode() updateLabels(); } +void LocationInformationWidget::updateLocationOnMap() +{ + emit coordinatesChanged(); +} + DiveLocationFilterProxyModel::DiveLocationFilterProxyModel(QObject *parent) { Q_UNUSED(parent) diff --git a/desktop-widgets/locationinformation.h b/desktop-widgets/locationinformation.h index 3a2696a54..114626454 100644 --- a/desktop-widgets/locationinformation.h +++ b/desktop-widgets/locationinformation.h @@ -15,6 +15,7 @@ public: protected: void showEvent(QShowEvent *); + void enableLocationButtons(bool enable); public slots: void acceptChanges(); @@ -33,6 +34,7 @@ public slots: void mergeSelectedDiveSites(); private slots: void updateLabels(); + void updateLocationOnMap(); signals: void startEditDiveSite(uint32_t uuid); void endEditDiveSite(); -- cgit v1.2.3-70-g09d2