diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f47491..2cd2aa7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,9 @@ RELEASING: ## Unreleased +### Added +- Exit digitization on right click or Escape key press ([#285](https://github.com/GIScience/orstools-qgis-plugin/issues/285)) + ## [1.9.0] - 2024-10-29 ### Fixed diff --git a/ORStools/gui/ORStoolsDialog.py b/ORStools/gui/ORStoolsDialog.py index 7ae6372..b3f30ff 100644 --- a/ORStools/gui/ORStoolsDialog.py +++ b/ORStools/gui/ORStoolsDialog.py @@ -634,7 +634,7 @@ def _on_linetool_init(self) -> None: self.line_tool.pointDrawn.connect( lambda point, idx: self._on_linetool_map_click(point, idx) ) - self.line_tool.doubleClicked.connect(self._on_linetool_map_doubleclick) + self.line_tool.digitizationEnded.connect(self._on_linetool_digitization_ended) def _on_linetool_map_click(self, point: QgsPointXY, idx: int) -> None: """Adds an item to QgsListWidget and annotates the point in the map canvas""" @@ -666,16 +666,17 @@ def _reindex_list_items(self) -> None: annotation = self._linetool_annotate_point(point, idx, crs) self.project.annotationManager().addAnnotation(annotation) - def _on_linetool_map_doubleclick(self) -> None: + def _on_linetool_digitization_ended(self) -> None: """ Populate line list widget with coordinates, end line drawing and show dialog again. """ self.line_tool.pointDrawn.disconnect() - self.line_tool.doubleClicked.disconnect() + self.line_tool.digitizationEnded.disconnect() + self.line_tool = None + QApplication.restoreOverrideCursor() self._iface.mapCanvas().setMapTool(self.last_maptool) - self.line_tool = None self.show() def color_duplicate_items(self, list_widget): diff --git a/ORStools/gui/ORStoolsDialogUI.py b/ORStools/gui/ORStoolsDialogUI.py index cd01815..3b6beb8 100644 --- a/ORStools/gui/ORStoolsDialogUI.py +++ b/ORStools/gui/ORStoolsDialogUI.py @@ -484,7 +484,7 @@ def retranslateUi(self, ORStoolsDialogBase): self.routing_travel_label.setText(_translate("ORStoolsDialogBase", "Go with")) self.routing_travel_combo.setToolTip(_translate("ORStoolsDialogBase", "Mode of travel")) self.routing_preference_combo.setToolTip(_translate("ORStoolsDialogBase", "Preference")) - self.routing_fromline_map.setToolTip(_translate("ORStoolsDialogBase", "

Add wayoints interactively from the map canvas.

Double-click will terminate waypoint selection.

")) + self.routing_fromline_map.setToolTip(_translate("ORStoolsDialogBase", "

Add wayoints interactively from the map canvas.

The Escape key, right- or double-click will terminate waypoint selection.

")) self.routing_fromline_clear.setToolTip(_translate("ORStoolsDialogBase", "

If waypoints are selected in the list, only these will be deleted. Else all waypoints will be deleted.

")) self.routing_fromline_list.setToolTip(_translate("ORStoolsDialogBase", "Select waypoints from the map!")) self.save_vertices.setToolTip(_translate("ORStoolsDialogBase", "

Save points in list to layer. Use the processing algorithms (batch jobs) to work with points from layers.

