summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEduardo M. Fleury <eduardo.fleury@openbossa.org>2009-10-08 17:30:57 (GMT)
committerEduardo M. Fleury <eduardo.fleury@openbossa.org>2009-10-15 14:37:49 (GMT)
commit80ffc2fa1766aa8009a30de495fc11ab6690bd87 (patch)
tree626e9d7aa11a8cef86ecb595da2a93446618dc7d
parentf81a563c74eece173a0cf1d6c3243604c0db0a5b (diff)
downloadQt-80ffc2fa1766aa8009a30de495fc11ab6690bd87.zip
Qt-80ffc2fa1766aa8009a30de495fc11ab6690bd87.tar.gz
Qt-80ffc2fa1766aa8009a30de495fc11ab6690bd87.tar.bz2
QGraphicsAnchorLayout: Add test for 'infinite' max size widgets
With four items anchored side by side, each of them being allowed to grow to QWIDGETSIZE_MAX, we have a situation of fair distribution because the layout itself can grow only to QWIDGETSIZE_MAX (and not four times this amount). This test identified an error on the expanding distribution logic. Signed-off-by: Eduardo M. Fleury <eduardo.fleury@openbossa.org> Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org>
-rw-r--r--tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp
index 286ea2d..cf4e9b8 100644
--- a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp
+++ b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp
@@ -73,6 +73,7 @@ private slots:
void expandingSequenceFairDistribution();
void expandingParallel();
void floatConflict();
+ void infiniteMaxSizes();
};
class RectWidget : public QGraphicsWidget
@@ -1585,5 +1586,53 @@ void tst_QGraphicsAnchorLayout::floatConflict()
delete p;
}
+void tst_QGraphicsAnchorLayout::infiniteMaxSizes()
+{
+ QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
+ l->setContentsMargins(0, 0, 0, 0);
+ l->setSpacing(0);
+
+ QSizeF min(10, 10);
+ QSizeF pref(50, 10);
+ QSizeF max(QWIDGETSIZE_MAX, 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");
+
+ //<!-- Trunk -->
+ 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);
+
+ a->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
+ c->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
+
+ QGraphicsWidget p;
+ p.setLayout(l);
+
+ 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));
+
+ 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));
+}
+
QTEST_MAIN(tst_QGraphicsAnchorLayout)
#include "tst_qgraphicsanchorlayout.moc"