From f2f7ad1e0a73ef28aee406de358e1308f817bf6d Mon Sep 17 00:00:00 2001 From: "Eduardo M. Fleury" Date: Thu, 5 Nov 2009 14:44:04 -0300 Subject: QGAL (Test): Add test where center anchor is simplified by parallel We were not handling the case where a parallel anchor is created to simplify a central anchor. Unfortunately no tests had shown that case yet. Signed-off-by: Eduardo M. Fleury Reviewed-by: Caio Marcelo de Oliveira Filho --- .../tst_qgraphicsanchorlayout.cpp | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp index cc96edbee3..8b52674cff 100644 --- a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp +++ b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp @@ -83,6 +83,7 @@ private slots: void infiniteMaxSizes(); void simplifiableUnfeasible(); void simplificationVsOrder(); + void parallelSimplificationOfCenter(); }; class RectWidget : public QGraphicsWidget @@ -1801,5 +1802,30 @@ void tst_QGraphicsAnchorLayout::simplificationVsOrder() } } +void tst_QGraphicsAnchorLayout::parallelSimplificationOfCenter() +{ + QSizeF min(10, 10); + QSizeF pref(20, 10); + QSizeF max(50, 10); + + QGraphicsWidget *a = createItem(min, pref, max, "A"); + QGraphicsWidget *b = createItem(min, pref, max, "B"); + + QGraphicsWidget parent; + QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout(&parent); + l->setContentsMargins(0, 0, 0, 0); + + l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft); + l->addAnchor(l, Qt::AnchorRight, a, Qt::AnchorRight); + + l->addAnchor(a, Qt::AnchorHorizontalCenter, b, Qt::AnchorLeft); + l->addAnchor(b, Qt::AnchorRight, a, Qt::AnchorRight); + + parent.resize(l->effectiveSizeHint(Qt::PreferredSize)); + + QCOMPARE(a->geometry(), QRectF(0, 0, 40, 10)); + QCOMPARE(b->geometry(), QRectF(20, 0, 20, 10)); +} + QTEST_MAIN(tst_QGraphicsAnchorLayout) #include "tst_qgraphicsanchorlayout.moc" -- cgit v1.2.3 From 92b51d119325adc7cef518c1260c71904fc68c40 Mon Sep 17 00:00:00 2001 From: "Eduardo M. Fleury" Date: Thu, 5 Nov 2009 20:11:37 -0300 Subject: QGAL (Test): Enable remaining tests in 'qgraphicsanchorlayout1' Some tests were still disabled because were not supported somewhere in the past. Signed-off-by: Eduardo M. Fleury Reviewed-by: Caio Marcelo de Oliveira Filho --- .../tst_qgraphicsanchorlayout1.cpp | 25 ++++++++-------------- 1 file changed, 9 insertions(+), 16 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp b/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp index 57e5c41be9..0fbd0692ce 100644 --- a/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp +++ b/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp @@ -423,7 +423,6 @@ void tst_QGraphicsAnchorLayout1::testAddAndRemoveAnchor() layout->setAnchor(layout, Qt::AnchorLeft, widget5, Qt::AnchorTop, 10); QCOMPARE( layout->count(), 4 ); - // ###: NOT SUPPORTED // anchor two edges of a widget (to define width / height) QTest::ignoreMessage(QtWarningMsg, "QGraphicsAnchorLayout::addAnchor(): Cannot anchor the item to itself"); layout->setAnchor(widget5, Qt::AnchorLeft, widget5, Qt::AnchorRight, 10); @@ -520,8 +519,6 @@ void tst_QGraphicsAnchorLayout1::testIsValid() widget->setLayout(layout); widget->setGeometry(QRectF(0,0,100,100)); - // ###: this shall change once isValid() is ready - // QCOMPARE(layout->isValid(), false); QCOMPARE(layout->isValid(), true); delete widget; } @@ -698,9 +695,8 @@ void tst_QGraphicsAnchorLayout1::testSpecialCases() layout2->setAnchor(widget1, Qt::AnchorRight, layout2, Qt::AnchorRight, 1); layout2->setAnchor(widget1, Qt::AnchorBottom, layout2, Qt::AnchorBottom, 1); - // ###: uncomment when simplification bug is solved - //widget->setGeometry(QRectF(0,0,100,100)); - //QCOMPARE(widget1->geometry(), QRectF(51,2,47,96)); + widget->setGeometry(QRectF(0,0,100,100)); + QCOMPARE(widget1->geometry(), QRectF(51,2,47,96)); delete widget; } @@ -900,9 +896,6 @@ void tst_QGraphicsAnchorLayout1::testBasicLayout_data() << BasicData(-1, Qt::AnchorLeft, 1, Qt::AnchorRight, 20) ; - // ### SIMPLIFICATION BUG FOR ITEM 1 - // ### remove this when bug is solved - theResult << BasicResult(0, QRectF(10, 10, 180, 80) ) << BasicResult(1, QRectF(10, 80, 10, 10) ) @@ -1732,8 +1725,6 @@ void tst_QGraphicsAnchorLayout1::testBasicLayout() QCOMPARE(expected, actual); } - // ###: not supported yet -/* // Test mirrored mode widget->setLayoutDirection(Qt::RightToLeft); layout->activate(); @@ -1745,10 +1736,13 @@ void tst_QGraphicsAnchorLayout1::testBasicLayout() if (mirroredRect.isValid()){ mirroredRect.moveLeft(size.width()-item.rect.width()-item.rect.left()); } - QCOMPARE(widgets[item.index]->geometry(), mirroredRect); + QRectF expected = truncate(mirroredRect); + QRectF actual = truncate(widgets[item.index]->geometry()); + + QCOMPARE(expected, actual); delete widgets[item.index]; } -*/ + delete widget; } @@ -2447,6 +2441,8 @@ void tst_QGraphicsAnchorLayout1::testDoubleSizePolicy_data() QTest::newRow("double size policy: expanding-preferred") << sizePolicy1 << sizePolicy2 << width1 << width2; } + // QGAL handling of ignored flag is different + if (0) { QSizePolicy sizePolicy1( QSizePolicy::Ignored, QSizePolicy::Ignored ); QSizePolicy sizePolicy2( QSizePolicy::Preferred, QSizePolicy::Preferred ); @@ -2514,9 +2510,6 @@ void tst_QGraphicsAnchorLayout1::testDoubleSizePolicy_data() void tst_QGraphicsAnchorLayout1::testDoubleSizePolicy() { - // ### Size policy is not yet supported - return; - QFETCH(QSizePolicy, policy1); QFETCH(QSizePolicy, policy2); QFETCH(qreal, width1); -- cgit v1.2.3 From 5f46db57f3baed15bfca2b4725e400808eabb7e5 Mon Sep 17 00:00:00 2001 From: Caio Marcelo de Oliveira Filho Date: Thu, 5 Nov 2009 23:49:43 -0300 Subject: QGAL (Test): redundant anchors shouldn't harm simplification Adds a simple test to check whether redundant anchors avoid simplification to happen. In this case, the use of addCornerAnchors generate redundant anchors. Signed-off-by: Caio Marcelo de Oliveira Filho Reviewed-by: Eduardo M. Fleury --- .../tst_qgraphicsanchorlayout.cpp | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp index 8b52674cff..c7ed309a2b 100644 --- a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp +++ b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp @@ -84,6 +84,7 @@ private slots: void simplifiableUnfeasible(); void simplificationVsOrder(); void parallelSimplificationOfCenter(); + void simplificationVsRedundance(); }; class RectWidget : public QGraphicsWidget @@ -1827,5 +1828,43 @@ void tst_QGraphicsAnchorLayout::parallelSimplificationOfCenter() QCOMPARE(b->geometry(), QRectF(20, 0, 20, 10)); } +/* + Test whether redundance of anchors (in this case by using addCornerAnchors), will + prevent simplification to take place when it should. +*/ +void tst_QGraphicsAnchorLayout::simplificationVsRedundance() +{ + QSizeF min(10, 10); + QSizeF pref(20, 10); + QSizeF max(50, 30); + + 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; + + l->addCornerAnchors(a, Qt::TopLeftCorner, l, Qt::TopLeftCorner); + l->addCornerAnchors(a, Qt::BottomLeftCorner, l, Qt::BottomLeftCorner); + + l->addCornerAnchors(b, Qt::TopLeftCorner, a, Qt::TopRightCorner); + l->addCornerAnchors(b, Qt::TopRightCorner, l, Qt::TopRightCorner); + + l->addCornerAnchors(c, Qt::TopLeftCorner, b, Qt::BottomLeftCorner); + l->addCornerAnchors(c, Qt::BottomLeftCorner, a, Qt::BottomRightCorner); + l->addCornerAnchors(c, Qt::TopRightCorner, b, Qt::BottomRightCorner); + l->addCornerAnchors(c, Qt::BottomRightCorner, l, Qt::BottomRightCorner); + + l->effectiveSizeHint(Qt::MinimumSize); + + QCOMPARE(layoutHasConflict(l), false); + + if (!hasSimplification) + QEXPECT_FAIL("", "Test depends on simplification.", Abort); + + QCOMPARE(usedSimplex(l, Qt::Horizontal), false); + QCOMPARE(usedSimplex(l, Qt::Vertical), false); +} + QTEST_MAIN(tst_QGraphicsAnchorLayout) #include "tst_qgraphicsanchorlayout.moc" -- cgit v1.2.3