summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJesus Sanchez-Palencia <jesus.palencia@openbossa.org>2009-09-25 21:53:15 (GMT)
committerJan-Arve Sæther <jan-arve.saether@nokia.com>2009-10-06 09:29:02 (GMT)
commit0d1e86fdfb7958a1affb93c7760c22fca9a0fcb2 (patch)
treea3f9333202fddba655742bfe6db4d413cd7979f3 /tests
parent89ea5d0cc0b00a1d4e8f3e700b86f168cf4437ed (diff)
downloadQt-0d1e86fdfb7958a1affb93c7760c22fca9a0fcb2.zip
Qt-0d1e86fdfb7958a1affb93c7760c22fca9a0fcb2.tar.gz
Qt-0d1e86fdfb7958a1affb93c7760c22fca9a0fcb2.tar.bz2
QGraphicsAnchorLayout: Adding a Float Conflict test case
Now we don't support floating items and so we should consider that the layout has a conflict when handling this situation. Signed-off-by: Jesus Sanchez-Palencia <jesus.palencia@openbossa.org> Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp69
-rw-r--r--tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp4
2 files changed, 72 insertions, 1 deletions
diff --git a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp
index 91e5bb3..b076631 100644
--- a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp
+++ b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp
@@ -72,6 +72,7 @@ private slots:
void expandingSequence();
void expandingSequenceFairDistribution();
void expandingParallel();
+ void floatConflict();
};
class RectWidget : public QGraphicsWidget
@@ -158,7 +159,17 @@ void tst_QGraphicsAnchorLayout::simple()
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
l->setContentsMargins(0, 0, 0, 0);
+
+ // Horizontal
+ l->addAnchor(w1, Qt::AnchorLeft, l, Qt::AnchorLeft);
l->addAnchor(w1, Qt::AnchorRight, w2, Qt::AnchorLeft);
+ l->addAnchor(w2, Qt::AnchorRight, l, Qt::AnchorRight);
+
+ // Vertical
+ l->addAnchor(w1, Qt::AnchorTop, l, Qt::AnchorTop);
+ l->addAnchor(w2, Qt::AnchorTop, l, Qt::AnchorTop);
+ l->addAnchor(w1, Qt::AnchorBottom, l, Qt::AnchorBottom);
+ l->addAnchor(w2, Qt::AnchorBottom, l, Qt::AnchorBottom);
QGraphicsWidget p;
p.setLayout(l);
@@ -1152,12 +1163,22 @@ void tst_QGraphicsAnchorLayout::delete_anchor()
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
l->setSpacing(0);
l->setContentsMargins(0, 0, 0, 0);
+
+ // Horizontal
l->addAnchor(l, Qt::AnchorLeft, w1, Qt::AnchorLeft);
l->addAnchor(w1, Qt::AnchorRight, w2, Qt::AnchorLeft);
l->addAnchor(w2, Qt::AnchorRight, l, Qt::AnchorRight);
l->addAnchor(w1, Qt::AnchorRight, w3, Qt::AnchorLeft);
l->addAnchor(w3, Qt::AnchorRight, l, Qt::AnchorRight);
+ // Vertical
+ l->addAnchor(w1, Qt::AnchorTop, l, Qt::AnchorTop);
+ l->addAnchor(w1, Qt::AnchorBottom, l, Qt::AnchorBottom);
+ l->addAnchor(w2, Qt::AnchorTop, l, Qt::AnchorTop);
+ l->addAnchor(w2, Qt::AnchorBottom, l, Qt::AnchorBottom);
+ l->addAnchor(w3, Qt::AnchorTop, l, Qt::AnchorTop);
+ l->addAnchor(w3, Qt::AnchorBottom, l, Qt::AnchorBottom);
+
QGraphicsAnchor *anchor = l->anchor(w3, Qt::AnchorRight, l, Qt::AnchorRight);
anchor->setSpacing(10);
@@ -1521,5 +1542,53 @@ void tst_QGraphicsAnchorLayout::expandingParallel()
QCOMPARE(newLayoutMaximumSize.width(), qreal(300));
}
+void tst_QGraphicsAnchorLayout::floatConflict()
+{
+ QGraphicsWidget *a = createItem(QSizeF(80,10), QSizeF(90,10), QSizeF(100,10), "a");
+ QGraphicsWidget *b = createItem(QSizeF(80,10), QSizeF(90,10), QSizeF(100,10), "b");
+
+ QGraphicsAnchorLayout *l;
+ QGraphicsWidget *p = new QGraphicsWidget(0, Qt::Window);
+
+ l = new QGraphicsAnchorLayout;
+ l->setContentsMargins(0, 0, 0, 0);
+
+ p->setLayout(l);
+
+ // horizontal
+ // with this anchor we have two floating items
+ setAnchor(l, a, Qt::AnchorRight, b, Qt::AnchorLeft);
+
+ // Just checking if the layout is handling well the removal of floating items
+ delete l->anchor(a, Qt::AnchorRight, b, Qt::AnchorLeft);
+ QCOMPARE(l->count(), 0);
+ QCOMPARE(layoutHasConflict(l), false);
+
+ // setting back the same anchor
+ setAnchor(l, a, Qt::AnchorRight, b, Qt::AnchorLeft);
+
+ // We don't support floating items but they should be counted as if they are in the layout
+ QCOMPARE(l->count(), 2);
+ // Although, we have an invalid situation
+ QCOMPARE(layoutHasConflict(l), true);
+
+ // Semi-floats are supported
+ setAnchor(l, a, Qt::AnchorLeft, l, Qt::AnchorLeft);
+ QCOMPARE(l->count(), 2);
+
+ // Vertically the layout has floating items. Therefore, we have a conflict
+ QCOMPARE(layoutHasConflict(l), true);
+
+ // No more floating items
+ setAnchor(l, b, Qt::AnchorRight, l, Qt::AnchorRight);
+ setAnchor(l, a, Qt::AnchorTop, l, Qt::AnchorTop);
+ setAnchor(l, a, Qt::AnchorBottom, l, Qt::AnchorBottom);
+ setAnchor(l, b, Qt::AnchorTop, l, Qt::AnchorTop);
+ setAnchor(l, b, Qt::AnchorBottom, l, Qt::AnchorBottom);
+ QCOMPARE(layoutHasConflict(l), false);
+
+ delete p;
+}
+
QTEST_MAIN(tst_QGraphicsAnchorLayout)
#include "tst_qgraphicsanchorlayout.moc"
diff --git a/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp b/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp
index a521b78..caf078e 100644
--- a/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp
+++ b/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp
@@ -530,16 +530,18 @@ void tst_QGraphicsAnchorLayout1::testIsValid()
TestWidget *widget1 = new TestWidget();
TestWidget *widget2 = new TestWidget();
+ // Vertically the layout has floating items. Therefore, we have a conflict
layout->setAnchor(layout, Qt::AnchorLeft, widget1, Qt::AnchorLeft, 0.1);
layout->setAnchor(layout, Qt::AnchorRight, widget1, Qt::AnchorRight, -0.1);
+ // Horizontally the layout has floating items. Therefore, we have a conflict
layout->setAnchor(layout, Qt::AnchorTop, widget2, Qt::AnchorTop, 0.1);
layout->setAnchor(layout, Qt::AnchorBottom, widget2, Qt::AnchorBottom, -0.1);
widget->setLayout(layout);
widget->setGeometry(QRectF(0,0,100,100));
- QCOMPARE(layout->isValid(), true);
+ QCOMPARE(layout->isValid(), false);
delete widget;
}
}