Skip to content

Commit 42cad6c

Browse files
merydiankoebi
andauthored
feat: exit digitization on right click and ESC button (#286)
Co-authored-by: Jakob Schnell <Jakob.Schnell@heigit.org>
1 parent 8497c67 commit 42cad6c

File tree

9 files changed

+40
-24
lines changed

9 files changed

+40
-24
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ RELEASING:
4242

4343
## Unreleased
4444

45+
### Added
46+
- Exit digitization on right click or Escape key press ([#285](https://github.com/GIScience/orstools-qgis-plugin/issues/285))
47+
4548
## [1.9.0] - 2024-10-29
4649

4750
### Fixed

ORStools/gui/ORStoolsDialog.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ def _on_linetool_init(self) -> None:
634634
self.line_tool.pointDrawn.connect(
635635
lambda point, idx: self._on_linetool_map_click(point, idx)
636636
)
637-
self.line_tool.doubleClicked.connect(self._on_linetool_map_doubleclick)
637+
self.line_tool.digitizationEnded.connect(self._on_linetool_digitization_ended)
638638

639639
def _on_linetool_map_click(self, point: QgsPointXY, idx: int) -> None:
640640
"""Adds an item to QgsListWidget and annotates the point in the map canvas"""
@@ -666,16 +666,17 @@ def _reindex_list_items(self) -> None:
666666
annotation = self._linetool_annotate_point(point, idx, crs)
667667
self.project.annotationManager().addAnnotation(annotation)
668668

669-
def _on_linetool_map_doubleclick(self) -> None:
669+
def _on_linetool_digitization_ended(self) -> None:
670670
"""
671671
Populate line list widget with coordinates, end line drawing and show dialog again.
672672
"""
673673

674674
self.line_tool.pointDrawn.disconnect()
675-
self.line_tool.doubleClicked.disconnect()
675+
self.line_tool.digitizationEnded.disconnect()
676+
self.line_tool = None
677+
676678
QApplication.restoreOverrideCursor()
677679
self._iface.mapCanvas().setMapTool(self.last_maptool)
678-
self.line_tool = None
679680
self.show()
680681

681682
def color_duplicate_items(self, list_widget):

ORStools/gui/ORStoolsDialogUI.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ def retranslateUi(self, ORStoolsDialogBase):
484484
self.routing_travel_label.setText(_translate("ORStoolsDialogBase", "Go with"))
485485
self.routing_travel_combo.setToolTip(_translate("ORStoolsDialogBase", "Mode of travel"))
486486
self.routing_preference_combo.setToolTip(_translate("ORStoolsDialogBase", "Preference"))
487-
self.routing_fromline_map.setToolTip(_translate("ORStoolsDialogBase", "<html><head/><body><p>Add wayoints interactively from the map canvas.</p><p>Double-click will terminate waypoint selection.</p></body></html>"))
487+
self.routing_fromline_map.setToolTip(_translate("ORStoolsDialogBase", "<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>"))
488488
self.routing_fromline_clear.setToolTip(_translate("ORStoolsDialogBase", "<html><head/><body><p>If waypoints are selected in the list, only these will be deleted. Else all waypoints will be deleted.</p></body></html>"))
489489
self.routing_fromline_list.setToolTip(_translate("ORStoolsDialogBase", "Select waypoints from the map!"))
490490
self.save_vertices.setToolTip(_translate("ORStoolsDialogBase", "<html><head/><body><p>Save points in list to layer. Use the processing algorithms (batch jobs) to work with points from layers.</p></body></html>"))

ORStools/gui/ORStoolsDialogUI.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@
273273
</sizepolicy>
274274
</property>
275275
<property name="toolTip">
276-
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Add wayoints interactively from the map canvas.&lt;/p&gt;&lt;p&gt;Double-click will terminate waypoint selection.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
276+
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Add wayoints interactively from the map canvas.&lt;/p&gt;&lt;p&gt;The Escape key, right- or double-click will terminate waypoint selection.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
277277
</property>
278278
<property name="text">
279279
<string/>

ORStools/i18n/orstools_de.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,8 @@ Duplikate entfernen oder Wegpunktoptimierung abwählen.</translation>
428428
</message>
429429
<message>
430430
<location filename="../gui/ORStoolsDialogUI.ui" line="276"/>
431-
<source>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Add wayoints interactively from the map canvas.&lt;/p&gt;&lt;p&gt;Double-click will terminate waypoint selection.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</source>
432-
<translation>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Wegpunkte aus Kartenansicht hinzufügen&lt;/p&gt;&lt;p&gt;Doppelklick beendet die Wegpunkt-Auswahl&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</translation>
431+
<source>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Add wayoints interactively from the map canvas.&lt;/p&gt;&lt;p&gt;The Escape key, right- or double-click will terminate waypoint selection.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</source>
432+
<translation>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Wegpunkte aus Kartenansicht hinzufügen&lt;/p&gt;&lt;p&gt;Escape, Rechts- oder Doppelklick beendeen die Wegpunkt-Auswahl.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</translation>
433433
</message>
434434
<message>
435435
<location filename="../gui/ORStoolsDialogUI.ui" line="296"/>
@@ -466,7 +466,7 @@ p, li { white-space: pre-wrap; }
466466
<translation>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
467467
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
468468
p, li { white-space: pre-wrap; }
469-
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;&quot;&gt;
469+
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:&apos;Ubuntu&apos;; font-size:11pt; font-weight:400; font-style:normal;&quot;&gt;
470470
&lt;p style=&quot; padding: 10px; -qt-block-indent:0; text-indent:0px ; background-color:#e7f2fa; color: #999999&quot;&gt;&lt;img stype=&quot;margin: 10px&quot; src=&quot;:/plugins/ORStools/img/icon_about.png&quot; width=16 height=16 /&gt; Sämtliche Einstellungen werden überschrieben&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</translation>
471471
</message>
472472
<message>
@@ -776,7 +776,7 @@ Duplikate entfernen oder Wegpunktoptimierung abwählen.</translation>
776776
<source>
777777
Did you forget to set an &lt;b&gt;API key&lt;/b&gt; for openrouteservice?&lt;br&gt;&lt;br&gt;
778778

779-
If you don't have an API key, please visit https://openrouteservice.org/sign-up to get one. &lt;br&gt;&lt;br&gt;
779+
If you don&apos;t have an API key, please visit https://openrouteservice.org/sign-up to get one. &lt;br&gt;&lt;br&gt;
780780
Then enter the API key for openrouteservice provider in Web ► ORS Tools ► Provider Settings or the
781781
settings symbol in the main ORS Tools GUI, next to the provider dropdown.</source>
782782
<translation>Haben Sie einen &lt;b&gt;API-Key&lt;/b&gt; für den openrouteservice gesetzt?&lt;br&gt;&lt;br&gt;

ORStools/utils/maptools.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from qgis.core import QgsWkbTypes
3131
from qgis.gui import QgsMapToolEmitPoint, QgsRubberBand
3232

33-
from qgis.PyQt.QtCore import pyqtSignal
33+
from qgis.PyQt.QtCore import pyqtSignal, Qt
3434
from qgis.PyQt.QtGui import QColor
3535

3636
from ORStools import DEFAULT_COLOR
@@ -66,14 +66,22 @@ def reset(self):
6666

6767
pointDrawn = pyqtSignal(["QgsPointXY", "int"])
6868

69+
def keyPressEvent(self, event) -> None:
70+
# Check if the pressed key is the Escape key
71+
if event.key() == Qt.Key_Escape:
72+
self.end_digitization()
73+
6974
def canvasReleaseEvent(self, e):
7075
"""Add marker to canvas and shows line."""
71-
new_point = self.toMapCoordinates(e.pos())
72-
self.points.append(new_point)
76+
if e.button() == Qt.RightButton:
77+
self.end_digitization()
78+
else:
79+
new_point = self.toMapCoordinates(e.pos())
80+
self.points.append(new_point)
7381

74-
# noinspection PyUnresolvedReferences
75-
self.pointDrawn.emit(new_point, self.points.index(new_point))
76-
self.showLine()
82+
# noinspection PyUnresolvedReferences
83+
self.pointDrawn.emit(new_point, self.points.index(new_point))
84+
self.showLine()
7785

7886
def showLine(self):
7987
"""Builds rubber band from all points and adds it to the map canvas."""
@@ -84,16 +92,19 @@ def showLine(self):
8492
self.rubberBand.addPoint(point, False)
8593
self.rubberBand.show()
8694

87-
doubleClicked = pyqtSignal()
95+
digitizationEnded = pyqtSignal()
8896

8997
# noinspection PyUnusedLocal
9098
def canvasDoubleClickEvent(self, e):
9199
"""Ends line drawing and deletes rubber band and markers from map canvas."""
92100
# noinspection PyUnresolvedReferences
93-
self.doubleClicked.emit()
94-
self.canvas.scene().removeItem(self.rubberBand)
95-
del self.rubberBand
101+
self.end_digitization()
96102

97103
def deactivate(self):
98104
super(LineTool, self).deactivate()
99105
self.deactivated.emit()
106+
107+
def end_digitization(self):
108+
self.digitizationEnded.emit()
109+
self.canvas.scene().removeItem(self.rubberBand)
110+
del self.rubberBand

tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
s = QgsSettings()
1313
data = s.value("ORStools/config")
1414

15+
1516
def pytest_sessionstart(session):
1617
"""
1718
Called after the Session object has been created and

tests/test_gui.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,4 @@ def test_ORStoolsDialog(self):
6363
dlg.line_tool.canvasDoubleClickEvent(map_dclick)
6464

6565
self.assertTrue(dlg.isVisible())
66-
self.assertEqual(
67-
dlg.routing_fromline_list.item(0).text(), "Point 0: -0.187575, 56.516620"
68-
)
66+
self.assertEqual(dlg.routing_fromline_list.item(0).text(), "Point 0: -0.187575, 56.516620")

tests/test_proc.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,9 @@ def test_export(self):
195195
export = ORSExportAlgo().create()
196196
dest_id = export.processAlgorithm(parameters, self.context, self.feedback)
197197
processed_layer = QgsProcessingUtils.mapLayerFromString(dest_id["OUTPUT"], self.context)
198-
processed_nodes = QgsProcessingUtils.mapLayerFromString(dest_id["OUTPUT_POINT"], self.context)
198+
processed_nodes = QgsProcessingUtils.mapLayerFromString(
199+
dest_id["OUTPUT_POINT"], self.context
200+
)
199201

200202
self.assertEqual(type(processed_layer), QgsVectorLayer)
201203
self.assertEqual(type(processed_nodes), QgsVectorLayer)

0 commit comments

Comments
 (0)