Allow styled text to be elided.
authorAndrew den Exter <andrew.den-exter@nokia.com>
Wed, 29 Feb 2012 01:37:42 +0000 (11:37 +1000)
committerQt by Nokia <qt-info@nokia.com>
Thu, 1 Mar 2012 06:55:06 +0000 (07:55 +0100)
Task-number: QTBUG-24521
Change-Id: Idd451d0a8a238a60691386726e34054c0368b658
Reviewed-by: Yann Bodson <yann.bodson@nokia.com>
src/quick/items/qquicktext.cpp
src/quick/items/qquicktext_p_p.h
tests/auto/qtquick2/qquicktext/data/fontSizeMode.qml
tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp

index f0ce26e..6d1cc0d 100644 (file)
@@ -612,6 +612,22 @@ void QQuickTextPrivate::setupCustomLineGeometry(QTextLine &line, qreal &height,
 #endif
 }
 
+void QQuickTextPrivate::elideFormats(
+        const int start, const int length, int offset, QList<QTextLayout::FormatRange> *elidedFormats)
+{
+    const int end = start + length;
+    QList<QTextLayout::FormatRange> formats = layout.additionalFormats();
+    for (int i = 0; i < formats.count(); ++i) {
+        QTextLayout::FormatRange format = formats.at(i);
+        const int formatLength = qMin(format.start + format.length, end) - qMax(format.start, start);
+        if (formatLength > 0) {
+            format.start = qMax(offset, format.start - start + offset);
+            format.length = formatLength;
+            elidedFormats->append(format);
+        }
+    }
+}
+
 QString QQuickTextPrivate::elidedText(qreal lineWidth, const QTextLine &line, QTextLine *nextLine) const
 {
     if (nextLine) {
@@ -624,12 +640,15 @@ QString QQuickTextPrivate::elidedText(qreal lineWidth, const QTextLine &line, QT
                 line.textLength() + nextLine->textLength());
     } else {
         QString elideText = layout.text().mid(line.textStart(), line.textLength());
-        elideText[elideText.length() - 1] = elideChar;
-        // Appending the elide character may push the line over the maximum width
-        // in which case the elided text will need to be elided.
-        QFontMetricsF metrics(layout.font());
-        if (metrics.width(elideChar) + line.naturalTextWidth() >= lineWidth)
-            elideText = metrics.elidedText(elideText, Qt::TextElideMode(elideMode), lineWidth);
+        if (!styledText) {
+            // QFontMetrics won't help eliding styled text.
+            elideText[elideText.length() - 1] = elideChar;
+            // Appending the elide character may push the line over the maximum width
+            // in which case the elided text will need to be elided.
+            QFontMetricsF metrics(layout.font());
+            if (metrics.width(elideChar) + line.naturalTextWidth() >= lineWidth)
+                elideText = metrics.elidedText(elideText, Qt::TextElideMode(elideMode), lineWidth);
+        }
         return elideText;
     }
 }
@@ -690,9 +709,8 @@ QRectF QQuickTextPrivate::setupTextLayout(qreal *const naturalWidth)
     const bool customLayout = isLineLaidOutConnected();
     const bool wasTruncated = truncated;
 
-    const bool singlelineElide = !styledText && elideMode != QQuickText::ElideNone && q->widthValid();
-    const bool multilineElide = !styledText
-            && elideMode == QQuickText::ElideRight
+    const bool singlelineElide = elideMode != QQuickText::ElideNone && q->widthValid();
+    const bool multilineElide = elideMode == QQuickText::ElideRight
             && q->widthValid()
             && (q->heightValid() || maximumLineCountValid);
     const bool canWrap = wrapMode != QQuickText::NoWrap && q->widthValid();
@@ -719,6 +737,8 @@ QRectF QQuickTextPrivate::setupTextLayout(qreal *const naturalWidth)
     qreal height = 0;
     QString elideText;
     bool once = true;
+    int elideStart = 0;
+    int elideEnd = 0;
 
     *naturalWidth = 0;
 
@@ -773,6 +793,9 @@ QRectF QQuickTextPrivate::setupTextLayout(qreal *const naturalWidth)
                 elideText = layoutText.at(line.textStart() - 1) != QChar::LineSeparator
                         ? elidedText(lineWidth, previousLine, &line)
                         : elidedText(lineWidth, previousLine);
+                elideStart = previousLine.textStart();
+                // elideEnd isn't required for right eliding.
+
                 // The previous line is the last one visible so move the current one off somewhere
                 // out of the way and back everything up one line.
                 line.setLineWidth(0);
@@ -800,6 +823,8 @@ QRectF QQuickTextPrivate::setupTextLayout(qreal *const naturalWidth)
                             0,
                             line.textStart(),
                             line.textLength());
+                    elideStart = line.textStart();
+                    elideEnd = elideStart + line.textLength();
                 } else {
                     br = br.united(line.naturalTextRect());
                 }
