Skip to content

Commit 0910624

Browse files
committed
refactor: remove non-functional attribute
Functionality related to the differentiation between single/double-click is handled by the dialog being visible via self.dlg.isVisible().
1 parent ae9674b commit 0910624

File tree

1 file changed

+72
-74
lines changed

1 file changed

+72
-74
lines changed

ORStools/utils/maptools.py

Lines changed: 72 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ def __init__(self, dlg):
7777
self.dlg.routing_preference_combo.currentIndexChanged.connect(self._toggle_preview)
7878
self.dlg.routing_travel_combo.currentIndexChanged.connect(self._toggle_preview)
7979

80-
self.last_click = "single-click"
8180
self.dragging_vertex = None
8281
self.moved_idxs = 0
8382
self.error_idxs = 0
@@ -175,95 +174,94 @@ def canvasReleaseEvent(self, event: QEvent) -> None:
175174
point = self.toMapCoordinates(event.pos())
176175
self.points.append(point)
177176

178-
if self.last_click == "single-click":
179-
if self.dragging_vertex:
180-
try:
177+
if self.dragging_vertex:
178+
try:
179+
self.dragging_vertex = False
180+
QApplication.restoreOverrideCursor()
181+
crs = self.dlg.canvas.mapSettings().destinationCrs()
182+
183+
annotation = self.dlg._linetool_annotate_point(point, self.move_i, crs=crs)
184+
self.dlg.annotations.insert(self.move_i, annotation)
185+
self.dlg.project.annotationManager().addAnnotation(annotation)
186+
187+
transformer = transform.transformToWGS(crs)
188+
point_wgs = transformer.transform(point)
189+
190+
items = [
191+
self.dlg.routing_fromline_list.item(x).text()
192+
for x in range(self.dlg.routing_fromline_list.count())
193+
]
194+
backup = items.copy()
195+
items[self.move_i] = (
196+
f"Point {self.move_i}: {point_wgs.x():.6f}, {point_wgs.y():.6f}"
197+
)
198+
199+
self.dlg.routing_fromline_list.clear()
200+
for i, x in enumerate(items):
201+
coords = x.split(":")[1]
202+
item = f"Point {i}:{coords}"
203+
self.dlg.routing_fromline_list.addItem(item)
204+
self.create_rubber_band()
205+
self.save_last_point(point, annotation)
206+
except ApiError as e:
207+
if self.get_error_code(e) == 2010:
181208
self.dragging_vertex = False
182-
QApplication.restoreOverrideCursor()
183-
crs = self.dlg.canvas.mapSettings().destinationCrs()
184-
185-
annotation = self.dlg._linetool_annotate_point(point, self.move_i, crs=crs)
186-
self.dlg.annotations.insert(self.move_i, annotation)
187-
self.dlg.project.annotationManager().addAnnotation(annotation)
188-
189-
transformer = transform.transformToWGS(crs)
190-
point_wgs = transformer.transform(point)
191-
192-
items = [
193-
self.dlg.routing_fromline_list.item(x).text()
194-
for x in range(self.dlg.routing_fromline_list.count())
195-
]
196-
backup = items.copy()
197-
items[self.move_i] = (
198-
f"Point {self.move_i}: {point_wgs.x():.6f}, {point_wgs.y():.6f}"
199-
)
200-
201209
self.dlg.routing_fromline_list.clear()
202210
for i, x in enumerate(items):
203211
coords = x.split(":")[1]
204212
item = f"Point {i}:{coords}"
205213
self.dlg.routing_fromline_list.addItem(item)
206-
self.create_rubber_band()
207-
self.save_last_point(point, annotation)
208-
except ApiError as e:
209-
if self.get_error_code(e) == 2010:
214+
self.dlg._reindex_list_items()
215+
self.radius_message_box(e)
216+
else:
217+
raise e
218+
except Exception as e:
219+
if "Connection refused" in str(e):
220+
self.api_key_message_bar()
221+
else:
222+
raise e
223+
# Not moving release
224+
else:
225+
try:
226+
if not self.dlg.isVisible():
227+
self.idx -= self.error_idxs
228+
self.dlg.create_vertex(point, self.idx)
229+
self.idx += 1
230+
self.error_idxs = 0
231+
232+
if self.dlg.routing_fromline_list.count() > 1:
233+
self.create_rubber_band()
210234
self.dragging_vertex = False
235+
except ApiError as e:
236+
if self.get_error_code(e) == 2010:
237+
self.error_idxs += 1
238+
num = len(self.dlg.routing_fromline_list) - 1
239+
240+
if num < 2:
211241
self.dlg.routing_fromline_list.clear()
212-
for i, x in enumerate(backup):
213-
coords = x.split(":")[1]
214-
item = f"Point {i}:{coords}"
215-
self.dlg.routing_fromline_list.addItem(item)
216-
self.dlg._reindex_list_items()
217-
self.radius_message_box(e)
218-
else:
219-
raise e
220-
except Exception as e:
221-
if "Connection refused" in str(e):
222-
self.api_key_message_bar()
242+
self.dlg._clear_annotations()
223243
else:
224-
raise e
225-
# Not moving release
226-
else:
227-
try:
228-
if not self.dlg.isVisible():
229-
self.idx -= self.error_idxs
230-
self.dlg.create_vertex(point, self.idx)
231-
self.idx += 1
232-
self.error_idxs = 0
233-
234-
if self.dlg.routing_fromline_list.count() > 1:
235-
self.create_rubber_band()
236-
self.dragging_vertex = False
237-
except ApiError as e:
238-
if self.get_error_code(e) == 2010:
239-
self.error_idxs += 1
240-
num = len(self.dlg.routing_fromline_list) - 1
241-
242-
if num < 2:
243-
self.dlg.routing_fromline_list.clear()
244-
self.dlg._clear_annotations()
245-
else:
246-
self.dlg.routing_fromline_list.takeItem(num)
247-
self.dlg._reindex_list_items()
248-
self.create_rubber_band()
249-
250-
self.radius_message_box(e)
251-
else:
252-
raise e
253-
except Exception as e:
254-
if "Connection refused" in str(e):
255-
self.api_key_message_bar()
256-
else:
257-
raise e
244+
self.dlg.routing_fromline_list.takeItem(num)
245+
self.dlg._reindex_list_items()
246+
self.create_rubber_band()
247+
248+
self.radius_message_box(e)
249+
else:
250+
raise e
251+
except Exception as e:
252+
if "Connection refused" in str(e):
253+
self.api_key_message_bar()
254+
else:
255+
raise e
258256

259-
self.last_click = "single-click"
260257

261258
def canvasDoubleClickEvent(self, e: QEvent) -> None:
262259
"""
263260
Populate line list widget with coordinates, end point moving and show dialog again.
264261
"""
265262
self.dlg.show()
266-
self.last_click = "double-click"
263+
# not resetting the cursor (and thus the cursor icon still being "+") suggest that you can still set points, which you can't.
264+
# Thus, we should set another, different cursor icon here?
267265

268266
def create_rubber_band(self) -> None:
269267
if self.dlg.optimization_group.isChecked() and self.dlg.routing_fromline_list.count() == 2:

0 commit comments

Comments
 (0)