From ff5becbd4dafbabb79c086dc0cc18111d9e82a15 Mon Sep 17 00:00:00 2001 From: Caio Marcelo de Oliveira Filho Date: Tue, 27 Oct 2009 16:04:10 -0300 Subject: QGAL: keep references to layout vertices We used to keep a reference just to the first vertex of the layout (corresponding to the left/top anchor point) inside the Graph class, as "root vertex". Since the notion of rootVertex isn't used by the Graph itself, now this is stored outside the graph, and we also store the central and last vertices. This avoids using internalVertex() function to find out the vertices based on the item (in the case, the 'q'). This will be useful when we do simplify vertices, since the original layout vertice might not be the "layout vertice" in the graph. Signed-off-by: Caio Marcelo de Oliveira Filho Reviewed-by: Eduardo M. Fleury --- src/gui/graphicsview/qgraph_p.h | 12 ----- src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 61 ++++++++++++++---------- src/gui/graphicsview/qgraphicsanchorlayout_p.h | 4 ++ 3 files changed, 39 insertions(+), 38 deletions(-) diff --git a/src/gui/graphicsview/qgraph_p.h b/src/gui/graphicsview/qgraph_p.h index f1fa185..b5b3c88 100644 --- a/src/gui/graphicsview/qgraph_p.h +++ b/src/gui/graphicsview/qgraph_p.h @@ -201,11 +201,6 @@ public: return l; } - void setRootVertex(Vertex *vertex) - { - userVertex = vertex; - } - QSet vertices() const { QSet setOfVertices; for (const_iterator it = constBegin(); it != constEnd(); ++it) { @@ -256,11 +251,6 @@ public: } #endif - Vertex *rootVertex() const - { - return userVertex; - } - protected: void createDirectedEdge(Vertex *from, Vertex *to, EdgeData *data) { @@ -286,8 +276,6 @@ protected: } private: - Vertex *userVertex; - QHash *> m_graph; }; diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index 41aa8aa..6bffd09 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -484,6 +484,10 @@ QGraphicsAnchorLayoutPrivate::QGraphicsAnchorLayoutPrivate() spacings[i] = -1; graphSimplified[i] = false; graphHasConflicts[i] = false; + + layoutFirstVertex[i] = 0; + layoutCentralVertex[i] = 0; + layoutLastVertex[i] = 0; } } @@ -663,7 +667,7 @@ bool QGraphicsAnchorLayoutPrivate::simplifyGraph(Orientation orientation) orientation == Horizontal ? "Horizontal" : "Vertical"); #endif - if (!graph[orientation].rootVertex()) + if (!layoutFirstVertex[orientation]) return true; bool dirty; @@ -700,7 +704,7 @@ bool QGraphicsAnchorLayoutPrivate::simplifyGraphIteration(QGraphicsAnchorLayoutP QSet visited; QStack > stack; - stack.push(qMakePair(static_cast(0), g.rootVertex())); + stack.push(qMakePair(static_cast(0), layoutFirstVertex[orientation])); QVector candidates; bool candidatesForward; @@ -959,9 +963,10 @@ void QGraphicsAnchorLayoutPrivate::createLayoutEdges() data->maxSize = QWIDGETSIZE_MAX; data->skipInPreferred = 1; - // Set the Layout Left edge as the root of the horizontal graph. - AnchorVertex *v = internalVertex(layout, Qt::AnchorLeft); - graph[Horizontal].setRootVertex(v); + // Save a reference to layout vertices + layoutFirstVertex[Horizontal] = internalVertex(layout, Qt::AnchorLeft); + layoutCentralVertex[Horizontal] = 0; + layoutLastVertex[Horizontal] = internalVertex(layout, Qt::AnchorRight); // Vertical data = new AnchorData; @@ -970,9 +975,10 @@ void QGraphicsAnchorLayoutPrivate::createLayoutEdges() data->maxSize = QWIDGETSIZE_MAX; data->skipInPreferred = 1; - // Set the Layout Top edge as the root of the vertical graph. - v = internalVertex(layout, Qt::AnchorTop); - graph[Vertical].setRootVertex(v); + // Save a reference to layout vertices + layoutFirstVertex[Vertical] = internalVertex(layout, Qt::AnchorTop); + layoutCentralVertex[Vertical] = 0; + layoutLastVertex[Vertical] = internalVertex(layout, Qt::AnchorBottom); } void QGraphicsAnchorLayoutPrivate::deleteLayoutEdges() @@ -1019,6 +1025,8 @@ void QGraphicsAnchorLayoutPrivate::createItemEdges(QGraphicsLayoutItem *item) void QGraphicsAnchorLayoutPrivate::createCenterAnchors( QGraphicsLayoutItem *item, Qt::AnchorPoint centerEdge) { + Q_Q(QGraphicsAnchorLayout); + Orientation orientation; switch (centerEdge) { case Qt::AnchorHorizontalCenter: @@ -1073,12 +1081,19 @@ void QGraphicsAnchorLayoutPrivate::createCenterAnchors( // Remove old one removeAnchor_helper(first, last); + + if (item == q) { + layoutCentralVertex[orientation] = internalVertex(q, centerEdge); + } + } void QGraphicsAnchorLayoutPrivate::removeCenterAnchors( QGraphicsLayoutItem *item, Qt::AnchorPoint centerEdge, bool substitute) { + Q_Q(QGraphicsAnchorLayout); + Orientation orientation; switch (centerEdge) { case Qt::AnchorHorizontalCenter: @@ -1151,6 +1166,10 @@ void QGraphicsAnchorLayoutPrivate::removeCenterAnchors( // by this time, the center vertex is deleted and merged into a non-centered internal anchor removeAnchor_helper(first, internalVertex(item, lastEdge)); } + + if (item == q) { + layoutCentralVertex[orientation] = 0; + } } @@ -1773,7 +1792,7 @@ void QGraphicsAnchorLayoutPrivate::calculateGraphs( // For minimum and maximum, use the path between the two layout sides as the // objective function. - AnchorVertex *v = internalVertex(q, pickEdge(Qt::AnchorRight, orientation)); + AnchorVertex *v = layoutLastVertex[orientation]; GraphPath trunkPath = graphPaths[orientation].value(v); bool feasible = calculateTrunk(orientation, trunkPath, trunkConstraints, trunkVariables); @@ -1955,7 +1974,7 @@ void QGraphicsAnchorLayoutPrivate::findPaths(Orientation orientation) QSet visited; - AnchorVertex *root = graph[orientation].rootVertex(); + AnchorVertex *root = layoutFirstVertex[orientation]; graphPaths[orientation].insert(root, GraphPath()); @@ -2077,28 +2096,18 @@ QGraphicsAnchorLayoutPrivate::getGraphParts(Orientation orientation) { Q_Q(QGraphicsAnchorLayout); - // Find layout vertices and edges for the current orientation. - AnchorVertex *layoutFirstVertex = \ - internalVertex(q, pickEdge(Qt::AnchorLeft, orientation)); - - AnchorVertex *layoutCentralVertex = \ - internalVertex(q, pickEdge(Qt::AnchorHorizontalCenter, orientation)); - - AnchorVertex *layoutLastVertex = \ - internalVertex(q, pickEdge(Qt::AnchorRight, orientation)); - - Q_ASSERT(layoutFirstVertex && layoutLastVertex); + Q_ASSERT(layoutFirstVertex[orientation] && layoutLastVertex[orientation]); AnchorData *edgeL1 = NULL; AnchorData *edgeL2 = NULL; // The layout may have a single anchor between Left and Right or two half anchors // passing through the center - if (layoutCentralVertex) { - edgeL1 = graph[orientation].edgeData(layoutFirstVertex, layoutCentralVertex); - edgeL2 = graph[orientation].edgeData(layoutCentralVertex, layoutLastVertex); + if (layoutCentralVertex[orientation]) { + edgeL1 = graph[orientation].edgeData(layoutFirstVertex[orientation], layoutCentralVertex[orientation]); + edgeL2 = graph[orientation].edgeData(layoutCentralVertex[orientation], layoutLastVertex[orientation]); } else { - edgeL1 = graph[orientation].edgeData(layoutFirstVertex, layoutLastVertex); + edgeL1 = graph[orientation].edgeData(layoutFirstVertex[orientation], layoutLastVertex[orientation]); } QLinkedList remainingConstraints; @@ -2288,7 +2297,7 @@ void QGraphicsAnchorLayoutPrivate::calculateVertexPositions( QSet visited; // Get root vertex - AnchorVertex *root = graph[orientation].rootVertex(); + AnchorVertex *root = layoutFirstVertex[orientation]; root->distance = 0; visited.insert(root); diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.h b/src/gui/graphicsview/qgraphicsanchorlayout_p.h index 7dd0d65..7d7bdb6 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.h +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.h @@ -504,6 +504,10 @@ public: // Internal graph of anchorage points and anchors, for both orientations Graph graph[2]; + AnchorVertex *layoutFirstVertex[2]; + AnchorVertex *layoutCentralVertex[2]; + AnchorVertex *layoutLastVertex[2]; + // Graph paths and constraints, for both orientations QMultiHash graphPaths[2]; QList constraints[2]; -- cgit v0.12 From d00f3afdd547b3206016b6d97f669b04f48a27d7 Mon Sep 17 00:00:00 2001 From: Caio Marcelo de Oliveira Filho Date: Wed, 4 Nov 2009 14:41:58 -0300 Subject: QGAL: escape vertices names in the serialized graph output Signed-off-by: Caio Marcelo de Oliveira Filho Reviewed-by: Eduardo M. Fleury --- src/gui/graphicsview/qgraph_p.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/graphicsview/qgraph_p.h b/src/gui/graphicsview/qgraph_p.h index b5b3c88..0a2bf27 100644 --- a/src/gui/graphicsview/qgraph_p.h +++ b/src/gui/graphicsview/qgraph_p.h @@ -236,7 +236,7 @@ public: EdgeData *data = edgeData(v, v1); bool forward = data->from == v; if (forward) { - edges += QString::fromAscii("%1->%2 [label=\"[%3,%4,%5]\" dir=both color=\"#000000:#a0a0a0\"] \n") + edges += QString::fromAscii("\"%1\"->\"%2\" [label=\"[%3,%4,%5]\" dir=both color=\"#000000:#a0a0a0\"] \n") .arg(v->toString()) .arg(v1->toString()) .arg(data->minSize) @@ -245,7 +245,7 @@ public: ; } } - strVertices += QString::fromAscii("%1 [label=\"%2\"]\n").arg(v->toString()).arg(v->toString()); + strVertices += QString::fromAscii("\"%1\" [label=\"%2\"]\n").arg(v->toString()).arg(v->toString()); } return QString::fromAscii("%1\n%2\n").arg(strVertices).arg(edges); } -- cgit v0.12 From 5c1c3e0366ce6992a514148815ef25b3f1f6f66b Mon Sep 17 00:00:00 2001 From: Caio Marcelo de Oliveira Filho Date: Wed, 4 Nov 2009 14:45:32 -0300 Subject: QGAL: add names to the items in some tests Those are useful when dumping the graph in dot format for debugging. Signed-off-by: Caio Marcelo de Oliveira Filho Reviewed-by: Eduardo M. Fleury --- tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp | 8 ++++---- tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp | 8 ++++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp index c8a9fac..09e2ee2 100644 --- a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp +++ b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp @@ -1951,7 +1951,7 @@ void tst_QGraphicsAnchorLayout::simplifiableUnfeasible() if (hasSimplification) QVERIFY(!usedSimplex(l, Qt::Horizontal)); - // Now we make it valid again + // Now we make it valid b->setMinimumWidth(100); l->invalidate(); @@ -1979,9 +1979,9 @@ void tst_QGraphicsAnchorLayout::simplificationVsOrder() QSizeF pref(20, 10); QSizeF max(50, 10); - QGraphicsWidget *a = createItem(min, pref, max); - QGraphicsWidget *b = createItem(min, pref, max); - QGraphicsWidget *c = createItem(min, pref, max); + QGraphicsWidget *a = createItem(min, pref, max, "A"); + QGraphicsWidget *b = createItem(min, pref, max, "B"); + QGraphicsWidget *c = createItem(min, pref, max, "C"); QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; diff --git a/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp b/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp index 1c7a159..2d6b44b 100644 --- a/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp +++ b/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp @@ -162,10 +162,14 @@ Q_DECLARE_METATYPE(AnchorItemSizeHintList) class TestWidget : public QGraphicsWidget { public: - inline TestWidget(QGraphicsItem *parent = 0) + inline TestWidget(QGraphicsItem *parent = 0, const QString &name = QString()) : QGraphicsWidget(parent) { setContentsMargins( 0,0,0,0 ); + if (name.isEmpty()) + setData(0, QString::fromAscii("w%1").arg(int(this))); + else + setData(0, name); } ~TestWidget() { @@ -1684,7 +1688,7 @@ void tst_QGraphicsAnchorLayout1::testBasicLayout() // Create dummy widgets QList widgets; for (int i = 0; i < widgetCount; ++i) { - TestWidget *w = new TestWidget; + TestWidget *w = new TestWidget(0, QString::fromAscii("W%1").arg(i)); widgets << w; } -- cgit v0.12 From 41369cd2946956b9a455e4f2014dcc38ffcbad52 Mon Sep 17 00:00:00 2001 From: Caio Marcelo de Oliveira Filho Date: Wed, 4 Nov 2009 14:54:49 -0300 Subject: QGAL: extend helper function to always return parallel anchor created Our helper function addAnchorMaybeParallel() returned 0 to indicate an unfeasible setup, so we ended up without the pointer to the new parallel anchor (which was created regardless the feasibility). While we don't make use of this information right now, vertex simplification will need to store those new parallel anchors even when they are not feasible. Signed-off-by: Caio Marcelo de Oliveira Filho Reviewed-by: Eduardo M. Fleury --- src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 25 ++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index 6bffd09..f0aeea4 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -533,13 +533,14 @@ inline static qreal checkAdd(qreal a, qreal b) Adds \a newAnchor to the graph \a g. Returns the newAnchor itself if it could be added without further changes to the graph. If a - new parallel anchor had to be created, then returns the new parallel anchor. In case the - addition is unfeasible -- because a parallel setup is not possible, returns 0. + new parallel anchor had to be created, then returns the new parallel anchor. If a parallel anchor + had to be created and it results in an unfeasible setup, \a feasible is set to false, otherwise + true. */ static AnchorData *addAnchorMaybeParallel(Graph *g, - AnchorData *newAnchor) + AnchorData *newAnchor, bool *feasible) { - bool feasible = true; + *feasible = true; // If already exists one anchor where newAnchor is supposed to be, we create a parallel // anchor. @@ -548,12 +549,12 @@ static AnchorData *addAnchorMaybeParallel(Graph *g, // At this point we can identify that the parallel anchor is not feasible, e.g. one // anchor minimum size is bigger than the other anchor maximum size. - feasible = parallel->refreshSizeHints_helper(0, false); + *feasible = parallel->refreshSizeHints_helper(0, false); newAnchor = parallel; } g->createEdge(newAnchor->from, newAnchor->to, newAnchor); - return feasible ? newAnchor : 0; + return newAnchor; } @@ -839,13 +840,21 @@ bool QGraphicsAnchorLayoutPrivate::simplifyGraphIteration(QGraphicsAnchorLayoutP // Add the sequence to the graph. // + // ### At this point we assume that if some parallel anchor will be created because + // of the new sequence, the other anchor will not be a center anchor (since we + // not deal with that case yet). This assumption will break once we start simplifying + // vertices. + AnchorData *possibleParallel = g.edgeData(beforeSequence, afterSequence); + Q_ASSERT(!possibleParallel || !possibleParallel->isCenterAnchor); + AnchorData *sequence = createSequence(&g, beforeSequence, candidates, afterSequence); // If 'beforeSequence' and 'afterSequence' already had an anchor between them, we'll // create a parallel anchor between the new sequence and the old anchor. - AnchorData *newAnchor = addAnchorMaybeParallel(&g, sequence); + bool newFeasible; + AnchorData *newAnchor = addAnchorMaybeParallel(&g, sequence, &newFeasible); - if (!newAnchor) { + if (!newFeasible) { *feasible = false; return false; } -- cgit v0.12 From 33faaf6fa1775dc74bb61acde8a48eae2b9f2635 Mon Sep 17 00:00:00 2001 From: "Eduardo M. Fleury" Date: Mon, 19 Oct 2009 16:36:53 -0300 Subject: 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 Reviewed-by: Caio Marcelo de Oliveira Filho --- src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 56 ++++++++++++++++++---- .../tst_qgraphicsanchorlayout.cpp | 6 +-- 2 files changed, 50 insertions(+), 12 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 getVariables(QList 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 QGraphicsAnchorLayoutPrivate::constraintsFromSizeHints( const QList &anchors) { + if (anchors.isEmpty()) + return QList(); + + // 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 anchorConstraints; + bool unboundedProblem = true; for (int i = 0; i < anchors.size(); ++i) { AnchorData *ad = anchors[i]; @@ -2079,6 +2102,7 @@ QList 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 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 QGraphicsAnchorLayoutPrivate::constraintsFromSizeHin QList< QList > 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 // Save sizeAtMaximum results for (int i = 0; i < variables.size(); ++i) { AnchorData *ad = static_cast(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; } } diff --git a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp index 09e2ee2..ce1ffad 100644 --- a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp +++ b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp @@ -1896,15 +1896,15 @@ void tst_QGraphicsAnchorLayout::infiniteMaxSizes() QGraphicsWidget p; p.setLayout(l); + QCOMPARE(int(p.effectiveSizeHint(Qt::MaximumSize).width()), + QWIDGETSIZE_MAX); + p.resize(200, 10); QCOMPARE(a->geometry(), QRectF(0, 0, 50, 10)); QCOMPARE(b->geometry(), QRectF(50, 0, 50, 10)); QCOMPARE(c->geometry(), QRectF(100, 0, 50, 10)); QCOMPARE(d->geometry(), QRectF(150, 0, 50, 10)); - if (!hasSimplification) - QEXPECT_FAIL("", "Without simplification there is no fair distribution.", Abort); - p.resize(1000, 10); QCOMPARE(a->geometry(), QRectF(0, 0, 450, 10)); QCOMPARE(b->geometry(), QRectF(450, 0, 50, 10)); -- cgit v0.12 From 56c04b7f546babf5bbe64a6d0175f635cb2fd204 Mon Sep 17 00:00:00 2001 From: "Eduardo M. Fleury" Date: Thu, 29 Oct 2009 16:19:59 -0300 Subject: QGAL: Update infiniteSizes test to avoid simplification The infiniteSizes test is supposed to work w/o simplification, to ensure that I'm adding a central anchor. With this anchor we force the problem to go to the simplex solver and expect it to solve things fine anyway. Signed-off-by: Eduardo M. Fleury Reviewed-by: Caio Marcelo de Oliveira Filho --- tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp index ce1ffad..00bfe65 100644 --- a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp +++ b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp @@ -1882,6 +1882,7 @@ void tst_QGraphicsAnchorLayout::infiniteMaxSizes() QGraphicsWidget *b = createItem(min, pref, max, "b"); QGraphicsWidget *c = createItem(min, pref, max, "c"); QGraphicsWidget *d = createItem(min, pref, max, "d"); + QGraphicsWidget *e = createItem(min, pref, max, "e"); // setAnchor(l, l, Qt::AnchorLeft, a, Qt::AnchorLeft, 0); @@ -1889,6 +1890,8 @@ void tst_QGraphicsAnchorLayout::infiniteMaxSizes() setAnchor(l, b, Qt::AnchorRight, c, Qt::AnchorLeft, 0); setAnchor(l, c, Qt::AnchorRight, d, Qt::AnchorLeft, 0); setAnchor(l, d, Qt::AnchorRight, l, Qt::AnchorRight, 0); + setAnchor(l, b, Qt::AnchorHorizontalCenter, e, Qt::AnchorLeft, 0); + setAnchor(l, e, Qt::AnchorRight, c, Qt::AnchorHorizontalCenter, 0); a->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); c->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); -- cgit v0.12 From 52d737eb6f4b79cd0c7fc7ee1d041fb19d286a27 Mon Sep 17 00:00:00 2001 From: "Eduardo M. Fleury" Date: Thu, 29 Oct 2009 17:14:09 -0300 Subject: QGAL: Do not create sizeHint constraints for dependent anchors Some anchors have their sizes linked directly to the size of others. That is the case for instance with center anchors where one half must have exactly the same size as the other. To make that more clear, adding "dependency" info to AnchorData and setting it accordingly. This is future proof in the sense that if someday we are allowed to anchor to other items in terms of percentages, like, anchor to 70% of an items' width, we would also need this notion. Knowing that, we no longer need to create size hint constraints for the slave anchors, only for the master ones. The size of slave anchors is enforced by the dependency constraint (sizeSlave = X * sizeMaster). Signed-off-by: Eduardo M. Fleury Reviewed-by: Caio Marcelo de Oliveira Filho --- src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 25 +++++++++++++++--------- src/gui/graphicsview/qgraphicsanchorlayout_p.h | 10 +++++++++- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index dbfce74..ad7d657 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -1080,12 +1080,14 @@ void QGraphicsAnchorLayoutPrivate::createCenterAnchors( c->variables.insert(data, 1.0); addAnchor_helper(item, firstEdge, item, centerEdge, data); data->isCenterAnchor = true; + data->dependency = AnchorData::Master; data->refreshSizeHints(0); data = new AnchorData; c->variables.insert(data, -1.0); addAnchor_helper(item, centerEdge, item, lastEdge, data); data->isCenterAnchor = true; + data->dependency = AnchorData::Slave; data->refreshSizeHints(0); itemCenterConstraints[orientation].append(c); @@ -2075,19 +2077,18 @@ QList QGraphicsAnchorLayoutPrivate::constraintsFromSizeHin // 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; + AnchorData *layoutEdge = NULL; if (layoutCentralVertex[orient]) { - layoutEdge1 = graph[orient].edgeData(layoutFirstVertex[orient], layoutCentralVertex[orient]); - layoutEdge2 = graph[orient].edgeData(layoutCentralVertex[orient], layoutLastVertex[orient]); + layoutEdge = graph[orient].edgeData(layoutFirstVertex[orient], layoutCentralVertex[orient]); } else { - layoutEdge1 = graph[orient].edgeData(layoutFirstVertex[orient], layoutLastVertex[orient]); + layoutEdge = 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; + if (layoutEdge->maxSize < QWIDGETSIZE_MAX) + layoutEdge = NULL; } // For each variable, create constraints based on size hints @@ -2096,6 +2097,12 @@ QList QGraphicsAnchorLayoutPrivate::constraintsFromSizeHin for (int i = 0; i < anchors.size(); ++i) { AnchorData *ad = anchors[i]; + // Anchors that have their size directly linked to another one don't need constraints + // For exammple, the second half of an item has exactly the same size as the first half + // thus constraining the latter is enough. + if (ad->dependency == AnchorData::Slave) + continue; + if ((ad->minSize == ad->maxSize) || qFuzzyCompare(ad->minSize, ad->maxSize)) { QSimplexConstraint *c = new QSimplexConstraint; c->variables.insert(ad, 1.0); @@ -2113,7 +2120,7 @@ QList QGraphicsAnchorLayoutPrivate::constraintsFromSizeHin // 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)) + if (ad == layoutEdge) continue; c = new QSimplexConstraint; @@ -2128,7 +2135,7 @@ QList QGraphicsAnchorLayoutPrivate::constraintsFromSizeHin // 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->variables.insert(layoutEdge, 1.0); c->constant = QWIDGETSIZE_MAX; c->ratio = QSimplexConstraint::LessOrEqual; anchorConstraints += c; diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.h b/src/gui/graphicsview/qgraphicsanchorlayout_p.h index 7d7bdb6..2f0237c 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.h +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.h @@ -150,6 +150,12 @@ struct AnchorData : public QSimplexVariable { Parallel }; + enum Dependency { + Independent = 0, + Master, + Slave + }; + AnchorData() : QSimplexVariable(), item(0), from(0), to(0), minSize(0), prefSize(0), expSize(0), maxSize(0), @@ -157,7 +163,8 @@ struct AnchorData : public QSimplexVariable { sizeAtExpanding(0), sizeAtMaximum(0), graphicsAnchor(0), skipInPreferred(0), type(Normal), hasSize(true), isLayoutAnchor(false), - isCenterAnchor(false), orientation(0) {} + isCenterAnchor(false), orientation(0), + dependency(Independent) {} virtual void updateChildrenSizes() {} virtual bool refreshSizeHints(const QLayoutStyleInfo *styleInfo); @@ -212,6 +219,7 @@ struct AnchorData : public QSimplexVariable { uint isLayoutAnchor : 1; // if this anchor is an internal layout anchor uint isCenterAnchor : 1; uint orientation : 1; + uint dependency : 2; // either Independent, Master or Slave }; #ifdef QT_DEBUG -- cgit v0.12 From d4d6901d82476e92f4c318d8d6e9da5d3410920f Mon Sep 17 00:00:00 2001 From: "Eduardo M. Fleury" Date: Tue, 27 Oct 2009 18:34:01 -0300 Subject: QGAL (Test): Disable simplification test when that is off Prevent failures when the test is run with QT_ANCHORLAYOUT_NO_SIMPLIFICATION Signed-off-by: Eduardo M. Fleury Reviewed-by: Caio Marcelo de Oliveira Filho --- tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp index 00bfe65..53e27dc 100644 --- a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp +++ b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp @@ -342,8 +342,10 @@ void tst_QGraphicsAnchorLayout::layoutDirection() QCOMPARE(checkReverseDirection(p), true); - QVERIFY(usedSimplex(l, Qt::Horizontal)); - QVERIFY(!usedSimplex(l, Qt::Vertical)); + if (hasSimplification) { + QVERIFY(usedSimplex(l, Qt::Horizontal)); + QVERIFY(!usedSimplex(l, Qt::Vertical)); + } delete p; delete view; -- cgit v0.12 From 6c758ba18ded5ed1ac518777cb59e519142d292c Mon Sep 17 00:00:00 2001 From: "Eduardo M. Fleury" Date: Tue, 27 Oct 2009 17:29:02 -0300 Subject: QGAL: Avoid false assertions due to floating point precision errors Signed-off-by: Eduardo M. Fleury Reviewed-by: Caio Marcelo de Oliveira Filho --- src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 22 ++++++++++++---------- src/gui/graphicsview/qsimplex_p.cpp | 2 +- src/gui/graphicsview/qsimplex_p.h | 2 +- .../tst_qgraphicsanchorlayout1.cpp | 17 ++++++++++++++++- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index ad7d657..baff206 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -341,16 +341,16 @@ void SequentialAnchorData::updateChildrenSizes() // ### REMOVE ME // ### 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(sizeAtPreferred > minSize || qFuzzyCompare(sizeAtPreferred, minSize)); - Q_ASSERT(sizeAtExpanding > minSize || qFuzzyCompare(sizeAtExpanding, minSize)); - Q_ASSERT(sizeAtMaximum > minSize || qFuzzyCompare(sizeAtMaximum, minSize)); + Q_ASSERT(sizeAtMinimum > minSize || qAbs(sizeAtMinimum - minSize) < 0.00000001); + Q_ASSERT(sizeAtPreferred > minSize || qAbs(sizeAtPreferred - minSize) < 0.00000001); + Q_ASSERT(sizeAtExpanding > minSize || qAbs(sizeAtExpanding - minSize) < 0.00000001); + Q_ASSERT(sizeAtMaximum > minSize || qAbs(sizeAtMaximum - minSize) < 0.00000001); // 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)); + // Q_ASSERT(sizeAtMinimum < maxSize || qAbs(sizeAtMinimum - maxSize) < 0.00000001); + // Q_ASSERT(sizeAtPreferred < maxSize || qAbs(sizeAtPreferred - maxSize) < 0.00000001); + // Q_ASSERT(sizeAtExpanding < maxSize || qAbs(sizeAtExpanding - maxSize) < 0.00000001); + // Q_ASSERT(sizeAtMaximum < maxSize || qAbs(sizeAtMaximum - maxSize) < 0.00000001); // Band here refers if the value is in the Minimum To Preferred // band (the lower band) or the Preferred To Maximum (the upper band). @@ -2536,8 +2536,9 @@ bool QGraphicsAnchorLayoutPrivate::solveMinMax(const QList QList variables = getVariables(constraints); for (int i = 0; i < variables.size(); ++i) { AnchorData *ad = static_cast(variables[i]); - Q_ASSERT(ad->result >= ad->minSize || qFuzzyCompare(ad->result, ad->minSize)); ad->sizeAtMinimum = ad->result; + Q_ASSERT(ad->sizeAtMinimum >= ad->minSize || + qAbs(ad->sizeAtMinimum - ad->minSize) < 0.00000001); } // Calculate maximum values @@ -2546,8 +2547,9 @@ bool QGraphicsAnchorLayoutPrivate::solveMinMax(const QList // Save sizeAtMaximum results for (int i = 0; i < variables.size(); ++i) { AnchorData *ad = static_cast(variables[i]); - // Q_ASSERT(ad->result <= ad->maxSize || qFuzzyCompare(ad->result, ad->maxSize)); ad->sizeAtMaximum = ad->result; + // Q_ASSERT(ad->sizeAtMaximum <= ad->maxSize || + // qAbs(ad->sizeAtMaximum - ad->maxSize) < 0.00000001); } } return feasible; diff --git a/src/gui/graphicsview/qsimplex_p.cpp b/src/gui/graphicsview/qsimplex_p.cpp index 86b10b4..cd40f9e 100644 --- a/src/gui/graphicsview/qsimplex_p.cpp +++ b/src/gui/graphicsview/qsimplex_p.cpp @@ -288,7 +288,7 @@ bool QSimplex::setConstraints(const QList newConstraints) // original problem. // Otherwise, we clean up our structures and report there is // no feasible solution. - if (valueAt(0, columns - 1) != 0.0) { + if ((valueAt(0, columns - 1) != 0.0) && (qAbs(valueAt(0, columns - 1)) > 0.00001)) { qWarning() << "QSimplex: No feasible solution!"; clearDataStructures(); return false; diff --git a/src/gui/graphicsview/qsimplex_p.h b/src/gui/graphicsview/qsimplex_p.h index 084ad7f..a5816d1 100644 --- a/src/gui/graphicsview/qsimplex_p.h +++ b/src/gui/graphicsview/qsimplex_p.h @@ -107,7 +107,7 @@ struct QSimplexConstraint Q_ASSERT(constant > 0 || qFuzzyCompare(1, 1 + constant)); - if ((leftHandSide == constant) || qFuzzyCompare(1000 + leftHandSide, 1000 + constant)) + if ((leftHandSide == constant) || qAbs(leftHandSide - constant) < 0.00000001) return true; switch (ratio) { diff --git a/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp b/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp index 2d6b44b..a7ce9be 100644 --- a/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp +++ b/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp @@ -1668,6 +1668,18 @@ inline QGraphicsLayoutItem *getItem( return widgets[index]; } +static QRectF truncate(QRectF original) +{ + QRectF result; + + result.setX(qRound(original.x() * 1000000) / 1000000.0); + result.setY(qRound(original.y() * 1000000) / 1000000.0); + result.setWidth(qRound(original.width() * 1000000) / 1000000.0); + result.setHeight(qRound(original.height() * 1000000) / 1000000.0); + + return result; +} + void tst_QGraphicsAnchorLayout1::testBasicLayout() { QFETCH(QSizeF, size); @@ -1716,7 +1728,10 @@ void tst_QGraphicsAnchorLayout1::testBasicLayout() // Validate for (int i = 0; i < result.count(); ++i) { const BasicLayoutTestResult item = result[i]; - QCOMPARE(widgets[item.index]->geometry(), item.rect); + QRectF expected = truncate(item.rect); + QRectF actual = truncate(widgets[item.index]->geometry()); + + QCOMPARE(expected, actual); } // ###: not supported yet -- cgit v0.12 From 95ec02845997c2dee796c680186c46ab29e5e9ce Mon Sep 17 00:00:00 2001 From: "Eduardo M. Fleury" Date: Wed, 4 Nov 2009 16:11:58 -0300 Subject: QGAL (test): Test parent widget size besides children sizes Sometimes a test fails due to a wrong child size and we spend a lot of time trying to understand why but, in fact the problem is in the parent size. This commit adds a test to check whether the parent widget was properly resized. Signed-off-by: Eduardo M. Fleury Reviewed-by: Caio Marcelo de Oliveira Filho --- .../qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp b/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp index a7ce9be..57e5c41 100644 --- a/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp +++ b/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp @@ -1720,10 +1720,8 @@ void tst_QGraphicsAnchorLayout1::testBasicLayout() widget->setLayout(layout); widget->setContentsMargins(0,0,0,0); - widget->setMinimumSize(size); - widget->setMaximumSize(size); - -// QTest::qWait(500); // layouting is asynchronous.. + widget->resize(size); + QCOMPARE(widget->size(), size); // Validate for (int i = 0; i < result.count(); ++i) { @@ -2231,8 +2229,8 @@ void tst_QGraphicsAnchorLayout1::testRemoveCenterAnchor() widget->setLayout(layout); widget->setContentsMargins(0,0,0,0); - widget->setMinimumSize(size); - widget->setMaximumSize(size); + widget->resize(size); + QCOMPARE(widget->size(), size); // Validate for (int i = 0; i < result.count(); ++i) { @@ -3072,8 +3070,8 @@ void tst_QGraphicsAnchorLayout1::testComplexCases() widget->setLayout(layout); widget->setContentsMargins(0,0,0,0); - widget->setMinimumSize(size); - widget->setMaximumSize(size); + widget->resize(size); + QCOMPARE(widget->size(), size); // QTest::qWait(500); // layouting is asynchronous.. -- cgit v0.12 From 07be7cc5016ba036d6cfe73e610b4f7dd99ecf53 Mon Sep 17 00:00:00 2001 From: "Eduardo M. Fleury" Date: Wed, 4 Nov 2009 11:04:00 -0300 Subject: QGAL: Remove support for QSizePolicy::Expanding After meeting with Jan-Arve, we are removing the support for the expanding size hint flag. The reason for that is that such feature adds too much complexity to the existing code and makes it harder for us to implement planned changes, like the support for out-of-order simplification. As these changes are consireded more important than the support for the expanding sizeHint, we are dropping expanding support for now. Once the QGAL is more stable and we have more time available, we can consider bringing it back. Signed-off-by: Eduardo M. Fleury Reviewed-by: Caio Marcelo de Oliveira Filho --- src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 210 ++--------------------- src/gui/graphicsview/qgraphicsanchorlayout_p.h | 12 +- 2 files changed, 20 insertions(+), 202 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index baff206..7ad994c 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -105,7 +105,7 @@ qreal QGraphicsAnchorPrivate::spacing() const static void internalSizeHints(QSizePolicy::Policy policy, qreal minSizeHint, qreal prefSizeHint, qreal maxSizeHint, qreal *minSize, qreal *prefSize, - qreal *expSize, qreal *maxSize) + qreal *maxSize) { // minSize, prefSize and maxSize are initialized // with item's preferred Size: this is QSizePolicy::Fixed. @@ -135,11 +135,6 @@ static void internalSizeHints(QSizePolicy::Policy policy, *prefSize = *minSize; else *prefSize = prefSizeHint; - - if (policy & QSizePolicy::ExpandFlag) - *expSize = *maxSize; - else - *expSize = *prefSize; } bool AnchorData::refreshSizeHints(const QLayoutStyleInfo *styleInfo) @@ -154,7 +149,6 @@ bool AnchorData::refreshSizeHints(const QLayoutStyleInfo *styleInfo) if (isLayoutAnchor) { minSize = 0; prefSize = 0; - expSize = 0; maxSize = QWIDGETSIZE_MAX; if (isCenterAnchor) maxSize /= 2; @@ -205,8 +199,8 @@ bool AnchorData::refreshSizeHints(const QLayoutStyleInfo *styleInfo) } maxSizeHint = QWIDGETSIZE_MAX; } - internalSizeHints(policy, minSizeHint, prefSizeHint, maxSizeHint, - &minSize, &prefSize, &expSize, &maxSize); + internalSizeHints(policy, minSizeHint, prefSizeHint, maxSizeHint, + &minSize, &prefSize, &maxSize); // Set the anchor effective sizes to preferred. // @@ -217,7 +211,6 @@ bool AnchorData::refreshSizeHints(const QLayoutStyleInfo *styleInfo) // recalculate and override the values we set here. sizeAtMinimum = prefSize; sizeAtPreferred = prefSize; - sizeAtExpanding = prefSize; sizeAtMaximum = prefSize; return true; @@ -227,7 +220,6 @@ void ParallelAnchorData::updateChildrenSizes() { firstEdge->sizeAtMinimum = secondEdge->sizeAtMinimum = sizeAtMinimum; firstEdge->sizeAtPreferred = secondEdge->sizeAtPreferred = sizeAtPreferred; - firstEdge->sizeAtExpanding = secondEdge->sizeAtExpanding = sizeAtExpanding; firstEdge->sizeAtMaximum = secondEdge->sizeAtMaximum = sizeAtMaximum; firstEdge->updateChildrenSizes(); @@ -257,16 +249,12 @@ bool ParallelAnchorData::refreshSizeHints_helper(const QLayoutStyleInfo *styleIn return false; } - expSize = qMax(firstEdge->expSize, secondEdge->expSize); - expSize = qMin(expSize, maxSize); - prefSize = qMax(firstEdge->prefSize, secondEdge->prefSize); - prefSize = qMin(prefSize, expSize); + prefSize = qMin(prefSize, maxSize); // See comment in AnchorData::refreshSizeHints() about sizeAt* values sizeAtMinimum = prefSize; sizeAtPreferred = prefSize; - sizeAtExpanding = prefSize; sizeAtMaximum = prefSize; return true; @@ -280,8 +268,7 @@ bool ParallelAnchorData::refreshSizeHints_helper(const QLayoutStyleInfo *styleIn 1 is at Maximum */ static QPair getFactor(qreal value, qreal min, - qreal pref, qreal exp, - qreal max) + qreal pref, qreal max) { QGraphicsAnchorLayoutPrivate::Interval interval; qreal lower; @@ -291,13 +278,9 @@ static QPair getFactor(qreal valu interval = QGraphicsAnchorLayoutPrivate::MinToPreferred; lower = min; upper = pref; - } else if (value < exp) { - interval = QGraphicsAnchorLayoutPrivate::PreferredToExpanding; - lower = pref; - upper = exp; } else { - interval = QGraphicsAnchorLayoutPrivate::ExpandingToMax; - lower = exp; + interval = QGraphicsAnchorLayoutPrivate::PreferredToMax; + lower = pref; upper = max; } @@ -313,7 +296,7 @@ static QPair getFactor(qreal valu static qreal interpolate(const QPair &factor, qreal min, qreal pref, - qreal exp, qreal max) + qreal max) { qreal lower; qreal upper; @@ -323,12 +306,8 @@ static qreal interpolate(const QPair minSize || qAbs(sizeAtMinimum - minSize) < 0.00000001); Q_ASSERT(sizeAtPreferred > minSize || qAbs(sizeAtPreferred - minSize) < 0.00000001); - Q_ASSERT(sizeAtExpanding > minSize || qAbs(sizeAtExpanding - minSize) < 0.00000001); Q_ASSERT(sizeAtMaximum > minSize || qAbs(sizeAtMaximum - minSize) < 0.00000001); // These may be false if this anchor was in parallel with the layout stucture // Q_ASSERT(sizeAtMinimum < maxSize || qAbs(sizeAtMinimum - maxSize) < 0.00000001); // Q_ASSERT(sizeAtPreferred < maxSize || qAbs(sizeAtPreferred - maxSize) < 0.00000001); - // Q_ASSERT(sizeAtExpanding < maxSize || qAbs(sizeAtExpanding - maxSize) < 0.00000001); // Q_ASSERT(sizeAtMaximum < maxSize || qAbs(sizeAtMaximum - maxSize) < 0.00000001); // Band here refers if the value is in the Minimum To Preferred // band (the lower band) or the Preferred To Maximum (the upper band). const QPair minFactor = - getFactor(sizeAtMinimum, minSize, prefSize, expSize, maxSize); + getFactor(sizeAtMinimum, minSize, prefSize, maxSize); const QPair prefFactor = - getFactor(sizeAtPreferred, minSize, prefSize, expSize, maxSize); - const QPair expFactor = - getFactor(sizeAtExpanding, minSize, prefSize, expSize, maxSize); + getFactor(sizeAtPreferred, minSize, prefSize, maxSize); const QPair maxFactor = - getFactor(sizeAtMaximum, minSize, prefSize, expSize, maxSize); + getFactor(sizeAtMaximum, minSize, prefSize, maxSize); for (int i = 0; i < m_edges.count(); ++i) { AnchorData *e = m_edges.at(i); - e->sizeAtMinimum = interpolate(minFactor, e->minSize, e->prefSize, e->expSize, e->maxSize); - e->sizeAtPreferred = interpolate(prefFactor, e->minSize, e->prefSize, e->expSize, e->maxSize); - e->sizeAtExpanding = interpolate(expFactor, e->minSize, e->prefSize, e->expSize, e->maxSize); - e->sizeAtMaximum = interpolate(maxFactor, e->minSize, e->prefSize, e->expSize, e->maxSize); + e->sizeAtMinimum = interpolate(minFactor, e->minSize, e->prefSize, e->maxSize); + e->sizeAtPreferred = interpolate(prefFactor, e->minSize, e->prefSize, e->maxSize); + e->sizeAtMaximum = interpolate(maxFactor, e->minSize, e->prefSize, e->maxSize); e->updateChildrenSizes(); } @@ -386,7 +360,6 @@ bool SequentialAnchorData::refreshSizeHints_helper(const QLayoutStyleInfo *style { minSize = 0; prefSize = 0; - expSize = 0; maxSize = 0; for (int i = 0; i < m_edges.count(); ++i) { @@ -398,14 +371,12 @@ bool SequentialAnchorData::refreshSizeHints_helper(const QLayoutStyleInfo *style minSize += edge->minSize; prefSize += edge->prefSize; - expSize += edge->expSize; maxSize += edge->maxSize; } // See comment in AnchorData::refreshSizeHints() about sizeAt* values sizeAtMinimum = prefSize; sizeAtPreferred = prefSize; - sizeAtExpanding = prefSize; sizeAtMaximum = prefSize; return true; @@ -480,7 +451,6 @@ QGraphicsAnchorLayoutPrivate::QGraphicsAnchorLayoutPrivate() for (int j = 0; j < 3; ++j) { sizeHints[i][j] = -1; } - sizeAtExpanding[i] = -1; interpolationProgress[i] = -1; spacings[i] = -1; @@ -1866,27 +1836,19 @@ bool QGraphicsAnchorLayoutPrivate::calculateTrunk(Orientation orientation, const if (feasible) { solvePreferred(allConstraints, variables); - // Note that we don't include the sizeHintConstraints, since they - // have a different logic for solveExpanding(). - solveExpanding(constraints, variables); - - // Calculate and set the preferred and expanding sizes for the layout, + // Calculate and set the preferred size for the layout, // from the edge sizes that were calculated above. qreal pref(0.0); - qreal expanding(0.0); foreach (const AnchorData *ad, path.positives) { pref += ad->sizeAtPreferred; - expanding += ad->sizeAtExpanding; } foreach (const AnchorData *ad, path.negatives) { pref -= ad->sizeAtPreferred; - expanding -= ad->sizeAtExpanding; } sizeHints[orientation][Qt::MinimumSize] = min; sizeHints[orientation][Qt::PreferredSize] = pref; sizeHints[orientation][Qt::MaximumSize] = max; - sizeAtExpanding[orientation] = expanding; } qDeleteAll(sizeHintConstraints); @@ -1900,13 +1862,11 @@ bool QGraphicsAnchorLayoutPrivate::calculateTrunk(Orientation orientation, const AnchorData *ad = path.positives.toList()[0]; ad->sizeAtMinimum = ad->minSize; ad->sizeAtPreferred = ad->prefSize; - ad->sizeAtExpanding = ad->expSize; ad->sizeAtMaximum = ad->maxSize; sizeHints[orientation][Qt::MinimumSize] = ad->sizeAtMinimum; sizeHints[orientation][Qt::PreferredSize] = ad->sizeAtPreferred; sizeHints[orientation][Qt::MaximumSize] = ad->sizeAtMaximum; - sizeAtExpanding[orientation] = ad->sizeAtExpanding; } #if defined(QT_DEBUG) || defined(Q_AUTOTEST_EXPORT) @@ -1932,7 +1892,6 @@ bool QGraphicsAnchorLayoutPrivate::calculateNonTrunk(const QListsizeAtMinimum = ad->sizeAtPreferred; - ad->sizeAtExpanding = ad->sizeAtPreferred; ad->sizeAtMaximum = ad->sizeAtPreferred; } } @@ -2406,7 +2365,6 @@ void QGraphicsAnchorLayoutPrivate::setupEdgesInterpolation( result = getFactor(current, sizeHints[orientation][Qt::MinimumSize], sizeHints[orientation][Qt::PreferredSize], - sizeAtExpanding[orientation], sizeHints[orientation][Qt::MaximumSize]); interpolationInterval[orientation] = result.first; @@ -2421,7 +2379,6 @@ void QGraphicsAnchorLayoutPrivate::setupEdgesInterpolation( - minimum size, - preferred size, - - size when all expanding anchors are expanded, - maximum size. These three key values are calculated in advance using linear @@ -2441,7 +2398,7 @@ void QGraphicsAnchorLayoutPrivate::interpolateEdge(AnchorVertex *base, interpolationProgress[orientation]); qreal edgeDistance = interpolate(factor, edge->sizeAtMinimum, edge->sizeAtPreferred, - edge->sizeAtExpanding, edge->sizeAtMaximum); + edge->sizeAtMaximum); Q_ASSERT(edge->from == base || edge->to == base); @@ -2628,139 +2585,6 @@ bool QGraphicsAnchorLayoutPrivate::solvePreferred(const QListexpSize), this - value depends on the anchor expanding property in the following way: - - - Expanding normal anchors want to grow towards their maximum size - - Non-expanding normal anchors want to remain at their preferred size. - - Sequential anchors wants to grow towards a size that is calculated by: - summarizing it's child anchors, where it will use preferred size for non-expanding anchors - and maximum size for expanding anchors. - - Parallel anchors want to grow towards the smallest maximum size of all the expanding anchors. - - 2) Clamp their desired values to the value they assume in the neighbour - keyframes (sizeAtPreferred and sizeAtExpanding) - - 3) Run simplex with a setup that ensures the following: - - a. Anchors will change their value from their sizeAtPreferred towards - their sizeAtMaximum as much as required to ensure that ALL anchors - reach their respective "desired" expanding sizes. - - b. No anchors will change their value beyond what is NEEDED to satisfy - the requirement above. - - The final result is that, at the "expanding" keyframe expanding anchors - will grow and take with them all anchors that are parallel to them. - However, non-expanding anchors will remain at their preferred size unless - they are forced to grow by a parallel expanding anchor. - - Note: For anchors where the sizeAtPreferred is bigger than sizeAtMaximum, - the visual effect when the layout grows from its preferred size is - the following: Expanding anchors will keep their size while non - expanding ones will shrink. Only after non-expanding anchors have - shrinked all the way, the expanding anchors will start to shrink too. -*/ -void QGraphicsAnchorLayoutPrivate::solveExpanding(const QList &constraints, - const QList &variables) -{ - QList itemConstraints; - QSimplexConstraint *objective = new QSimplexConstraint; - bool hasExpanding = false; - - // Construct the simplex constraints and objective - for (int i = 0; i < variables.size(); ++i) { - // For each anchor - AnchorData *ad = variables[i]; - - // Clamp the desired expanding size - qreal upperBoundary = qMax(ad->sizeAtPreferred, ad->sizeAtMaximum); - qreal lowerBoundary = qMin(ad->sizeAtPreferred, ad->sizeAtMaximum); - qreal boundedExpSize = qBound(lowerBoundary, ad->expSize, upperBoundary); - - // Expanding anchors are those that want to move from their preferred size - if (boundedExpSize != ad->sizeAtPreferred) - hasExpanding = true; - - // Lock anchor between boundedExpSize and sizeAtMaximum (ensure 3.a) - if (boundedExpSize == ad->sizeAtMaximum || qFuzzyCompare(boundedExpSize, ad->sizeAtMaximum)) { - // The interval has only one possible value, we can use an "Equal" - // constraint and don't need to add this variable to the objective. - QSimplexConstraint *itemC = new QSimplexConstraint; - itemC->ratio = QSimplexConstraint::Equal; - itemC->variables.insert(ad, 1.0); - itemC->constant = boundedExpSize; - itemConstraints << itemC; - } else { - // Add MoreOrEqual and LessOrEqual constraints. - QSimplexConstraint *itemC = new QSimplexConstraint; - itemC->ratio = QSimplexConstraint::MoreOrEqual; - itemC->variables.insert(ad, 1.0); - itemC->constant = qMin(boundedExpSize, ad->sizeAtMaximum); - itemConstraints << itemC; - - itemC = new QSimplexConstraint; - itemC->ratio = QSimplexConstraint::LessOrEqual; - itemC->variables.insert(ad, 1.0); - itemC->constant = qMax(boundedExpSize, ad->sizeAtMaximum); - itemConstraints << itemC; - - // Create objective to avoid the anchors from moving away from - // the preferred size more than the needed amount. (ensure 3.b) - // The objective function is the distance between sizeAtPreferred - // and sizeAtExpanding, it will be minimized. - if (ad->sizeAtExpanding < ad->sizeAtMaximum) { - // Try to shrink this variable towards its sizeAtPreferred value - objective->variables.insert(ad, 1.0); - } else { - // Try to grow this variable towards its sizeAtPreferred value - objective->variables.insert(ad, -1.0); - } - } - } - - // Solve - if (hasExpanding == false) { - // If no anchors are expanding, we don't need to run the simplex - // Set all variables to their preferred size - for (int i = 0; i < variables.size(); ++i) { - variables[i]->sizeAtExpanding = variables[i]->sizeAtPreferred; - } - } else { - // Run simplex - QSimplex simplex; - - // Satisfy expanding (3.a) - bool feasible = simplex.setConstraints(constraints + itemConstraints); - Q_ASSERT(feasible); - - // Reduce damage (3.b) - simplex.setObjective(objective); - simplex.solveMin(); - - // Collect results - for (int i = 0; i < variables.size(); ++i) { - variables[i]->sizeAtExpanding = variables[i]->result; - } - } - - delete objective; - qDeleteAll(itemConstraints); -} - -/*! - \internal Returns true if there are no arrangement that satisfies all constraints. Otherwise returns false. diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.h b/src/gui/graphicsview/qgraphicsanchorlayout_p.h index 2f0237c..1e11ee2 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.h +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.h @@ -158,9 +158,9 @@ struct AnchorData : public QSimplexVariable { AnchorData() : QSimplexVariable(), item(0), from(0), to(0), - minSize(0), prefSize(0), expSize(0), maxSize(0), + minSize(0), prefSize(0), maxSize(0), sizeAtMinimum(0), sizeAtPreferred(0), - sizeAtExpanding(0), sizeAtMaximum(0), + sizeAtMaximum(0), graphicsAnchor(0), skipInPreferred(0), type(Normal), hasSize(true), isLayoutAnchor(false), isCenterAnchor(false), orientation(0), @@ -201,7 +201,6 @@ struct AnchorData : public QSimplexVariable { // size. qreal minSize; qreal prefSize; - qreal expSize; qreal maxSize; // These attributes define which sizes should that anchor be in when the @@ -209,7 +208,6 @@ struct AnchorData : public QSimplexVariable { // calculated by the Simplex solver based on the current layout setup. qreal sizeAtMinimum; qreal sizeAtPreferred; - qreal sizeAtExpanding; qreal sizeAtMaximum; QGraphicsAnchor *graphicsAnchor; @@ -345,8 +343,7 @@ public: // Interval represents which interpolation interval are we operating in. enum Interval { MinToPreferred = 0, - PreferredToExpanding, - ExpandingToMax + PreferredToMax }; // Several structures internal to the layout are duplicated to handle @@ -487,8 +484,6 @@ public: GraphPath path, qreal *min, qreal *max); bool solvePreferred(const QList &constraints, const QList &variables); - void solveExpanding(const QList &constraints, - const QList &variables); bool hasConflicts() const; #ifdef QT_DEBUG @@ -499,7 +494,6 @@ public: qreal spacings[NOrientations]; // Size hints from simplex engine qreal sizeHints[2][3]; - qreal sizeAtExpanding[2]; // Items QVector items; -- cgit v0.12 From 77f81c95635ecac0fc3516b4a4b71f84ffb56bfd Mon Sep 17 00:00:00 2001 From: "Eduardo M. Fleury" Date: Wed, 4 Nov 2009 11:37:53 -0300 Subject: QGAL (test): Remove expanding tests After the removal of the expanding size hint support. Signed-off-by: Eduardo M. Fleury Reviewed-by: Caio Marcelo de Oliveira Filho --- .../tst_qgraphicsanchorlayout.cpp | 238 +-------------------- 1 file changed, 10 insertions(+), 228 deletions(-) diff --git a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp index 53e27dc..cc96edb 100644 --- a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp +++ b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp @@ -79,9 +79,6 @@ private slots: void delete_anchor(); void conflicts(); void sizePolicy(); - void expandingSequence(); - void expandingSequenceFairDistribution(); - void expandingParallel(); void floatConflict(); void infiniteMaxSizes(); void simplifiableUnfeasible(); @@ -1611,217 +1608,6 @@ void tst_QGraphicsAnchorLayout::conflicts() delete p; } -void tst_QGraphicsAnchorLayout::expandingSequence() -{ - QSizeF min(10, 10); - QSizeF pref(50, 10); - QSizeF max(100, 10); - - QGraphicsWidget *a = createItem(min, pref, max, "a"); - QGraphicsWidget *b = createItem(min, pref, max, "b"); - - b->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); - - QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; - l->setContentsMargins(0, 0, 0, 0); - - // horizontal - setAnchor(l, l, Qt::AnchorLeft, a, Qt::AnchorLeft, 0); - setAnchor(l, a, Qt::AnchorRight, b, Qt::AnchorLeft, 0); - setAnchor(l, b, Qt::AnchorRight, l, Qt::AnchorRight, 0); - - // vertical - l->addAnchors(l, a, Qt::Vertical); - l->addAnchors(l, b, Qt::Vertical); - - QCOMPARE(l->count(), 2); - - QGraphicsWidget p; - p.setLayout(l); - - QSizeF layoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize); - QCOMPARE(layoutMinimumSize.width(), qreal(20)); - - QSizeF layoutExpandedSize(pref.width() + max.width(), layoutMinimumSize.height()); - p.resize(layoutExpandedSize); - - QCOMPARE(a->geometry().size(), pref); - QCOMPARE(b->geometry().size(), max); - - QSizeF layoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize); - QCOMPARE(layoutMaximumSize.width(), qreal(200)); - - if (hasSimplification) { - QVERIFY(!usedSimplex(l, Qt::Horizontal)); - QVERIFY(!usedSimplex(l, Qt::Vertical)); - } -} - -void tst_QGraphicsAnchorLayout::expandingSequenceFairDistribution() -{ - QSizeF min(10, 10); - QSizeF pref(50, 10); - QSizeF max(100, 10); - - QGraphicsWidget *a = createItem(min, pref, max, "a"); - QGraphicsWidget *b = createItem(min, pref, max, "b"); - QGraphicsWidget *c = createItem(min, pref, max, "c"); - QGraphicsWidget *d = createItem(min, pref, max, "d"); - - b->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); - d->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); - - QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; - l->setContentsMargins(0, 0, 0, 0); - - // horizontal - setAnchor(l, l, Qt::AnchorLeft, a, Qt::AnchorLeft, 0); - setAnchor(l, a, Qt::AnchorRight, b, Qt::AnchorLeft, 0); - setAnchor(l, b, Qt::AnchorRight, c, Qt::AnchorLeft, 0); - setAnchor(l, c, Qt::AnchorRight, d, Qt::AnchorLeft, 0); - setAnchor(l, d, Qt::AnchorRight, l, Qt::AnchorRight, 0); - - // vertical - l->addAnchors(l, a, Qt::Vertical); - l->addAnchors(l, b, Qt::Vertical); - l->addAnchors(l, c, Qt::Vertical); - l->addAnchors(l, d, Qt::Vertical); - - QCOMPARE(l->count(), 4); - - QGraphicsWidget p; - p.setLayout(l); - - QSizeF layoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize); - QCOMPARE(layoutMinimumSize.width(), qreal(40)); - - QSizeF layoutPartialExpandedSize((2 * pref.width()) + (2 * (pref.width() + 10)), - layoutMinimumSize.height()); - p.resize(layoutPartialExpandedSize); - - QCOMPARE(a->geometry().size(), pref); - QCOMPARE(b->geometry().size(), pref + QSizeF(10, 0)); - QCOMPARE(c->geometry().size(), pref); - QCOMPARE(d->geometry().size(), pref + QSizeF(10, 0)); - - QSizeF layoutExpandedSize((2 * pref.width()) + (2 * max.width()), - layoutMinimumSize.height()); - p.resize(layoutExpandedSize); - - QCOMPARE(a->geometry().size(), pref); - QCOMPARE(b->geometry().size(), max); - QCOMPARE(c->geometry().size(), pref); - QCOMPARE(d->geometry().size(), max); - - QSizeF layoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize); - QCOMPARE(layoutMaximumSize.width(), qreal(400)); - - if (hasSimplification) { - QVERIFY(!usedSimplex(l, Qt::Horizontal)); - QVERIFY(!usedSimplex(l, Qt::Vertical)); - } - - // Now we change D to have more "room for growth" from its preferred size - // to its maximum size. We expect a proportional fair distribution. Note that - // this seems to not conform with what QGraphicsLinearLayout does. - d->setMaximumSize(QSizeF(150, 10)); - - QSizeF newLayoutExpandedSize((2 * pref.width()) + (max.width() + 150), - layoutMinimumSize.height()); - p.resize(newLayoutExpandedSize); - - QCOMPARE(a->geometry().size(), pref); - QCOMPARE(b->geometry().size(), max); - QCOMPARE(c->geometry().size(), pref); - QCOMPARE(d->geometry().size(), QSizeF(150, 10)); - - QSizeF newLayoutPartialExpandedSize((4 * pref.width()) + 75, - layoutMinimumSize.height()); - p.resize(newLayoutPartialExpandedSize); - - QCOMPARE(a->geometry().size(), pref); - QCOMPARE(b->geometry().size(), pref + QSizeF(25, 0)); - QCOMPARE(c->geometry().size(), pref); - QCOMPARE(d->geometry().size(), pref + QSizeF(50, 0)); - - if (hasSimplification) { - QVERIFY(!usedSimplex(l, Qt::Horizontal)); - QVERIFY(!usedSimplex(l, Qt::Vertical)); - } -} - -void tst_QGraphicsAnchorLayout::expandingParallel() -{ - QSizeF min(10, 10); - QSizeF pref(50, 10); - QSizeF max(100, 10); - QSizeF max2(100, 50); - - QGraphicsWidget *a = createItem(min, pref, max, "a"); - QGraphicsWidget *b = createItem(min, pref, max, "b"); - QGraphicsWidget *c = createItem(min, pref, max2, "c"); - - b->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); - - QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; - l->setContentsMargins(0, 0, 0, 0); - - // horizontal - setAnchor(l, l, Qt::AnchorLeft, a, Qt::AnchorLeft, 0); - setAnchor(l, l, Qt::AnchorLeft, b, Qt::AnchorLeft, 0); - - setAnchor(l, a, Qt::AnchorRight, c, Qt::AnchorLeft, 0); - setAnchor(l, b, Qt::AnchorRight, c, Qt::AnchorLeft, 0); - - setAnchor(l, c, Qt::AnchorRight, l, Qt::AnchorRight, 0); - - // vertical - l->addAnchors(l, c, Qt::Vertical); - setAnchor(l, l, Qt::AnchorTop, a, Qt::AnchorTop, 0); - setAnchor(l, a, Qt::AnchorBottom, c, Qt::AnchorVerticalCenter, 0); - setAnchor(l, b, Qt::AnchorTop, c, Qt::AnchorVerticalCenter, 0); - setAnchor(l, b, Qt::AnchorBottom, l, Qt::AnchorBottom, 0); - - QCOMPARE(l->count(), 3); - - QGraphicsWidget p; - p.setLayout(l); - - QSizeF layoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize); - QCOMPARE(layoutMinimumSize.width(), qreal(20)); - - QSizeF layoutExpandedSize(pref.width() + max.width(), layoutMinimumSize.height()); - p.resize(layoutExpandedSize); - - QCOMPARE(a->geometry().size(), max); - QCOMPARE(b->geometry().size(), max); - QCOMPARE(c->geometry().size(), QSizeF(pref.width(), 20)); - - QSizeF layoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize); - QCOMPARE(layoutMaximumSize.width(), qreal(200)); - - // - // Change the parallel connection to a paralell connection of b with a center... - // - QGraphicsAnchor *anchor = l->anchor(b, Qt::AnchorRight, c, Qt::AnchorLeft); - delete anchor; - setAnchor(l, b, Qt::AnchorRight, a, Qt::AnchorHorizontalCenter, 0); - a->setMaximumSize(max + QSizeF(100, 0)); - - QSizeF newLayoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize); - QCOMPARE(newLayoutMinimumSize.width(), qreal(30)); - - QSizeF newLayoutExpandedSize = layoutExpandedSize + QSizeF(100, 0); - p.resize(newLayoutExpandedSize); - - QCOMPARE(a->geometry().size(), max + QSizeF(100, 0)); - QCOMPARE(b->geometry().size(), max); - QCOMPARE(c->geometry().size(), QSizeF(pref.width(), 20)); - - QSizeF newLayoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize); - QCOMPARE(newLayoutMaximumSize.width(), qreal(300)); -} - void tst_QGraphicsAnchorLayout::floatConflict() { QGraphicsWidget *a = createItem(QSizeF(80,10), QSizeF(90,10), QSizeF(100,10), "a"); @@ -1895,9 +1681,6 @@ void tst_QGraphicsAnchorLayout::infiniteMaxSizes() setAnchor(l, b, Qt::AnchorHorizontalCenter, e, Qt::AnchorLeft, 0); setAnchor(l, e, Qt::AnchorRight, c, Qt::AnchorHorizontalCenter, 0); - a->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); - c->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); - QGraphicsWidget p; p.setLayout(l); @@ -1911,17 +1694,16 @@ void tst_QGraphicsAnchorLayout::infiniteMaxSizes() QCOMPARE(d->geometry(), QRectF(150, 0, 50, 10)); p.resize(1000, 10); - QCOMPARE(a->geometry(), QRectF(0, 0, 450, 10)); - QCOMPARE(b->geometry(), QRectF(450, 0, 50, 10)); - QCOMPARE(c->geometry(), QRectF(500, 0, 450, 10)); - QCOMPARE(d->geometry(), QRectF(950, 0, 50, 10)); - - qreal expMaxSize = (QWIDGETSIZE_MAX - 100.0) / 2; - p.resize(QWIDGETSIZE_MAX, 10); - QCOMPARE(a->geometry(), QRectF(0, 0, expMaxSize, 10)); - QCOMPARE(b->geometry(), QRectF(expMaxSize, 0, 50, 10)); - QCOMPARE(c->geometry(), QRectF(expMaxSize + 50, 0, expMaxSize, 10)); - QCOMPARE(d->geometry(), QRectF(QWIDGETSIZE_MAX - 50, 0, 50, 10)); + QCOMPARE(a->geometry(), QRectF(0, 0, 250, 10)); + QCOMPARE(b->geometry(), QRectF(250, 0, 250, 10)); + QCOMPARE(c->geometry(), QRectF(500, 0, 250, 10)); + QCOMPARE(d->geometry(), QRectF(750, 0, 250, 10)); + + p.resize(40000, 10); + QCOMPARE(a->geometry(), QRectF(0, 0, 10000, 10)); + QCOMPARE(b->geometry(), QRectF(10000, 0, 10000, 10)); + QCOMPARE(c->geometry(), QRectF(20000, 0, 10000, 10)); + QCOMPARE(d->geometry(), QRectF(30000, 0, 10000, 10)); } void tst_QGraphicsAnchorLayout::simplifiableUnfeasible() -- cgit v0.12