From 3b2e59130bf264ec63bf51b2049989f697d91ca1 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 2 Feb 2015 11:23:31 -0600 Subject: [PATCH] Fix Text wrapping when growing from 0 width. The fix for QTBUG-30896 caused a regression in the test case. Now check both width and implicit width validity before resetting widthExceeded. Change-Id: I4aba2aad299746906cfe20e288fa60cfe2acc64f Reviewed-by: Andrew den Exter --- src/quick/items/qquicktext.cpp | 2 +- .../auto/quick/qquicktext/data/growFromZeroWidth.qml | 8 ++++++++ tests/auto/quick/qquicktext/tst_qquicktext.cpp | 19 +++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 tests/auto/quick/qquicktext/data/growFromZeroWidth.qml diff --git a/src/quick/items/qquicktext.cpp b/src/quick/items/qquicktext.cpp index be86b29..bff3887 100644 --- a/src/quick/items/qquicktext.cpp +++ b/src/quick/items/qquicktext.cpp @@ -955,7 +955,7 @@ QRectF QQuickTextPrivate::setupTextLayout(qreal *const baseline) // If the horizontal alignment is not left and the width was not valid we need to relayout // now that we know the maximum line width. - if (!implicitWidthValid && unwrappedLineCount > 1 && q->effectiveHAlign() != QQuickText::AlignLeft) { + if (!q->widthValid() && !implicitWidthValid && unwrappedLineCount > 1 && q->effectiveHAlign() != QQuickText::AlignLeft) { widthExceeded = false; heightExceeded = false; continue; diff --git a/tests/auto/quick/qquicktext/data/growFromZeroWidth.qml b/tests/auto/quick/qquicktext/data/growFromZeroWidth.qml new file mode 100644 index 0000000..a264191 --- /dev/null +++ b/tests/auto/quick/qquicktext/data/growFromZeroWidth.qml @@ -0,0 +1,8 @@ +import QtQuick 2.0 + +Text { + width: 0 + wrapMode: Text.Wrap + horizontalAlignment: Text.AlignHCenter + text: "AA\nBBBBBBB\nCCCCCCCCCCCCCCCC" +} diff --git a/tests/auto/quick/qquicktext/tst_qquicktext.cpp b/tests/auto/quick/qquicktext/tst_qquicktext.cpp index 2e5212d..7453268 100644 --- a/tests/auto/quick/qquicktext/tst_qquicktext.cpp +++ b/tests/auto/quick/qquicktext/tst_qquicktext.cpp @@ -148,6 +148,8 @@ private slots: void hover(); + void growFromZeroWidth(); + private: QStringList standard; QStringList richText; @@ -3881,6 +3883,23 @@ void tst_qquicktext::hover() QVERIFY(mouseArea->property("wasHovered").toBool()); } +void tst_qquicktext::growFromZeroWidth() +{ + QQmlComponent component(&engine, testFile("growFromZeroWidth.qml")); + + QScopedPointer object(component.create()); + + QQuickText *text = qobject_cast(object.data()); + QVERIFY(text); + + QCOMPARE(text->lineCount(), 3); + + text->setWidth(80); + + // the new width should force our contents to wrap + QVERIFY(text->lineCount() > 3); +} + QTEST_MAIN(tst_qquicktext) #include "tst_qquicktext.moc" -- 2.7.4