From ac4772fc575d3fa313bad97f73afc2d2743a5e20 Mon Sep 17 00:00:00 2001 From: Yann Lanthony Date: Thu, 26 Jul 2018 15:20:20 +0200 Subject: [PATCH] [ui][commands] add MoveNodeCommand add undoable command to move a Node to a target position --- meshroom/ui/commands.py | 17 +++++++++++++++++ meshroom/ui/graph.py | 13 +++++++++++++ 2 files changed, 30 insertions(+) diff --git a/meshroom/ui/commands.py b/meshroom/ui/commands.py index a916e5cb..62229c7a 100755 --- a/meshroom/ui/commands.py +++ b/meshroom/ui/commands.py @@ -258,6 +258,23 @@ class ListAttributeRemoveCommand(GraphCommand): listAttribute.insert(self.index, self.value) +class MoveNodeCommand(GraphCommand): + """ Move a node to a given position. """ + def __init__(self, graph, node, position, parent=None): + super(MoveNodeCommand, self).__init__(graph, parent) + self.nodeName = node.name + self.oldPosition = node.position + self.newPosition = position + self.setText("Move {}".format(self.nodeName)) + + def redoImpl(self): + self.graph.node(self.nodeName).position = self.newPosition + return True + + def undoImpl(self): + self.graph.node(self.nodeName).position = self.oldPosition + + class UpgradeNodeCommand(GraphCommand): """ Perform node upgrade on a CompatibilityNode. diff --git a/meshroom/ui/graph.py b/meshroom/ui/graph.py index 45bfd114..a365d6de 100644 --- a/meshroom/ui/graph.py +++ b/meshroom/ui/graph.py @@ -252,6 +252,19 @@ class UIGraph(QObject): """ return self.push(commands.AddNodeCommand(self._graph, nodeType, **kwargs)) + @Slot(Node, QPoint) + def moveNode(self, node, position): + """ + Move 'node' to the given 'position'. + + Args: + node (Node): the node to move + position (QPoint): the target position + """ + if isinstance(position, QPoint): + position = Position(position.x(), position.y()) + self.push(commands.MoveNodeCommand(self._graph, node, position)) + @Slot(Node) def removeNode(self, node): self.push(commands.RemoveNodeCommand(self._graph, node))