From 376c4fdd263f59f6739d045d441e07a97f5c5122 Mon Sep 17 00:00:00 2001 From: Caio Marcelo de Oliveira Filho Date: Wed, 12 Aug 2009 17:26:52 -0300 Subject: Revert "QGraphicsAnchorLayoutPrivate: Avoiding extra loops in getGraphParts" This reverts commit 9e701f76f7478ea078e58076c91fee0d2ec505b4 and also add a comment explaining why is needed to delay the creation of the nonTrunkVariables to a later moment. Signed-off-by: Caio Marcelo de Oliveira Filho Reviewed-by: Artur Duque de Souza --- src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index 9a1cdd0..e3914b8 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -1543,7 +1543,6 @@ QGraphicsAnchorLayoutPrivate::getGraphParts(Orientation orientation) } QList trunkConstraints; - QList nonTrunkConstraints; QSet trunkVariables; trunkVariables += edgeL1; @@ -1551,7 +1550,6 @@ QGraphicsAnchorLayoutPrivate::getGraphParts(Orientation orientation) trunkVariables += edgeL2; bool dirty; - bool hasNonTrunkConstraints = false; do { dirty = false; @@ -1577,9 +1575,15 @@ QGraphicsAnchorLayoutPrivate::getGraphParts(Orientation orientation) it = remainingConstraints.erase(it); dirty = true; } else { - nonTrunkConstraints += c; - it = remainingConstraints.erase(it); - hasNonTrunkConstraints = true; + // Note that we don't erase the constraint if it's not + // a match, since in a next iteration of a do-while we + // can pass on it again and it will be a match. + // + // For example: if trunk share a variable with + // remainingConstraints[1] and it shares with + // remainingConstraints[0], we need a second iteration + // of the do-while loop to match both. + ++it; } } } while (dirty); @@ -1587,8 +1591,15 @@ QGraphicsAnchorLayoutPrivate::getGraphParts(Orientation orientation) QList< QList > result; result += trunkConstraints; - if (hasNonTrunkConstraints) + if (!remainingConstraints.isEmpty()) { + QList nonTrunkConstraints; + QLinkedList::iterator it = remainingConstraints.begin(); + while (it != remainingConstraints.end()) { + nonTrunkConstraints += *it; + ++it; + } result += nonTrunkConstraints; + } return result; } -- cgit v0.12