diff options
author | David Faure <david.faure@kdab.com> | 2022-05-25 22:07:36 +0200 |
---|---|---|
committer | David Faure <david.faure@kdab.com> | 2022-05-26 16:58:42 +0200 |
commit | 09c7457f4ab8021e7637e60e6c3d1f644639aec1 (patch) | |
tree | a616cc26d117d741d593542d7dc41a67a79de96f /tests/benchmarks/widgets/graphicsview | |
parent | 2996ca031efcd97ef9866186ae53e96ed75c9fbf (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 'tests/benchmarks/widgets/graphicsview')
-rw-r--r-- | tests/benchmarks/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/benchmarks/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/benchmarks/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index fd74a7b3b9..efeecf4989 100644 --- a/tests/benchmarks/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/benchmarks/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -5,6 +5,7 @@ #include <QGraphicsItem> #include <QGraphicsScene> #include <QGraphicsView> +#include <QTextDocument> class tst_QGraphicsItem : public QObject { @@ -33,6 +34,7 @@ private slots: void shear(); void translate(); void createTextItem(); + void createTextItemNoLayouting(); }; tst_QGraphicsItem::tst_QGraphicsItem() @@ -216,5 +218,22 @@ void tst_QGraphicsItem::createTextItem() } } +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" |