")) diff --git a/ORStools/gui/ORStoolsDialogUI.ui b/ORStools/gui/ORStoolsDialogUI.ui index 68aa672..f8f1548 100644 --- a/ORStools/gui/ORStoolsDialogUI.ui +++ b/ORStools/gui/ORStoolsDialogUI.ui @@ -273,7 +273,7 @@ - <html><head/><body><p>Add wayoints interactively from the map canvas.</p><p>Double-click will terminate waypoint selection.</p></body></html> + <html><head/><body><p>Add wayoints interactively from the map canvas.</p><p>The Escape key, right- or double-click will terminate waypoint selection.</p></body></html> diff --git a/ORStools/i18n/orstools_de.ts b/ORStools/i18n/orstools_de.ts index 6dfcda0..2c24ecf 100644 --- a/ORStools/i18n/orstools_de.ts +++ b/ORStools/i18n/orstools_de.ts @@ -428,8 +428,8 @@ Duplikate entfernen oder Wegpunktoptimierung abwählen. - <html><head/><body><p>Add wayoints interactively from the map canvas.</p><p>Double-click will terminate waypoint selection.</p></body></html> - <html><head/><body><p>Wegpunkte aus Kartenansicht hinzufügen</p><p>Doppelklick beendet die Wegpunkt-Auswahl</p></body></html> + <html><head/><body><p>Add wayoints interactively from the map canvas.</p><p>The Escape key, right- or double-click will terminate waypoint selection.</p></body></html> + <html><head/><body><p>Wegpunkte aus Kartenansicht hinzufügen</p><p>Escape, Rechts- oder Doppelklick beendeen die Wegpunkt-Auswahl.</p></body></html> @@ -466,7 +466,7 @@ p, li { white-space: pre-wrap; } <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"> +</style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"> <p style=" padding: 10px; -qt-block-indent:0; text-indent:0px ; background-color:#e7f2fa; color: #999999"><img stype="margin: 10px" src=":/plugins/ORStools/img/icon_about.png" width=16 height=16 /> Sämtliche Einstellungen werden überschrieben</p></body></html> @@ -776,7 +776,7 @@ Duplikate entfernen oder Wegpunktoptimierung abwählen. Did you forget to set an <b>API key</b> for openrouteservice?<br><br> - If you don't have an API key, please visit https://openrouteservice.org/sign-up to get one. <br><br> + If you don't have an API key, please visit https://openrouteservice.org/sign-up to get one. <br><br> Then enter the API key for openrouteservice provider in Web ► ORS Tools ► Provider Settings or the settings symbol in the main ORS Tools GUI, next to the provider dropdown. Haben Sie einen <b>API-Key</b> für den openrouteservice gesetzt?<br><br> diff --git a/ORStools/utils/maptools.py b/ORStools/utils/maptools.py index 76b05ba..46011f9 100644 --- a/ORStools/utils/maptools.py +++ b/ORStools/utils/maptools.py @@ -30,7 +30,7 @@ from qgis.core import QgsWkbTypes from qgis.gui import QgsMapToolEmitPoint, QgsRubberBand -from qgis.PyQt.QtCore import pyqtSignal +from qgis.PyQt.QtCore import pyqtSignal, Qt from qgis.PyQt.QtGui import QColor from ORStools import DEFAULT_COLOR @@ -66,14 +66,22 @@ def reset(self): pointDrawn = pyqtSignal(["QgsPointXY", "int"]) + def keyPressEvent(self, event) -> None: + # Check if the pressed key is the Escape key + if event.key() == Qt.Key_Escape: + self.end_digitization() + def canvasReleaseEvent(self, e): """Add marker to canvas and shows line.""" - new_point = self.toMapCoordinates(e.pos()) - self.points.append(new_point) + if e.button() == Qt.RightButton: + self.end_digitization() + else: + new_point = self.toMapCoordinates(e.pos()) + self.points.append(new_point) - # noinspection PyUnresolvedReferences - self.pointDrawn.emit(new_point, self.points.index(new_point)) - self.showLine() + # noinspection PyUnresolvedReferences + self.pointDrawn.emit(new_point, self.points.index(new_point)) + self.showLine() def showLine(self): """Builds rubber band from all points and adds it to the map canvas.""" @@ -84,16 +92,19 @@ def showLine(self): self.rubberBand.addPoint(point, False) self.rubberBand.show() - doubleClicked = pyqtSignal() + digitizationEnded = pyqtSignal() # noinspection PyUnusedLocal def canvasDoubleClickEvent(self, e): """Ends line drawing and deletes rubber band and markers from map canvas.""" # noinspection PyUnresolvedReferences - self.doubleClicked.emit() - self.canvas.scene().removeItem(self.rubberBand) - del self.rubberBand + self.end_digitization() def deactivate(self): super(LineTool, self).deactivate() self.deactivated.emit() + + def end_digitization(self): + self.digitizationEnded.emit() + self.canvas.scene().removeItem(self.rubberBand) + del self.rubberBand diff --git a/tests/conftest.py b/tests/conftest.py index 78dcd20..d2ac028 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -12,6 +12,7 @@ s = QgsSettings() data = s.value("ORStools/config") + def pytest_sessionstart(session): """ Called after the Session object has been created and diff --git a/tests/test_gui.py b/tests/test_gui.py index b9b0372..4986b81 100644 --- a/tests/test_gui.py +++ b/tests/test_gui.py @@ -63,6 +63,4 @@ def test_ORStoolsDialog(self): dlg.line_tool.canvasDoubleClickEvent(map_dclick) self.assertTrue(dlg.isVisible()) - self.assertEqual( - dlg.routing_fromline_list.item(0).text(), "Point 0: -0.187575, 56.516620" - ) + self.assertEqual(dlg.routing_fromline_list.item(0).text(), "Point 0: -0.187575, 56.516620") diff --git a/tests/test_proc.py b/tests/test_proc.py index ebe9f3d..083da84 100644 --- a/tests/test_proc.py +++ b/tests/test_proc.py @@ -195,7 +195,9 @@ def test_export(self): export = ORSExportAlgo().create() dest_id = export.processAlgorithm(parameters, self.context, self.feedback) processed_layer = QgsProcessingUtils.mapLayerFromString(dest_id["OUTPUT"], self.context) - processed_nodes = QgsProcessingUtils.mapLayerFromString(dest_id["OUTPUT_POINT"], self.context) + processed_nodes = QgsProcessingUtils.mapLayerFromString( + dest_id["OUTPUT_POINT"], self.context + ) self.assertEqual(type(processed_layer), QgsVectorLayer) self.assertEqual(type(processed_nodes), QgsVectorLayer)