From daee9af969a04a2919a948ba1f5d314626925a9a Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Fri, 25 Jan 2019 21:15:43 +0100 Subject: 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 --- src/widgets/itemviews/qitemdelegate.cpp | 31 +++++++++++++++++++++---------- src/widgets/itemviews/qitemdelegate.h | 5 +++++ src/widgets/styles/qcommonstyle.cpp | 2 +- src/widgets/styles/qfusionstyle.cpp | 14 +++++++------- src/widgets/styles/qstyle_p.h | 2 +- 5 files changed, 35 insertions(+), 19 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/itemviews/qitemdelegate.cpp b/src/widgets/itemviews/qitemdelegate.cpp index 16d4a21f50..f85004c49c 100644 --- a/src/widgets/itemviews/qitemdelegate.cpp +++ b/src/widgets/itemviews/qitemdelegate.cpp @@ -724,8 +724,8 @@ void QItemDelegate::drawDecoration(QPainter *painter, const QStyleOptionViewItem QPoint p = QStyle::alignedRect(option.direction, option.decorationAlignment, pixmap.size(), rect).topLeft(); if (option.state & QStyle::State_Selected) { - QPixmap *pm = selected(pixmap, option.palette, option.state & QStyle::State_Enabled); - painter->drawPixmap(p, *pm); + const QPixmap pm = selectedPixmap(pixmap, option.palette, option.state & QStyle::State_Enabled); + painter->drawPixmap(p, pm); } else { 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)); } +#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 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 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); - QPixmap *pm = QPixmapCache::find(key); - if (!pm) { + const QString key = qPixmapSerial(pixmap.cacheKey(), enabled); + QPixmap pm; + if (!QPixmapCache::find(key, &pm)) { QImage img = pixmap.toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied); 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.end(); - QPixmap selected = QPixmap(QPixmap::fromImage(img)); - int n = (img.sizeInBytes() >> 10) + 1; + pm = QPixmap(QPixmap::fromImage(img)); + const int n = (img.sizeInBytes() >> 10) + 1; if (QPixmapCache::cacheLimit() < n) QPixmapCache::setCacheLimit(n); - QPixmapCache::insert(key, selected); - pm = QPixmapCache::find(key); + QPixmapCache::insert(key, pm); } return pm; } diff --git a/src/widgets/itemviews/qitemdelegate.h b/src/widgets/itemviews/qitemdelegate.h index 539dec4374..e504615fb2 100644 --- a/src/widgets/itemviews/qitemdelegate.h +++ b/src/widgets/itemviews/qitemdelegate.h @@ -113,7 +113,12 @@ protected: const QStyleOptionViewItem &option) 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; +#endif + static QPixmap selectedPixmap(const QPixmap &pixmap, const QPalette &palette, bool enabled); QRect doCheck(const QStyleOptionViewItem &option, const QRect &bounding, const QVariant &variant) const; diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index 2bfc1acc26..1980dc47a9 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -751,7 +751,7 @@ void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, Q QString pixmapName = QStyleHelper::uniqueName(QLatin1String("$qt_ia-") % QLatin1String(metaObject()->className()), opt, QSize(size, size)) % HexString(pe); - if (!QPixmapCache::find(pixmapName, pixmap)) { + if (!QPixmapCache::find(pixmapName, &pixmap)) { qreal pixelRatio = p->device()->devicePixelRatioF(); int border = qRound(pixelRatio*(size/5)); int sqsize = qRound(pixelRatio*(2*(size/2))); diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp index 7c58adeb85..0e95d6efa4 100644 --- a/src/widgets/styles/qfusionstyle.cpp +++ b/src/widgets/styles/qfusionstyle.cpp @@ -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()) % HexString(type) % HexString(color.rgba()); - if (!QPixmapCache::find(cacheKey, cachePixmap)) { + if (!QPixmapCache::find(cacheKey, &cachePixmap)) { cachePixmap = styleCachePixmap(rect.size()); cachePixmap.fill(Qt::transparent); QPainter cachePainter(&cachePixmap); @@ -1272,7 +1272,7 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio pixmapName += QString::number(- int(header->orientation)); QPixmap cache; - if (!QPixmapCache::find(pixmapName, cache)) { + if (!QPixmapCache::find(pixmapName, &cache)) { cache = styleCachePixmap(rect.size()); cache.fill(Qt::transparent); 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(option)) { QPixmap cache; 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.fill(Qt::transparent); @@ -2745,7 +2745,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption if (!comboBox->frame) pixmapName += QLatin1String("-frameless"); - if (!QPixmapCache::find(pixmapName, cache)) { + if (!QPixmapCache::find(pixmapName, &cache)) { cache = styleCachePixmap(comboBox->rect.size()); cache.fill(Qt::transparent); QPainter cachePainter(&cache); @@ -2852,7 +2852,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption QRect pixmapRect(0, 0, groove.width(), groove.height()); // draw background groove - if (!QPixmapCache::find(groovePixmapName, cache)) { + if (!QPixmapCache::find(groovePixmapName, &cache)) { cache = styleCachePixmap(pixmapRect.size()); cache.fill(Qt::transparent); QPainter groovePainter(&cache); @@ -2880,7 +2880,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption // draw blue groove highlight QRect clipRect; groovePixmapName += QLatin1String("_blue"); - if (!QPixmapCache::find(groovePixmapName, cache)) { + if (!QPixmapCache::find(groovePixmapName, &cache)) { cache = styleCachePixmap(pixmapRect.size()); cache.fill(Qt::transparent); QPainter groovePainter(&cache); @@ -2987,7 +2987,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption // draw handle if ((option->subControls & SC_SliderHandle) ) { 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.fill(Qt::transparent); QRect pixmapRect(0, 0, handle.width(), handle.height()); diff --git a/src/widgets/styles/qstyle_p.h b/src/widgets/styles/qstyle_p.h index 94e4540d0b..cdea29f944 100644 --- a/src/widgets/styles/qstyle_p.h +++ b/src/widgets/styles/qstyle_p.h @@ -96,7 +96,7 @@ inline QPixmap styleCachePixmap(const QSize &size) int txType = painter->deviceTransform().type() | painter->worldTransform().type(); \ bool doPixmapCache = (!option->rect.isEmpty()) \ && ((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); \ } else { \ if (doPixmapCache) { \ -- cgit v1.2.3