From 4ac334851d1ceb92a582d3cfad40b0c0536899f1 Mon Sep 17 00:00:00 2001 From: brenda-br Date: Thu, 2 Feb 2023 19:12:02 +0530 Subject: Fix #26 Node Line added after undoing delete action --- src/main/python/utils/graphics.py | 12 ++++++++++++ src/main/python/utils/undo.py | 1 + 2 files changed, 13 insertions(+) diff --git a/src/main/python/utils/graphics.py b/src/main/python/utils/graphics.py index bb113ce..979841f 100644 --- a/src/main/python/utils/graphics.py +++ b/src/main/python/utils/graphics.py @@ -105,6 +105,12 @@ class CustomScene(QGraphicsScene): # (slot) used to delete all selected items, and add undo action for each of them if self.selectedItems(): for item in self.selectedItems(): + self.count = 0 + if(issubclass(item.__class__,shapes.NodeItem)): + for i in item.lineGripItems: + for j in i.lines: + self.count+=1 + self.undoStack.push(deleteCommand(j, self)) self.undoStack.push(deleteCommand(item, self)) def itemMoved(self, movedItem, lastPos): @@ -135,3 +141,9 @@ class CustomScene(QGraphicsScene): self.itemMoved(self.movingItem, self.oldPos) self.movingItem = None #clear movingitem reference return super(CustomScene, self).mouseReleaseEvent(event) + def reInsertLines(self): + currentIndex = self.undoStack.index() + index = self.count+1 + if(self.count!=0): + self.count-=1 + self.undoStack.command(currentIndex-index).undo() diff --git a/src/main/python/utils/undo.py b/src/main/python/utils/undo.py index 6a46b27..090ce9d 100644 --- a/src/main/python/utils/undo.py +++ b/src/main/python/utils/undo.py @@ -54,6 +54,7 @@ class deleteCommand(QUndoCommand): self.scene.addItem(self.diagramItem) self.scene.update() self.scene.advance() + self.scene.reInsertLines() def redo(self): self.scene.removeItem(self.diagramItem) -- cgit From a27d2a38e06cd4ab534cd0df3967446059464595 Mon Sep 17 00:00:00 2001 From: brenda-br Date: Mon, 6 Feb 2023 13:29:44 +0530 Subject: Fix #26 Delete Function of Node Line and Node Item working properly --- src/main/python/utils/graphics.py | 7 +++++++ 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 -- cgit From 42942f4c0f6aee658ffd2c374588c402debca33d Mon Sep 17 00:00:00 2001 From: brenda-br Date: Mon, 6 Feb 2023 13:47:36 +0530 Subject: Reconnect Lines on redo function --- src/main/python/utils/undo.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/python/utils/undo.py b/src/main/python/utils/undo.py index 3cc832f..2f28964 100644 --- a/src/main/python/utils/undo.py +++ b/src/main/python/utils/undo.py @@ -66,6 +66,8 @@ class deleteCommand(QUndoCommand): def redo(self): self.scene.removeItem(self.diagramItem) self.scene.advance() + if(issubclass(self.diagramItem.__class__,shapes.Line)): + self.reconnectLines() def findLGIndex(self): startIndex = None -- cgit From 5e9fdd9682bb41b952eb39b5869cc4dc5fc59ecb Mon Sep 17 00:00:00 2001 From: brenda-br Date: Mon, 6 Feb 2023 20:56:13 +0530 Subject: Undeletable Line Grips --- src/main/python/utils/graphics.py | 11 ++++++++--- src/main/python/utils/undo.py | 11 +++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main/python/utils/graphics.py b/src/main/python/utils/graphics.py index a6910ae..c9dbed7 100644 --- a/src/main/python/utils/graphics.py +++ b/src/main/python/utils/graphics.py @@ -105,13 +105,17 @@ class CustomScene(QGraphicsScene): # (slot) used to delete all selected items, and add undo action for each of them if self.selectedItems(): for item in self.selectedItems(): + if(issubclass(item.__class__,shapes.LineGripItem) or issubclass(item.__class__,shapes.SizeGripItem) ): + itemToDelete = item.parentItem() + else: + itemToDelete = item self.count = 0 - if(issubclass(item.__class__,shapes.NodeItem)): - for i in item.lineGripItems: + if(issubclass(itemToDelete.__class__,shapes.NodeItem)): + for i in itemToDelete.lineGripItems: for j in i.lines: self.count+=1 self.undoStack.push(deleteCommand(j, self)) - self.undoStack.push(deleteCommand(item, self)) + self.undoStack.push(deleteCommand(itemToDelete, self)) def itemMoved(self, movedItem, lastPos): #item move event, checks if item is moved @@ -141,6 +145,7 @@ class CustomScene(QGraphicsScene): self.itemMoved(self.movingItem, self.oldPos) self.movingItem = None #clear movingitem reference return super(CustomScene, self).mouseReleaseEvent(event) + def reInsertLines(self): currentIndex = self.undoStack.index() index = self.count+1 diff --git a/src/main/python/utils/undo.py b/src/main/python/utils/undo.py index 2f28964..8e21fe7 100644 --- a/src/main/python/utils/undo.py +++ b/src/main/python/utils/undo.py @@ -83,8 +83,15 @@ class deleteCommand(QUndoCommand): return startIndex,endIndex def reconnectLines(self): - self.startGrip.lineGripItems[self.indexLGS].lines.append(self.diagramItem) - self.endGrip.lineGripItems[self.indexLGE].lines.append(self.diagramItem) + try: + self.startGrip.lineGripItems[self.indexLGS].lines.append(self.diagramItem) + except: + pass + try: + self.endGrip.lineGripItems[self.indexLGE].lines.append(self.diagramItem) + except: + pass + class moveCommand(QUndoCommand): """ QUndoCommand for move item event -- cgit From d44ab6e457741c9759efe51cf7e9c29c82221440 Mon Sep 17 00:00:00 2001 From: brenda-br Date: Sun, 12 Feb 2023 16:37:32 +0530 Subject: Fix #26 Fix on Undo Command --- src/main/python/utils/undo.py | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/main/python/utils/undo.py b/src/main/python/utils/undo.py index 8e21fe7..ea41d0b 100644 --- a/src/main/python/utils/undo.py +++ b/src/main/python/utils/undo.py @@ -50,19 +50,20 @@ class deleteCommand(QUndoCommand): 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.startGrip = item.startGripItem.parentItem() + self.endGrip = item.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): - self.scene.addItem(self.diagramItem) - self.scene.update() - self.scene.advance() - self.scene.reInsertLines() - if(issubclass(self.diagramItem.__class__,shapes.Line)): - self.reconnectLines() - + if self.diagramItem not in self.scene.items(): + self.scene.addItem(self.diagramItem) + 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() @@ -74,24 +75,20 @@ class deleteCommand(QUndoCommand): endIndex = None for indexLG,i in enumerate(self.startGrip.lineGripItems): for j in i.lines: - if(j == self.diagramItem): + if j == self.diagramItem: startIndex = indexLG for indexLG,i in enumerate(self.endGrip.lineGripItems): for j in i.lines: - if(j == self.diagramItem): + if j == self.diagramItem: endIndex = indexLG return startIndex,endIndex def reconnectLines(self): - try: + if self.diagramItem not in self.startGrip.lineGripItems[self.indexLGS].lines: self.startGrip.lineGripItems[self.indexLGS].lines.append(self.diagramItem) - except: - pass - try: + if self.diagramItem not in self.endGrip.lineGripItems[self.indexLGE].lines: self.endGrip.lineGripItems[self.indexLGE].lines.append(self.diagramItem) - except: - pass - + class moveCommand(QUndoCommand): """ QUndoCommand for move item event -- cgit From e2a3e90d7b48196d7efee5330e60298f3270356e Mon Sep 17 00:00:00 2001 From: brenda-br Date: Sun, 12 Feb 2023 17:01:23 +0530 Subject: Fix #29 Redo Action Node Lines connected to parent item --- src/main/python/utils/undo.py | 50 ++++++++++++++++++++++++++++++++----------- 1 file 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 -- cgit From ef7ea4c100e23b4e1ef19d64fc144ea39531d25d Mon Sep 17 00:00:00 2001 From: brenda-br Date: Sun, 12 Feb 2023 17:59:35 +0530 Subject: Fix #30 Node Line not connecting to its Node Item --- src/main/python/shapes/shapes.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/python/shapes/shapes.py b/src/main/python/shapes/shapes.py index 5876f6e..8225a12 100644 --- a/src/main/python/shapes/shapes.py +++ b/src/main/python/shapes/shapes.py @@ -396,12 +396,13 @@ class LineGripItem(QGraphicsPathItem): self.tempLine.endGap = gap self.tempLine.setStartGripItem(self) self.tempLine.setEndGripItem(item) - # update line with end point so it sets final path - self.tempLine.updateLine(endPoint=endPoint) - self.lines.append(self.tempLine) - item.lines.append(self.tempLine) - tag = 1 - break + if self.tempLine.startGripItem.parentItem() != self.tempLine.endGripItem.parentItem(): + # update line with end point so it sets final path + self.tempLine.updateLine(endPoint=endPoint) + self.lines.append(self.tempLine) + item.lines.append(self.tempLine) + tag = 1 + break # end point on line elif type(item) == Line and item != self.tempLine: self.tempLine.setStartGripItem(self) -- cgit From bba17b5009e7b7542c6df063fb2f57b094b4389c Mon Sep 17 00:00:00 2001 From: brenda-br Date: Sun, 12 Feb 2023 19:03:10 +0530 Subject: reinsertLines Function indexing fix --- src/main/python/utils/graphics.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/python/utils/graphics.py b/src/main/python/utils/graphics.py index c9dbed7..8dc7682 100644 --- a/src/main/python/utils/graphics.py +++ b/src/main/python/utils/graphics.py @@ -148,14 +148,14 @@ class CustomScene(QGraphicsScene): def reInsertLines(self): currentIndex = self.undoStack.index() - 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 + 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) - self.undoStack.command(currentIndex-index).undo() + self.undoStack.setIndex(currentIndex-i) + i+=1 -- cgit From 278478886a4023056671700f32b6a6491a835ee2 Mon Sep 17 00:00:00 2001 From: brenda-br Date: Tue, 14 Feb 2023 11:25:47 +0530 Subject: Minor changes on Deleting Node Line and Filtering Move Command when reinserting Lines --- src/main/python/utils/graphics.py | 26 ++++++++++++++++---------- 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): """ -- cgit