From 40993321cd67c1fe722977ed94c91cedff4bb1f8 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Wed, 7 Oct 2020 23:44:44 +0200 Subject: QQuickTextEdit: ensure we update document width when padding has changed We use an if-test to check if the document width has changed before we set the new value. The problem is that the value we test against is different than the value we set. The result is that we can sometimes skip setting a new width on the document, even if padding has changed. This patch ensures that we use the same width for both testing and setting. Pick-to: 5.15 Change-Id: Ia8391999e8cc2b5be72fe525d396bf8c17ba0fa2 Reviewed-by: Mitch Curtis --- tests/auto/quick/qquicktextedit/data/wordwrap.qml | 8 +++++++ .../quick/qquicktextedit/tst_qquicktextedit.cpp | 25 ++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 tests/auto/quick/qquicktextedit/data/wordwrap.qml (limited to 'tests/auto/quick/qquicktextedit') diff --git a/tests/auto/quick/qquicktextedit/data/wordwrap.qml b/tests/auto/quick/qquicktextedit/data/wordwrap.qml new file mode 100644 index 0000000000..8c356a2fef --- /dev/null +++ b/tests/auto/quick/qquicktextedit/data/wordwrap.qml @@ -0,0 +1,8 @@ +import QtQuick 2.6 + +TextEdit { + width: 200 + height: 200 + text: "X Y Z X Y Z X Y Z X Y Z X Y Z X Y Z X Y Z X Y Z" + wrapMode: TextEdit.WordWrap +} diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp index d0ba99f42d..f732c4bbd1 100644 --- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp +++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp @@ -218,6 +218,7 @@ private slots: void doubleSelect_QTBUG_38704(); void padding(); + void paddingAndWrap(); void QTBUG_51115_readOnlyResetsSelection(); void keys_shortcutoverride(); @@ -5795,6 +5796,30 @@ void tst_qquicktextedit::padding() delete root; } +void tst_qquicktextedit::paddingAndWrap() +{ + // Check that the document ends up with the correct width if + // we set left and right padding after component completed. + QScopedPointer window(new QQuickView); + window->setSource(testFileUrl("wordwrap.qml")); + QTRY_COMPARE(window->status(), QQuickView::Ready); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QQuickItem *root = window->rootObject(); + QVERIFY(root); + QQuickTextEdit *obj = qobject_cast(root); + QVERIFY(obj != nullptr); + QTextDocument *doc = QQuickTextEditPrivate::get(obj)->document; + + QCOMPARE(doc->textWidth(), obj->width()); + obj->setLeftPadding(10); + obj->setRightPadding(10); + QCOMPARE(doc->textWidth(), obj->width() - obj->leftPadding() - obj->rightPadding()); + obj->setLeftPadding(0); + obj->setRightPadding(0); + QCOMPARE(doc->textWidth(), obj->width()); +} + void tst_qquicktextedit::QTBUG_51115_readOnlyResetsSelection() { QQuickView view; -- cgit v1.2.3