summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSona Kurazyan <sona.kurazyan@qt.io>2019-12-04 10:57:08 +0100
committerSona Kurazyan <sona.kurazyan@qt.io>2019-12-05 17:34:02 +0100
commit81459dd9c05f057981ddf2db0c2302030a73cb01 (patch)
tree5a8cf88419a779db11e5d61d33b7057ad4e7085e /tests
parent1f592da7f175aa75726eece2fab8f5c1edde193f (diff)
Copy formatting attributes when cloning an empty QTextDocument
When cloning a QTextDocument, the text fragment of the original document is copied into the new one, which results into copying also the formatting attributes. However, when the text document is empty, the corresponding text fragment is also empty, so nothing is copied. If we want to transfer the formatting attributes for an empty document, we need to set them explicitly. Fixes: QTBUG-80399 Change-Id: I382cd0821723436120af47c06ec7bfa849636307 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
index 52e56feb5a..33d4976b2a 100644
--- a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
+++ b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
@@ -125,6 +125,7 @@ private slots:
void clonePreservesResources();
void clonePreservesUserStates();
void clonePreservesIndentWidth();
+ void clonePreservesFormatsWhenEmpty();
void blockCount();
void defaultStyleSheet();
@@ -2342,6 +2343,32 @@ void tst_QTextDocument::clonePreservesIndentWidth()
delete clone;
}
+void tst_QTextDocument::clonePreservesFormatsWhenEmpty()
+{
+ QTextDocument document;
+ QTextCursor cursor(&document);
+
+ // Change a few char format attributes
+ QTextCharFormat charFormat;
+ charFormat.setFontPointSize(charFormat.fontPointSize() + 1);
+ charFormat.setFontWeight(charFormat.fontWeight() + 1);
+ cursor.setBlockCharFormat(charFormat);
+
+ // Change a few block format attributes
+ QTextBlockFormat blockFormat;
+ blockFormat.setAlignment(Qt::AlignRight); // The default is Qt::AlignLeft
+ blockFormat.setIndent(blockFormat.indent() + 1);
+ cursor.setBlockFormat(blockFormat);
+
+ auto clone = document.clone();
+ QTextCursor cloneCursor(clone);
+
+ QCOMPARE(cloneCursor.blockCharFormat().fontPointSize(), charFormat.fontPointSize());
+ QCOMPARE(cloneCursor.blockCharFormat().fontWeight(), charFormat.fontWeight());
+ QCOMPARE(cloneCursor.blockFormat().alignment(), blockFormat.alignment());
+ QCOMPARE(cloneCursor.blockFormat().indent(), blockFormat.indent());
+}
+
void tst_QTextDocument::blockCount()
{
QCOMPARE(doc->blockCount(), 1);