diff options
author | Eduardo M. Fleury <eduardo.fleury@openbossa.org> | 2009-10-19 19:36:53 (GMT) |
---|---|---|
committer | Eduardo M. Fleury <eduardo.fleury@openbossa.org> | 2009-11-04 23:27:40 (GMT) |
commit | 33faaf6fa1775dc74bb61acde8a48eae2b9f2635 (patch) | |
tree | 469a2069c17b98a016493121de8cd6e43042c17e /src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | |
parent | 41369cd2946956b9a455e4f2014dcc38ffcbad52 (diff) | |
download | Qt-33faaf6fa1775dc74bb61acde8a48eae2b9f2635.zip Qt-33faaf6fa1775dc74bb61acde8a48eae2b9f2635.tar.gz Qt-33faaf6fa1775dc74bb61acde8a48eae2b9f2635.tar.bz2 |
QGAL: Do not restrict maximum size of layout anchors
This commit improves the way QGAL handles setups where most anchors
or items do not have explicit maximum sizes.
By default the internal layout anchors and others, have maximum size
of QWIDGETSIZE_MAX. It happens though that this value is rather arbitrary
but yet, can restrict the size of other paths in the layout.
For instance, in the setup below, where the maximum sizes of A and B is
not set:
________ ________
| | item A | | item B | |
o---o--------o---o--------o---o
| |________| |________| |
| |
| (layout structural anchor) |
o-----------------------------o
| |
the bottom path, of maximum size QWIDGETSIZE_MAX, restricts the lenght
of the path at the top, of maximum size of 2 x QWIDGETSIZE_MAX.
This introduces the need of fair distribution in the path A-B. While
that's not an issue when the path is simplified to a single anchor,
it may lead to unbalanced distributions if such simplification is
not possible. As this case may arise when we have center anchors
in the top path, it may appear in real-world cases.
To work around that, we do not limit the maximum width of the layout
anchor or parallel anchors that may have taken its place. The practical
result in the example above is that the sizeAtMaximum will be set at
2 x QWIDGETSIZE_MAX, with a good distribution of A and B.
On the other hand, this oversized layout is not a problem because the
effectiveSizeHint code enforces the respect of QWIDGETSIZE_MAX. That
means the layout will interpolate only between zero and QWIDGETSIZE_MAX
even though its internal maximum size is twice that value.
Signed-off-by: Eduardo M. Fleury <eduardo.fleury@openbossa.org>
Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org>
Diffstat (limited to 'src/gui/graphicsview/qgraphicsanchorlayout_p.cpp')
-rw-r--r-- | src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 56 |
1 files changed, 47 insertions, 9 deletions
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index f0aeea4..dbfce74 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -342,13 +342,15 @@ void SequentialAnchorData::updateChildrenSizes() // ### check whether we are guarantee to get those or we need to warn stuff at this // point. Q_ASSERT(sizeAtMinimum > minSize || qFuzzyCompare(sizeAtMinimum, minSize)); - Q_ASSERT(sizeAtMinimum < maxSize || qFuzzyCompare(sizeAtMinimum, maxSize)); Q_ASSERT(sizeAtPreferred > minSize || qFuzzyCompare(sizeAtPreferred, minSize)); - Q_ASSERT(sizeAtPreferred < maxSize || qFuzzyCompare(sizeAtPreferred, maxSize)); Q_ASSERT(sizeAtExpanding > minSize || qFuzzyCompare(sizeAtExpanding, minSize)); - Q_ASSERT(sizeAtExpanding < maxSize || qFuzzyCompare(sizeAtExpanding, maxSize)); Q_ASSERT(sizeAtMaximum > minSize || qFuzzyCompare(sizeAtMaximum, minSize)); - Q_ASSERT(sizeAtMaximum < maxSize || qFuzzyCompare(sizeAtMaximum, maxSize)); + + // These may be false if this anchor was in parallel with the layout stucture + // Q_ASSERT(sizeAtMinimum < maxSize || qFuzzyCompare(sizeAtMinimum, maxSize)); + // Q_ASSERT(sizeAtPreferred < maxSize || qFuzzyCompare(sizeAtPreferred, maxSize)); + // Q_ASSERT(sizeAtExpanding < maxSize || qFuzzyCompare(sizeAtExpanding, maxSize)); + // Q_ASSERT(sizeAtMaximum < maxSize || qFuzzyCompare(sizeAtMaximum, maxSize)); // Band here refers if the value is in the Minimum To Preferred // band (the lower band) or the Preferred To Maximum (the upper band). @@ -1752,8 +1754,6 @@ QList<AnchorData *> getVariables(QList<QSimplexConstraint *> constraints) void QGraphicsAnchorLayoutPrivate::calculateGraphs( QGraphicsAnchorLayoutPrivate::Orientation orientation) { - Q_Q(QGraphicsAnchorLayout); - #if defined(QT_DEBUG) || defined(Q_AUTOTEST_EXPORT) lastCalculationUsedSimplex[orientation] = false; #endif @@ -2069,7 +2069,30 @@ void QGraphicsAnchorLayoutPrivate::updateAnchorSizes(Orientation orientation) QList<QSimplexConstraint *> QGraphicsAnchorLayoutPrivate::constraintsFromSizeHints( const QList<AnchorData *> &anchors) { + if (anchors.isEmpty()) + return QList<QSimplexConstraint *>(); + + // Look for the layout edge. That can be either the first half in case the + // layout is split in two, or the whole layout anchor. + Orientation orient = Orientation(anchors.first()->orientation); + AnchorData *layoutEdge1 = NULL; + AnchorData *layoutEdge2 = NULL; + if (layoutCentralVertex[orient]) { + layoutEdge1 = graph[orient].edgeData(layoutFirstVertex[orient], layoutCentralVertex[orient]); + layoutEdge2 = graph[orient].edgeData(layoutCentralVertex[orient], layoutLastVertex[orient]); + } else { + layoutEdge1 = graph[orient].edgeData(layoutFirstVertex[orient], layoutLastVertex[orient]); + // If maxSize is less then "infinite", that means there are other anchors + // grouped together with this one. We can't ignore its maximum value so we + // set back the variable to NULL to prevent the continue condition from being + // satisfied in the loop below. + if (layoutEdge1->maxSize < QWIDGETSIZE_MAX) + layoutEdge1 = NULL; + } + + // For each variable, create constraints based on size hints QList<QSimplexConstraint *> anchorConstraints; + bool unboundedProblem = true; for (int i = 0; i < anchors.size(); ++i) { AnchorData *ad = anchors[i]; @@ -2079,6 +2102,7 @@ QList<QSimplexConstraint *> QGraphicsAnchorLayoutPrivate::constraintsFromSizeHin c->constant = ad->minSize; c->ratio = QSimplexConstraint::Equal; anchorConstraints += c; + unboundedProblem = false; } else { QSimplexConstraint *c = new QSimplexConstraint; c->variables.insert(ad, 1.0); @@ -2086,14 +2110,30 @@ QList<QSimplexConstraint *> QGraphicsAnchorLayoutPrivate::constraintsFromSizeHin c->ratio = QSimplexConstraint::MoreOrEqual; anchorConstraints += c; + // We avoid adding restrictions to the layout internal anchors. That's + // to prevent unnecessary fair distribution from happening due to this + // artificial restriction. + if ((ad == layoutEdge1) || (ad == layoutEdge2)) + continue; + c = new QSimplexConstraint; c->variables.insert(ad, 1.0); c->constant = ad->maxSize; c->ratio = QSimplexConstraint::LessOrEqual; anchorConstraints += c; + unboundedProblem = false; } } + // If no upper boundary restriction was added, add one to avoid unbounded problem + if (unboundedProblem) { + QSimplexConstraint *c = new QSimplexConstraint; + c->variables.insert(layoutEdge1, 1.0); + c->constant = QWIDGETSIZE_MAX; + c->ratio = QSimplexConstraint::LessOrEqual; + anchorConstraints += c; + } + return anchorConstraints; } @@ -2103,8 +2143,6 @@ QList<QSimplexConstraint *> QGraphicsAnchorLayoutPrivate::constraintsFromSizeHin QList< QList<QSimplexConstraint *> > QGraphicsAnchorLayoutPrivate::getGraphParts(Orientation orientation) { - Q_Q(QGraphicsAnchorLayout); - Q_ASSERT(layoutFirstVertex[orientation] && layoutLastVertex[orientation]); AnchorData *edgeL1 = NULL; @@ -2501,7 +2539,7 @@ bool QGraphicsAnchorLayoutPrivate::solveMinMax(const QList<QSimplexConstraint *> // Save sizeAtMaximum results for (int i = 0; i < variables.size(); ++i) { AnchorData *ad = static_cast<AnchorData *>(variables[i]); - Q_ASSERT(ad->result <= ad->maxSize || qFuzzyCompare(ad->result, ad->maxSize)); + // Q_ASSERT(ad->result <= ad->maxSize || qFuzzyCompare(ad->result, ad->maxSize)); ad->sizeAtMaximum = ad->result; } } |