@@ -825,6 +850,8 @@ QRectF QQuickTextPrivate::setupTextLayout(qreal *const naturalWidth)
                         elideText = wrappedLine
                                 ? elidedText(lineWidth, line, &nextLine)
                                 : elidedText(lineWidth, line);
+                        elideStart = line.textStart();
+                        // elideEnd isn't required for right eliding.
                     } else {
                         br = br.united(line.naturalTextRect());
                     }
@@ -917,6 +944,33 @@ QRectF QQuickTextPrivate::setupTextLayout(qreal *const naturalWidth)
     if (elide) {
         if (!elideLayout)
             elideLayout = new QTextLayout;
+        if (styledText) {
+            QList<QTextLayout::FormatRange> formats;
+            switch (elideMode) {
+            case QQuickText::ElideRight:
+                elideFormats(elideStart, elideText.length() - 1, 0, &formats);
+                break;
+            case QQuickText::ElideLeft:
+                elideFormats(elideEnd - elideText.length() + 1, elideText.length() - 1, 1, &formats);
+                break;
+            case QQuickText::ElideMiddle: {
+                const int index = elideText.indexOf(elideChar);
+                if (index != -1) {
+                    elideFormats(elideStart, index, 0, &formats);
+                    elideFormats(
+                            elideEnd - elideText.length() + index + 1,
+                            elideText.length() - index - 1,
+                            index + 1,
+                            &formats);
+                }
+                break;
+            }
+            default:
+                break;
+            }
+            elideLayout->setAdditionalFormats(formats);
+        }
+
         elideLayout->setFont(layout.font());
         elideLayout->setTextOption(layout.textOption());
         elideLayout->setText(elideText);
index e61eea9..3be6254 100644 (file)
@@ -82,7 +82,9 @@ public:
     void mirrorChange();
     bool isLineLaidOutConnected();
     void setLineGeometry(QTextLine &line, qreal lineWidth, qreal &height);
+
     QString elidedText(qreal lineWidth, const QTextLine &line, QTextLine *nextLine = 0) const;
+    void elideFormats(int start, int length, int offset, QList<QTextLayout::FormatRange> *elidedFormats);
 
     QRectF layedOutTextRect;
 
index 20f7535..84f7ce8 100644 (file)
@@ -19,6 +19,4 @@ Item {
         font.pixelSize: 30
         font.family: "Helvetica"
     }
-
-    TextInput { focus: true; objectName: "input" }
 }
index 2be2dcd..3fd05db 100644 (file)
@@ -58,6 +58,8 @@
 
 DEFINE_BOOL_CONFIG_OPTION(qmlDisableDistanceField, QML_DISABLE_DISTANCEFIELD)
 
+Q_DECLARE_METATYPE(QQuickText::TextFormat)
+
 class tst_qquicktext : public QDeclarativeDataTest
 {
     Q_OBJECT
@@ -69,6 +71,7 @@ private slots:
     void width();
     void wrap();
     void elide();
+    void multilineElide_data();
     void multilineElide();
     void textFormat();
 
@@ -440,10 +443,12 @@ void tst_qquicktext::elide()
             QCOMPARE(textObject->elideMode(), m);
             QCOMPARE(textObject->width(), 100.);
 
+            if (m != QQuickText::ElideNone && !standard.at(i).contains('\n'))
+                QVERIFY(textObject->contentWidth() <= textObject->width());
+
             delete textObject;
         }
 
-        // richtext - does nothing
         for (int i = 0; i < richText.size(); i++)
         {
             QString componentStr = "import QtQuick 2.0\nText { "+elide+" width: 100; text: \"" + richText.at(i) + "\" }";
@@ -454,17 +459,29 @@ void tst_qquicktext::elide()
             QCOMPARE(textObject->elideMode(), m);
             QCOMPARE(textObject->width(), 100.);
 
+            if (m != QQuickText::ElideNone && standard.at(i).contains("<br>"))
+                QVERIFY(textObject->contentWidth() <= textObject->width());
+
             delete textObject;
         }
     }
 }
 
