From c5e914f7a689e31c9b06a6bc036e277134305f16 Mon Sep 17 00:00:00 2001 From: Kahiu Date: Tue, 14 Nov 2023 13:58:16 +0300 Subject: [PATCH 1/5] Enable double-clicking to edit for NCS pathway and IM items. --- .../gui/model_component_widget.py | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/src/cplus_plugin/gui/model_component_widget.py b/src/cplus_plugin/gui/model_component_widget.py index 1564a28f1..41c53bc68 100644 --- a/src/cplus_plugin/gui/model_component_widget.py +++ b/src/cplus_plugin/gui/model_component_widget.py @@ -51,6 +51,8 @@ def __init__(self, parent=None, item_model=None): if self._item_model is not None: self.item_model = self._item_model + self.lst_model_items.doubleClicked.connect(self._on_double_click_item) + add_icon = FileUtils.get_icon("symbologyAdd.svg") self.btn_add.setIcon(add_icon) self.btn_add.clicked.connect(self._on_add_item) @@ -209,6 +211,31 @@ def _on_selection_changed( """ self._update_ui_on_selection_changed() + def _on_double_click_item(self, index: QtCore.QModelIndex): + """Slot raised when an item has been double-clicked.""" + if self._item_model is None: + return + + item = self._item_model.itemFromIndex(index) + if item is None: + return + + if not item.isEnabled(): + return + + self._handle_double_click(item) + + def _handle_double_click(self, item: ModelComponentItemType): + """Handle double-clicking of an item. + + To be implemented by sub-classes. + + :param item: Model component item that has received the + double click event. + :type item: ModelComponentItem + """ + pass + def _update_ui_on_selection_changed(self): """Update UI properties on selection changed.""" self.btn_remove.setEnabled(True) @@ -371,11 +398,17 @@ def _on_edit_item(self): return item = selected_items[0] + self._edit_ncs_pathway_item(item) + def _handle_double_click(self, item: NcsPathwayItem): + """Show editor dialog.""" + self._edit_ncs_pathway_item(item) + + def _edit_ncs_pathway_item(self, item: NcsPathwayItem): + """Shows dialog for editing an item.""" # If editing, remove the current name of the model component excluded_names = self.model_names() excluded_names.remove(item.model_component.name.lower()) - ncs_editor = NcsPathwayEditorDialog( self, item.ncs_pathway, excluded_names=excluded_names ) @@ -559,11 +592,17 @@ def _on_edit_item(self): return item = selected_items[0] + self._edit_implementation_model_item(item) + def _handle_double_click(self, item: ImplementationModelItem): + """Show dialog for editing implementation model.""" + self._edit_implementation_model_item(item) + + def _edit_implementation_model_item(self, item): + """Load dialog for editing implementation model.""" # If editing, remove the current name of the model component excluded_names = self.model_names() excluded_names.remove(item.model_component.name.lower()) - editor = ImplementationModelEditorDialog( self, item.implementation_model, excluded_names=excluded_names ) From c7c948958ac98dcb54e28122ee4c5fab196228ff Mon Sep 17 00:00:00 2001 From: Kahiu Date: Wed, 15 Nov 2023 09:25:44 +0300 Subject: [PATCH 2/5] Enable double-clicking to edit priority layer items. --- src/cplus_plugin/gui/qgis_cplus_main.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/cplus_plugin/gui/qgis_cplus_main.py b/src/cplus_plugin/gui/qgis_cplus_main.py index dc6784f0d..dc10f4b6a 100644 --- a/src/cplus_plugin/gui/qgis_cplus_main.py +++ b/src/cplus_plugin/gui/qgis_cplus_main.py @@ -203,6 +203,10 @@ def prepare_input(self): self.edit_pwl_btn.clicked.connect(self.edit_priority_layer) self.remove_pwl_btn.clicked.connect(self.remove_priority_layer) + self.priority_layers_list.itemDoubleClicked.connect( + self._on_double_click_priority_layer + ) + # Add priority groups list into the groups frame self.priority_groups_list = CustomTreeWidget() @@ -621,12 +625,23 @@ def edit_priority_layer(self): current_text = self.priority_layers_list.currentItem().data( QtCore.Qt.DisplayRole ) + if current_text == "": self.show_message( tr("Could not fetch the selected priority layer for editing."), Qgis.Critical, ) return + + self._show_priority_layer_editor(current_text) + + def _on_double_click_priority_layer(self, list_item: QtWidgets.QListWidgetItem): + """Slot raised when a priority list item has been double clicked.""" + layer_name = list_item.text() + self._show_priority_layer_editor(layer_name) + + def _show_priority_layer_editor(self, current_text): + """Shows the dialog for editing a priority layer.""" layer = settings_manager.find_layer_by_name(current_text) layer_dialog = PriorityLayerDialog(layer) layer_dialog.exec_() From 62b79c17b80e4e252b6ed2ef5c6313ce5169e3ff Mon Sep 17 00:00:00 2001 From: Kahiu Date: Thu, 16 Nov 2023 11:50:28 +0300 Subject: [PATCH 3/5] Add docstrings. --- .../gui/model_component_widget.py | 19 ++++++++++++++++--- src/cplus_plugin/lib/extent_check.py | 4 ++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/cplus_plugin/gui/model_component_widget.py b/src/cplus_plugin/gui/model_component_widget.py index 41c53bc68..065c5d4fe 100644 --- a/src/cplus_plugin/gui/model_component_widget.py +++ b/src/cplus_plugin/gui/model_component_widget.py @@ -212,7 +212,11 @@ def _on_selection_changed( self._update_ui_on_selection_changed() def _on_double_click_item(self, index: QtCore.QModelIndex): - """Slot raised when an item has been double-clicked.""" + """Slot raised when an item has been double-clicked. + + :param index: Index of the clicked item. + :type index: QtCore.QModelIndex + """ if self._item_model is None: return @@ -401,7 +405,11 @@ def _on_edit_item(self): self._edit_ncs_pathway_item(item) def _handle_double_click(self, item: NcsPathwayItem): - """Show editor dialog.""" + """Show editor dialog. + + :param item: NCS pathway item receiving the event. + :type item: NcsPathwayItem + """ self._edit_ncs_pathway_item(item) def _edit_ncs_pathway_item(self, item: NcsPathwayItem): @@ -595,7 +603,12 @@ def _on_edit_item(self): self._edit_implementation_model_item(item) def _handle_double_click(self, item: ImplementationModelItem): - """Show dialog for editing implementation model.""" + """Show dialog for editing implementation model. + + :param item: Implementation model item that has received the + event. + :type item: ImplementationModelItem + """ self._edit_implementation_model_item(item) def _edit_implementation_model_item(self, item): diff --git a/src/cplus_plugin/lib/extent_check.py b/src/cplus_plugin/lib/extent_check.py index c81874bc3..e7b7947bb 100644 --- a/src/cplus_plugin/lib/extent_check.py +++ b/src/cplus_plugin/lib/extent_check.py @@ -28,10 +28,14 @@ def extent_within_pilot(new_extent: QgsRectangle) -> bool: extent_list[0], extent_list[2], extent_list[1], extent_list[3] ) + print(pilot_extent.toString()) + print(new_extent.toString()) + default_crs = QgsCoordinateReferenceSystem.fromEpsgId(DEFAULT_CRS_ID) project_crs = QgsProject.instance().crs() if default_crs != project_crs: + print("Projections are different") coordinate_xform = QgsCoordinateTransform( default_crs, project_crs, QgsProject.instance() ) From 533da76bdb080193a3339e6dfab6b19a0e20e199 Mon Sep 17 00:00:00 2001 From: Kahiu Date: Fri, 17 Nov 2023 15:16:50 +0300 Subject: [PATCH 4/5] Use display role for PWL item. --- src/cplus_plugin/gui/qgis_cplus_main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cplus_plugin/gui/qgis_cplus_main.py b/src/cplus_plugin/gui/qgis_cplus_main.py index c206ecc35..93366dce7 100644 --- a/src/cplus_plugin/gui/qgis_cplus_main.py +++ b/src/cplus_plugin/gui/qgis_cplus_main.py @@ -639,7 +639,7 @@ def edit_priority_layer(self): def _on_double_click_priority_layer(self, list_item: QtWidgets.QListWidgetItem): """Slot raised when a priority list item has been double clicked.""" - layer_name = list_item.text() + layer_name = list_item.data(QtCore.Qt.DisplayRole) self._show_priority_layer_editor(layer_name) def _show_priority_layer_editor(self, current_text): From 7d33a286bd549d2c78f4e72102b8e9ef15f6f4d4 Mon Sep 17 00:00:00 2001 From: Kahiu Date: Fri, 17 Nov 2023 15:53:43 +0300 Subject: [PATCH 5/5] Use PWL uuid to fetch item. --- src/cplus_plugin/gui/qgis_cplus_main.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/cplus_plugin/gui/qgis_cplus_main.py b/src/cplus_plugin/gui/qgis_cplus_main.py index 93366dce7..209c41468 100644 --- a/src/cplus_plugin/gui/qgis_cplus_main.py +++ b/src/cplus_plugin/gui/qgis_cplus_main.py @@ -624,27 +624,29 @@ def edit_priority_layer(self): Qgis.Critical, ) return - current_text = self.priority_layers_list.currentItem().data( - QtCore.Qt.DisplayRole + + layer_identifier = self.priority_layers_list.currentItem().data( + QtCore.Qt.UserRole ) - if current_text == "": + if layer_identifier == "": self.show_message( tr("Could not fetch the selected priority layer for editing."), Qgis.Critical, ) return - self._show_priority_layer_editor(current_text) + self._show_priority_layer_editor(layer_identifier) def _on_double_click_priority_layer(self, list_item: QtWidgets.QListWidgetItem): """Slot raised when a priority list item has been double clicked.""" - layer_name = list_item.data(QtCore.Qt.DisplayRole) + layer_name = list_item.data(QtCore.Qt.UserRole) self._show_priority_layer_editor(layer_name) - def _show_priority_layer_editor(self, current_text): + def _show_priority_layer_editor(self, layer_identifier: str): """Shows the dialog for editing a priority layer.""" - layer = settings_manager.find_layer_by_name(current_text) + layer_uuid = uuid.UUID(layer_identifier) + layer = settings_manager.get_priority_layer(layer_uuid) layer_dialog = PriorityLayerDialog(layer) layer_dialog.exec_()