aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquicktextedit
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2020-10-07 23:44:44 +0200
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2020-10-08 14:47:37 +0200
commit40993321cd67c1fe722977ed94c91cedff4bb1f8 (patch)
tree8d1965deec9cca257489a581fbcc56a0cee3c75e /tests/auto/quick/qquicktextedit
parent93455f77c2cef4e7cbcb4ca96c82076e552cae1a (diff)
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 <mitch.curtis@qt.io>
Diffstat (limited to 'tests/auto/quick/qquicktextedit')
-rw-r--r--tests/auto/quick/qquicktextedit/data/wordwrap.qml8
-rw-r--r--tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp25
2 files changed, 33 insertions, 0 deletions
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<QQuickView> 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<QQuickTextEdit *>(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;