Fix crash in tst_qquicktext::implicitSize

This reverts commit 1e938c348b936328fafbcaae4c0c7d91003143e5
and bb2f4d08d9d138e4f70d6d6db46e24e34500becc.

bb2f4d08d9d causes the crash, but 1e938c348b93 amends it, so
this reverts both. When the cause of the crash has been determined
and mitigated, the patches can be recreated.

Fixes: QTBUG-103719
Change-Id: Ifc36b3771a96f6c85387a5306a0402d4c508d006
Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2022-05-20 11:44:36 +02:00
parent 2dc82c2177
commit 4fe9374589
7 changed files with 8 additions and 91 deletions

View File

@ -634,41 +634,6 @@ bool QTextDocument::useDesignMetrics() const
return d->defaultTextOption.useDesignMetrics();
}
/*!
\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 triggers a laying out of the
document, which makes everything work as expected, but takes time.
Temporarily disabling the layout process 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 in 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

View File

@ -62,7 +62,6 @@ class Q_GUI_EXPORT QTextDocument : public QObject
Q_PROPERTY(QSizeF pageSize READ pageSize WRITE setPageSize)
Q_PROPERTY(QFont defaultFont READ defaultFont WRITE setDefaultFont)
Q_PROPERTY(bool useDesignMetrics READ useDesignMetrics WRITE setUseDesignMetrics)
Q_PROPERTY(bool layoutEnabled READ isLayoutEnabled WRITE setLayoutEnabled)
Q_PROPERTY(QSizeF size READ size)
Q_PROPERTY(qreal textWidth READ textWidth WRITE setTextWidth)
Q_PROPERTY(int blockCount READ blockCount)
@ -219,9 +218,6 @@ public:
void setUseDesignMetrics(bool b);
bool useDesignMetrics() const;
void setLayoutEnabled(bool b);
bool isLayoutEnabled() const;
void drawContents(QPainter *painter, const QRectF &rect = QRectF());
void setTextWidth(qreal width);

View File

@ -291,11 +291,6 @@ public:
return get(object->document());
}
// Only test the width for 0:
// * setTextWidth(x) leads to height -1, which is valid
// * the default page size of (-1, -1) means size determined from contents, this is valid too
bool canLayout() const { return layoutEnabled && !qIsNull(pageSize.width()); }
private:
QTextDocumentPrivate(const QTextDocumentPrivate& m);
QTextDocumentPrivate& operator= (const QTextDocumentPrivate& m);
@ -342,7 +337,6 @@ private:
public:
bool inContentsChange;
bool layoutEnabled = true;
QTextOption defaultTextOption;
Qt::CursorMoveStyle defaultCursorMoveStyle;
#ifndef QT_NO_CSSPARSER

View File

@ -3705,7 +3705,7 @@ void QTextDocumentLayout::draw(QPainter *painter, const PaintContext &context)
}
QFixed width = fd->size.width;
if (d->document->pageSize().width() == -1 && d->viewportRect.isValid()) {
if (d->document->pageSize().width() == 0 && 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->canLayout())
if (d->docPrivate->pageSize.isNull())
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->canLayout())
if (d->docPrivate->pageSize.isNull())
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->canLayout())
if (d->docPrivate->pageSize.isNull())
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->canLayout() || !block.isValid() || !block.isVisible())
if (d->docPrivate->pageSize.isNull() || !block.isValid() || !block.isVisible())
return QRectF();
d->ensureLayoutedByPosition(block.position() + block.length());
QTextFrame *frame = d->document->frameAt(block.position());

View File

@ -1521,7 +1521,7 @@ void QTextEditPrivate::relayoutDocument()
QVariant alignmentProperty = doc->documentLayout()->property("contentHasAlignment");
if (alignmentProperty.userType() == QMetaType::Bool && !alignmentProperty.toBool()) {
width = -1;
width = 0;
}
}

View File

@ -1194,9 +1194,8 @@ void tst_QTextEdit::undoRedoShouldRepositionTextEditCursor()
void tst_QTextEdit::lineWrapModes()
{
ed->setLineWrapMode(QTextEdit::NoWrap);
// NoWrap at the same time as having all lines that are all left aligned means we optimize to
// only layout once. The effect is that the width is always -1
QCOMPARE(ed->document()->pageSize().width(), qreal(-1));
// NoWrap at the same time as having all lines that are all left aligned means we optimize to only layout once. The effect is that the width is always 0
QCOMPARE(ed->document()->pageSize().width(), qreal(0));
QTextCursor cursor = QTextCursor(ed->document());
cursor.insertText(QString("A simple line"));

View File

@ -5,7 +5,6 @@
#include <QGraphicsItem>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QTextDocument>
class tst_QGraphicsItem : public QObject
{
@ -34,8 +33,6 @@ private slots:
void shear();
void translate();
void createTextItem();
void createTextItemZeroWidth();
void createTextItemNoLayouting();
};
tst_QGraphicsItem::tst_QGraphicsItem()
@ -219,39 +216,5 @@ void tst_QGraphicsItem::createTextItem()
}
}
void tst_QGraphicsItem::createTextItemZeroWidth()
{
// Ensure QFontDatabase loaded the font beforehand
QFontInfo(qApp->font()).family();
const QString text = "This is some text";
QBENCHMARK {
QGraphicsTextItem item;
item.document()->setTextWidth(0);
// Prepare everything
item.setPlainText(text);
QTextOption option = item.document()->defaultTextOption();
option.setAlignment(Qt::AlignHCenter);
item.document()->setDefaultTextOption(option);
// And (in a real app) set actual text width here
}
}
void tst_QGraphicsItem::createTextItemNoLayouting()
{
// Ensure QFontDatabase loaded the font beforehand
QFontInfo(qApp->font()).family();
const QString text = "This is some text";
QBENCHMARK {
QGraphicsTextItem item;
item.document()->setLayoutEnabled(false);
// Prepare everything
item.setPlainText(text);
QTextOption option = item.document()->defaultTextOption();
option.setAlignment(Qt::AlignHCenter);
item.document()->setDefaultTextOption(option);
// And (in a real app) enable layouting here
}
}
QTEST_MAIN(tst_QGraphicsItem)
#include "tst_qgraphicsitem.moc"