summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qtextdocumentlayout.cpp
diff options
context:
space:
mode:
authorDavid Faure <[email protected]>2022-05-16 23:58:30 +0200
committerDavid Faure <[email protected]>2022-05-17 22:37:40 +0200
commitbb2f4d08d9d138e4f70d6d6db46e24e34500becc (patch)
tree94a38a14157c6b3e0cbaa41692364b45584d29ca /src/gui/text/qtextdocumentlayout.cpp
parent7fa17b5f7998926c8f8650694a977eb7a24ae191 (diff)
QTextDocument/QGraphicsTextItem: skip layout in setTextWidth(0)
In a QGraphicsTextItem without a width yet, there's no need to do any layouting. The use case is obviously items with an app-defined size, not the default where text items adapt to their contents. 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 QTextEdit was abusing the width 0 to mean "no wrap, width comes from contents", but since the value -1 means that already in QTextDocument, QTextEdit now uses a width of -1 for that meaning. Change-Id: I67ad59c305e5dd34830886e4e6c56dde03c93668 Reviewed-by: Qt CI Bot <[email protected]> Reviewed-by: Volker Hilsheimer <[email protected]>
Diffstat (limited to 'src/gui/text/qtextdocumentlayout.cpp')
-rw-r--r--src/gui/text/qtextdocumentlayout.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/gui/text/qtextdocumentlayout.cpp b/src/gui/text/qtextdocumentlayout.cpp
index 81eb0f49fbe..6b75449ae9e 100644
--- a/src/gui/text/qtextdocumentlayout.cpp
+++ b/src/gui/text/qtextdocumentlayout.cpp
@@ -3705,7 +3705,7 @@ void QTextDocumentLayout::draw(QPainter *painter, const PaintContext &context)
}
QFixed width = fd->size.width;
- if (d->document->pageSize().width() == 0 && d->viewportRect.isValid()) {
+ if (d->document->pageSize().width() == -1 && d->viewportRect.isValid()) {
// we're in NoWrap mode, meaning the frame should expand to the viewport
// so that backgrounds are drawn correctly
fd->size.width = qMax(width, QFixed::fromReal(d->viewportRect.right()));
@@ -3754,7 +3754,7 @@ void QTextDocumentLayout::documentChanged(int from, int oldLength, int length)
for (; blockIt.isValid() && blockIt != endIt; blockIt = blockIt.next())
blockIt.clearLayout();
- if (d->docPrivate->pageSize.isNull())
+ if (!d->docPrivate->canLayout())
return;
QRectF updateRect;
@@ -4032,7 +4032,7 @@ QRectF QTextDocumentLayout::tableCellBoundingRect(QTextTable *table, const QText
QRectF QTextDocumentLayout::tableBoundingRect(QTextTable *table) const
{
Q_D(const QTextDocumentLayout);
- if (d->docPrivate->pageSize.isNull())
+ if (!d->docPrivate->canLayout())
return QRectF();
d->ensureLayoutFinished();
@@ -4059,7 +4059,7 @@ QRectF QTextDocumentLayout::tableBoundingRect(QTextTable *table) const
QRectF QTextDocumentLayout::frameBoundingRect(QTextFrame *frame) const
{
Q_D(const QTextDocumentLayout);
- if (d->docPrivate->pageSize.isNull())
+ if (!d->docPrivate->canLayout())
return QRectF();
d->ensureLayoutFinished();
return d->frameBoundingRectInternal(frame);
@@ -4088,7 +4088,7 @@ QRectF QTextDocumentLayoutPrivate::frameBoundingRectInternal(QTextFrame *frame)
QRectF QTextDocumentLayout::blockBoundingRect(const QTextBlock &block) const
{
Q_D(const QTextDocumentLayout);
- if (d->docPrivate->pageSize.isNull() || !block.isValid() || !block.isVisible())
+ if (!d->docPrivate->canLayout() || !block.isValid() || !block.isVisible())
return QRectF();
d->ensureLayoutedByPosition(block.position() + block.length());
QTextFrame *frame = d->document->frameAt(block.position());