diff options
author | Jean-Michaël Celerier <jeanmichael.celerier@gmail.com> | 2017-07-09 19:27:35 +0200 |
---|---|---|
committer | Jean-Michaël Celerier <jean-michael.celerier@kdab.com> | 2019-01-08 08:25:02 +0000 |
commit | e6a7b61d273c2985dee63df34e5941ee90754e2a (patch) | |
tree | dc27b083dcb810e70b9616b12adab7a9c64c0efe /tests/auto/gui/painting | |
parent | 4e6a42cdd050c8714686fa53b3246c4fc66d18fd (diff) |
Add clear, reserve and capacity methods to QPainterPath
This allows anticipating and reusing internal allocations of
QPainterPathElements instead of using the common `m_myPath = QPainterPath{}` pattern.
[ChangeLog][QtGui][QPainterPath] Added clear(), reserve(), capacity().
clear() removes allocated QPainterPath elements but preserves allocated memory, which can be
useful for application with complex paths that are often recreated. reserve() and capacity()
follow QVector semantics.
Change-Id: I763461e2a421feda9053d3eb512af2fcf07ade2b
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'tests/auto/gui/painting')
-rw-r--r-- | tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp b/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp index 16215714f3..69c961c1a1 100644 --- a/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp +++ b/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp @@ -43,6 +43,8 @@ public slots: void cleanupTestCase(); private slots: void getSetCheck(); + void clear(); + void reserveAndCapacity(); void swap(); void contains_QPointF_data(); @@ -148,6 +150,47 @@ void tst_QPainterPath::swap() QCOMPARE(p2.boundingRect().toRect(), QRect( 0, 0,10,10)); } +void tst_QPainterPath::clear() +{ + QPainterPath p1; + QPainterPath p2; + p1.clear(); + QCOMPARE(p1, p2); + + p1.addRect(0, 0, 10, 10); + p1.clear(); + QCOMPARE(p1, p2); + + QCOMPARE(p1.fillRule(), Qt::OddEvenFill); + p1.setFillRule(Qt::WindingFill); + p1.clear(); + QCOMPARE(p1.fillRule(), Qt::WindingFill); +} + +void tst_QPainterPath::reserveAndCapacity() +{ + QPainterPath p; + QVERIFY(p.capacity() == 0); + + p.addRect(0, 0, 10, 10); + QVERIFY(p.capacity() > 0); + + p.clear(); + QVERIFY(p.capacity() > 0); + + p = QPainterPath{}; + QVERIFY(p.capacity() == 0); + + p.moveTo(100, 100); + QVERIFY(p.capacity() > 1); + + p.reserve(1000); + QVERIFY(p.capacity() >= 1000); + + p.reserve(0); + QVERIFY(p.capacity() >= 1000); +} + Q_DECLARE_METATYPE(QPainterPath) void tst_QPainterPath::currentPosition() |