Don't crash when calculating the implicit width of truncated lines.
authorAndrew den Exter <andrew.den-exter@nokia.com>
Tue, 17 Apr 2012 07:28:50 +0000 (17:28 +1000)
committerQt by Nokia <qt-info@nokia.com>
Tue, 17 Apr 2012 09:06:15 +0000 (11:06 +0200)
Remember to call beginLayout() on the QTextLayout before creating
lines or the layout data won't be allocated.

Change-Id: Ic344ca376fc25e38c50078135deb02dee3afc4f1
Reviewed-by: Chris Adams <christopher.adams@nokia.com>
Reviewed-by: Yann Bodson <yann.bodson@nokia.com>
src/quick/items/qquicktext.cpp
tests/auto/quick/qquicktext/tst_qquicktext.cpp

index 70a1551..f34c062 100644 (file)
@@ -913,12 +913,13 @@ QRectF QQuickTextPrivate::setupTextLayout(qreal *const naturalWidth, qreal *cons
                 QTextLayout widthLayout(layoutText.mid(characterCount), scaledFont);
                 widthLayout.setTextOption(layout.textOption());
 
+                widthLayout.beginLayout();
                 for (; unwrappedLineCount <= maxLineCount; ++unwrappedLineCount) {
                     QTextLine line = widthLayout.createLine();
                     if (!line.isValid())
                         break;
                 }
-
+                widthLayout.endLayout();
                 *naturalWidth = qMax(*naturalWidth, widthLayout.maximumWidth());
             }
 
index 86de501..7ef232b 100644 (file)
@@ -1582,18 +1582,20 @@ void tst_qquicktext::implicitSize()
     QFETCH(QString, wrap);
     QFETCH(QString, elide);
     QString componentStr = "import QtQuick 2.0\nText { "
+            "property real iWidth: implicitWidth; "
             "text: \"" + text + "\"; "
             "width: " + width + "; "
             "textFormat: " + format + "; "
             "wrapMode: " + wrap + "; "
             "elide: " + elide + "; "
-            "maximumLineCount: 1 }";
+            "maximumLineCount: 2 }";
     QQmlComponent textComponent(&engine);
     textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
     QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
 
     QVERIFY(textObject->width() < textObject->implicitWidth());
     QVERIFY(textObject->height() == textObject->implicitHeight());
+    QCOMPARE(textObject->property("iWidth").toReal(), textObject->implicitWidth());
 
     textObject->resetWidth();
     QVERIFY(textObject->width() == textObject->implicitWidth());