diff options
author | brenda-br | 2023-02-06 13:29:44 +0530 |
---|---|---|
committer | brenda-br | 2023-02-06 13:29:44 +0530 |
commit | a27d2a38e06cd4ab534cd0df3967446059464595 (patch) | |
tree | 9e888af49900cbec620232574d240de6e81d2b63 /src/main/python/utils | |
parent | 4ac334851d1ceb92a582d3cfad40b0c0536899f1 (diff) | |
download | Chemical-PFD-a27d2a38e06cd4ab534cd0df3967446059464595.tar.gz Chemical-PFD-a27d2a38e06cd4ab534cd0df3967446059464595.tar.bz2 Chemical-PFD-a27d2a38e06cd4ab534cd0df3967446059464595.zip |
Fix #26 Delete Function of Node Line and Node Item working properly
Diffstat (limited to 'src/main/python/utils')
-rw-r--r-- | src/main/python/utils/graphics.py | 7 | ||||
-rw-r--r-- | src/main/python/utils/undo.py | 27 |
2 files changed, 32 insertions, 2 deletions
diff --git a/src/main/python/utils/graphics.py b/src/main/python/utils/graphics.py index 979841f..a6910ae 100644 --- a/src/main/python/utils/graphics.py +++ b/src/main/python/utils/graphics.py @@ -146,4 +146,11 @@ class CustomScene(QGraphicsScene): index = self.count+1 if(self.count!=0): self.count-=1 + currentLine = self.undoStack.command(currentIndex-index).diagramItem + startGrip = self.undoStack.command(currentIndex-index).startGrip + endGrip = self.undoStack.command(currentIndex-index).endGrip + index_LineGripStart = self.undoStack.command(currentIndex-index).indexLGS + index_LineGripEnd = self.undoStack.command(currentIndex-index).indexLGE + startGrip.lineGripItems[index_LineGripStart].lines.append(currentLine) + endGrip.lineGripItems[index_LineGripEnd].lines.append(currentLine) self.undoStack.command(currentIndex-index).undo() diff --git a/src/main/python/utils/undo.py b/src/main/python/utils/undo.py index 090ce9d..3cc832f 100644 --- a/src/main/python/utils/undo.py +++ b/src/main/python/utils/undo.py @@ -3,6 +3,7 @@ Contains custom undo commands that can be pushed to undo stack """ from PyQt5.QtWidgets import QUndoCommand from re import compile +import shapes def repl(x): return f"{x[0][0]} {x[0][1].lower()}" @@ -43,11 +44,15 @@ class deleteCommand(QUndoCommand): """ QUndoCommand for delete item event """ - def __init__(self, item, scene, parent = None): + def __init__(self, item, scene,parent = None): super(deleteCommand, self).__init__(parent) self.scene = scene item.setSelected(False) self.diagramItem = item + if(issubclass(self.diagramItem.__class__,shapes.Line)): + self.startGrip = self.diagramItem.startGripItem.parentItem() + self.endGrip = self.diagramItem.endGripItem.parentItem() + self.indexLGS,self.indexLGE = self.findLGIndex() self.setText(f"Delete {objectName(self.diagramItem)} at {self.diagramItem.pos().x()}, {self.diagramItem.y()}") def undo(self): @@ -55,11 +60,29 @@ class deleteCommand(QUndoCommand): self.scene.update() self.scene.advance() self.scene.reInsertLines() + if(issubclass(self.diagramItem.__class__,shapes.Line)): + self.reconnectLines() def redo(self): self.scene.removeItem(self.diagramItem) self.scene.advance() - + + 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): + self.startGrip.lineGripItems[self.indexLGS].lines.append(self.diagramItem) + self.endGrip.lineGripItems[self.indexLGE].lines.append(self.diagramItem) class moveCommand(QUndoCommand): """ QUndoCommand for move item event |