summaryrefslogtreecommitdiffstats
path: root/tests/auto/qgraphicsanchorlayout
diff options
context:
space:
mode:
authorAnselmo Lacerda S. de Melo <anselmo.melo@openbossa.org>2009-09-16 23:30:37 (GMT)
committerJan-Arve Sæther <jan-arve.saether@nokia.com>2009-09-18 08:28:27 (GMT)
commit91cd65ff36b0465c3eef4e1575f064c1cf7e9236 (patch)
tree24fa0319b394db719bcdb5354651d52cf1a6a1aa /tests/auto/qgraphicsanchorlayout
parent301ba29eb8b08d9c040ee80c8a6e4e98bea91dee (diff)
downloadQt-91cd65ff36b0465c3eef4e1575f064c1cf7e9236.zip
Qt-91cd65ff36b0465c3eef4e1575f064c1cf7e9236.tar.gz
Qt-91cd65ff36b0465c3eef4e1575f064c1cf7e9236.tar.bz2
QGraphicsAnchorLayout: Added an auto test for size policy
Added an auto test for the currently supported size policies set. This is a simple test containing a single item anchored to the layout vertical and horizontally. The size policies are set, then the item's minimum, preferred and maximum sizes are compared to the expected ones, according to each policy. Signed-off-by: Anselmo Lacerda S. de Melo <anselmo.melo@openbossa.org>
Diffstat (limited to 'tests/auto/qgraphicsanchorlayout')
-rw-r--r--tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp86
1 files changed, 86 insertions, 0 deletions
diff --git a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp
index f982973..385fb3e 100644
--- a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp
+++ b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp
@@ -66,6 +66,7 @@ private slots:
void hardComplexS60();
void delete_anchor();
void conflicts();
+ void sizePolicy();
};
class RectWidget : public QGraphicsWidget
@@ -250,6 +251,11 @@ void tst_QGraphicsAnchorLayout::layoutDirection()
QGraphicsWidget *b = createItem(min, pref, max, "b");
QGraphicsWidget *c = createItem(min, pref, QSizeF(100, 20), "c");
+ a->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
+ b->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
+ c->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
+
+
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
l->setContentsMargins(0, 5, 10, 15);
// horizontal
@@ -1100,7 +1106,87 @@ void tst_QGraphicsAnchorLayout::delete_anchor()
delete p;
delete view;
+}
+
+void tst_QGraphicsAnchorLayout::sizePolicy()
+{
+ QGraphicsScene scene;
+ QSizeF minSize(0, 0);
+ QSizeF prefSize(50, 50);
+ QSizeF maxSize(100, 100);
+ QGraphicsWidget *w1 = createItem(minSize, prefSize, maxSize, "w1");
+
+ QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
+ l->setSpacing(0);
+ l->setContentsMargins(0, 0, 0, 0);
+
+ // horizontal
+ QGraphicsAnchor *anchor = l->addAnchor(l, Qt::AnchorLeft, w1, Qt::AnchorLeft);
+ anchor->setSpacing(0);
+
+ anchor = l->addAnchor(w1, Qt::AnchorRight, l, Qt::AnchorRight);
+ anchor->setSpacing(0);
+ // vertical
+ anchor = l->addAnchor(l, Qt::AnchorTop, w1, Qt::AnchorTop);
+ anchor->setSpacing(0);
+
+ anchor = l->addAnchor(w1, Qt::AnchorBottom, l, Qt::AnchorBottom);
+ anchor->setSpacing(0);
+
+ QGraphicsWidget *p = new QGraphicsWidget;
+ p->setLayout(l);
+
+ scene.addItem(p);
+ QGraphicsView *view = new QGraphicsView(&scene);
+
+ // QSizePolicy::Minimum
+ w1->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
+ QApplication::processEvents();
+ w1->adjustSize();
+
+ QCOMPARE(l->effectiveSizeHint(Qt::MinimumSize), QSizeF(50, 50));
+ QCOMPARE(l->effectiveSizeHint(Qt::PreferredSize), QSizeF(50, 50));
+ QCOMPARE(l->effectiveSizeHint(Qt::MaximumSize), QSizeF(100, 100));
+
+ // QSizePolicy::Maximum
+ w1->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
+ QApplication::processEvents();
+ w1->adjustSize();
+
+ QCOMPARE(l->effectiveSizeHint(Qt::MinimumSize), QSizeF(0, 0));
+ QCOMPARE(l->effectiveSizeHint(Qt::PreferredSize), QSizeF(50, 50));
+ QCOMPARE(l->effectiveSizeHint(Qt::MaximumSize), QSizeF(50, 50));
+
+ // QSizePolicy::Fixed
+ w1->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+ QApplication::processEvents();
+ w1->adjustSize();
+
+ QCOMPARE(l->effectiveSizeHint(Qt::MinimumSize), QSizeF(50, 50));
+ QCOMPARE(l->effectiveSizeHint(Qt::PreferredSize), QSizeF(50, 50));
+ QCOMPARE(l->effectiveSizeHint(Qt::MaximumSize), QSizeF(50, 50));
+
+ // QSizePolicy::Preferred
+ w1->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
+ QApplication::processEvents();
+ w1->adjustSize();
+
+ QCOMPARE(l->effectiveSizeHint(Qt::MinimumSize), QSizeF(0, 0));
+ QCOMPARE(l->effectiveSizeHint(Qt::PreferredSize), QSizeF(50, 50));
+ QCOMPARE(l->effectiveSizeHint(Qt::MaximumSize), QSizeF(100, 100));
+
+ // QSizePolicy::Ignored
+ w1->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
+ QApplication::processEvents();
+ w1->adjustSize();
+
+ QCOMPARE(l->effectiveSizeHint(Qt::MinimumSize), QSizeF(0, 0));
+ QCOMPARE(l->effectiveSizeHint(Qt::PreferredSize), QSizeF(0, 0));
+ QCOMPARE(l->effectiveSizeHint(Qt::MaximumSize), QSizeF(100, 100));
+
+ delete p;
+ delete view;
}
void tst_QGraphicsAnchorLayout::conflicts()