diff options
author | Martin Jones <martin.jones@nokia.com> | 2011-01-24 06:08:46 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2011-01-24 06:08:46 (GMT) |
commit | 6f78a6080b84cc3ef96b73a4ff58d1b5a72f08f4 (patch) | |
tree | 7d22096d7c681ed1b8f7111575582f4b48f95f7f /tests/auto/declarative/qdeclarativeitem | |
parent | 44060d2129b461754f6bd86153889a869f12440a (diff) | |
download | Qt-6f78a6080b84cc3ef96b73a4ff58d1b5a72f08f4.zip Qt-6f78a6080b84cc3ef96b73a4ff58d1b5a72f08f4.tar.gz Qt-6f78a6080b84cc3ef96b73a4ff58d1b5a72f08f4.tar.bz2 |
Expose implicitWidth and implicitHeight properties of Item.
Overridden as readonly for elements that have an inherent implicit size
such as Text, TextEdit, TextInput, positioners, Loader.
Task-number: QTBUG-14957
Reviewed-by: Michael Brasser
Diffstat (limited to 'tests/auto/declarative/qdeclarativeitem')
-rw-r--r-- | tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp index dbed799..e636383 100644 --- a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp +++ b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp @@ -83,6 +83,9 @@ private slots: void mouseFocus(); void transformCrash(); + void implicitSize(); + void testQtQuick11Attributes(); + void testQtQuick11Attributes_data(); private: template<typename T> @@ -915,6 +918,83 @@ void tst_QDeclarativeItem::transformCrash() delete canvas; } +void tst_QDeclarativeItem::implicitSize() +{ + QDeclarativeView *canvas = new QDeclarativeView(0); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/implicitsize.qml")); + canvas->show(); + + QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(canvas->rootObject()); + QVERIFY(item); + QCOMPARE(item->width(), qreal(80)); + QCOMPARE(item->height(), qreal(60)); + + QCOMPARE(item->implicitWidth(), qreal(200)); + QCOMPARE(item->implicitHeight(), qreal(100)); + + QMetaObject::invokeMethod(item, "resetSize"); + + QCOMPARE(item->width(), qreal(200)); + QCOMPARE(item->height(), qreal(100)); + + QMetaObject::invokeMethod(item, "changeImplicit"); + + QCOMPARE(item->implicitWidth(), qreal(150)); + QCOMPARE(item->implicitHeight(), qreal(80)); + QCOMPARE(item->width(), qreal(150)); + QCOMPARE(item->height(), qreal(80)); + + delete canvas; +} + +void tst_QDeclarativeItem::testQtQuick11Attributes() +{ + QFETCH(QString, code); + QFETCH(QString, warning); + QFETCH(QString, error); + + QDeclarativeEngine engine; + QObject *obj; + + QDeclarativeComponent valid(&engine); + valid.setData("import QtQuick 1.1; Item { " + code.toUtf8() + " }", QUrl("")); + obj = valid.create(); + QVERIFY(obj); + QVERIFY(valid.errorString().isEmpty()); + delete obj; + + QDeclarativeComponent invalid(&engine); + invalid.setData("import QtQuick 1.0; Item { " + code.toUtf8() + " }", QUrl("")); + QTest::ignoreMessage(QtWarningMsg, warning.toUtf8()); + obj = invalid.create(); + QCOMPARE(invalid.errorString(), error); + delete obj; +} + +void tst_QDeclarativeItem::testQtQuick11Attributes_data() +{ + QTest::addColumn<QString>("code"); + QTest::addColumn<QString>("warning"); + QTest::addColumn<QString>("error"); + + QTest::newRow("implicitWidth") << "implicitWidth: 100" + << "QDeclarativeComponent: Component is not ready" + << ":1 Property \"implicitWidth\" not available in QtQuick/Item 1.0\n"; + + QTest::newRow("implicitHeight") << "implicitHeight: 100" + << "QDeclarativeComponent: Component is not ready" + << ":1 Property \"implicitHeight\" not available in QtQuick/Item 1.0\n"; + + QTest::newRow("onImplicitWidthChanged") << "onImplicitWidthChanged: x" + << "QDeclarativeComponent: Component is not ready" + << ":1 Signal \"onImplicitWidthChanged\" not available in QtQuick/Item 1.0\n"; + + QTest::newRow("onImplicitHeightChanged") << "onImplicitHeightChanged: x" + << "QDeclarativeComponent: Component is not ready" + << ":1 Signal \"onImplicitHeightChanged\" not available in QtQuick/Item 1.0\n"; +} + + template<typename T> T *tst_QDeclarativeItem::findItem(QGraphicsObject *parent, const QString &objectName) { |