From 1e938c348b936328fafbcaae4c0c7d91003143e5 Mon Sep 17 00:00:00 2001 From: David Faure Date: Fri, 29 Apr 2022 16:35:34 +0200 Subject: QTextDocument: add setLayoutEnabled() This allows to set up everything first - without paying for layouting at every step - and only then trigger layouting. Same performance behavior as setTextWidth(0), but this is a more explicit/readable API. Change-Id: I044dbd8b1301b1c97a92f9a29ccde2baf27a7665 Reviewed-by: Volker Hilsheimer --- .../graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tests/benchmarks') diff --git a/tests/benchmarks/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/benchmarks/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index 536d366b63..b8684610a8 100644 --- a/tests/benchmarks/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/benchmarks/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -35,6 +35,7 @@ private slots: void translate(); void createTextItem(); void createTextItemZeroWidth(); + void createTextItemNoLayouting(); }; tst_QGraphicsItem::tst_QGraphicsItem() @@ -235,5 +236,22 @@ void tst_QGraphicsItem::createTextItemZeroWidth() } } +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" -- cgit v1.2.3