OpenCoverage

qpixmapcache.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/image/qpixmapcache.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtGui module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#define Q_TEST_QPIXMAPCACHE-
41#include "qpixmapcache.h"-
42#include "qobject.h"-
43#include "qdebug.h"-
44#include "qpixmapcache_p.h"-
45-
46QT_BEGIN_NAMESPACE-
47-
48/*!-
49 \class QPixmapCache-
50 \inmodule QtGui-
51-
52 \brief The QPixmapCache class provides an application-wide cache for pixmaps.-
53-
54 This class is a tool for optimized drawing with QPixmap. You can-
55 use it to store temporary pixmaps that are expensive to generate-
56 without using more storage space than cacheLimit(). Use insert()-
57 to insert pixmaps, find() to find them, and clear() to empty the-
58 cache.-
59-
60 QPixmapCache contains no member data, only static functions to-
61 access the global pixmap cache. It creates an internal QCache-
62 object for caching the pixmaps.-
63-
64 The cache associates a pixmap with a user-provided string as a key,-
65 or with a QPixmapCache::Key that the cache generates.-
66 Using QPixmapCache::Key for keys is faster than using strings. The string API is-
67 very convenient for complex keys but the QPixmapCache::Key API will be very-
68 efficient and convenient for a one-to-one object-to-pixmap mapping - in-
69 this case, you can store the keys as members of an object.-
70-
71 If two pixmaps are inserted into the cache using equal keys then the-
72 last pixmap will replace the first pixmap in the cache. This follows the-
73 behavior of the QHash and QCache classes.-
74-
75 The cache becomes full when the total size of all pixmaps in the-
76 cache exceeds cacheLimit(). The initial cache limit is 10240 KB (10 MB);-
77 you can change this by calling setCacheLimit() with the required value.-
78 A pixmap takes roughly (\e{width} * \e{height} * \e{depth})/8 bytes of-
79 memory.-
80-
81 The \e{Qt Quarterly} article-
82 \l{http://doc.qt.io/archives/qq/qq12-qpixmapcache.html}{Optimizing-
83 with QPixmapCache} explains how to use QPixmapCache to speed up-
84 applications by caching the results of painting.-
85-
86 \sa QCache, QPixmap-
87*/-
88-
89static int cache_limit = 10240; // 10 MB cache limit-
90-
91/*!-
92 \class QPixmapCache::Key-
93 \brief The QPixmapCache::Key class can be used for efficient access-
94 to the QPixmapCache.-
95 \inmodule QtGui-
96 \since 4.6-
97-
98 Use QPixmapCache::insert() to receive an instance of Key generated-
99 by the pixmap cache. You can store the key in your own objects for-
100 a very efficient one-to-one object-to-pixmap mapping.-
101*/-
102-
103/*!-
104 Constructs an empty Key object.-
105*/-
106QPixmapCache::Key::Key() : d(0)-
107{-
108}
never executed: end of block
0
109-
110/*!-
111 \internal-
112 Constructs a copy of \a other.-
113*/-
114QPixmapCache::Key::Key(const Key &other)-
115{-
116 if (other.d)
other.dDescription
TRUEnever evaluated
FALSEnever evaluated
0
117 ++(other.d->ref);
never executed: ++(other.d->ref);
0
118 d = other.d;-
119}
never executed: end of block
0
120-
121/*!-
122 Destroys the key.-
123*/-
124QPixmapCache::Key::~Key()-
125{-
126 if (d && --(d->ref) == 0)
dDescription
TRUEnever evaluated
FALSEnever evaluated
--(d->ref) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
127 delete d;
never executed: delete d;
0
128}
never executed: end of block
0
129-
130/*!-
131 \internal-
132-
133 Returns \c true if this key is the same as the given \a key; otherwise returns-
134 false.-
135*/-
136bool QPixmapCache::Key::operator ==(const Key &key) const-
137{-
138 return (d == key.d);
never executed: return (d == key.d);
0
139}-
140-
141/*!-
142 \fn bool QPixmapCache::Key::operator !=(const Key &key) const-
143 \internal-
144*/-
145-
146/*!-
147 \fn QPixmapCache::Key::Key(Key &&)-
148 \internal-
149 \since 5.6-
150*/-
151-
152/*!-
153 \fn QPixmapCache::Key &QPixmapCache::Key::operator=(Key &&)-
154 \internal-
155 \since 5.6-
156*/-
157-
158/*!-
159 \fn void QPixmapCache::Key::swap(Key &)-
160 \internal-
161 \since 5.6-
162*/-
163-
164/*!-
165 Returns \c true if there is a cached pixmap associated with this key.-
166 Otherwise, if pixmap was flushed, the key is no longer valid.-
167 \since 5.7-
168*/-
169bool QPixmapCache::Key::isValid() const Q_DECL_NOTHROW-
170{-
171 return d && d->isValid;
never executed: return d && d->isValid;
0
172}-
173-
174/*!-
175 \internal-
176*/-
177QPixmapCache::Key &QPixmapCache::Key::operator =(const Key &other)-
178{-
179 if (d != other.d) {
d != other.dDescription
TRUEnever evaluated
FALSEnever evaluated
0
180 if (other.d)
other.dDescription
TRUEnever evaluated
FALSEnever evaluated
0
181 ++(other.d->ref);
never executed: ++(other.d->ref);
0
182 if (d && --(d->ref) == 0)
dDescription
TRUEnever evaluated
FALSEnever evaluated
--(d->ref) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
183 delete d;
never executed: delete d;
0
184 d = other.d;-
185 }
never executed: end of block
0
186 return *this;
never executed: return *this;
0
187}-
188-
189class QPMCache : public QObject, public QCache<QPixmapCache::Key, QPixmapCacheEntry>-
190{-
191 Q_OBJECT-
192public:-
193 QPMCache();-
194 ~QPMCache();-
195-
196 void timerEvent(QTimerEvent *) Q_DECL_OVERRIDE;-
197 bool insert(const QString& key, const QPixmap &pixmap, int cost);-
198 QPixmapCache::Key insert(const QPixmap &pixmap, int cost);-
199 bool replace(const QPixmapCache::Key &key, const QPixmap &pixmap, int cost);-
200 bool remove(const QString &key);-
201 bool remove(const QPixmapCache::Key &key);-
202-
203 void resizeKeyArray(int size);-
204 QPixmapCache::Key createKey();-
205 void releaseKey(const QPixmapCache::Key &key);-
206 void clear();-
207-
208 QPixmap *object(const QString &key) const;-
209 QPixmap *object(const QPixmapCache::Key &key) const;-
210-
211 static inline QPixmapCache::KeyData *get(const QPixmapCache::Key &key)-
212 {return key.d;}
never executed: return key.d;
0
213-
214 static QPixmapCache::KeyData* getKeyData(QPixmapCache::Key *key);-
215-
216 bool flushDetachedPixmaps(bool nt);-
217-
218private:-
219 enum { soon_time = 10000, flush_time = 30000 };-
220 int *keyArray;-
221 int theid;-
222 int ps;-
223 int keyArraySize;-
224 int freeKey;-
225 QHash<QString, QPixmapCache::Key> cacheKeys;-
226 bool t;-
227};-
228-
229QT_BEGIN_INCLUDE_NAMESPACE-
230#include "qpixmapcache.moc"-
231QT_END_INCLUDE_NAMESPACE-
232-
233uint qHash(const QPixmapCache::Key &k)-
234{-
235 return qHash(QPMCache::get(k)->key);
never executed: return qHash(QPMCache::get(k)->key);
0
236}-
237-
238QPMCache::QPMCache()-
239 : QObject(0),-
240 QCache<QPixmapCache::Key, QPixmapCacheEntry>(cache_limit * 1024),-
241 keyArray(0), theid(0), ps(0), keyArraySize(0), freeKey(0), t(false)-
242{-
243}
never executed: end of block
0
244QPMCache::~QPMCache()-
245{-
246 clear();-
247 free(keyArray);-
248}
never executed: end of block
0
249-
250/*-
251 This is supposed to cut the cache size down by about 25% in a-
252 minute once the application becomes idle, to let any inserted pixmap-
253 remain in the cache for some time before it becomes a candidate for-
254 cleaning-up, and to not cut down the size of the cache while the-
255 cache is in active use.-
256-
257 When the last detached pixmap has been deleted from the cache, kill the-
258 timer so Qt won't keep the CPU from going into sleep mode. Currently-
259 the timer is not restarted when the pixmap becomes unused, but it does-
260 restart once something else is added (i.e. the cache space is actually needed).-
261-
262 Returns \c true if any were removed.-
263*/-
264bool QPMCache::flushDetachedPixmaps(bool nt)-
265{-
266 int mc = maxCost();-
267 setMaxCost(nt ? totalCost() * 3 / 4 : totalCost() -1);-
268 setMaxCost(mc);-
269 ps = totalCost();-
270-
271 bool any = false;-
272 QHash<QString, QPixmapCache::Key>::iterator it = cacheKeys.begin();-
273 while (it != cacheKeys.end()) {
it != cacheKeys.end()Description
TRUEnever evaluated
FALSEnever evaluated
0
274 if (!contains(it.value())) {
!contains(it.value())Description
TRUEnever evaluated
FALSEnever evaluated
0
275 releaseKey(it.value());-
276 it = cacheKeys.erase(it);-
277 any = true;-
278 } else {
never executed: end of block
0
279 ++it;-
280 }
never executed: end of block
0
281 }-
282-
283 return any;
never executed: return any;
0
284}-
285-
286void QPMCache::timerEvent(QTimerEvent *)-
287{-
288 bool nt = totalCost() == ps;-
289 if (!flushDetachedPixmaps(nt)) {
!flushDetachedPixmaps(nt)Description
TRUEnever evaluated
FALSEnever evaluated
0
290 killTimer(theid);-
291 theid = 0;-
292 } else if (nt != t) {
never executed: end of block
nt != tDescription
TRUEnever evaluated
FALSEnever evaluated
0
293 killTimer(theid);-
294 theid = startTimer(nt ? soon_time : flush_time);-
295 t = nt;-
296 }
never executed: end of block
0
297}
never executed: end of block
0
298-
299-
300QPixmap *QPMCache::object(const QString &key) const-
301{-
302 QPixmapCache::Key cacheKey = cacheKeys.value(key);-
303 if (!cacheKey.d || !cacheKey.d->isValid) {
!cacheKey.dDescription
TRUEnever evaluated
FALSEnever evaluated
!cacheKey.d->isValidDescription
TRUEnever evaluated
FALSEnever evaluated
0
304 const_cast<QPMCache *>(this)->cacheKeys.remove(key);-
305 return 0;
never executed: return 0;
0
306 }-
307 QPixmap *ptr = QCache<QPixmapCache::Key, QPixmapCacheEntry>::object(cacheKey);-
308 //We didn't find the pixmap in the cache, the key is not valid anymore-
309 if (!ptr) {
!ptrDescription
TRUEnever evaluated
FALSEnever evaluated
0
310 const_cast<QPMCache *>(this)->cacheKeys.remove(key);-
311 }
never executed: end of block
0
312 return ptr;
never executed: return ptr;
0
313}-
314-
315QPixmap *QPMCache::object(const QPixmapCache::Key &key) const-
316{-
317 Q_ASSERT(key.d->isValid);-
318 QPixmap *ptr = QCache<QPixmapCache::Key, QPixmapCacheEntry>::object(key);-
319 //We didn't find the pixmap in the cache, the key is not valid anymore-
320 if (!ptr)
!ptrDescription
TRUEnever evaluated
FALSEnever evaluated
0
321 const_cast<QPMCache *>(this)->releaseKey(key);
never executed: const_cast<QPMCache *>(this)->releaseKey(key);
0
322 return ptr;
never executed: return ptr;
0
323}-
324-
325bool QPMCache::insert(const QString& key, const QPixmap &pixmap, int cost)-
326{-
327 QPixmapCache::Key cacheKey;-
328 QPixmapCache::Key oldCacheKey = cacheKeys.value(key);-
329 //If for the same key we add already a pixmap we should delete it-
330 if (oldCacheKey.d) {
oldCacheKey.dDescription
TRUEnever evaluated
FALSEnever evaluated
0
331 QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(oldCacheKey);-
332 cacheKeys.remove(key);-
333 }
never executed: end of block
0
334-
335 //we create a new key the old one has been removed-
336 cacheKey = createKey();-
337-
338 bool success = QCache<QPixmapCache::Key, QPixmapCacheEntry>::insert(cacheKey, new QPixmapCacheEntry(cacheKey, pixmap), cost);-
339 if (success) {
successDescription
TRUEnever evaluated
FALSEnever evaluated
0
340 cacheKeys.insert(key, cacheKey);-
341 if (!theid) {
!theidDescription
TRUEnever evaluated
FALSEnever evaluated
0
342 theid = startTimer(flush_time);-
343 t = false;-
344 }
never executed: end of block
0
345 } else {
never executed: end of block
0
346 //Insertion failed we released the new allocated key-
347 releaseKey(cacheKey);-
348 }
never executed: end of block
0
349 return success;
never executed: return success;
0
350}-
351-
352QPixmapCache::Key QPMCache::insert(const QPixmap &pixmap, int cost)-
353{-
354 QPixmapCache::Key cacheKey = createKey();-
355 bool success = QCache<QPixmapCache::Key, QPixmapCacheEntry>::insert(cacheKey, new QPixmapCacheEntry(cacheKey, pixmap), cost);-
356 if (success) {
successDescription
TRUEnever evaluated
FALSEnever evaluated
0
357 if (!theid) {
!theidDescription
TRUEnever evaluated
FALSEnever evaluated
0
358 theid = startTimer(flush_time);-
359 t = false;-
360 }
never executed: end of block
0
361 } else {
never executed: end of block
0
362 //Insertion failed we released the key and return an invalid one-
363 releaseKey(cacheKey);-
364 }
never executed: end of block
0
365 return cacheKey;
never executed: return cacheKey;
0
366}-
367-
368bool QPMCache::replace(const QPixmapCache::Key &key, const QPixmap &pixmap, int cost)-
369{-
370 Q_ASSERT(key.d->isValid);-
371 //If for the same key we had already an entry so we should delete the pixmap and use the new one-
372 QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(key);-
373-
374 QPixmapCache::Key cacheKey = createKey();-
375-
376 bool success = QCache<QPixmapCache::Key, QPixmapCacheEntry>::insert(cacheKey, new QPixmapCacheEntry(cacheKey, pixmap), cost);-
377 if (success) {
successDescription
TRUEnever evaluated
FALSEnever evaluated
0
378 if(!theid) {
!theidDescription
TRUEnever evaluated
FALSEnever evaluated
0
379 theid = startTimer(flush_time);-
380 t = false;-
381 }
never executed: end of block
0
382 const_cast<QPixmapCache::Key&>(key) = cacheKey;-
383 } else {
never executed: end of block
0
384 //Insertion failed we released the key-
385 releaseKey(cacheKey);-
386 }
never executed: end of block
0
387 return success;
never executed: return success;
0
388}-
389-
390bool QPMCache::remove(const QString &key)-
391{-
392 QPixmapCache::Key cacheKey = cacheKeys.value(key);-
393 //The key was not in the cache-
394 if (!cacheKey.d)
!cacheKey.dDescription
TRUEnever evaluated
FALSEnever evaluated
0
395 return false;
never executed: return false;
0
396 cacheKeys.remove(key);-
397 return QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(cacheKey);
never executed: return QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(cacheKey);
0
398}-
399-
400bool QPMCache::remove(const QPixmapCache::Key &key)-
401{-
402 return QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(key);
never executed: return QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(key);
0
403}-
404-
405void QPMCache::resizeKeyArray(int size)-
406{-
407 if (size <= keyArraySize || size == 0)
size <= keyArraySizeDescription
TRUEnever evaluated
FALSEnever evaluated
size == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
408 return;
never executed: return;
0
409 keyArray = q_check_ptr(reinterpret_cast<int *>(realloc(keyArray,-
410 size * sizeof(int))));-
411 for (int i = keyArraySize; i != size; ++i)
i != sizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
412 keyArray[i] = i + 1;
never executed: keyArray[i] = i + 1;
0
413 keyArraySize = size;-
414}
never executed: end of block
0
415-
416QPixmapCache::Key QPMCache::createKey()-
417{-
418 if (freeKey == keyArraySize)
freeKey == keyArraySizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
419 resizeKeyArray(keyArraySize ? keyArraySize << 1 : 2);
never executed: resizeKeyArray(keyArraySize ? keyArraySize << 1 : 2);
0
420 int id = freeKey;-
421 freeKey = keyArray[id];-
422 QPixmapCache::Key key;-
423 QPixmapCache::KeyData *d = QPMCache::getKeyData(&key);-
424 d->key = ++id;-
425 return key;
never executed: return key;
0
426}-
427-
428void QPMCache::releaseKey(const QPixmapCache::Key &key)-
429{-
430 if (key.d->key > keyArraySize || key.d->key <= 0)
key.d->key > keyArraySizeDescription
TRUEnever evaluated
FALSEnever evaluated
key.d->key <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
431 return;
never executed: return;
0
432 key.d->key--;-
433 keyArray[key.d->key] = freeKey;-
434 freeKey = key.d->key;-
435 key.d->isValid = false;-
436 key.d->key = 0;-
437}
never executed: end of block
0
438-
439void QPMCache::clear()-
440{-
441 free(keyArray);-
442 keyArray = 0;-
443 freeKey = 0;-
444 keyArraySize = 0;-
445 //Mark all keys as invalid-
446 QList<QPixmapCache::Key> keys = QCache<QPixmapCache::Key, QPixmapCacheEntry>::keys();-
447 for (int i = 0; i < keys.size(); ++i)
i < keys.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
448 keys.at(i).d->isValid = false;
never executed: keys.at(i).d->isValid = false;
0
449 QCache<QPixmapCache::Key, QPixmapCacheEntry>::clear();-
450}
never executed: end of block
0
451-
452QPixmapCache::KeyData* QPMCache::getKeyData(QPixmapCache::Key *key)-
453{-
454 if (!key->d)
!key->dDescription
TRUEnever evaluated
FALSEnever evaluated
0
455 key->d = new QPixmapCache::KeyData;
never executed: key->d = new QPixmapCache::KeyData;
0
456 return key->d;
never executed: return key->d;
0
457}-
458-
459Q_GLOBAL_STATIC(QPMCache, pm_cache)
never executed: end of block
never executed: guard.store(QtGlobalStatic::Destroyed);
never executed: return &holder.value;
guard.load() =...c::InitializedDescription
TRUEnever evaluated
FALSEnever evaluated
0
460-
461int Q_AUTOTEST_EXPORT q_QPixmapCache_keyHashSize()-
462{-
463 return pm_cache()->size();
never executed: return pm_cache()->size();
0
464}-
465-
466QPixmapCacheEntry::~QPixmapCacheEntry()-
467{-
468 pm_cache()->releaseKey(key);-
469}
never executed: end of block
0
470-
471/*!-
472 \obsolete-
473 \overload-
474-
475 Returns the pixmap associated with the \a key in the cache, or-
476 null if there is no such pixmap.-
477-
478 \warning If valid, you should copy the pixmap immediately (this is-
479 fast). Subsequent insertions into the cache could cause the-
480 pointer to become invalid. For this reason, we recommend you use-
481 bool find(const QString&, QPixmap*) instead.-
482-
483 Example:-
484 \snippet code/src_gui_image_qpixmapcache.cpp 0-
485*/-
486-
487QPixmap *QPixmapCache::find(const QString &key)-
488{-
489 return pm_cache()->object(key);
never executed: return pm_cache()->object(key);
0
490}-
491-
492-
493/*!-
494 \obsolete-
495-
496 Use bool find(const QString&, QPixmap*) instead.-
497*/-
498-
499bool QPixmapCache::find(const QString &key, QPixmap& pixmap)-
500{-
501 return find(key, &pixmap);
never executed: return find(key, &pixmap);
0
502}-
503-
504/*!-
505 Looks for a cached pixmap associated with the given \a key in the cache.-
506 If the pixmap is found, the function sets \a pixmap to that pixmap and-
507 returns \c true; otherwise it leaves \a pixmap alone and returns \c false.-
508-
509 \since 4.6-
510-
511 Example:-
512 \snippet code/src_gui_image_qpixmapcache.cpp 1-
513*/-
514-
515bool QPixmapCache::find(const QString &key, QPixmap* pixmap)-
516{-
517 QPixmap *ptr = pm_cache()->object(key);-
518 if (ptr && pixmap)
ptrDescription
TRUEnever evaluated
FALSEnever evaluated
pixmapDescription
TRUEnever evaluated
FALSEnever evaluated
0
519 *pixmap = *ptr;
never executed: *pixmap = *ptr;
0
520 return ptr != 0;
never executed: return ptr != 0;
0
521}-
522-
523/*!-
524 Looks for a cached pixmap associated with the given \a key in the cache.-
525 If the pixmap is found, the function sets \a pixmap to that pixmap and-
526 returns \c true; otherwise it leaves \a pixmap alone and returns \c false. If-
527 the pixmap is not found, it means that the \a key is no longer valid,-
528 so it will be released for the next insertion.-
529-
530 \since 4.6-
531*/-
532bool QPixmapCache::find(const Key &key, QPixmap* pixmap)-
533{-
534 //The key is not valid anymore, a flush happened before probably-
535 if (!key.d || !key.d->isValid)
!key.dDescription
TRUEnever evaluated
FALSEnever evaluated
!key.d->isValidDescription
TRUEnever evaluated
FALSEnever evaluated
0
536 return false;
never executed: return false;
0
537 QPixmap *ptr = pm_cache()->object(key);-
538 if (ptr && pixmap)
ptrDescription
TRUEnever evaluated
FALSEnever evaluated
pixmapDescription
TRUEnever evaluated
FALSEnever evaluated
0
539 *pixmap = *ptr;
never executed: *pixmap = *ptr;
0
540 return ptr != 0;
never executed: return ptr != 0;
0
541}-
542-
543/*!-
544 Inserts a copy of the pixmap \a pixmap associated with the \a key into-
545 the cache.-
546-
547 All pixmaps inserted by the Qt library have a key starting with-
548 "$qt", so your own pixmap keys should never begin "$qt".-
549-
550 When a pixmap is inserted and the cache is about to exceed its-
551 limit, it removes pixmaps until there is enough room for the-
552 pixmap to be inserted.-
553-
554 The oldest pixmaps (least recently accessed in the cache) are-
555 deleted when more space is needed.-
556-
557 The function returns \c true if the object was inserted into the-
558 cache; otherwise it returns \c false.-
559-
560 \sa setCacheLimit()-
561*/-
562-
563bool QPixmapCache::insert(const QString &key, const QPixmap &pixmap)-
564{-
565 return pm_cache()->insert(key, pixmap, pixmap.width() * pixmap.height() * pixmap.depth() / 8);
never executed: return pm_cache()->insert(key, pixmap, pixmap.width() * pixmap.height() * pixmap.depth() / 8);
0
566}-
567-
568/*!-
569 Inserts a copy of the given \a pixmap into the cache and returns a key-
570 that can be used to retrieve it.-
571-
572 When a pixmap is inserted and the cache is about to exceed its-
573 limit, it removes pixmaps until there is enough room for the-
574 pixmap to be inserted.-
575-
576 The oldest pixmaps (least recently accessed in the cache) are-
577 deleted when more space is needed.-
578-
579 \sa setCacheLimit(), replace()-
580-
581 \since 4.6-
582*/-
583QPixmapCache::Key QPixmapCache::insert(const QPixmap &pixmap)-
584{-
585 return pm_cache()->insert(pixmap, pixmap.width() * pixmap.height() * pixmap.depth() / 8);
never executed: return pm_cache()->insert(pixmap, pixmap.width() * pixmap.height() * pixmap.depth() / 8);
0
586}-
587-
588/*!-
589 Replaces the pixmap associated with the given \a key with the \a pixmap-
590 specified. Returns \c true if the \a pixmap has been correctly inserted into-
591 the cache; otherwise returns \c false.-
592-
593 \sa setCacheLimit(), insert()-
594-
595 \since 4.6-
596*/-
597bool QPixmapCache::replace(const Key &key, const QPixmap &pixmap)-
598{-
599 //The key is not valid anymore, a flush happened before probably-
600 if (!key.d || !key.d->isValid)
!key.dDescription
TRUEnever evaluated
FALSEnever evaluated
!key.d->isValidDescription
TRUEnever evaluated
FALSEnever evaluated
0
601 return false;
never executed: return false;
0
602 return pm_cache()->replace(key, pixmap, pixmap.width() * pixmap.height() * pixmap.depth() / 8);
never executed: return pm_cache()->replace(key, pixmap, pixmap.width() * pixmap.height() * pixmap.depth() / 8);
0
603}-
604-
605/*!-
606 Returns the cache limit (in kilobytes).-
607-
608 The default cache limit is 10240 KB.-
609-
610 \sa setCacheLimit()-
611*/-
612-
613int QPixmapCache::cacheLimit()-
614{-
615 return cache_limit;
never executed: return cache_limit;
0
616}-
617-
618/*!-
619 Sets the cache limit to \a n kilobytes.-
620-
621 The default setting is 10240 KB.-
622-
623 \sa cacheLimit()-
624*/-
625-
626void QPixmapCache::setCacheLimit(int n)-
627{-
628 cache_limit = n;-
629 pm_cache()->setMaxCost(1024 * cache_limit);-
630}
never executed: end of block
0
631-
632/*!-
633 Removes the pixmap associated with \a key from the cache.-
634*/-
635void QPixmapCache::remove(const QString &key)-
636{-
637 pm_cache()->remove(key);-
638}
never executed: end of block
0
639-
640/*!-
641 Removes the pixmap associated with \a key from the cache and releases-
642 the key for a future insertion.-
643-
644 \since 4.6-
645*/-
646void QPixmapCache::remove(const Key &key)-
647{-
648 //The key is not valid anymore, a flush happened before probably-
649 if (!key.d || !key.d->isValid)
!key.dDescription
TRUEnever evaluated
FALSEnever evaluated
!key.d->isValidDescription
TRUEnever evaluated
FALSEnever evaluated
0
650 return;
never executed: return;
0
651 pm_cache()->remove(key);-
652}
never executed: end of block
0
653-
654/*!-
655 Removes all pixmaps from the cache.-
656*/-
657-
658void QPixmapCache::clear()-
659{-
660 QT_TRY {-
661 if (pm_cache.exists())
pm_cache.exists()Description
TRUEnever evaluated
FALSEnever evaluated
0
662 pm_cache->clear();
never executed: pm_cache->clear();
0
663 } QT_CATCH(const std::bad_alloc &) {
never executed: end of block
dead code: { }
-
664 // if we ran out of memory during pm_cache(), it's no leak,
dead code: { }
-
665 // so just ignore it.
dead code: { }
-
666 }
dead code: { }
-
667}-
668-
669void QPixmapCache::flushDetachedPixmaps()-
670{-
671 pm_cache()->flushDetachedPixmaps(true);-
672}
never executed: end of block
0
673-
674int QPixmapCache::totalUsed()-
675{-
676 return (pm_cache()->totalCost()+1023) / 1024;
never executed: return (pm_cache()->totalCost()+1023) / 1024;
0
677}-
678-
679/*!-
680 \fn QPixmapCache::KeyData::KeyData()-
681-
682 \internal-
683*/-
684/*!-
685 \fn QPixmapCache::KeyData::KeyData(const KeyData &other)-
686 \internal-
687*/-
688/*!-
689 \fn QPixmapCache::KeyData::~KeyData()-
690-
691 \internal-
692*/-
693QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9