Skip to content

Commit

Permalink
Merge pull request #295 from gkahiu/fix_ncs_im_delete
Browse files Browse the repository at this point in the history
Sync Deletion of NCS Pathways in Implementation Models
  • Loading branch information
Samweli authored Nov 21, 2023
2 parents ea9267d + ee4fb07 commit baf7082
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 6 deletions.
37 changes: 33 additions & 4 deletions src/cplus_plugin/gui/component_item_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,19 +352,24 @@ def ncs_pathways(self) -> typing.List[NcsPathway]:
return [ncs_item.ncs_pathway for ncs_item in self.ncs_items]

def ncs_item_from_original_pathway(
self, ncs_pathway: NcsPathway
self, ncs_pathway: typing.Union[NcsPathway, str]
) -> typing.Union[NcsPathwayItem, None]:
"""Retrieves the NCS item corresponding to the original NCS
pathway i.e. before it is added to this implementation
model item.
:param ncs_pathway: Original NCS pathway data model.
:type ncs_pathway: NcsPathway
:param ncs_pathway: Original NCS pathway data model or
unique identifier of the NCS pathway.
:type ncs_pathway: NcsPathway, str
:returns: The matching NCS pathway item in this implementation
model item, else None if there is no matching item.
"""
ncs_uuid = str(ncs_pathway.uuid)
if isinstance(ncs_pathway, NcsPathway):
ncs_uuid = str(ncs_pathway.uuid)
else:
ncs_uuid = ncs_pathway

if ncs_uuid not in self._uuid_remap:
return None

Expand Down Expand Up @@ -1209,6 +1214,10 @@ def update_ncs_pathway_items(self, ncs_pathway: NcsPathway) -> bool:
If the NCS pathway model is not valid then the NCS pathway items
in the implementation model item will not be updated.
:param ncs_pathway: Original NCS pathway object whose corresponding
models are to be updated.
:type ncs_pathway: NcsPathway
:returns: True if matching NCS pathway items have been updated,
else False.
:rtype: bool
Expand All @@ -1228,6 +1237,26 @@ def update_ncs_pathway_items(self, ncs_pathway: NcsPathway) -> bool:

return True

def remove_ncs_pathway_items(self, ncs_pathway_uuid: str):
"""Delete NCS pathway items matching the given NCS pathway model.
If the NCS pathway model is not valid then the NCS pathway items
in the implementation model item will not be deleted.
:param ncs_pathway_uuid: Unique identifier of the NCS pathway object
whose corresponding models are to be removed in the implementation
models.
:type ncs_pathway_uuid: str
"""
for im_item in self.model_items():
ncs_item_for_original = im_item.ncs_item_from_original_pathway(
ncs_pathway_uuid
)
if ncs_item_for_original is None:
continue

status = self.remove_ncs_pathway_item(ncs_item_for_original.uuid, im_item)

def remove_implementation_model(self, uuid_str: str) -> bool:
"""Remove an implementation model item from the model.
Expand Down
9 changes: 9 additions & 0 deletions src/cplus_plugin/gui/implementation_model_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def __init__(

settings_manager.settings_updated[str, object].connect(self.on_settings_changed)
self.ncs_pathway_view.ncs_pathway_updated.connect(self.on_ncs_pathway_updated)
self.ncs_pathway_view.ncs_pathway_removed.connect(self.on_ncs_pathway_removed)
self.ncs_pathway_view.items_reloaded.connect(self._on_ncs_pathways_reloaded)

self.load()
Expand Down Expand Up @@ -125,6 +126,14 @@ def on_ncs_pathway_updated(self, ncs_pathway: NcsPathway):
"""Slot raised when an NCS pathway has been updated."""
self.implementation_model_view.update_ncs_pathway_items(ncs_pathway)

def on_ncs_pathway_removed(self, ncs_pathway_uuid: str):
"""Slot raised when an NCS pathway has been removed.
:param ncs_pathway_uuid: Unique identified of the removed NCS pathway item.
:type ncs_pathway_uuid: str
"""
self.implementation_model_view.remove_ncs_pathway_items(ncs_pathway_uuid)

def enable_default_items(self, enable: bool):
"""Enable or disable default NCS pathway and implementation model items.
Expand Down
17 changes: 15 additions & 2 deletions src/cplus_plugin/gui/model_component_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ class NcsComponentWidget(ModelComponentWidget):
"""Widget for displaying and managing NCS pathways."""

ncs_pathway_updated = QtCore.pyqtSignal(NcsPathway)
ncs_pathway_removed = QtCore.pyqtSignal(str)
items_reloaded = QtCore.pyqtSignal()

def __init__(self, parent=None):
Expand Down Expand Up @@ -443,8 +444,9 @@ def _on_remove_item(self):
ncs = selected_items[0].ncs_pathway

msg = self.tr(
f"Do you want to remove '{ncs.name}'?\nClick Yes to "
f"proceed or No to cancel."
f"Do you want to remove '{ncs.name}'? The corresponding "
f"NCS pathways used in the implementation models will "
f"also be removed.\nClick Yes to proceed or No to cancel."
)

if (
Expand All @@ -457,6 +459,7 @@ def _on_remove_item(self):
== QtWidgets.QMessageBox.Yes
):
self.item_model.remove_ncs_pathway(str(ncs.uuid))
self.ncs_pathway_removed.emit(str(ncs.uuid))
settings_manager.remove_ncs_pathway(str(ncs.uuid))
self.clear_description()

Expand Down Expand Up @@ -806,3 +809,13 @@ def update_ncs_pathway_items(self, ncs_pathway: NcsPathway) -> bool:
:rtype: bool
"""
return self.item_model.update_ncs_pathway_items(ncs_pathway)

def remove_ncs_pathway_items(self, ncs_pathway_uuid: str):
"""Delete NCS pathway items used for IMs that are linked to the
given NCS pathway.
:param ncs_pathway_uuid: NCS pathway whose corresponding items will be
deleted in the implementation model items that contain it.
:type ncs_pathway_uuid: str
"""
self.item_model.remove_ncs_pathway_items(ncs_pathway_uuid)

0 comments on commit baf7082

Please sign in to comment.