Skip to content

Commit

Permalink
Merge pull request #290 from gkahiu/editor_double_click
Browse files Browse the repository at this point in the history
Item Editor on Double Click
  • Loading branch information
Samweli authored Nov 21, 2023
2 parents 2f281a4 + 7d33a28 commit ea9267d
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 6 deletions.
56 changes: 54 additions & 2 deletions src/cplus_plugin/gui/model_component_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -209,6 +211,35 @@ 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.
:param index: Index of the clicked item.
:type index: QtCore.QModelIndex
"""
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)
Expand Down Expand Up @@ -371,11 +402,21 @@ 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.
: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):
"""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
)
Expand Down Expand Up @@ -559,11 +600,22 @@ 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.
: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):
"""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
)
Expand Down
25 changes: 21 additions & 4 deletions src/cplus_plugin/gui/qgis_cplus_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -620,16 +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
layer = settings_manager.find_layer_by_name(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.UserRole)
self._show_priority_layer_editor(layer_name)

def _show_priority_layer_editor(self, layer_identifier: str):
"""Shows the dialog for editing a priority layer."""
layer_uuid = uuid.UUID(layer_identifier)
layer = settings_manager.get_priority_layer(layer_uuid)
layer_dialog = PriorityLayerDialog(layer)
layer_dialog.exec_()

Expand Down

0 comments on commit ea9267d

Please sign in to comment.