summaryrefslogtreecommitdiffstats
path: root/src/gui
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 /src/gui
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 'src/gui')
-rw-r--r--src/gui/text/qtextdocument.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp
index e94f635651..4b35509ace 100644
--- a/src/gui/text/qtextdocument.cpp
+++ b/src/gui/text/qtextdocument.cpp
@@ -347,7 +347,19 @@ QTextDocument *QTextDocument::clone(QObject *parent) const
{
Q_D(const QTextDocument);
QTextDocument *doc = new QTextDocument(parent);
- QTextCursor(doc).insertFragment(QTextDocumentFragment(this));
+ if (isEmpty()) {
+ const QTextCursor thisCursor(const_cast<QTextDocument *>(this));
+
+ const auto blockFormat = thisCursor.blockFormat();
+ if (blockFormat.isValid() && !blockFormat.isEmpty())
+ QTextCursor(doc).setBlockFormat(blockFormat);
+
+ const auto blockCharFormat = thisCursor.blockCharFormat();
+ if (blockCharFormat.isValid() && !blockCharFormat.isEmpty())
+ QTextCursor(doc).setBlockCharFormat(blockCharFormat);
+ } else {
+ QTextCursor(doc).insertFragment(QTextDocumentFragment(this));
+ }
doc->rootFrame()->setFrameFormat(rootFrame()->frameFormat());
QTextDocumentPrivate *priv = doc->d_func();
priv->title = d->title;