diff options
author | brenda-br | 2023-02-12 17:01:23 +0530 |
---|---|---|
committer | brenda-br | 2023-02-12 17:01:23 +0530 |
commit | e2a3e90d7b48196d7efee5330e60298f3270356e (patch) | |
tree | 6f3f2e25b26dc054b305060079f692502a285248 /src/main | |
parent | d44ab6e457741c9759efe51cf7e9c29c82221440 (diff) | |
download | Chemical-PFD-e2a3e90d7b48196d7efee5330e60298f3270356e.tar.gz Chemical-PFD-e2a3e90d7b48196d7efee5330e60298f3270356e.tar.bz2 Chemical-PFD-e2a3e90d7b48196d7efee5330e60298f3270356e.zip |
Fix #29 Redo Action Node Lines connected to parent item
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/python/utils/undo.py | 50 |
1 files changed, 38 insertions, 12 deletions
diff --git a/src/main/python/utils/undo.py b/src/main/python/utils/undo.py index ea41d0b..c044eab 100644 --- a/src/main/python/utils/undo.py +++ b/src/main/python/utils/undo.py @@ -27,19 +27,46 @@ class addCommand(QUndoCommand): self.scene = scene self.diagramItem = addItem self.itemPos = addItem.pos() + if(issubclass(self.diagramItem.__class__,shapes.Line)): + self.startGrip = addItem.startGripItem.parentItem() + self.endGrip = addItem.endGripItem.parentItem() + self.indexLGS,self.indexLGE = self.findLGIndex() self.setText(f"Add {objectName(self.diagramItem)} at {self.itemPos.x()}, {self.itemPos.y()}") def undo(self): - self.scene.removeItem(self.diagramItem) - self.scene.update() - self.scene.advance() + if self.diagramItem in self.scene.items(): + self.scene.removeItem(self.diagramItem) + self.scene.update() + self.scene.advance() def redo(self): - self.scene.addItem(self.diagramItem) - self.diagramItem.setPos(self.itemPos) - self.scene.clearSelection() - self.scene.advance() - + if self.diagramItem not in self.scene.items(): + self.scene.addItem(self.diagramItem) + self.diagramItem.setPos(self.itemPos) + self.scene.clearSelection() + self.scene.advance() + if(issubclass(self.diagramItem.__class__,shapes.Line)): + self.reconnectLines() + + def findLGIndex(self): + startIndex = None + endIndex = None + for indexLG,i in enumerate(self.startGrip.lineGripItems): + for j in i.lines: + if j == self.diagramItem: + startIndex = indexLG + for indexLG,i in enumerate(self.endGrip.lineGripItems): + for j in i.lines: + if j == self.diagramItem: + endIndex = indexLG + return startIndex,endIndex + + def reconnectLines(self): + if self.diagramItem not in self.startGrip.lineGripItems[self.indexLGS].lines: + self.startGrip.lineGripItems[self.indexLGS].lines.append(self.diagramItem) + if self.diagramItem not in self.endGrip.lineGripItems[self.indexLGE].lines: + self.endGrip.lineGripItems[self.indexLGE].lines.append(self.diagramItem) + class deleteCommand(QUndoCommand): """ QUndoCommand for delete item event @@ -65,10 +92,9 @@ class deleteCommand(QUndoCommand): self.reconnectLines() def redo(self): - self.scene.removeItem(self.diagramItem) - self.scene.advance() - if(issubclass(self.diagramItem.__class__,shapes.Line)): - self.reconnectLines() + if self.diagramItem in self.scene.items(): + self.scene.removeItem(self.diagramItem) + self.scene.advance() def findLGIndex(self): startIndex = None |