diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/python/utils/graphics.py | 26 | ||||
-rw-r--r-- | src/main/python/utils/undo.py | 34 |
2 files changed, 33 insertions, 27 deletions
diff --git a/src/main/python/utils/graphics.py b/src/main/python/utils/graphics.py index 8dc7682..615843f 100644 --- a/src/main/python/utils/graphics.py +++ b/src/main/python/utils/graphics.py @@ -115,7 +115,8 @@ class CustomScene(QGraphicsScene): for j in i.lines: self.count+=1 self.undoStack.push(deleteCommand(j, self)) - self.undoStack.push(deleteCommand(itemToDelete, self)) + if itemToDelete.__class__ != shapes.line.Grabber: + self.undoStack.push(deleteCommand(itemToDelete, self)) def itemMoved(self, movedItem, lastPos): #item move event, checks if item is moved @@ -148,14 +149,19 @@ class CustomScene(QGraphicsScene): def reInsertLines(self): currentIndex = self.undoStack.index() - i = 2 - while i != self.count+2: - currentLine = self.undoStack.command(currentIndex-i).diagramItem - startGrip = self.undoStack.command(currentIndex-i).startGrip - endGrip = self.undoStack.command(currentIndex-i).endGrip - index_LineGripStart = self.undoStack.command(currentIndex-i).indexLGS - index_LineGripEnd = self.undoStack.command(currentIndex-i).indexLGE - startGrip.lineGripItems[index_LineGripStart].lines.append(currentLine) - endGrip.lineGripItems[index_LineGripEnd].lines.append(currentLine) + i = 2 + skipper = 0 + while i != self.count+2+skipper: + currentCommand = self.undoStack.command(currentIndex-i) + if not self.undoStack.text(currentIndex-i).__contains__('Move'): + currentLine = currentCommand.diagramItem + startGrip = currentCommand.startGripItem + endGrip = currentCommand.endGripItem + index_LineGripStart = currentCommand.indexLGS + index_LineGripEnd = currentCommand.indexLGE + startGrip.lineGripItems[index_LineGripStart].lines.append(currentLine) + endGrip.lineGripItems[index_LineGripEnd].lines.append(currentLine) + else: + skipper+=1 self.undoStack.setIndex(currentIndex-i) i+=1 diff --git a/src/main/python/utils/undo.py b/src/main/python/utils/undo.py index c044eab..51610f5 100644 --- a/src/main/python/utils/undo.py +++ b/src/main/python/utils/undo.py @@ -27,9 +27,9 @@ 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() + if(issubclass(self.diagramItem.__class__,shapes.Line) and addItem != None): + self.startGripItem = addItem.startGripItem.parentItem() + self.endGripItem = addItem.endGripItem.parentItem() self.indexLGS,self.indexLGE = self.findLGIndex() self.setText(f"Add {objectName(self.diagramItem)} at {self.itemPos.x()}, {self.itemPos.y()}") @@ -51,21 +51,21 @@ class addCommand(QUndoCommand): def findLGIndex(self): startIndex = None endIndex = None - for indexLG,i in enumerate(self.startGrip.lineGripItems): + for indexLG,i in enumerate(self.startGripItem.lineGripItems): for j in i.lines: if j == self.diagramItem: startIndex = indexLG - for indexLG,i in enumerate(self.endGrip.lineGripItems): + for indexLG,i in enumerate(self.endGripItem.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) + if self.diagramItem not in self.startGripItem.lineGripItems[self.indexLGS].lines: + self.startGripItem.lineGripItems[self.indexLGS].lines.append(self.diagramItem) + if self.diagramItem not in self.endGripItem.lineGripItems[self.indexLGE].lines: + self.endGripItem.lineGripItems[self.indexLGE].lines.append(self.diagramItem) class deleteCommand(QUndoCommand): """ @@ -77,8 +77,8 @@ class deleteCommand(QUndoCommand): item.setSelected(False) self.diagramItem = item if(issubclass(self.diagramItem.__class__,shapes.Line)): - self.startGrip = item.startGripItem.parentItem() - self.endGrip = item.endGripItem.parentItem() + self.startGripItem = item.startGripItem.parentItem() + self.endGripItem = item.endGripItem.parentItem() self.indexLGS,self.indexLGE = self.findLGIndex() self.setText(f"Delete {objectName(self.diagramItem)} at {self.diagramItem.pos().x()}, {self.diagramItem.y()}") @@ -99,21 +99,21 @@ class deleteCommand(QUndoCommand): def findLGIndex(self): startIndex = None endIndex = None - for indexLG,i in enumerate(self.startGrip.lineGripItems): + for indexLG,i in enumerate(self.startGripItem.lineGripItems): for j in i.lines: if j == self.diagramItem: startIndex = indexLG - for indexLG,i in enumerate(self.endGrip.lineGripItems): + for indexLG,i in enumerate(self.endGripItem.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) + if self.diagramItem not in self.startGripItem.lineGripItems[self.indexLGS].lines: + self.startGripItem.lineGripItems[self.indexLGS].lines.append(self.diagramItem) + if self.diagramItem not in self.endGripItem.lineGripItems[self.indexLGE].lines: + self.endGripItem.lineGripItems[self.indexLGE].lines.append(self.diagramItem) class moveCommand(QUndoCommand): """ |