src/gui/image/qpixmapcache.cpp
changeset 30 5dc02b23752f
parent 18 2f34d5167611
child 33 3e2da88830cd
--- a/src/gui/image/qpixmapcache.cpp	Wed Jun 23 19:07:03 2010 +0300
+++ b/src/gui/image/qpixmapcache.cpp	Tue Jul 06 15:10:48 2010 +0300
@@ -39,6 +39,7 @@
 **
 ****************************************************************************/
 
+#define Q_TEST_QPIXMAPCACHE
 #include "qpixmapcache.h"
 #include "qobject.h"
 #include "qdebug.h"
@@ -194,6 +195,9 @@
 
     static QPixmapCache::KeyData* getKeyData(QPixmapCache::Key *key);
 
+    QList< QPair<QString,QPixmap> > allPixmaps() const;
+    void flushDetachedPixmaps(bool nt);
+
 private:
     int *keyArray;
     int theid;
@@ -235,10 +239,9 @@
   When the last pixmap has been deleted from the cache, kill the
   timer so Qt won't keep the CPU from going into sleep mode.
 */
-void QPMCache::timerEvent(QTimerEvent *)
+void QPMCache::flushDetachedPixmaps(bool nt)
 {
     int mc = maxCost();
-    bool nt = totalCost() == ps;
     setMaxCost(nt ? totalCost() * 3 / 4 : totalCost() -1);
     setMaxCost(mc);
     ps = totalCost();
@@ -252,6 +255,12 @@
             ++it;
         }
     }
+}
+
+void QPMCache::timerEvent(QTimerEvent *)
+{
+    bool nt = totalCost() == ps;
+    flushDetachedPixmaps(nt);
 
     if (!size()) {
         killTimer(theid);
@@ -263,6 +272,7 @@
     }
 }
 
+
 QPixmap *QPMCache::object(const QString &key) const
 {
     QPixmapCache::Key cacheKey = cacheKeys.value(key);
@@ -422,6 +432,20 @@
     return key->d;
 }
 
+QList< QPair<QString,QPixmap> > QPMCache::allPixmaps() const
+{
+    QList< QPair<QString,QPixmap> > r;
+    QHash<QString, QPixmapCache::Key>::const_iterator it = cacheKeys.begin();
+    while (it != cacheKeys.end()) {
+        QPixmap *ptr = QCache<QPixmapCache::Key, QPixmapCacheEntry>::object(it.value());
+        if (ptr)
+            r.append(QPair<QString,QPixmap>(it.key(),*ptr));
+        ++it;
+    }
+    return r;
+}
+
+
 Q_GLOBAL_STATIC(QPMCache, pm_cache)
 
 int Q_AUTOTEST_EXPORT q_QPixmapCache_keyHashSize()
@@ -633,4 +657,19 @@
     }
 }
 
+void QPixmapCache::flushDetachedPixmaps()
+{
+    pm_cache()->flushDetachedPixmaps(true);
+}
+
+int QPixmapCache::totalUsed()
+{
+    return (pm_cache()->totalCost()+1023) / 1024;
+}
+
+QList< QPair<QString,QPixmap> > QPixmapCache::allPixmaps()
+{
+    return pm_cache()->allPixmaps();
+}
+
 QT_END_NAMESPACE