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

View File

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