summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2020-06-01 11:54:45 +0200
committerMarc Mutz <marc.mutz@kdab.com>2021-07-14 17:56:01 +0200
commit85e82de916e8799ee1198c63566b7a1f5e47f514 (patch)
treed662e279ff93cf38cb5010eb2f582cf6d47aa0bc /src/gui
parent5a7f4c1f4964a4bf6595002478fbcd474cedd8a6 (diff)
QPainter: replace manual memory management [3/5]: engine
Use unique_ptr to indicate ownership, even though it's conditional (on QPaintEngine::autoDestruct()). That just requires a custom deleter. Change-Id: Icf8e356c333f9617b2e5172b14f13197e63c9502 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/painting/qpainter.cpp12
-rw-r--r--src/gui/painting/qpainter_p.h10
2 files changed, 14 insertions, 8 deletions
diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp
index eca80f55f0..eb51e9cc24 100644
--- a/src/gui/painting/qpainter.cpp
+++ b/src/gui/painting/qpainter.cpp
@@ -1545,7 +1545,7 @@ QPaintDevice *QPainter::device() const
bool QPainter::isActive() const
{
Q_D(const QPainter);
- return d->engine;
+ return d->engine != nullptr;
}
void QPainterPrivate::initFrom(const QPaintDevice *device)
@@ -1744,7 +1744,7 @@ bool QPainter::begin(QPaintDevice *pd)
else if (pd->devType() == QInternal::Image)
static_cast<QImage *>(pd)->detach();
- d->engine = pd->paintEngine();
+ d->engine.reset(pd->paintEngine());
if (!d->engine) {
qWarning("QPainter::begin: Paint device returned engine == 0, type: %d", pd->devType());
@@ -1753,7 +1753,7 @@ bool QPainter::begin(QPaintDevice *pd)
d->device = pd;
- d->extended = d->engine->isExtended() ? static_cast<QPaintEngineEx *>(d->engine) : nullptr;
+ d->extended = d->engine->isExtended() ? static_cast<QPaintEngineEx *>(d->engine.get()) : nullptr;
if (d->emulationEngine)
d->emulationEngine->real_engine = d->extended;
@@ -1911,9 +1911,7 @@ bool QPainter::end()
qWarning("QPainter::end: Painter ended with %d saved states", int(d->savedStates.size()));
}
- if (d->engine->autoDestruct()) {
- delete d->engine;
- }
+ d->engine.reset();
if (d->emulationEngine) {
delete d->emulationEngine;
@@ -1939,7 +1937,7 @@ bool QPainter::end()
QPaintEngine *QPainter::paintEngine() const
{
Q_D(const QPainter);
- return d->engine;
+ return d->engine.get();
}
/*!
diff --git a/src/gui/painting/qpainter_p.h b/src/gui/painting/qpainter_p.h
index 8994bcd3e7..c9caca7901 100644
--- a/src/gui/painting/qpainter_p.h
+++ b/src/gui/painting/qpainter_p.h
@@ -268,7 +268,15 @@ public:
QPaintDevice *device;
QPaintDevice *original_device;
QPaintDevice *helper_device;
- QPaintEngine *engine;
+ struct QPaintEngineDestructor {
+ void operator()(QPaintEngine *pe) const noexcept
+ {
+ if (pe && pe->autoDestruct())
+ delete pe;
+ }
+ };
+
+ std::unique_ptr<QPaintEngine, QPaintEngineDestructor> engine;
QEmulationPaintEngine *emulationEngine;
QPaintEngineEx *extended;
QBrush colorBrush; // for fill with solid color