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 | |
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')
3 files changed, 138 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) { diff --git a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp index ae521a5..faea448 100644 --- a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp +++ b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp @@ -101,6 +101,8 @@ private slots: void clickLink(); void QTBUG_12291(); + void implicitSize_data(); + void implicitSize(); private: QStringList standard; @@ -1050,6 +1052,33 @@ void tst_qdeclarativetext::lineCount() QCOMPARE(myText->maximumLineCount(), 2); } +void tst_qdeclarativetext::implicitSize_data() +{ + QTest::addColumn<QString>("text"); + QTest::addColumn<QString>("wrap"); + QTest::newRow("plain") << "The quick red fox jumped over the lazy brown dog" << "Text.NoWrap"; + QTest::newRow("richtext") << "<b>The quick red fox jumped over the lazy brown dog</b>" << "Text.NoWrap"; + QTest::newRow("plain_wrap") << "The quick red fox jumped over the lazy brown dog" << "Text.Wrap"; + QTest::newRow("richtext_wrap") << "<b>The quick red fox jumped over the lazy brown dog</b>" << "Text.Wrap"; +} + +void tst_qdeclarativetext::implicitSize() +{ + QFETCH(QString, text); + QFETCH(QString, wrap); + QString componentStr = "import QtQuick 1.1\nText { text: \"" + text + "\"; width: 50; wrapMode: " + wrap + " }"; + QDeclarativeComponent textComponent(&engine); + textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); + QDeclarativeText *textObject = qobject_cast<QDeclarativeText*>(textComponent.create()); + + QVERIFY(textObject->width() < textObject->implicitWidth()); + QVERIFY(textObject->height() == textObject->implicitHeight()); + + textObject->resetWidth(); + QVERIFY(textObject->width() == textObject->implicitWidth()); + QVERIFY(textObject->height() == textObject->implicitHeight()); +} + QTEST_MAIN(tst_qdeclarativetext) #include "tst_qdeclarativetext.moc" diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp index 89e8fec..582b20f 100644 --- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp +++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp @@ -127,6 +127,8 @@ private slots: void openInputPanelOnFocus(); void geometrySignals(); void pastingRichText_QTBUG_14003(); + void implicitSize_data(); + void implicitSize(); private: void simulateKey(QDeclarativeView *, int key); @@ -1447,6 +1449,33 @@ void tst_qdeclarativetextedit::pastingRichText_QTBUG_14003() #endif } +void tst_qdeclarativetextedit::implicitSize_data() +{ + QTest::addColumn<QString>("text"); + QTest::addColumn<QString>("wrap"); + QTest::newRow("plain") << "The quick red fox jumped over the lazy brown dog" << "TextEdit.NoWrap"; + QTest::newRow("richtext") << "<b>The quick red fox jumped over the lazy brown dog</b>" << "TextEdit.NoWrap"; + QTest::newRow("plain_wrap") << "The quick red fox jumped over the lazy brown dog" << "TextEdit.Wrap"; + QTest::newRow("richtext_wrap") << "<b>The quick red fox jumped over the lazy brown dog</b>" << "TextEdit.Wrap"; +} + +void tst_qdeclarativetextedit::implicitSize() +{ + QFETCH(QString, text); + QFETCH(QString, wrap); + QString componentStr = "import QtQuick 1.1\nTextEdit { text: \"" + text + "\"; width: 50; wrapMode: " + wrap + " }"; + QDeclarativeComponent textComponent(&engine); + textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); + QDeclarativeTextEdit *textObject = qobject_cast<QDeclarativeTextEdit*>(textComponent.create()); + + QVERIFY(textObject->width() < textObject->implicitWidth()); + QVERIFY(textObject->height() == textObject->implicitHeight()); + + textObject->resetWidth(); + QVERIFY(textObject->width() == textObject->implicitWidth()); + QVERIFY(textObject->height() == textObject->implicitHeight()); +} + QTEST_MAIN(tst_qdeclarativetextedit) #include "tst_qdeclarativetextedit.moc" |