diff options
author | Andrew den Exter <andrew.den-exter@nokia.com> | 2012-04-20 11:40:40 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-04-20 08:05:15 +0200 |
commit | 04794c29cee0d97fb3b32e1c71a072e34ee37e9c (patch) | |
tree | b161691c1af10d24432e2cc8ba753a80c3adc7ab /tests/auto | |
parent | 2e0a348927d5d9ad47cad724bc687c72e592c8d6 (diff) |
Fix eliding when text width is reset by an implicitWidth change.
After emitting implicit size changed signals, reevaluate any conditions
that were dependent on the validity of the item dimensions.
Change-Id: Ie4ee0c87a22cf82752c207c69d426056c36ede67
Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/quick/qquickitem2/data/implicitsize.qml | 15 | ||||
-rw-r--r-- | tests/auto/quick/qquickitem2/tst_qquickitem.cpp | 42 | ||||
-rw-r--r-- | tests/auto/quick/qquicktext/tst_qquicktext.cpp | 52 |
3 files changed, 109 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickitem2/data/implicitsize.qml b/tests/auto/quick/qquickitem2/data/implicitsize.qml index cc6aaf7d60..756e230a87 100644 --- a/tests/auto/quick/qquickitem2/data/implicitsize.qml +++ b/tests/auto/quick/qquickitem2/data/implicitsize.qml @@ -16,4 +16,19 @@ Item { implicitWidth = 150 implicitHeight = 80 } + + function increaseImplicit() { + implicitWidth = 200 + implicitHeight = 100 + } + + function assignImplicitBinding() { + width = Qt.binding(function() { return implicitWidth < 175 ? implicitWidth : 175 }) + height = Qt.binding(function() { return implicitHeight < 90 ? implicitHeight : 90 }) + } + + function assignUndefinedBinding() { + width = Qt.binding(function() { return implicitWidth < 175 ? undefined : 175 }) + height = Qt.binding(function() { return implicitHeight < 90 ? undefined : 90 }) + } } diff --git a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp index 34f51875c9..44b05586ce 100644 --- a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp +++ b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp @@ -1350,6 +1350,48 @@ void tst_QQuickItem::implicitSize() QCOMPARE(item->width(), qreal(150)); QCOMPARE(item->height(), qreal(80)); + QMetaObject::invokeMethod(item, "assignImplicitBinding"); + + QCOMPARE(item->implicitWidth(), qreal(150)); + QCOMPARE(item->implicitHeight(), qreal(80)); + QCOMPARE(item->width(), qreal(150)); + QCOMPARE(item->height(), qreal(80)); + + QMetaObject::invokeMethod(item, "increaseImplicit"); + + QCOMPARE(item->implicitWidth(), qreal(200)); + QCOMPARE(item->implicitHeight(), qreal(100)); + QCOMPARE(item->width(), qreal(175)); + QCOMPARE(item->height(), qreal(90)); + + QMetaObject::invokeMethod(item, "changeImplicit"); + + QCOMPARE(item->implicitWidth(), qreal(150)); + QCOMPARE(item->implicitHeight(), qreal(80)); + QCOMPARE(item->width(), qreal(150)); + QCOMPARE(item->height(), qreal(80)); + + QMetaObject::invokeMethod(item, "assignUndefinedBinding"); + + QCOMPARE(item->implicitWidth(), qreal(150)); + QCOMPARE(item->implicitHeight(), qreal(80)); + QCOMPARE(item->width(), qreal(150)); + QCOMPARE(item->height(), qreal(80)); + + QMetaObject::invokeMethod(item, "increaseImplicit"); + + QCOMPARE(item->implicitWidth(), qreal(200)); + QCOMPARE(item->implicitHeight(), qreal(100)); + QCOMPARE(item->width(), qreal(175)); + QCOMPARE(item->height(), qreal(90)); + + 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; } diff --git a/tests/auto/quick/qquicktext/tst_qquicktext.cpp b/tests/auto/quick/qquicktext/tst_qquicktext.cpp index 125e056dad..297fa0106f 100644 --- a/tests/auto/quick/qquicktext/tst_qquicktext.cpp +++ b/tests/auto/quick/qquicktext/tst_qquicktext.cpp @@ -72,6 +72,8 @@ private slots: void elide(); void multilineElide_data(); void multilineElide(); + void implicitElide_data(); + void implicitElide(); void textFormat(); void alignments_data(); @@ -531,6 +533,56 @@ void tst_qquicktext::multilineElide() delete canvas; } +void tst_qquicktext::implicitElide_data() +{ + QTest::addColumn<QString>("width"); + QTest::addColumn<QString>("initialText"); + QTest::addColumn<QString>("text"); + + QTest::newRow("maximum width, empty") + << "Math.min(implicitWidth, 100)" + << ""; + QTest::newRow("maximum width, short") + << "Math.min(implicitWidth, 100)" + << "the"; + QTest::newRow("maximum width, long") + << "Math.min(implicitWidth, 100)" + << "the quick brown fox jumped over the lazy dog"; + QTest::newRow("reset width, empty") + << "implicitWidth > 100 ? 100 : undefined" + << ""; + QTest::newRow("reset width, short") + << "implicitWidth > 100 ? 100 : undefined" + << "the"; + QTest::newRow("reset width, long") + << "implicitWidth > 100 ? 100 : undefined" + << "the quick brown fox jumped over the lazy dog"; +} + +void tst_qquicktext::implicitElide() +{ + QFETCH(QString, width); + QFETCH(QString, initialText); + + QString componentStr = + "import QtQuick 2.0\n" + "Text {\n" + "width: " + width + "\n" + "text: \"" + initialText + "\"\n" + "elide: Text.ElideRight\n" + "}"; + QQmlComponent textComponent(&engine); + textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); + QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create()); + + QVERIFY(textObject->contentWidth() <= textObject->width()); + + textObject->setText("the quick brown fox jumped over"); + + QVERIFY(textObject->contentWidth() > 0); + QVERIFY(textObject->contentWidth() <= textObject->width()); +} + void tst_qquicktext::textFormat() { { |