aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2018-04-09 14:05:53 +0200
committerMitch Curtis <mitch.curtis@qt.io>2018-04-17 10:30:18 +0000
commit56ade46b4234bb828b8e4f9a6bf83b5687bd122e (patch)
treeb2834ac9af2564280df343be9db702689c596278 /tests
parent0b394e30bba4f6bb7e6f7dbe5585a2e15aa0f21d (diff)
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 <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quick/qquicktext/data/elideParentChanged.qml13
-rw-r--r--tests/auto/quick/qquicktext/tst_qquicktext.cpp41
2 files changed, 54 insertions, 0 deletions
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 <QFontMetrics>
#include <qmath.h>
#include <QtQuick/QQuickView>
+#include <QtQuick/qquickitemgrabresult.h>
#include <private/qguiapplication_p.h>
#include <limits.h>
#include <QtGui/QMouseEvent>
@@ -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<QQuickItemGrabResult> 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<QQuickText::TextFormat>("format");