summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qtextdocument.cpp
diff options
context:
space:
mode:
authorDavid Faure <david.faure@kdab.com>2022-05-25 22:07:36 +0200
committerDavid Faure <david.faure@kdab.com>2022-05-26 16:58:42 +0200
commit09c7457f4ab8021e7637e60e6c3d1f644639aec1 (patch)
treea616cc26d117d741d593542d7dc41a67a79de96f /src/gui/text/qtextdocument.cpp
parent2996ca031efcd97ef9866186ae53e96ed75c9fbf (diff)
QTextDocument: add setLayoutEnabled()
This allows to set up everything first - without paying for the layout calculation at every step - and only then trigger the layout once. Results: 0.065 msecs to create a QGraphicsTextItem with some text (layouted) 0.036 msecs to set everything up in a QGraphicsTextItem with 0 width Change-Id: I138bd1d58941d029bc0a36d2730216778f1fbd97 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/gui/text/qtextdocument.cpp')
-rw-r--r--src/gui/text/qtextdocument.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp
index c01c858cc5..71511257f5 100644
--- a/src/gui/text/qtextdocument.cpp
+++ b/src/gui/text/qtextdocument.cpp
@@ -635,6 +635,40 @@ bool QTextDocument::useDesignMetrics() const
}
/*!
+ \property QTextDocument::layoutEnabled
+ \since 6.4
+ \brief whether QTextDocument should recalculate the layout after every change
+
+ If this property is set to true, any change to the document triggers a layout,
+ which makes everything work as expected but takes time.
+
+ Temporarily disabling the layout can save time when making multiple changes
+ (not just text content, but also default font, default text option....)
+ so that the document is only laid out once at the end. This can be useful when
+ the text width or page size isn't yet known, for instance.
+
+ By default, this property is \c true.
+
+ \sa setTextWidth
+*/
+
+void QTextDocument::setLayoutEnabled(bool b)
+{
+ Q_D(QTextDocument);
+ if (d->layoutEnabled == b)
+ return;
+ d->layoutEnabled = b;
+ if (b && d->lout)
+ d->lout->documentChanged(0, 0, d->length());
+}
+
+bool QTextDocument::isLayoutEnabled() const
+{
+ Q_D(const QTextDocument);
+ return d->layoutEnabled;
+}
+
+/*!
\since 4.2
Draws the content of the document with painter \a p, clipped to \a rect.