11using namespace std::chrono_literals;
66 const qint64 costMax = std::numeric_limits<qsizetype>::max();
114 if (
d && --(
d->ref) == 0)
159 return d &&
d->isValid;
170 if (
d && --(
d->ref) == 0)
190 void resizeKeyArray(
int size);
203 bool flushDetachedPixmaps(
bool nt);
206 static constexpr auto soon_time = 10
s;
207 static constexpr auto flush_time = 30
s;
218#include "qpixmapcache.moc"
227size_t QPixmapCache::Key::hash(
size_t seed)
const noexcept
235 keyArray(
nullptr), theid(0), ps(0), keyArraySize(0), freeKey(0),
t(
false)
264 setMaxCost(nt ? currentTotal * 3 / 4 : currentTotal - 1);
267 return size() != oldSize;
276 }
else if (nt !=
t) {
278 theid =
startTimer(nt ? soon_time : flush_time);
287 return object(
it.value());
309 k.d->stringKey =
key;
310 cacheKeys[
key] = std::move(k);
332 const auto cacheKey = cacheKeys.
take(
key);
343 if (
size <= keyArraySize ||
size == 0)
345 keyArray = q_check_ptr(
static_cast<int *
>(realloc(keyArray,
346 size *
sizeof(
int))));
347 for (
int i = keyArraySize;
i !=
size; ++
i)
354 if (freeKey == keyArraySize)
357 freeKey = keyArray[
id];
371 if (keyData->
key > keyArraySize || keyData->
key <= 0)
374 keyArray[keyData->
key] = freeKey;
375 freeKey = keyData->
key;
390 key.d->isValid =
false;
411 return pm_cache()->size();
416 pm_cache()->releaseKey(
key);
437 return ptr !=
nullptr;
454 if (!
key.d || !
key.d->isValid)
459 return ptr !=
nullptr;
511#if QT_DEPRECATED_SINCE(6, 6)
543 return pm_cache()->maxCost();
558 pm_cache()->setMaxCost(
n);
568 pm_cache()->remove(
key);
582 if (!
key.d || !
key.d->isValid)
584 pm_cache()->remove(
key);
596 if (pm_cache.exists())
598 }
QT_CATCH(
const std::bad_alloc &) {
608 pm_cache()->flushDetachedPixmaps(
true);
615 return (pm_cache()->totalCost()+1023) / 1024;
bool remove(const Key &key) noexcept(std::is_nothrow_destructible_v< Node >)
void setMaxCost(qsizetype m) noexcept(std::is_nothrow_destructible_v< Node >)
T * object(const Key &key) const noexcept
qsizetype maxCost() const noexcept
qsizetype totalCost() const noexcept
qsizetype size() const noexcept
void clear() noexcept(std::is_nothrow_destructible_v< Node >)
bool insert(const Key &key, T *object, qsizetype cost=1)
QList< QPixmapCache::Key > keys() const
static QCoreApplication * instance() noexcept
Returns a pointer to the application's QCoreApplication (or QGuiApplication/QApplication) instance.
static bool closingDown()
Returns true if the application objects are being destroyed; otherwise returns false.
bool remove(const Key &key)
Removes the item that has the key from the hash.
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
T take(const Key &key)
Removes the item with the key from the hash and returns the value associated with it.
const_iterator cend() const noexcept
int startTimer(int interval, Qt::TimerType timerType=Qt::CoarseTimer)
This is an overloaded function that will start a timer of type timerType and a timeout of interval mi...
void killTimer(int id)
Kills the timer with timer identifier, id.
bool remove(const QString &key)
bool insert(const QString &key, const QPixmap &pixmap, int cost)
void releaseKey(const QPixmapCache::Key &key)
static QPixmapCache::KeyData * getKeyData(QPixmapCache::Key *key)
bool flushDetachedPixmaps(bool nt)
QPixmap * object(const QString &key) const
static QPixmapCache::KeyData * get(const QPixmapCache::Key &key)
void resizeKeyArray(int size)
QPixmapCache::Key createKey()
void timerEvent(QTimerEvent *) override
This event handler can be reimplemented in a subclass to receive timer events for the object.
The QPixmapCache::Key class can be used for efficient access to the QPixmapCache.
Key & operator=(Key &&other) noexcept
Key()
Constructs an empty Key object.
bool isValid() const noexcept
Returns true if there is a cached pixmap associated with this key.
bool operator==(const Key &key) const
static bool find(const QString &key, QPixmap *pixmap)
Looks for a cached pixmap associated with the given key in the cache.
static void remove(const QString &key)
Removes the pixmap associated with key from the cache.
static int cacheLimit()
Returns the cache limit (in kilobytes).
static bool insert(const QString &key, const QPixmap &pixmap)
Inserts a copy of the pixmap pixmap associated with the key into the cache.
static void setCacheLimit(int)
Sets the cache limit to n kilobytes.
static void clear()
Removes all pixmaps from the cache.
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool isNull() const
Returns true if this string is null; otherwise returns false.
static QThread * currentThread()
cache insert(employee->id(), employee)
QSet< QString >::iterator it
Combined button and popup list for selecting options.
size_t qHash(const QFileSystemWatcherPathKey &key, size_t seed=0)
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
static ControlElement< T > * ptr(QWidget *widget)
constexpr const T & qBound(const T &min, const T &val, const T &max)
GLenum GLuint GLintptr GLsizeiptr size
[1]
static bool qt_pixmapcache_thread_test()
static qsizetype cost(const QPixmap &pixmap)
int Q_AUTOTEST_EXPORT q_QPixmapCache_keyHashSize()
static const int cache_limit_default
Q_AUTOTEST_EXPORT int qt_qpixmapcache_qpixmapcache_total_used()
Q_AUTOTEST_EXPORT void qt_qpixmapcache_flush_detached_pixmaps()
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
#define QT_BEGIN_INCLUDE_NAMESPACE
#define Q_AUTOTEST_EXPORT
#define QT_END_INCLUDE_NAMESPACE
settings remove("monkey")