+void tst_qquicktext::multilineElide_data()
+{
+    QTest::addColumn<QQuickText::TextFormat>("format");
+    QTest::newRow("plain") << QQuickText::PlainText;
+    QTest::newRow("styled") << QQuickText::StyledText;
+}
+
 void tst_qquicktext::multilineElide()
 {
+    QFETCH(QQuickText::TextFormat, format);
     QQuickView *canvas = createView(testFile("multilineelide.qml"));
 
     QQuickText *myText = qobject_cast<QQuickText*>(canvas->rootObject());
     QVERIFY(myText != 0);
+    myText->setTextFormat(format);
 
     QCOMPARE(myText->lineCount(), 3);
     QCOMPARE(myText->truncated(), true);
@@ -1843,17 +1860,15 @@ void tst_qquicktext::imgTagsError()
 void tst_qquicktext::fontSizeMode_data()
 {
     QTest::addColumn<QString>("text");
-    QTest::addColumn<bool>("canElide");
-    QTest::newRow("plain") << "The quick red fox jumped over the lazy brown dog" << true;
-    QTest::newRow("richtext") << "<b>The quick red fox jumped over the lazy brown dog</b>" << false;
+    QTest::newRow("plain") << "The quick red fox jumped over the lazy brown dog";
+    QTest::newRow("styled") << "<b>The quick red fox jumped over the lazy brown dog</b>";
 }
 
 void tst_qquicktext::fontSizeMode()
 {
     QFETCH(QString, text);
-    QFETCH(bool, canElide);
 
-    QQuickView *canvas = createView(testFile("fontSizeMode.qml"));
+    QScopedPointer<QQuickView> canvas(createView(testFile("fontSizeMode.qml")));
     canvas->show();
 
     QQuickText *myText = canvas->rootObject()->findChild<QQuickText*>("myText");
@@ -1881,29 +1896,27 @@ void tst_qquicktext::fontSizeMode()
     QVERIFY(horizontalFitWidth <= myText->width() + 2); // rounding
     QVERIFY(horizontalFitHeight <= myText->height() + 2);
 
-    if (canElide) {
-        // Elide won't affect the size with HorizontalFit.
-        myText->setElideMode(QQuickText::ElideRight);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-        QVERIFY(!myText->truncated());
-        QCOMPARE(myText->contentWidth(), horizontalFitWidth);
-        QCOMPARE(myText->contentHeight(), horizontalFitHeight);
-
-        myText->setElideMode(QQuickText::ElideLeft);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-        QVERIFY(!myText->truncated());
-        QCOMPARE(myText->contentWidth(), horizontalFitWidth);
-        QCOMPARE(myText->contentHeight(), horizontalFitHeight);
-
-        myText->setElideMode(QQuickText::ElideMiddle);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-        QVERIFY(!myText->truncated());
-        QCOMPARE(myText->contentWidth(), horizontalFitWidth);
-        QCOMPARE(myText->contentHeight(), horizontalFitHeight);
-
-        myText->setElideMode(QQuickText::ElideNone);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-    }
+    // Elide won't affect the size with HorizontalFit.
+    myText->setElideMode(QQuickText::ElideRight);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+    QVERIFY(!myText->truncated());
+    QCOMPARE(myText->contentWidth(), horizontalFitWidth);
+    QCOMPARE(myText->contentHeight(), horizontalFitHeight);
+
+    myText->setElideMode(QQuickText::ElideLeft);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+    QVERIFY(!myText->truncated());
+    QCOMPARE(myText->contentWidth(), horizontalFitWidth);
+    QCOMPARE(myText->contentHeight(), horizontalFitHeight);
+
+    myText->setElideMode(QQuickText::ElideMiddle);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+    QVERIFY(!myText->truncated());
+    QCOMPARE(myText->contentWidth(), horizontalFitWidth);
+    QCOMPARE(myText->contentHeight(), horizontalFitHeight);
+
+    myText->setElideMode(QQuickText::ElideNone);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
 
     myText->setFontSizeMode(QQuickText::VerticalFit);
     QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
@@ -1913,29 +1926,27 @@ void tst_qquicktext::fontSizeMode()
     QVERIFY(verticalFitHeight <= myText->height() + 2);
     QVERIFY(verticalFitHeight > originalHeight);
 
-    if (canElide) {
-        // Elide won't affect the height of a single line with VerticalFit but will crop the width.
-        myText->setElideMode(QQuickText::ElideRight);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-        QVERIFY(myText->truncated());
-        QVERIFY(myText->contentWidth() <= myText->width() + 2);
-        QCOMPARE(myText->contentHeight(), verticalFitHeight);
-
-        myText->setElideMode(QQuickText::ElideLeft);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-        QVERIFY(myText->truncated());
-        QVERIFY(myText->contentWidth() <= myText->width() + 2);
-        QCOMPARE(myText->contentHeight(), verticalFitHeight);
-
-        myText->setElideMode(QQuickText::ElideMiddle);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-        QVERIFY(myText->truncated());
-        QVERIFY(myText->contentWidth() <= myText->width() + 2);
-        QCOMPARE(myText->contentHeight(), verticalFitHeight);
-
-        myText->setElideMode(QQuickText::ElideNone);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-    }
+    // Elide won't affect the height of a single line with VerticalFit but will crop the width.
+    myText->setElideMode(QQuickText::ElideRight);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+    QVERIFY(myText->truncated());
+    QVERIFY(myText->contentWidth() <= myText->width() + 2);
+    QCOMPARE(myText->contentHeight(), verticalFitHeight);
+
+    myText->setElideMode(QQuickText::ElideLeft);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+    QVERIFY(myText->truncated());
+    QVERIFY(myText->contentWidth() <= myText->width() + 2);
+    QCOMPARE(myText->contentHeight(), verticalFitHeight);
+
+    myText->setElideMode(QQuickText::ElideMiddle);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+    QVERIFY(myText->truncated());
+    QVERIFY(myText->contentWidth() <= myText->width() + 2);
+    QCOMPARE(myText->contentHeight(), verticalFitHeight);
+
+    myText->setElideMode(QQuickText::ElideNone);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
 
     myText->setFontSizeMode(QQuickText::Fit);
     QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
@@ -1943,29 +1954,27 @@ void tst_qquicktext::fontSizeMode()
     QCOMPARE(myText->contentWidth(), horizontalFitWidth);
     QCOMPARE(myText->contentHeight(), horizontalFitHeight);
 
-    if (canElide) {
-        // Elide won't affect the size with Fit.
-        myText->setElideMode(QQuickText::ElideRight);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-        QVERIFY(!myText->truncated());
-        QCOMPARE(myText->contentWidth(), horizontalFitWidth);
-        QCOMPARE(myText->contentHeight(), horizontalFitHeight);
-
-        myText->setElideMode(QQuickText::ElideLeft);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-        QVERIFY(!myText->truncated());
-        QCOMPARE(myText->contentWidth(), horizontalFitWidth);
-        QCOMPARE(myText->contentHeight(), horizontalFitHeight);
-
-        myText->setElideMode(QQuickText::ElideMiddle);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-        QVERIFY(!myText->truncated());
-        QCOMPARE(myText->contentWidth(), horizontalFitWidth);
-        QCOMPARE(myText->contentHeight(), horizontalFitHeight);
-
-        myText->setElideMode(QQuickText::ElideNone);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-    }
+    // Elide won't affect the size with Fit.
+    myText->setElideMode(QQuickText::ElideRight);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+    QVERIFY(!myText->truncated());
+    QCOMPARE(myText->contentWidth(), horizontalFitWidth);
+    QCOMPARE(myText->contentHeight(), horizontalFitHeight);
+
+    myText->setElideMode(QQuickText::ElideLeft);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+    QVERIFY(!myText->truncated());
+    QCOMPARE(myText->contentWidth(), horizontalFitWidth);
+    QCOMPARE(myText->contentHeight(), horizontalFitHeight);
+
+    myText->setElideMode(QQuickText::ElideMiddle);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+    QVERIFY(!myText->truncated());
+    QCOMPARE(myText->contentWidth(), horizontalFitWidth);
+    QCOMPARE(myText->contentHeight(), horizontalFitHeight);
+
+    myText->setElideMode(QQuickText::ElideNone);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
 
     myText->setFontSizeMode(QQuickText::FixedSize);
     myText->setWrapMode(QQuickText::Wrap);
@@ -1985,17 +1994,15 @@ void tst_qquicktext::fontSizeMode()
     QCOMPARE(myText->contentWidth(), horizontalFitWidth);
     QCOMPARE(myText->contentHeight(), horizontalFitHeight);
 
-    if (canElide) {
-        // Elide won't affect the size with HorizontalFit.
-        myText->setElideMode(QQuickText::ElideRight);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-        QVERIFY(!myText->truncated());
-        QCOMPARE(myText->contentWidth(), horizontalFitWidth);
-        QCOMPARE(myText->contentHeight(), horizontalFitHeight);
+    // Elide won't affect the size with HorizontalFit.
+    myText->setElideMode(QQuickText::ElideRight);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+    QVERIFY(!myText->truncated());
+    QCOMPARE(myText->contentWidth(), horizontalFitWidth);
+    QCOMPARE(myText->contentHeight(), horizontalFitHeight);
 
-        myText->setElideMode(QQuickText::ElideNone);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-    }
+    myText->setElideMode(QQuickText::ElideNone);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
 
     myText->setFontSizeMode(QQuickText::VerticalFit);
     QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
@@ -2006,17 +2013,15 @@ void tst_qquicktext::fontSizeMode()
     QVERIFY(verticalFitHeight <= myText->height() + 2);
     QVERIFY(verticalFitHeight < originalHeight);
 
-    if (canElide) {
-        // Elide won't affect the height or width of a wrapped text with VerticalFit.
-        myText->setElideMode(QQuickText::ElideRight);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-        QVERIFY(!myText->truncated());
-        QCOMPARE(myText->contentWidth(), verticalFitWidth);
-        QCOMPARE(myText->contentHeight(), verticalFitHeight);
+    // Elide won't affect the height or width of a wrapped text with VerticalFit.
+    myText->setElideMode(QQuickText::ElideRight);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+    QVERIFY(!myText->truncated());
+    QCOMPARE(myText->contentWidth(), verticalFitWidth);
+    QCOMPARE(myText->contentHeight(), verticalFitHeight);
 
-        myText->setElideMode(QQuickText::ElideNone);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-    }
+    myText->setElideMode(QQuickText::ElideNone);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
 
     myText->setFontSizeMode(QQuickText::Fit);
     QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
@@ -2024,17 +2029,15 @@ void tst_qquicktext::fontSizeMode()
     QCOMPARE(myText->contentWidth(), verticalFitWidth);
     QCOMPARE(myText->contentHeight(), verticalFitHeight);
 
-    if (canElide) {
-        // Elide won't affect the size with Fit.
-        myText->setElideMode(QQuickText::ElideRight);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-        QVERIFY(!myText->truncated());
-        QCOMPARE(myText->contentWidth(), verticalFitWidth);
-        QCOMPARE(myText->contentHeight(), verticalFitHeight);
+    // Elide won't affect the size with Fit.
+    myText->setElideMode(QQuickText::ElideRight);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+    QVERIFY(!myText->truncated());
+    QCOMPARE(myText->contentWidth(), verticalFitWidth);
+    QCOMPARE(myText->contentHeight(), verticalFitHeight);
 
-        myText->setElideMode(QQuickText::ElideNone);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-    }
+    myText->setElideMode(QQuickText::ElideNone);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
 
     myText->setFontSizeMode(QQuickText::FixedSize);
     myText->setMaximumLineCount(2);
@@ -2051,17 +2054,15 @@ void tst_qquicktext::fontSizeMode()
     QCOMPARE(myText->contentWidth(), horizontalFitWidth);
     QCOMPARE(myText->contentHeight(), horizontalFitHeight);
 
-    if (canElide) {
-        // Elide won't affect the size with HorizontalFit.
-        myText->setElideMode(QQuickText::ElideRight);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-        QVERIFY(!myText->truncated());
-        QCOMPARE(myText->contentWidth(), horizontalFitWidth);
-        QCOMPARE(myText->contentHeight(), horizontalFitHeight);
+    // Elide won't affect the size with HorizontalFit.
+    myText->setElideMode(QQuickText::ElideRight);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+    QVERIFY(!myText->truncated());
+    QCOMPARE(myText->contentWidth(), horizontalFitWidth);
+    QCOMPARE(myText->contentHeight(), horizontalFitHeight);
 
-        myText->setElideMode(QQuickText::ElideNone);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-    }
+    myText->setElideMode(QQuickText::ElideNone);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
 
     myText->setFontSizeMode(QQuickText::VerticalFit);
     QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
@@ -2072,17 +2073,15 @@ void tst_qquicktext::fontSizeMode()
     QVERIFY(verticalFitHeight <= myText->height() + 2);
     QVERIFY(verticalFitHeight < originalHeight);
 
-    if (canElide) {
-        // Elide won't affect the height or width of a wrapped text with VerticalFit.
-        myText->setElideMode(QQuickText::ElideRight);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-        QVERIFY(!myText->truncated());
-        QCOMPARE(myText->contentWidth(), verticalFitWidth);
-        QCOMPARE(myText->contentHeight(), verticalFitHeight);
+    // Elide won't affect the height or width of a wrapped text with VerticalFit.
+    myText->setElideMode(QQuickText::ElideRight);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+    QVERIFY(!myText->truncated());
+    QCOMPARE(myText->contentWidth(), verticalFitWidth);
+    QCOMPARE(myText->contentHeight(), verticalFitHeight);
 
-        myText->setElideMode(QQuickText::ElideNone);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-    }
+    myText->setElideMode(QQuickText::ElideNone);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
 
     myText->setFontSizeMode(QQuickText::Fit);
     QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
@@ -2090,33 +2089,29 @@ void tst_qquicktext::fontSizeMode()
     QCOMPARE(myText->contentWidth(), verticalFitWidth);
     QCOMPARE(myText->contentHeight(), verticalFitHeight);
 
-    if (canElide) {
-        // Elide won't affect the size with Fit.
-        myText->setElideMode(QQuickText::ElideRight);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-        QVERIFY(!myText->truncated());
-        QCOMPARE(myText->contentWidth(), verticalFitWidth);
-        QCOMPARE(myText->contentHeight(), verticalFitHeight);
+    // Elide won't affect the size with Fit.
+    myText->setElideMode(QQuickText::ElideRight);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+    QVERIFY(!myText->truncated());
+    QCOMPARE(myText->contentWidth(), verticalFitWidth);
+    QCOMPARE(myText->contentHeight(), verticalFitHeight);
 
-        myText->setElideMode(QQuickText::ElideNone);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-    }
+    myText->setElideMode(QQuickText::ElideNone);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
 }
 
 void tst_qquicktext::fontSizeModeMultiline_data()
 {
     QTest::addColumn<QString>("text");
-    QTest::addColumn<bool>("canElide");
-    QTest::newRow("plain") << "The quick red fox jumped\n over the lazy brown dog" << true;
-    QTest::newRow("richtext") << "<b>The quick red fox jumped<br/> over the lazy brown dog</b>" << false;
+    QTest::newRow("plain") << "The quick red fox jumped\n over the lazy brown dog";
+    QTest::newRow("styledtext") << "<b>The quick red fox jumped<br/> over the lazy brown dog</b>";
 }
 
 void tst_qquicktext::fontSizeModeMultiline()
 {
     QFETCH(QString, text);
-    QFETCH(bool, canElide);
 
-    QQuickView *canvas = createView(testFile("fontSizeMode.qml"));
+    QScopedPointer<QQuickView> canvas(createView(testFile("fontSizeMode.qml")));
     canvas->show();
 
     QQuickText *myText = canvas->rootObject()->findChild<QQuickText*>("myText");
@@ -2146,31 +2141,29 @@ void tst_qquicktext::fontSizeModeMultiline()
     QVERIFY(horizontalFitWidth <= myText->width() + 2); // rounding
     QVERIFY(horizontalFitHeight > myText->height());
 
-    if (canElide) {
-        // Right eliding will remove the last line
-        myText->setElideMode(QQuickText::ElideRight);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-        QVERIFY(myText->truncated());
-        QCOMPARE(myText->lineCount(), 1);
-        QVERIFY(myText->contentWidth() <= myText->width() + 2);
-        QVERIFY(myText->contentHeight() <= myText->height() + 2);
-
-        // Left or middle eliding wont have any effect.
-        myText->setElideMode(QQuickText::ElideLeft);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-        QVERIFY(!myText->truncated());
-        QCOMPARE(myText->contentWidth(), horizontalFitWidth);
-        QCOMPARE(myText->contentHeight(), horizontalFitHeight);
-
-        myText->setElideMode(QQuickText::ElideMiddle);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-        QVERIFY(!myText->truncated());
-        QCOMPARE(myText->contentWidth(), horizontalFitWidth);
-        QCOMPARE(myText->contentHeight(), horizontalFitHeight);
-
-        myText->setElideMode(QQuickText::ElideNone);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-    }
+    // Right eliding will remove the last line
+    myText->setElideMode(QQuickText::ElideRight);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+    QVERIFY(myText->truncated());
+    QCOMPARE(myText->lineCount(), 1);
+    QVERIFY(myText->contentWidth() <= myText->width() + 2);
+    QVERIFY(myText->contentHeight() <= myText->height() + 2);
+
+    // Left or middle eliding wont have any effect.
+    myText->setElideMode(QQuickText::ElideLeft);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+    QVERIFY(!myText->truncated());
+    QCOMPARE(myText->contentWidth(), horizontalFitWidth);
+    QCOMPARE(myText->contentHeight(), horizontalFitHeight);
+
+    myText->setElideMode(QQuickText::ElideMiddle);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+    QVERIFY(!myText->truncated());
+    QCOMPARE(myText->contentWidth(), horizontalFitWidth);
+    QCOMPARE(myText->contentHeight(), horizontalFitHeight);
+
+    myText->setElideMode(QQuickText::ElideNone);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
 
     myText->setFontSizeMode(QQuickText::VerticalFit);
     QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
@@ -2180,30 +2173,28 @@ void tst_qquicktext::fontSizeModeMultiline()
     QVERIFY(verticalFitWidth <= myText->width() + 2);
     QVERIFY(verticalFitHeight <= myText->height() + 2);
 
-    if (canElide) {
-        // Elide will have no effect.
-        myText->setElideMode(QQuickText::ElideRight);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-        QVERIFY(!myText->truncated());
-        QVERIFY(myText->contentWidth() <= myText->width() + 2);
-        QCOMPARE(myText->contentWidth(), verticalFitWidth);
-        QCOMPARE(myText->contentHeight(), verticalFitHeight);
-
-        myText->setElideMode(QQuickText::ElideLeft);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-        QVERIFY(!myText->truncated());
-        QCOMPARE(myText->contentWidth(), verticalFitWidth);
-        QCOMPARE(myText->contentHeight(), verticalFitHeight);
-
-        myText->setElideMode(QQuickText::ElideMiddle);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-        QVERIFY(!myText->truncated());
-        QCOMPARE(myText->contentWidth(), verticalFitWidth);
-        QCOMPARE(myText->contentHeight(), verticalFitHeight);
-
-        myText->setElideMode(QQuickText::ElideNone);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-    }
+    // Elide will have no effect.
+    myText->setElideMode(QQuickText::ElideRight);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+    QVERIFY(!myText->truncated());
+    QVERIFY(myText->contentWidth() <= myText->width() + 2);
+    QCOMPARE(myText->contentWidth(), verticalFitWidth);
+    QCOMPARE(myText->contentHeight(), verticalFitHeight);
+
+    myText->setElideMode(QQuickText::ElideLeft);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+    QVERIFY(!myText->truncated());
+    QCOMPARE(myText->contentWidth(), verticalFitWidth);
+    QCOMPARE(myText->contentHeight(), verticalFitHeight);
+
+    myText->setElideMode(QQuickText::ElideMiddle);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+    QVERIFY(!myText->truncated());
+    QCOMPARE(myText->contentWidth(), verticalFitWidth);
+    QCOMPARE(myText->contentHeight(), verticalFitHeight);
+
+    myText->setElideMode(QQuickText::ElideNone);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
 
     myText->setFontSizeMode(QQuickText::Fit);
     QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
@@ -2211,29 +2202,27 @@ void tst_qquicktext::fontSizeModeMultiline()
     QCOMPARE(myText->contentWidth(), verticalFitWidth);
     QCOMPARE(myText->contentHeight(), verticalFitHeight);
 
-    if (canElide) {
-        // Elide won't affect the size with Fit.
-        myText->setElideMode(QQuickText::ElideRight);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-        QVERIFY(!myText->truncated());
-        QCOMPARE(myText->contentWidth(), verticalFitWidth);
-        QCOMPARE(myText->contentHeight(), verticalFitHeight);
-
-        myText->setElideMode(QQuickText::ElideLeft);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-        QVERIFY(!myText->truncated());
-        QCOMPARE(myText->contentWidth(), verticalFitWidth);
-        QCOMPARE(myText->contentHeight(), verticalFitHeight);
-
-        myText->setElideMode(QQuickText::ElideMiddle);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-        QVERIFY(!myText->truncated());
-        QCOMPARE(myText->contentWidth(), verticalFitWidth);
-        QCOMPARE(myText->contentHeight(), verticalFitHeight);
-
-        myText->setElideMode(QQuickText::ElideNone);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-    }
+    // Elide won't affect the size with Fit.
+    myText->setElideMode(QQuickText::ElideRight);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+    QVERIFY(!myText->truncated());
+    QCOMPARE(myText->contentWidth(), verticalFitWidth);
+    QCOMPARE(myText->contentHeight(), verticalFitHeight);
+
+    myText->setElideMode(QQuickText::ElideLeft);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+    QVERIFY(!myText->truncated());
+    QCOMPARE(myText->contentWidth(), verticalFitWidth);
+    QCOMPARE(myText->contentHeight(), verticalFitHeight);
+
+    myText->setElideMode(QQuickText::ElideMiddle);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+    QVERIFY(!myText->truncated());
+    QCOMPARE(myText->contentWidth(), verticalFitWidth);
+    QCOMPARE(myText->contentHeight(), verticalFitHeight);
+
+    myText->setElideMode(QQuickText::ElideNone);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
 
     myText->setFontSizeMode(QQuickText::FixedSize);
     myText->setWrapMode(QQuickText::Wrap);
@@ -2253,17 +2242,15 @@ void tst_qquicktext::fontSizeModeMultiline()
     QCOMPARE(myText->contentWidth(), horizontalFitWidth);
     QCOMPARE(myText->contentHeight(), horizontalFitHeight);
 
-    if (canElide) {
-        // Text will be elided vertically with HorizontalFit
-        myText->setElideMode(QQuickText::ElideRight);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-        QVERIFY(myText->truncated());
-        QVERIFY(myText->contentWidth() <= myText->width() + 2);
-        QVERIFY(myText->contentHeight() <= myText->height() + 2);
+    // Text will be elided vertically with HorizontalFit
+    myText->setElideMode(QQuickText::ElideRight);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+    QVERIFY(myText->truncated());
+    QVERIFY(myText->contentWidth() <= myText->width() + 2);
+    QVERIFY(myText->contentHeight() <= myText->height() + 2);
 
-        myText->setElideMode(QQuickText::ElideNone);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-    }
+    myText->setElideMode(QQuickText::ElideNone);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
 
     myText->setFontSizeMode(QQuickText::VerticalFit);
     QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
@@ -2274,17 +2261,15 @@ void tst_qquicktext::fontSizeModeMultiline()
     QVERIFY(verticalFitHeight <= myText->height() + 2);
     QVERIFY(verticalFitHeight < originalHeight);
 
-    if (canElide) {
-        // Elide won't affect the height or width of a wrapped text with VerticalFit.
-        myText->setElideMode(QQuickText::ElideRight);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-        QVERIFY(!myText->truncated());
-        QCOMPARE(myText->contentWidth(), verticalFitWidth);
-        QCOMPARE(myText->contentHeight(), verticalFitHeight);
+    // Elide won't affect the height or width of a wrapped text with VerticalFit.
+    myText->setElideMode(QQuickText::ElideRight);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+    QVERIFY(!myText->truncated());
+    QCOMPARE(myText->contentWidth(), verticalFitWidth);
+    QCOMPARE(myText->contentHeight(), verticalFitHeight);
 
-        myText->setElideMode(QQuickText::ElideNone);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-    }
+    myText->setElideMode(QQuickText::ElideNone);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
 
     myText->setFontSizeMode(QQuickText::Fit);
     QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
@@ -2292,17 +2277,15 @@ void tst_qquicktext::fontSizeModeMultiline()
     QCOMPARE(myText->contentWidth(), verticalFitWidth);
     QCOMPARE(myText->contentHeight(), verticalFitHeight);
 
-    if (canElide) {
-        // Elide won't affect the size with Fit.
-        myText->setElideMode(QQuickText::ElideRight);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-        QVERIFY(!myText->truncated());
-        QCOMPARE(myText->contentWidth(), verticalFitWidth);
-        QCOMPARE(myText->contentHeight(), verticalFitHeight);
+    // Elide won't affect the size with Fit.
+    myText->setElideMode(QQuickText::ElideRight);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+    QVERIFY(!myText->truncated());
+    QCOMPARE(myText->contentWidth(), verticalFitWidth);
+    QCOMPARE(myText->contentHeight(), verticalFitHeight);
 
-        myText->setElideMode(QQuickText::ElideNone);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-    }
+    myText->setElideMode(QQuickText::ElideNone);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
 
     myText->setFontSizeMode(QQuickText::FixedSize);
     myText->setMaximumLineCount(2);
@@ -2319,17 +2302,15 @@ void tst_qquicktext::fontSizeModeMultiline()
     QCOMPARE(myText->contentWidth(), horizontalFitWidth);
     QCOMPARE(myText->contentHeight(), horizontalFitHeight);
 
-    if (canElide) {
-        // Elide won't affect the size with HorizontalFit.
-        myText->setElideMode(QQuickText::ElideRight);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-        QVERIFY(myText->truncated());
-        QVERIFY(myText->contentWidth() <= myText->width() + 2);
-        QVERIFY(myText->contentHeight() <= myText->height() + 2);
+    // Elide won't affect the size with HorizontalFit.
+    myText->setElideMode(QQuickText::ElideRight);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+    QVERIFY(myText->truncated());
+    QVERIFY(myText->contentWidth() <= myText->width() + 2);
+    QVERIFY(myText->contentHeight() <= myText->height() + 2);
 
-        myText->setElideMode(QQuickText::ElideNone);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-    }
+    myText->setElideMode(QQuickText::ElideNone);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
 
     myText->setFontSizeMode(QQuickText::VerticalFit);
     QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
@@ -2340,17 +2321,15 @@ void tst_qquicktext::fontSizeModeMultiline()
     QVERIFY(verticalFitHeight <= myText->height() + 2);
     QVERIFY(verticalFitHeight < originalHeight);
 
-    if (canElide) {
-        // Elide won't affect the height or width of a wrapped text with VerticalFit.
-        myText->setElideMode(QQuickText::ElideRight);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-        QVERIFY(!myText->truncated());
-        QCOMPARE(myText->contentWidth(), verticalFitWidth);
-        QCOMPARE(myText->contentHeight(), verticalFitHeight);
+    // Elide won't affect the height or width of a wrapped text with VerticalFit.
+    myText->setElideMode(QQuickText::ElideRight);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+    QVERIFY(!myText->truncated());
+    QCOMPARE(myText->contentWidth(), verticalFitWidth);
+    QCOMPARE(myText->contentHeight(), verticalFitHeight);
 
-        myText->setElideMode(QQuickText::ElideNone);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-    }
+    myText->setElideMode(QQuickText::ElideNone);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
 
     myText->setFontSizeMode(QQuickText::Fit);
     QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
@@ -2358,17 +2337,15 @@ void tst_qquicktext::fontSizeModeMultiline()
     QCOMPARE(myText->contentWidth(), verticalFitWidth);
     QCOMPARE(myText->contentHeight(), verticalFitHeight);
 
-    if (canElide) {
-        // Elide won't affect the size with Fit.
-        myText->setElideMode(QQuickText::ElideRight);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-        QVERIFY(!myText->truncated());
-        QCOMPARE(myText->contentWidth(), verticalFitWidth);
-        QCOMPARE(myText->contentHeight(), verticalFitHeight);
+    // Elide won't affect the size with Fit.
+    myText->setElideMode(QQuickText::ElideRight);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
+    QVERIFY(!myText->truncated());
+    QCOMPARE(myText->contentWidth(), verticalFitWidth);
+    QCOMPARE(myText->contentHeight(), verticalFitHeight);
 
-        myText->setElideMode(QQuickText::ElideNone);
-        QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
-    }
+    myText->setElideMode(QQuickText::ElideNone);
+    QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false);
 }
 
 void tst_qquicktext::multilengthStrings_data()