QPainterPath: fix handling of fill rules

fillRule() contained a major blunder: instead of checking if the
d-pointer was allocated, and return a default value if it wasn't,
it checked whether the path contained any points. This means that

  QPainterPath p;
  p.setFillRule(x);
  Q_ASSERT(p.fillRule() == x);

was failing.

As a drive-by to test this change, fix another mistake in clear():
clear is documented to clear the elements in a path, but instead
it also changed the fill rule.

This commit partially reverses 697910e5fb.

Change-Id: Ieb8145694b672439c3380d9ccb87d1206a2dd115
Pick-to: 5.12 5.15 6.0 6.1
Done-with: Milian Wolff
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
This commit is contained in:
Giuseppe D'Angelo 2021-03-25 18:26:49 +01:00
parent b9f27335e7
commit 0b4ccbf81e
3 changed files with 12 additions and 3 deletions

View File

@ -1341,7 +1341,7 @@ void QPainterPath::addRegion(const QRegion &region)
*/ */
Qt::FillRule QPainterPath::fillRule() const Qt::FillRule QPainterPath::fillRule() const
{ {
return isEmpty() ? Qt::OddEvenFill : d_func()->fillRule; return !d_func() ? Qt::OddEvenFill : d_func()->fillRule;
} }
/*! /*!

View File

@ -292,7 +292,6 @@ inline void QPainterPathPrivate::clear()
elements.clear(); elements.clear();
cStart = 0; cStart = 0;
fillRule = Qt::OddEvenFill;
bounds = {}; bounds = {};
controlBounds = {}; controlBounds = {};

View File

@ -173,8 +173,18 @@ void tst_QPainterPath::clear()
p1.setFillRule(Qt::WindingFill); p1.setFillRule(Qt::WindingFill);
QVERIFY(p1 != p3); QVERIFY(p1 != p3);
p1.clear(); p1.clear();
QCOMPARE(p1.fillRule(), Qt::OddEvenFill); QVERIFY(p1 != p3);
p1.setFillRule(Qt::OddEvenFill);
QCOMPARE(p1, p2); QCOMPARE(p1, p2);
QPainterPath p4;
QCOMPARE(p4.fillRule(), Qt::OddEvenFill);
p4.setFillRule(Qt::WindingFill);
QCOMPARE(p4.fillRule(), Qt::WindingFill);
p4.clear();
QCOMPARE(p4.fillRule(), Qt::WindingFill);
p4 = QPainterPath();
QCOMPARE(p4.fillRule(), Qt::OddEvenFill);
} }
void tst_QPainterPath::reserveAndCapacity() void tst_QPainterPath::reserveAndCapacity()