diff options
author | Lubomir I. Ivanov <neolit123@gmail.com> | 2017-11-27 00:26:46 +0200 |
---|---|---|
committer | Lubomir I. Ivanov <neolit123@gmail.com> | 2017-11-27 22:59:22 +0100 |
commit | a084ea5b261b10d336f7a474a5b57705550d8825 (patch) | |
tree | c27cc5ca6905f340a2eddd268e62d903e4fa2b78 /desktop-widgets | |
parent | fe69b304b2496233142d9018ab5c6a7675ea089c (diff) | |
download | subsurface-a084ea5b261b10d336f7a474a5b57705550d8825.tar.gz |
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 <neolit123@gmail.com>
Diffstat (limited to 'desktop-widgets')
-rw-r--r-- | desktop-widgets/locationInformation.ui | 31 | ||||
-rw-r--r-- | desktop-widgets/locationinformation.cpp | 27 | ||||
-rw-r--r-- | 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 @@ </property> </widget> </item> - <item row="7" column="2" rowspan="2" colspan="2"> + <item row="7" column="2" rowspan="2" colspan="3"> <widget class="QPlainTextEdit" name="diveSiteNotes"> <property name="focusPolicy"> <enum>Qt::ClickFocus</enum> </property> </widget> </item> - <item row="1" column="2" colspan="2"> + <item row="1" column="2" colspan="3"> <widget class="QLineEdit" name="diveSiteName"/> </item> - <item row="5" column="2" colspan="2"> + <item row="5" column="2" colspan="3"> <widget class="QLineEdit" name="diveSiteDescription"/> </item> - <item row="3" column="3"> + <item row="3" column="4"> <widget class="QToolButton" name="geoCodeButton"> <property name="toolTip"> <string>Reverse geo lookup</string> @@ -81,7 +81,7 @@ </property> </widget> </item> - <item row="0" column="0" colspan="4"> + <item row="0" column="0" colspan="5"> <widget class="KMessageWidget" name="diveSiteMessage"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> @@ -91,7 +91,7 @@ </property> </widget> </item> - <item row="9" column="0" colspan="4"> + <item row="9" column="0" colspan="5"> <widget class="QGroupBox" name="diveSiteGroupBox"> <property name="title"> <string>Dive sites on same coordinates</string> @@ -139,7 +139,7 @@ </property> </widget> </item> - <item row="4" column="2" colspan="2"> + <item row="4" column="2" colspan="3"> <widget class="QLabel" name="locationTags"> <property name="text"> <string/> @@ -153,9 +153,23 @@ </property> </widget> </item> - <item row="2" column="2" colspan="2"> + <item row="2" column="2" colspan="3"> <widget class="QLineEdit" name="diveSiteCountry"/> </item> + <item row="3" column="3"> + <widget class="QToolButton" name="updateLocationButton"> + <property name="toolTip"> + <string>Update location on map</string> + </property> + <property name="text"> + <string/> + </property> + <property name="icon"> + <iconset resource="../subsurface.qrc"> + <normaloff>:/mapwidget-marker-selected</normaloff>:/mapwidget-marker-selected</iconset> + </property> + </widget> + </item> </layout> </widget> <customwidgets> @@ -170,6 +184,7 @@ <tabstop>diveSiteName</tabstop> <tabstop>diveSiteCountry</tabstop> <tabstop>diveSiteCoordinates</tabstop> + <tabstop>updateLocationButton</tabstop> <tabstop>geoCodeButton</tabstop> <tabstop>diveSiteDescription</tabstop> <tabstop>diveSiteNotes</tabstop> 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<QSortFilterProxyModel *>(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(); |