From bfb30ad32adc593258e679242d4f7ac99863292f Mon Sep 17 00:00:00 2001 From: Zsolt Kovari Date: Thu, 10 Oct 2024 11:50:24 +0200 Subject: [PATCH] handle child node --- .../plotlyst/view/widget/world/conceit.py | 26 +++++++++++++++++-- .../plotlyst/view/widget/world/editor.py | 9 +++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/main/python/plotlyst/view/widget/world/conceit.py b/src/main/python/plotlyst/view/widget/world/conceit.py index 31bb4db13..740c91af5 100644 --- a/src/main/python/plotlyst/view/widget/world/conceit.py +++ b/src/main/python/plotlyst/view/widget/world/conceit.py @@ -27,6 +27,7 @@ from plotlyst.common import recursive from plotlyst.core.domain import WorldConceit, WorldBuilding, WorldConceitType, Novel from plotlyst.service.persistence import RepositoryPersistenceManager +from plotlyst.view.common import fade_in from plotlyst.view.icons import IconRegistry from plotlyst.view.widget.input import TextEditBubbleWidget from plotlyst.view.widget.tree import ItemBasedNode, TreeSettings, ItemBasedTreeView, ContainerNode @@ -200,13 +201,34 @@ def _node(self, conceit: WorldConceit) -> ConceitNode: def _save(self): self.repo.update_world(self._novel) + def _addConceitUnder(self, parent: ConceitNode): + conceit = WorldConceit('Conceit', type=parent.item().type) + child = self._initNode(conceit) + parent.addChild(child) + fade_in(child) + + parent.item().children.append(conceit) + self._save() + + def _deleteConceit(self, node: ConceitNode): + conceit: WorldConceit = node.item() + if isinstance(node.parent().parent(), ConceitNode): + parent: ConceitNode = node.parent().parent() + parent.item().children.remove(conceit) + else: + self._novel.world.conceits.remove(conceit) + + self._deleteNode(node) + self.conceitDeleted.emit(conceit) + self._save() + @overrides def _initNode(self, conceit: WorldConceit) -> ConceitNode: node = ConceitNode(conceit, readOnly=self._readOnly, settings=self._settings) self._nodes[conceit] = node node.selectionChanged.connect(partial(self._selectionChanged, node)) - # node.added.connect(partial(self._addLocationUnder, node)) - # node.deleted.connect(partial(self._deleteLocation, node)) + node.added.connect(partial(self._addConceitUnder, node)) + node.deleted.connect(partial(self._deleteConceit, node)) # if not self._readOnly: # self._enhanceWithDnd(node) diff --git a/src/main/python/plotlyst/view/widget/world/editor.py b/src/main/python/plotlyst/view/widget/world/editor.py index 17e0cf95e..b978e7607 100644 --- a/src/main/python/plotlyst/view/widget/world/editor.py +++ b/src/main/python/plotlyst/view/widget/world/editor.py @@ -689,6 +689,7 @@ def __init__(self, novel: Novel, element: WorldBuildingEntityElement, parent=Non self._wdgEditor.layout().addWidget(self._splitter) self._wdgTree = ConceitsTreeView(novel) + self._wdgTree.conceitDeleted.connect(self._conceitNodeDeleted) self._wdgDisplay = QWidget() flow(self._wdgDisplay, 10, 8) self._splitter.addWidget(self._wdgTree) @@ -787,6 +788,14 @@ def _conceitRemoved(self, bubble: ConceitBubble): self._wdgTree.refresh() self.save() + def _conceitNodeDeleted(self, conceit: WorldConceit): + for i in range(self._wdgDisplay.layout().count()): + wdg = self._wdgDisplay.layout().itemAt(i).widget() + if wdg and isinstance(wdg, ConceitBubble): + if wdg.conceit == conceit: + fade_out_and_gc(self._wdgDisplay, wdg) + return + class SectionElementEditor(WorldBuildingEntityElementWidget): WORLD_BLOCK_MIMETYPE = 'application/world-block'