From 56ade46b4234bb828b8e4f9a6bf83b5687bd122e Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Mon, 9 Apr 2018 14:05:53 +0200 Subject: Fix Text with ElideRight not being rendered when reparented Consider the following example: Item { width: 100 height: 30 Text { width: parent ? parent.width : 0 height: parent ? parent.height : 0 elide: Text.ElideRight text: "wot" } } When setting the Text item's parent to null, its explicit width and height are set to 0. When restoring its parent (the Item), its explicit width and height are set to 100 and 30 again, but the text itself is still not rendered. The cause can be seen here: if (!(widthChanged || widthMaximum) && !d->isLineLaidOutConnected()) { // only height has changed if (newGeometry.height() > oldGeometry.height()) { if (!d->heightExceeded) // Height is adequate and growing. goto geomChangeDone; heightExceeded was false, because 30 > 12 (or whatever the implicit height happened to be), so the text was not laid out again, even though it went from having an explicit height of 0 to an explicit height of 30. Fix the issue by only executing the goto if the old explicit height wasn't 0. Task-number: QTBUG-60328 Task-number: QTBUG-67145 Change-Id: I7f4d2f95bc95c850133ba91ac2d1a02c7ee159b6 Reviewed-by: Eskil Abrahamsen Blomfeldt --- .../quick/qquicktext/data/elideParentChanged.qml | 13 +++++++ tests/auto/quick/qquicktext/tst_qquicktext.cpp | 41 ++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 tests/auto/quick/qquicktext/data/elideParentChanged.qml (limited to 'tests/auto/quick') diff --git a/tests/auto/quick/qquicktext/data/elideParentChanged.qml b/tests/auto/quick/qquicktext/data/elideParentChanged.qml new file mode 100644 index 0000000000..f605cf58f1 --- /dev/null +++ b/tests/auto/quick/qquicktext/data/elideParentChanged.qml @@ -0,0 +1,13 @@ +import QtQuick 2.0 + +Item { + width: 100 + height: 30 + + Text { + width: parent ? parent.width : 0 + height: parent ? parent.height : 0 + elide: Text.ElideRight + text: "wot" + } +} diff --git a/tests/auto/quick/qquicktext/tst_qquicktext.cpp b/tests/auto/quick/qquicktext/tst_qquicktext.cpp index 609a84ce82..89d2590c03 100644 --- a/tests/auto/quick/qquicktext/tst_qquicktext.cpp +++ b/tests/auto/quick/qquicktext/tst_qquicktext.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -64,6 +65,7 @@ private slots: void width(); void wrap(); void elide(); + void elideParentChanged(); void multilineElide_data(); void multilineElide(); void implicitElide_data(); @@ -554,6 +556,45 @@ void tst_qquicktext::elide() } } +// QTBUG-60328 +// Tests that text with elide set is rendered after +// having its parent cleared and then set again. +void tst_qquicktext::elideParentChanged() +{ + QQuickView window; + window.setSource(testFileUrl("elideParentChanged.qml")); + QTRY_COMPARE(window.status(), QQuickView::Ready); + + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + + QQuickItem *root = window.rootObject(); + QVERIFY(root); + QCOMPARE(root->childItems().size(), 1); + + // Store a snapshot of the scene so that we can compare it later. + QSharedPointer grabResult = root->grabToImage(); + QTRY_VERIFY(!grabResult->image().isNull()); + const QImage expectedItemImageGrab(grabResult->image()); + + // Clear the text's parent. It shouldn't render anything. + QQuickItem *text = root->childItems().first(); + text->setParentItem(nullptr); + QCOMPARE(text->width(), 0.0); + QCOMPARE(text->height(), 0.0); + + // Set the parent back to what it was. The text should + // be rendered identically to how it was before. + text->setParentItem(root); + QCOMPARE(text->width(), 100.0); + QCOMPARE(text->height(), 30.0); + + grabResult = root->grabToImage(); + QTRY_VERIFY(!grabResult->image().isNull()); + const QImage actualItemImageGrab(grabResult->image()); + QCOMPARE(actualItemImageGrab, expectedItemImageGrab); +} + void tst_qquicktext::multilineElide_data() { QTest::addColumn("format"); -- cgit v1.2.3