summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorCaio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org>2009-08-13 18:21:08 (GMT)
committerCaio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org>2009-08-13 18:35:31 (GMT)
commitc938d16249e24c297f2b36b4711a3e592de5e7d6 (patch)
treedec298eb87049315a7726438e1b13d3f06fa6b40 /src
parentd9634121cf977f6b03c75135ced06d4f038ada1a (diff)
downloadQt-c938d16249e24c297f2b36b4711a3e592de5e7d6.zip
Qt-c938d16249e24c297f2b36b4711a3e592de5e7d6.tar.gz
Qt-c938d16249e24c297f2b36b4711a3e592de5e7d6.tar.bz2
QGraphicsAnchorLayout: simplify updating of anchor sizes
Instead of going through all anchors after the calculation of the graphs, do it as early as possible for each part (trunk and nonTrunks) and recursively updates the children in case of a simplified graph. Signed-off-by: Caio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org> Reviewed-by: Artur Duque de Souza <artur.souza@openbossa.org>
Diffstat (limited to 'src')
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout_p.cpp58
1 files changed, 13 insertions, 45 deletions
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
index ee2144c..e75bf19 100644
--- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
+++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
@@ -1177,6 +1177,15 @@ void QGraphicsAnchorLayoutPrivate::calculateGraphs(
// and variables internally.
solvePreferred(trunkConstraints);
+ // Propagate the new sizes down the simplified graph, ie. tell the
+ // group anchors to set their children anchors sizes.
+
+ // ### we calculated variables already a few times, can't we reuse that?
+ QList<AnchorData *> trunkVariables = getVariables(trunkConstraints);
+
+ for (int i = 0; i < trunkVariables.count(); ++i)
+ trunkVariables.at(i)->updateChildrenSizes();
+
// Calculate and set the preferred size for the layout from the edge sizes that
// were calculated above.
qreal pref(0.0);
@@ -1198,6 +1207,9 @@ void QGraphicsAnchorLayoutPrivate::calculateGraphs(
ad->sizeAtPreferred = ad->prefSize;
ad->sizeAtMaximum = ad->maxSize;
+ // Propagate
+ ad->updateChildrenSizes();
+
sizeHints[orientation][Qt::MinimumSize] = ad->sizeAtMinimum;
sizeHints[orientation][Qt::PreferredSize] = ad->sizeAtPreferred;
sizeHints[orientation][Qt::MaximumSize] = ad->sizeAtMaximum;
@@ -1228,6 +1240,7 @@ void QGraphicsAnchorLayoutPrivate::calculateGraphs(
Q_ASSERT(ad);
ad->sizeAtMinimum = ad->sizeAtPreferred;
ad->sizeAtMaximum = ad->sizeAtPreferred;
+ ad->updateChildrenSizes();
}
// Delete the constraints, we won't use them anymore.
@@ -1240,51 +1253,6 @@ void QGraphicsAnchorLayoutPrivate::calculateGraphs(
qDeleteAll(constraints[orientation]);
constraints[orientation].clear();
graphPaths[orientation].clear(); // ###
-
- // Propagate the new sizes down the simplified graph, ie. tell the group anchors
- // to set their children anchors sizes.
-
- // ### Note that we can split the anchors into two categories:
- // 1) Those that appeared in at least one constraint and so went through the
- // Simplex solver. Either as a Trunk or Non-Trunk variable.
- // 2) Those that did not go through the Simplex solver at all.
- //
- // Anchors of the type (1) had its effective sizes (ie. sizeAtMinimum/Pref/Max)
- // properly set by the "solveMinMax" and "solvePreferred" methods.
- //
- // However, those of type (2), still need to have their effective sizes set,
- // in that case, to their own nominal values.
- //
- // Due to the above reasons, we can't simply iterate on the variables that
- // belong to a graph part. We have to iterate through _all_ root anchors
- // in graph[orientation]. That's why we collect "allAnchors". We gotta make
- // this better somehow.
-
- // ### Did I say that's ugly?
- QSet<AnchorData *> allAnchors;
- QQueue<AnchorVertex *> queue;
- queue << graph[orientation].rootVertex();
- while (!queue.isEmpty()) {
- AnchorVertex *vertex = queue.dequeue();
- QList<AnchorVertex *> adjacentVertices = graph[orientation].adjacentVertices(vertex);
- for (int i = 0; i < adjacentVertices.count(); ++i) {
- AnchorData *edge = graph[orientation].edgeData(vertex, adjacentVertices[i]);
- if (allAnchors.contains(edge))
- continue;
- allAnchors << edge;
- queue << adjacentVertices[i];
- }
- }
-
- // Ok, now that we have all anchors, actually propagate the sizes down its children.
- // Note that for anchors that didn't have its effectiveSizes set yet, we use the
- // nominal one instead.
- QSet<AnchorData *>::const_iterator iter;
- for (iter = allAnchors.constBegin(); iter != allAnchors.constEnd(); ++iter)
- (*iter)->updateChildrenSizes();
-
- // Restore the graph. See the ### note next to the simplifyGraph() call.
- //restoreSimplifiedGraph(orientation);
}
void QGraphicsAnchorLayoutPrivate::setAnchorSizeHintsFromDefaults(Orientation orientation)