| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QPIXMAPCACHE_H |
| 5 | #define QPIXMAPCACHE_H |
| 6 | |
| 7 | #include <QtGui/qtguiglobal.h> |
| 8 | #include <QtGui/qpixmap.h> |
| 9 | |
| 10 | QT_BEGIN_NAMESPACE |
| 11 | |
| 12 | |
| 13 | class Q_GUI_EXPORT QPixmapCache |
| 14 | { |
| 15 | public: |
| 16 | class KeyData; |
| 17 | class Q_GUI_EXPORT Key |
| 18 | { |
| 19 | public: |
| 20 | Key(); |
| 21 | Key(const Key &other); |
| 22 | Key(Key &&other) noexcept : d(other.d) { other.d = nullptr; } |
| 23 | Key &operator =(Key &&other) noexcept { swap(other); return *this; } |
| 24 | ~Key(); |
| 25 | bool operator ==(const Key &key) const; |
| 26 | inline bool operator !=(const Key &key) const |
| 27 | { return !operator==(key); } |
| 28 | Key &operator =(const Key &other); |
| 29 | |
| 30 | void swap(Key &other) noexcept { qt_ptr_swap(lhs&: d, rhs&: other.d); } |
| 31 | bool isValid() const noexcept; |
| 32 | |
| 33 | private: |
| 34 | friend size_t qHash(const QPixmapCache::Key &k, size_t seed = 0) noexcept |
| 35 | { return k.hash(seed); } |
| 36 | size_t hash(size_t seed) const noexcept; |
| 37 | |
| 38 | KeyData *d; |
| 39 | friend class QPMCache; |
| 40 | friend class QPixmapCache; |
| 41 | }; |
| 42 | |
| 43 | static int cacheLimit(); |
| 44 | static void setCacheLimit(int); |
| 45 | static bool find(const QString &key, QPixmap *pixmap); |
| 46 | static bool find(const Key &key, QPixmap *pixmap); |
| 47 | static bool insert(const QString &key, const QPixmap &pixmap); |
| 48 | static Key insert(const QPixmap &pixmap); |
| 49 | #if QT_DEPRECATED_SINCE(6, 6) |
| 50 | QT_DEPRECATED_VERSION_X_6_6("Use remove(key), followed by key = insert(pixmap)." ) |
| 51 | QT_GUI_INLINE_SINCE(6, 6) |
| 52 | static bool replace(const Key &key, const QPixmap &pixmap); |
| 53 | #endif |
| 54 | static void remove(const QString &key); |
| 55 | static void remove(const Key &key); |
| 56 | static void clear(); |
| 57 | }; |
| 58 | Q_DECLARE_SHARED(QPixmapCache::Key) |
| 59 | |
| 60 | #if QT_DEPRECATED_SINCE(6, 6) |
| 61 | #if QT_GUI_INLINE_IMPL_SINCE(6, 6) |
| 62 | bool QPixmapCache::replace(const Key &key, const QPixmap &pixmap) |
| 63 | { |
| 64 | if (!key.isValid()) |
| 65 | return false; |
| 66 | remove(key); |
| 67 | const_cast<Key&>(key) = insert(pixmap); |
| 68 | return key.isValid(); |
| 69 | } |
| 70 | #endif // QT_GUI_INLINE_IMPL_SINCE(6, 6) |
| 71 | #endif // QT_DEPRECATED_SINCE(6, 6) |
| 72 | |
| 73 | QT_END_NAMESPACE |
| 74 | |
| 75 | #endif // QPIXMAPCACHE_H |
| 76 | |