Skip to content

Commit

Permalink
handle child node
Browse files Browse the repository at this point in the history
  • Loading branch information
zkovari committed Oct 10, 2024
1 parent 814b564 commit bfb30ad
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/main/python/plotlyst/view/widget/world/conceit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions src/main/python/plotlyst/view/widget/world/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit bfb30ad

Please sign in to comment.