[commands] fix RemoveNode command

re-create deleted edges on undo
This commit is contained in:
Yann Lanthony 2017-10-02 16:14:46 +02:00
parent a4b27acdcf
commit c98b2b7b41

View file

@ -89,9 +89,10 @@ class RemoveNodeCommand(GraphCommand):
self.nodeDesc = node.toDict()
self.nodeName = node.getName()
self.setText("Remove Node {}".format(self.nodeName))
self.edges = {}
def redoImpl(self):
self.graph.removeNode(self.nodeName)
self.edges = self.graph.removeNode(self.nodeName)
return True
def undoImpl(self):
@ -100,6 +101,15 @@ class RemoveNodeCommand(GraphCommand):
), self.nodeName)
assert (node.getName() == self.nodeName)
# recreate edges deleted on node removal
for key, value in self.edges.items():
iNode, iAttr = key.split(".")
oNode, oAttr = value.split(".")
self.graph.addEdge(self.graph.node(oNode).attribute(oAttr),
self.graph.node(iNode).attribute(iAttr))
node.updateInternals()
class SetAttributeCommand(GraphCommand):
def __init__(self, graph, attribute, value, parent=None):