QtGui: mark obsolete QPixmapCache::find() functions as deprecated

QPixmapCache::find(QString) and QPixmapCache::find(QString, QPixmap&)
are deprecated since Qt4 times.
Explicit mark them as deprecated so they can be removed with Qt6.

Change-Id: Iaf185f69afe02203559a1c812fbb4a95c9049a1d
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
This commit is contained in:
Christian Ehrlicher 2019-01-25 21:15:43 +01:00
parent df39627fa3
commit daee9af969
13 changed files with 57 additions and 33 deletions

View File

@ -61,10 +61,10 @@
QPixmap cached(const QString &img) QPixmap cached(const QString &img)
{ {
if (QPixmap *p = QPixmapCache::find(img))
return *p;
QPixmap pm; QPixmap pm;
if (QPixmapCache::find(img, &pm))
return pm;
pm = QPixmap::fromImage(QImage(img), Qt::OrderedDither | Qt::OrderedAlphaDither); pm = QPixmap::fromImage(QImage(img), Qt::OrderedDither | Qt::OrderedAlphaDither);
if (pm.isNull()) if (pm.isNull())
return QPixmap(); return QPixmap();

View File

@ -315,9 +315,9 @@ QPixmap QPixmapIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::St
% HexString<uint>(actualSize.height()); % HexString<uint>(actualSize.height());
if (mode == QIcon::Active) { if (mode == QIcon::Active) {
if (QPixmapCache::find(key % HexString<uint>(mode), pm)) if (QPixmapCache::find(key % HexString<uint>(mode), &pm))
return pm; // horray return pm; // horray
if (QPixmapCache::find(key % HexString<uint>(QIcon::Normal), pm)) { if (QPixmapCache::find(key % HexString<uint>(QIcon::Normal), &pm)) {
QPixmap active = pm; QPixmap active = pm;
if (QGuiApplication *guiApp = qobject_cast<QGuiApplication *>(qApp)) if (QGuiApplication *guiApp = qobject_cast<QGuiApplication *>(qApp))
active = static_cast<QGuiApplicationPrivate*>(QObjectPrivate::get(guiApp))->applyQIconStyleHelper(QIcon::Active, pm); active = static_cast<QGuiApplicationPrivate*>(QObjectPrivate::get(guiApp))->applyQIconStyleHelper(QIcon::Active, pm);
@ -326,7 +326,7 @@ QPixmap QPixmapIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::St
} }
} }
if (!QPixmapCache::find(key % HexString<uint>(mode), pm)) { if (!QPixmapCache::find(key % HexString<uint>(mode), &pm)) {
if (pm.size() != actualSize) if (pm.size() != actualSize)
pm = pm.scaled(actualSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); pm = pm.scaled(actualSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
if (pe->mode != mode && mode != QIcon::Normal) { if (pe->mode != mode && mode != QIcon::Normal) {

View File

@ -469,10 +469,13 @@ QPixmapCacheEntry::~QPixmapCacheEntry()
pm_cache()->releaseKey(key); pm_cache()->releaseKey(key);
} }
#if QT_DEPRECATED_SINCE(5, 13)
/*! /*!
\obsolete \obsolete
\overload \overload
Use bool find(const QString &, QPixmap *) instead.
Returns the pixmap associated with the \a key in the cache, or Returns the pixmap associated with the \a key in the cache, or
null if there is no such pixmap. null if there is no such pixmap.
@ -494,13 +497,14 @@ QPixmap *QPixmapCache::find(const QString &key)
/*! /*!
\obsolete \obsolete
Use bool find(const QString&, QPixmap*) instead. Use bool find(const QString &, QPixmap *) instead.
*/ */
bool QPixmapCache::find(const QString &key, QPixmap& pixmap) bool QPixmapCache::find(const QString &key, QPixmap &pixmap)
{ {
return find(key, &pixmap); return find(key, &pixmap);
} }
#endif
/*! /*!
Looks for a cached pixmap associated with the given \a key in the cache. Looks for a cached pixmap associated with the given \a key in the cache.
@ -513,7 +517,7 @@ bool QPixmapCache::find(const QString &key, QPixmap& pixmap)
\snippet code/src_gui_image_qpixmapcache.cpp 1 \snippet code/src_gui_image_qpixmapcache.cpp 1
*/ */
bool QPixmapCache::find(const QString &key, QPixmap* pixmap) bool QPixmapCache::find(const QString &key, QPixmap *pixmap)
{ {
QPixmap *ptr = pm_cache()->object(key); QPixmap *ptr = pm_cache()->object(key);
if (ptr && pixmap) if (ptr && pixmap)
@ -530,7 +534,7 @@ bool QPixmapCache::find(const QString &key, QPixmap* pixmap)
\since 4.6 \since 4.6
*/ */
bool QPixmapCache::find(const Key &key, QPixmap* pixmap) bool QPixmapCache::find(const Key &key, QPixmap *pixmap)
{ {
//The key is not valid anymore, a flush happened before probably //The key is not valid anymore, a flush happened before probably
if (!key.d || !key.d->isValid) if (!key.d || !key.d->isValid)

View File

@ -76,8 +76,12 @@ public:
static int cacheLimit(); static int cacheLimit();
static void setCacheLimit(int); static void setCacheLimit(int);
#if QT_DEPRECATED_SINCE(5, 13)
QT_DEPRECATED_X("Use bool find(const QString &, QPixmap *) instead")
static QPixmap *find(const QString &key); static QPixmap *find(const QString &key);
QT_DEPRECATED_X("Use bool find(const QString &, QPixmap *) instead")
static bool find(const QString &key, QPixmap &pixmap); static bool find(const QString &key, QPixmap &pixmap);
#endif
static bool find(const QString &key, QPixmap *pixmap); static bool find(const QString &key, QPixmap *pixmap);
static bool find(const Key &key, QPixmap *pixmap); static bool find(const Key &key, QPixmap *pixmap);
static bool insert(const QString &key, const QPixmap &pixmap); static bool insert(const QString &key, const QPixmap &pixmap);

View File

@ -111,7 +111,7 @@ Q_GUI_EXPORT QPixmap qt_pixmapForBrush(int brushStyle, bool invert)
QString key = QLatin1String("$qt-brush$") QString key = QLatin1String("$qt-brush$")
% HexString<uint>(brushStyle) % HexString<uint>(brushStyle)
% QLatin1Char(invert ? '1' : '0'); % QLatin1Char(invert ? '1' : '0');
if (!QPixmapCache::find(key, pm)) { if (!QPixmapCache::find(key, &pm)) {
pm = QBitmap::fromData(QSize(8, 8), qt_patternForBrush(brushStyle, invert), pm = QBitmap::fromData(QSize(8, 8), qt_patternForBrush(brushStyle, invert),
QImage::Format_MonoLSB); QImage::Format_MonoLSB);
QPixmapCache::insert(key, pm); QPixmapCache::insert(key, pm);

View File

@ -6210,7 +6210,7 @@ static QPixmap generateWavyPixmap(qreal maxRadius, const QPen &pen)
% HexString<qreal>(pen.widthF()); % HexString<qreal>(pen.widthF());
QPixmap pixmap; QPixmap pixmap;
if (QPixmapCache::find(key, pixmap)) if (QPixmapCache::find(key, &pixmap))
return pixmap; return pixmap;
const qreal halfPeriod = qMax(qreal(2), qreal(radiusBase * 1.61803399)); // the golden ratio const qreal halfPeriod = qMax(qreal(2), qreal(radiusBase * 1.61803399)); // the golden ratio

View File

@ -76,7 +76,7 @@ QPixmap QAbstractFileIconEngine::pixmap(const QSize &size, QIcon::Mode mode,
key += QLatin1Char('_') + QString::number(size.width()); key += QLatin1Char('_') + QString::number(size.width());
QPixmap result; QPixmap result;
if (!QPixmapCache::find(key, result)) { if (!QPixmapCache::find(key, &result)) {
result = filePixmap(size, mode, state); result = filePixmap(size, mode, state);
if (!result.isNull()) if (!result.isNull())
QPixmapCache::insert(key, result); QPixmapCache::insert(key, result);

View File

@ -458,7 +458,7 @@ static QPixmap qt_patternForAlpha(uchar alpha, int screen)
% HexString<uchar>(alpha) % HexString<uchar>(alpha)
% HexString<int>(screen); % HexString<int>(screen);
if (!QPixmapCache::find(key, pm)) { if (!QPixmapCache::find(key, &pm)) {
// #### why not use a mono image here???? // #### why not use a mono image here????
QImage pattern(DITHER_SIZE, DITHER_SIZE, QImage::Format_ARGB32); QImage pattern(DITHER_SIZE, DITHER_SIZE, QImage::Format_ARGB32);
pattern.fill(0xffffffff); pattern.fill(0xffffffff);

View File

@ -724,8 +724,8 @@ void QItemDelegate::drawDecoration(QPainter *painter, const QStyleOptionViewItem
QPoint p = QStyle::alignedRect(option.direction, option.decorationAlignment, QPoint p = QStyle::alignedRect(option.direction, option.decorationAlignment,
pixmap.size(), rect).topLeft(); pixmap.size(), rect).topLeft();
if (option.state & QStyle::State_Selected) { if (option.state & QStyle::State_Selected) {
QPixmap *pm = selected(pixmap, option.palette, option.state & QStyle::State_Enabled); const QPixmap pm = selectedPixmap(pixmap, option.palette, option.state & QStyle::State_Enabled);
painter->drawPixmap(p, *pm); painter->drawPixmap(p, pm);
} else { } else {
painter->drawPixmap(p, pixmap); painter->drawPixmap(p, pixmap);
} }
@ -1001,17 +1001,29 @@ static QString qPixmapSerial(quint64 i, bool enabled)
return QString((const QChar *)ptr, int(&arr[sizeof(arr) / sizeof(ushort)] - ptr)); return QString((const QChar *)ptr, int(&arr[sizeof(arr) / sizeof(ushort)] - ptr));
} }
#if QT_DEPRECATED_SINCE(5, 13)
QPixmap *QItemDelegate::selected(const QPixmap &pixmap, const QPalette &palette, bool enabled) const
{
const QString key = qPixmapSerial(pixmap.cacheKey(), enabled);
QPixmap *pm = QPixmapCache::find(key);
if (pm)
return pm;
selectedPixmap(pixmap, palette, enabled);
return QPixmapCache::find(key);
}
#endif
/*! /*!
\internal \internal
Returns the selected version of the given \a pixmap using the given \a palette. Returns the selected version of the given \a pixmap using the given \a palette.
The \a enabled argument decides whether the normal or disabled highlight color of The \a enabled argument decides whether the normal or disabled highlight color of
the palette is used. the palette is used.
*/ */
QPixmap *QItemDelegate::selected(const QPixmap &pixmap, const QPalette &palette, bool enabled) const QPixmap QItemDelegate::selectedPixmap(const QPixmap &pixmap, const QPalette &palette, bool enabled)
{ {
QString key = qPixmapSerial(pixmap.cacheKey(), enabled); const QString key = qPixmapSerial(pixmap.cacheKey(), enabled);
QPixmap *pm = QPixmapCache::find(key); QPixmap pm;
if (!pm) { if (!QPixmapCache::find(key, &pm)) {
QImage img = pixmap.toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied); QImage img = pixmap.toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied);
QColor color = palette.color(enabled ? QPalette::Normal : QPalette::Disabled, QColor color = palette.color(enabled ? QPalette::Normal : QPalette::Disabled,
@ -1023,13 +1035,12 @@ QPixmap *QItemDelegate::selected(const QPixmap &pixmap, const QPalette &palette,
painter.fillRect(0, 0, img.width(), img.height(), color); painter.fillRect(0, 0, img.width(), img.height(), color);
painter.end(); painter.end();
QPixmap selected = QPixmap(QPixmap::fromImage(img)); pm = QPixmap(QPixmap::fromImage(img));
int n = (img.sizeInBytes() >> 10) + 1; const int n = (img.sizeInBytes() >> 10) + 1;
if (QPixmapCache::cacheLimit() < n) if (QPixmapCache::cacheLimit() < n)
QPixmapCache::setCacheLimit(n); QPixmapCache::setCacheLimit(n);
QPixmapCache::insert(key, selected); QPixmapCache::insert(key, pm);
pm = QPixmapCache::find(key);
} }
return pm; return pm;
} }

View File

@ -113,7 +113,12 @@ protected:
const QStyleOptionViewItem &option) const; const QStyleOptionViewItem &option) const;
QPixmap decoration(const QStyleOptionViewItem &option, const QVariant &variant) const; QPixmap decoration(const QStyleOptionViewItem &option, const QVariant &variant) const;
#if QT_DEPRECATED_SINCE(5, 13)
QT_DEPRECATED_X("Use selectedPixmap() instead")
QPixmap *selected(const QPixmap &pixmap, const QPalette &palette, bool enabled) const; QPixmap *selected(const QPixmap &pixmap, const QPalette &palette, bool enabled) const;
#endif
static QPixmap selectedPixmap(const QPixmap &pixmap, const QPalette &palette, bool enabled);
QRect doCheck(const QStyleOptionViewItem &option, const QRect &bounding, QRect doCheck(const QStyleOptionViewItem &option, const QRect &bounding,
const QVariant &variant) const; const QVariant &variant) const;

View File

@ -751,7 +751,7 @@ void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, Q
QString pixmapName = QStyleHelper::uniqueName(QLatin1String("$qt_ia-") QString pixmapName = QStyleHelper::uniqueName(QLatin1String("$qt_ia-")
% QLatin1String(metaObject()->className()), opt, QSize(size, size)) % QLatin1String(metaObject()->className()), opt, QSize(size, size))
% HexString<uint>(pe); % HexString<uint>(pe);
if (!QPixmapCache::find(pixmapName, pixmap)) { if (!QPixmapCache::find(pixmapName, &pixmap)) {
qreal pixelRatio = p->device()->devicePixelRatioF(); qreal pixelRatio = p->device()->devicePixelRatioF();
int border = qRound(pixelRatio*(size/5)); int border = qRound(pixelRatio*(size/5));
int sqsize = qRound(pixelRatio*(2*(size/2))); int sqsize = qRound(pixelRatio*(2*(size/2)));

View File

@ -261,7 +261,7 @@ static void qt_fusion_draw_arrow(Qt::ArrowType type, QPainter *painter, const QS
QString cacheKey = QStyleHelper::uniqueName(QLatin1String("fusion-arrow"), option, rect.size()) QString cacheKey = QStyleHelper::uniqueName(QLatin1String("fusion-arrow"), option, rect.size())
% HexString<uint>(type) % HexString<uint>(type)
% HexString<uint>(color.rgba()); % HexString<uint>(color.rgba());
if (!QPixmapCache::find(cacheKey, cachePixmap)) { if (!QPixmapCache::find(cacheKey, &cachePixmap)) {
cachePixmap = styleCachePixmap(rect.size()); cachePixmap = styleCachePixmap(rect.size());
cachePixmap.fill(Qt::transparent); cachePixmap.fill(Qt::transparent);
QPainter cachePainter(&cachePixmap); QPainter cachePainter(&cachePixmap);
@ -1272,7 +1272,7 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio
pixmapName += QString::number(- int(header->orientation)); pixmapName += QString::number(- int(header->orientation));
QPixmap cache; QPixmap cache;
if (!QPixmapCache::find(pixmapName, cache)) { if (!QPixmapCache::find(pixmapName, &cache)) {
cache = styleCachePixmap(rect.size()); cache = styleCachePixmap(rect.size());
cache.fill(Qt::transparent); cache.fill(Qt::transparent);
QRect pixmapRect(0, 0, rect.width(), rect.height()); QRect pixmapRect(0, 0, rect.width(), rect.height());
@ -2030,7 +2030,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption
if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) { if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
QPixmap cache; QPixmap cache;
QString pixmapName = QStyleHelper::uniqueName(QLatin1String("spinbox"), spinBox, spinBox->rect.size()); QString pixmapName = QStyleHelper::uniqueName(QLatin1String("spinbox"), spinBox, spinBox->rect.size());
if (!QPixmapCache::find(pixmapName, cache)) { if (!QPixmapCache::find(pixmapName, &cache)) {
cache = styleCachePixmap(spinBox->rect.size()); cache = styleCachePixmap(spinBox->rect.size());
cache.fill(Qt::transparent); cache.fill(Qt::transparent);
@ -2745,7 +2745,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption
if (!comboBox->frame) if (!comboBox->frame)
pixmapName += QLatin1String("-frameless"); pixmapName += QLatin1String("-frameless");
if (!QPixmapCache::find(pixmapName, cache)) { if (!QPixmapCache::find(pixmapName, &cache)) {
cache = styleCachePixmap(comboBox->rect.size()); cache = styleCachePixmap(comboBox->rect.size());
cache.fill(Qt::transparent); cache.fill(Qt::transparent);
QPainter cachePainter(&cache); QPainter cachePainter(&cache);
@ -2852,7 +2852,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption
QRect pixmapRect(0, 0, groove.width(), groove.height()); QRect pixmapRect(0, 0, groove.width(), groove.height());
// draw background groove // draw background groove
if (!QPixmapCache::find(groovePixmapName, cache)) { if (!QPixmapCache::find(groovePixmapName, &cache)) {
cache = styleCachePixmap(pixmapRect.size()); cache = styleCachePixmap(pixmapRect.size());
cache.fill(Qt::transparent); cache.fill(Qt::transparent);
QPainter groovePainter(&cache); QPainter groovePainter(&cache);
@ -2880,7 +2880,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption
// draw blue groove highlight // draw blue groove highlight
QRect clipRect; QRect clipRect;
groovePixmapName += QLatin1String("_blue"); groovePixmapName += QLatin1String("_blue");
if (!QPixmapCache::find(groovePixmapName, cache)) { if (!QPixmapCache::find(groovePixmapName, &cache)) {
cache = styleCachePixmap(pixmapRect.size()); cache = styleCachePixmap(pixmapRect.size());
cache.fill(Qt::transparent); cache.fill(Qt::transparent);
QPainter groovePainter(&cache); QPainter groovePainter(&cache);
@ -2987,7 +2987,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption
// draw handle // draw handle
if ((option->subControls & SC_SliderHandle) ) { if ((option->subControls & SC_SliderHandle) ) {
QString handlePixmapName = QStyleHelper::uniqueName(QLatin1String("slider_handle"), option, handle.size()); QString handlePixmapName = QStyleHelper::uniqueName(QLatin1String("slider_handle"), option, handle.size());
if (!QPixmapCache::find(handlePixmapName, cache)) { if (!QPixmapCache::find(handlePixmapName, &cache)) {
cache = styleCachePixmap(handle.size()); cache = styleCachePixmap(handle.size());
cache.fill(Qt::transparent); cache.fill(Qt::transparent);
QRect pixmapRect(0, 0, handle.width(), handle.height()); QRect pixmapRect(0, 0, handle.width(), handle.height());

View File

@ -96,7 +96,7 @@ inline QPixmap styleCachePixmap(const QSize &size)
int txType = painter->deviceTransform().type() | painter->worldTransform().type(); \ int txType = painter->deviceTransform().type() | painter->worldTransform().type(); \
bool doPixmapCache = (!option->rect.isEmpty()) \ bool doPixmapCache = (!option->rect.isEmpty()) \
&& ((txType <= QTransform::TxTranslate) || (painter->deviceTransform().type() == QTransform::TxScale)); \ && ((txType <= QTransform::TxTranslate) || (painter->deviceTransform().type() == QTransform::TxScale)); \
if (doPixmapCache && QPixmapCache::find(unique, internalPixmapCache)) { \ if (doPixmapCache && QPixmapCache::find(unique, &internalPixmapCache)) { \
painter->drawPixmap(option->rect.topLeft(), internalPixmapCache); \ painter->drawPixmap(option->rect.topLeft(), internalPixmapCache); \
} else { \ } else { \
if (doPixmapCache) { \ if (doPixmapCache) { \