summaryrefslogtreecommitdiffstats
path: root/tests/auto/qgraphicslayoutitem
diff options
context:
space:
mode:
authorJohn Tapsell <john.tapsell.ext@basyskom.de>2011-11-07 16:07:27 (GMT)
committerJan-Arve Saether <jan-arve.saether@nokia.com>2011-11-08 12:53:10 (GMT)
commit546efb2cdb64e968e3376a2d426e653e4da4f5d2 (patch)
treea05e50b099640cac88a7141a190945e4a13dc437 /tests/auto/qgraphicslayoutitem
parent6968b3fe1354c289767b2b21bc723bb5fd1576ae (diff)
downloadQt-546efb2cdb64e968e3376a2d426e653e4da4f5d2.zip
Qt-546efb2cdb64e968e3376a2d426e653e4da4f5d2.tar.gz
Qt-546efb2cdb64e968e3376a2d426e653e4da4f5d2.tar.bz2
QGraphicsLayoutItem - bound constraint the minimum and maximum size
The scenario was this: If you had a height for width item, and that item had a maximum width of 50. If you called item->effectiveSizeHint(Qt::PreferredSize, QSizeF(100,-1)); it would return (100, ?), thus violating its own maximum width. Merge-request: 1423 Reviewed-by: Jan-Arve Saether <jan-arve.saether@nokia.com>
Diffstat (limited to 'tests/auto/qgraphicslayoutitem')
-rw-r--r--tests/auto/qgraphicslayoutitem/tst_qgraphicslayoutitem.cpp108
1 files changed, 108 insertions, 0 deletions
diff --git a/tests/auto/qgraphicslayoutitem/tst_qgraphicslayoutitem.cpp b/tests/auto/qgraphicslayoutitem/tst_qgraphicslayoutitem.cpp
index a8b6c08..34ca5d4 100644
--- a/tests/auto/qgraphicslayoutitem/tst_qgraphicslayoutitem.cpp
+++ b/tests/auto/qgraphicslayoutitem/tst_qgraphicslayoutitem.cpp
@@ -44,6 +44,7 @@
#include <qgraphicslayoutitem.h>
#include <float.h>
#include <limits.h>
+#include <QtGui/qgraphicswidget.h>
class tst_QGraphicsLayoutItem : public QObject {
Q_OBJECT
@@ -60,6 +61,8 @@ private slots:
void contentsRect();
void effectiveSizeHint_data();
void effectiveSizeHint();
+ void effectiveSizeHint2_data();
+ void effectiveSizeHint2();
void getContentsMargins();
void isLayout_data();
void isLayout();
@@ -104,6 +107,40 @@ public:
};
+class RectWidget : public QGraphicsWidget
+{
+public:
+ RectWidget(QGraphicsItem *parent = 0) : QGraphicsWidget(parent), m_fnConstraint(fn2000_div_w) {}
+
+
+ QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const
+ {
+ if (constraint.width() < 0 && constraint.height() < 0 && m_sizeHints[which].isValid()) {
+ return m_sizeHints[which];
+ }
+ if (m_fnConstraint) {
+ return m_fnConstraint(which, constraint);
+ }
+ return QGraphicsWidget::sizeHint(which, constraint);
+ }
+
+ void setSizeHint(Qt::SizeHint which, const QSizeF &size) {
+ m_sizeHints[which] = size;
+ updateGeometry();
+ }
+
+ void setConstraintFunction(QSizeF (*fnConstraint)(Qt::SizeHint, const QSizeF &)) {
+ m_fnConstraint = fnConstraint;
+ }
+
+ QSizeF m_sizeHints[Qt::NSizeHints];
+ QSizeF (*m_fnConstraint)(Qt::SizeHint, const QSizeF &);
+
+ static QSizeF fn2000_div_w(Qt::SizeHint /*which*/, const QSizeF &constraint = QSizeF()) {
+ return QSizeF(constraint.width(), 2000.0/constraint.width());
+ }
+};
+
// This will be called before the first test function is executed.
// It is only called once.
void tst_QGraphicsLayoutItem::initTestCase()
@@ -183,6 +220,77 @@ void tst_QGraphicsLayoutItem::effectiveSizeHint()
QCOMPARE(r.height(), constraint.height());
}
+
+void tst_QGraphicsLayoutItem::effectiveSizeHint2_data()
+{
+ QTest::addColumn<QSizeF>("minimumSize");
+ QTest::addColumn<QSizeF>("preferredSize");
+ QTest::addColumn<QSizeF>("maximumSize");
+ QTest::addColumn<QSizeF>("minimumSizeHint");
+ QTest::addColumn<QSizeF>("preferredSizeHint");
+ QTest::addColumn<QSizeF>("maximumSizeHint");
+
+ QTest::addColumn<QSizeF>("inputConstraint");
+ QTest::addColumn<QSizeF>("expectedMinimumESH");
+ QTest::addColumn<QSizeF>("expectedPreferredESH");
+ QTest::addColumn<QSizeF>("expectedMaximumESH");
+
+ QTest::newRow("P1-a")
+ << QSizeF( 6, 4) << QSizeF( 60, 40) << QSizeF( 600, 400)
+ << QSizeF( -1, -1) << QSizeF( -1, -1) << QSizeF( -1, -1)
+ << QSizeF(-1, -1)
+ << QSizeF(6, 4) << QSizeF( 60, 40) << QSizeF(600, 400);
+
+ QTest::newRow("P1-hfw-1")
+ << QSizeF( -1, -1) << QSizeF( -1, -1) << QSizeF( -1, -1)
+ << QSizeF( 6, 4) << QSizeF( 60, 40) << QSizeF(600, 400)
+ << QSizeF(200, -1)
+ << QSizeF(200, 10) << QSizeF(200, 10) << QSizeF(200, 10);
+
+ QTest::newRow("P1-hfw-2")
+ << QSizeF( 6, -1) << QSizeF( 60, -1) << QSizeF(600, -1)
+ << QSizeF( -1, -1) << QSizeF( -1, -1) << QSizeF( -1, -1)
+ << QSizeF(200, -1)
+ << QSizeF(200, 10) << QSizeF(200, 10) << QSizeF(200, 10);
+
+ // constraint is bigger than max width
+ QTest::newRow("P1-hfw-3")
+ << QSizeF( 5, -1) << QSizeF( 50, -1) << QSizeF(500, -1)
+ << QSizeF( -1, -1) << QSizeF( -1, -1) << QSizeF( -1, -1)
+ << QSizeF(600, -1)
+ << QSizeF(500, 4) << QSizeF(500, 4) << QSizeF(500, 4);
+
+}
+
+void tst_QGraphicsLayoutItem::effectiveSizeHint2()
+{
+ QFETCH(QSizeF, minimumSize);
+ QFETCH(QSizeF, preferredSize);
+ QFETCH(QSizeF, maximumSize);
+ QFETCH(QSizeF, minimumSizeHint);
+ QFETCH(QSizeF, preferredSizeHint);
+ QFETCH(QSizeF, maximumSizeHint);
+
+ QFETCH(QSizeF, inputConstraint);
+ QFETCH(QSizeF, expectedMinimumESH);
+ QFETCH(QSizeF, expectedPreferredESH);
+ QFETCH(QSizeF, expectedMaximumESH);
+
+ RectWidget *item = new RectWidget;
+ item->setMinimumSize(minimumSize);
+ item->setPreferredSize(preferredSize);
+ item->setMaximumSize(maximumSize);
+ item->setSizeHint(Qt::MinimumSize, minimumSizeHint);
+ item->setSizeHint(Qt::PreferredSize, preferredSizeHint);
+ item->setSizeHint(Qt::MaximumSize, maximumSizeHint);
+
+ QCOMPARE(item->effectiveSizeHint(Qt::MinimumSize, inputConstraint), expectedMinimumESH);
+ QCOMPARE(item->effectiveSizeHint(Qt::PreferredSize, inputConstraint), expectedPreferredESH);
+ QCOMPARE(item->effectiveSizeHint(Qt::MaximumSize, inputConstraint), expectedMaximumESH);
+
+}
+
+
// void getContentsMargins(qreal* left, qreal* top, qreal* right, qreal* bottom) const public
void tst_QGraphicsLayoutItem::getContentsMargins()
{