[ui] Vertically align duplicated nodes correctly

When a node is duplicated more than once in a single "duplicate"
operation, it happens that several of the duplicated nodes
overlap. This patch takes into account all the newly duplicated
(and already moved) nodes before moving them into their final
position.
This commit is contained in:
Candice Bentéjac 2022-07-21 08:37:11 +02:00
parent b77274a027
commit c4c8b5c8d5

View file

@ -574,6 +574,7 @@ class UIGraph(QObject):
list[Node]: the list of duplicated nodes
"""
nodes = self.filterNodes(nodes)
nPositions = []
# enable updates between duplication and layout to get correct depths during layout
with self.groupedGraphModification("Duplicate Selected Nodes", disableUpdates=False):
# disable graph updates during duplication
@ -581,8 +582,19 @@ class UIGraph(QObject):
duplicates = self.push(commands.DuplicateNodesCommand(self._graph, nodes))
# move nodes below the bounding box formed by the duplicated node(s)
bbox = self._layout.boundingBox(duplicates)
for n in duplicates:
self.moveNode(n, Position(n.x, bbox[3] + self.layout.gridSpacing + n.y))
idx = duplicates.index(n)
yPos = n.y + self.layout.gridSpacing + bbox[3]
if idx > 0 and (n.x, yPos) in nPositions:
# make sure the node will not be moved on top of another node
while (n.x, yPos) in nPositions:
yPos = yPos + self.layout.gridSpacing + self.layout.nodeHeight
self.moveNode(n, Position(n.x, yPos))
else:
self.moveNode(n, Position(n.x, bbox[3] + self.layout.gridSpacing + n.y))
nPositions.append((n.x, n.y))
return duplicates
@Slot(QObject, result="QVariantList")