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>
This commit is contained in:
parent
5a7f4c1f49
commit
85e82de916
@ -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();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user