summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/python/shapes/shapes.py13
-rw-r--r--src/main/python/utils/graphics.py32
-rw-r--r--src/main/python/utils/undo.py88
3 files changed, 110 insertions, 23 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)
diff --git a/src/main/python/utils/graphics.py b/src/main/python/utils/graphics.py
index bb113ce..615843f 100644
--- a/src/main/python/utils/graphics.py
+++ b/src/main/python/utils/graphics.py
@@ -105,7 +105,18 @@ 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.undoStack.push(deleteCommand(item, self))
+ if(issubclass(item.__class__,shapes.LineGripItem) or issubclass(item.__class__,shapes.SizeGripItem) ):
+ itemToDelete = item.parentItem()
+ else:
+ itemToDelete = item
+ self.count = 0
+ 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))
+ 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
@@ -135,3 +146,22 @@ 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()
+ 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 6a46b27..51610f5 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()}"
@@ -26,39 +27,94 @@ class addCommand(QUndoCommand):
self.scene = scene
self.diagramItem = addItem
self.itemPos = addItem.pos()
+ 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()}")
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.startGripItem.lineGripItems):
+ for j in i.lines:
+ if j == self.diagramItem:
+ startIndex = indexLG
+ 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.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):
"""
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.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()}")
def undo(self):
- self.scene.addItem(self.diagramItem)
- self.scene.update()
- self.scene.advance()
-
+ 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()
-
+ if self.diagramItem in self.scene.items():
+ self.scene.removeItem(self.diagramItem)
+ self.scene.advance()
+
+ def findLGIndex(self):
+ startIndex = None
+ endIndex = None
+ 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.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.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):
"""
QUndoCommand for move item event