QLabel: remove private member cachedimage

Simplify the code - member cachedimage is not really needed as QPixmap
has a scaled() function by itself.

Change-Id: I89cc237ef611f8516588e8b2e7b4056845bc6c69
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit cf0c9de6ed6a4edd6e8e21734e975d2554caa74f)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Christian Ehrlicher 2024-06-16 20:29:20 +02:00 committed by Qt Cherry-pick Bot
parent 755f964364
commit 1c66b77f52
2 changed files with 3 additions and 11 deletions

View File

@ -33,7 +33,6 @@ QLabelPrivate::QLabelPrivate()
text(), text(),
pixmap(), pixmap(),
scaledpixmap(), scaledpixmap(),
cachedimage(),
#ifndef QT_NO_PICTURE #ifndef QT_NO_PICTURE
picture(), picture(),
#endif #endif
@ -1096,13 +1095,9 @@ void QLabel::paintEvent(QPaintEvent *)
QSize scaledSize = d->scaledcontents ? (cr.size() * dpr) QSize scaledSize = d->scaledcontents ? (cr.size() * dpr)
: (d->pixmap->size() * (dpr / d->pixmap->devicePixelRatio())); : (d->pixmap->size() * (dpr / d->pixmap->devicePixelRatio()));
if (!d->scaledpixmap || d->scaledpixmap->size() != scaledSize) { if (!d->scaledpixmap || d->scaledpixmap->size() != scaledSize) {
if (!d->cachedimage) d->scaledpixmap =
d->cachedimage = d->pixmap->toImage(); d->pixmap->scaled(scaledSize,
d->scaledpixmap.reset();
QImage scaledImage =
d->cachedimage->scaled(scaledSize,
Qt::IgnoreAspectRatio, Qt::SmoothTransformation); Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
d->scaledpixmap = QPixmap::fromImage(std::move(scaledImage));
d->scaledpixmap->setDevicePixelRatio(dpr); d->scaledpixmap->setDevicePixelRatio(dpr);
} }
pix = *d->scaledpixmap; pix = *d->scaledpixmap;
@ -1310,7 +1305,6 @@ void QLabelPrivate::clearContents()
picture.reset(); picture.reset();
#endif #endif
scaledpixmap.reset(); scaledpixmap.reset();
cachedimage.reset();
pixmap.reset(); pixmap.reset();
text.clear(); text.clear();
@ -1456,7 +1450,6 @@ void QLabel::setScaledContents(bool enable)
d->scaledcontents = enable; d->scaledcontents = enable;
if (!enable) { if (!enable) {
d->scaledpixmap.reset(); d->scaledpixmap.reset();
d->cachedimage.reset();
} }
update(contentsRect()); update(contentsRect());
} }

View File

@ -88,7 +88,6 @@ public:
QString text; QString text;
std::optional<QPixmap> pixmap; std::optional<QPixmap> pixmap;
std::optional<QPixmap> scaledpixmap; std::optional<QPixmap> scaledpixmap;
std::optional<QImage> cachedimage;
#ifndef QT_NO_PICTURE #ifndef QT_NO_PICTURE
std::optional<QPicture> picture; std::optional<QPicture> picture;
#endif #endif