[ui] make Nodes moves undoable

Handle nodes move and auto-layout on Python side by using GraphLayout and MoveNodeCommand.

* Node QML component relies on underlying core.Node object's position
* MoveNodeCommand is called after a Node has been dragged
* partial/full auto-layout for specific graph operations (Duplication, Augmentation...) are now part of those operations
* serialized position in node data allows to properly restore nodes coordinates on undo/redo
* remove all layout/node moving code from QML
This commit is contained in:
Yann Lanthony 2018-07-26 22:37:01 +02:00
parent 830173047c
commit f415745a4a
8 changed files with 75 additions and 124 deletions

View file

@ -87,10 +87,11 @@ class GraphCommand(UndoCommand):
class AddNodeCommand(GraphCommand):
def __init__(self, graph, nodeType, parent=None, **kwargs):
def __init__(self, graph, nodeType, position, parent=None, **kwargs):
super(AddNodeCommand, self).__init__(graph, parent)
self.nodeType = nodeType
self.nodeName = None
self.position = position
self.kwargs = kwargs
# Serialize Attributes as link expressions
for key, value in self.kwargs.items():
@ -102,7 +103,7 @@ class AddNodeCommand(GraphCommand):
value[idx] = v.asLinkExpr()
def redoImpl(self):
node = self.graph.addNewNode(self.nodeType, **self.kwargs)
node = self.graph.addNewNode(self.nodeType, position=self.position, **self.kwargs)
self.nodeName = node.name
self.setText("Add Node {}".format(self.nodeName))
return node