src/gui/image/qimagepixmapcleanuphooks.cpp
branchRCL_3
changeset 8 3f74d0d4af4c
parent 4 3b1da2848fc7
--- a/src/gui/image/qimagepixmapcleanuphooks.cpp	Mon Mar 15 12:43:09 2010 +0200
+++ b/src/gui/image/qimagepixmapcleanuphooks.cpp	Thu Apr 08 14:19:33 2010 +0300
@@ -62,12 +62,12 @@
     return qt_image_and_pixmap_cleanup_hooks();
 }
 
-void QImagePixmapCleanupHooks::addPixmapModificationHook(_qt_pixmap_cleanup_hook_pm hook)
+void QImagePixmapCleanupHooks::addPixmapDataModificationHook(_qt_pixmap_cleanup_hook_pmd hook)
 {
     pixmapModificationHooks.append(hook);
 }
 
-void QImagePixmapCleanupHooks::addPixmapDestructionHook(_qt_pixmap_cleanup_hook_pm hook)
+void QImagePixmapCleanupHooks::addPixmapDataDestructionHook(_qt_pixmap_cleanup_hook_pmd hook)
 {
     pixmapDestructionHooks.append(hook);
 }
@@ -78,12 +78,12 @@
     imageHooks.append(hook);
 }
 
-void QImagePixmapCleanupHooks::removePixmapModificationHook(_qt_pixmap_cleanup_hook_pm hook)
+void QImagePixmapCleanupHooks::removePixmapDataModificationHook(_qt_pixmap_cleanup_hook_pmd hook)
 {
     pixmapModificationHooks.removeAll(hook);
 }
 
-void QImagePixmapCleanupHooks::removePixmapDestructionHook(_qt_pixmap_cleanup_hook_pm hook)
+void QImagePixmapCleanupHooks::removePixmapDataDestructionHook(_qt_pixmap_cleanup_hook_pmd hook)
 {
     pixmapDestructionHooks.removeAll(hook);
 }
@@ -93,24 +93,34 @@
     imageHooks.removeAll(hook);
 }
 
-void QImagePixmapCleanupHooks::executePixmapModificationHooks(QPixmap* pm)
+void QImagePixmapCleanupHooks::executePixmapDataModificationHooks(QPixmapData* pmd)
 {
     QImagePixmapCleanupHooks *h = qt_image_and_pixmap_cleanup_hooks();
+    // the global destructor for the pixmap and image hooks might have
+    // been called already if the app is "leaking" global
+    // pixmaps/images
+    if (!h)
+        return;
     for (int i = 0; i < h->pixmapModificationHooks.count(); ++i)
-        h->pixmapModificationHooks[i](pm);
+        h->pixmapModificationHooks[i](pmd);
 
     if (qt_pixmap_cleanup_hook_64)
-        qt_pixmap_cleanup_hook_64(pm->cacheKey());
+        qt_pixmap_cleanup_hook_64(pmd->cacheKey());
 }
 
-void QImagePixmapCleanupHooks::executePixmapDestructionHooks(QPixmap* pm)
+void QImagePixmapCleanupHooks::executePixmapDataDestructionHooks(QPixmapData* pmd)
 {
     QImagePixmapCleanupHooks *h = qt_image_and_pixmap_cleanup_hooks();
+    // the global destructor for the pixmap and image hooks might have
+    // been called already if the app is "leaking" global
+    // pixmaps/images
+    if (!h)
+        return;
     for (int i = 0; i < h->pixmapDestructionHooks.count(); ++i)
-        h->pixmapDestructionHooks[i](pm);
+        h->pixmapDestructionHooks[i](pmd);
 
     if (qt_pixmap_cleanup_hook_64)
-        qt_pixmap_cleanup_hook_64(pm->cacheKey());
+        qt_pixmap_cleanup_hook_64(pmd->cacheKey());
 }
 
 void QImagePixmapCleanupHooks::executeImageHooks(qint64 key)
@@ -122,19 +132,32 @@
         qt_image_cleanup_hook_64(key);
 }
 
-void QImagePixmapCleanupHooks::enableCleanupHooks(const QPixmap &pixmap)
-{
-    enableCleanupHooks(const_cast<QPixmap &>(pixmap).data_ptr().data());
-}
 
 void QImagePixmapCleanupHooks::enableCleanupHooks(QPixmapData *pixmapData)
 {
     pixmapData->is_cached = true;
 }
 
+void QImagePixmapCleanupHooks::enableCleanupHooks(const QPixmap &pixmap)
+{
+    enableCleanupHooks(const_cast<QPixmap &>(pixmap).data_ptr().data());
+}
+
 void QImagePixmapCleanupHooks::enableCleanupHooks(const QImage &image)
 {
     const_cast<QImage &>(image).data_ptr()->is_cached = true;
 }
 
+bool QImagePixmapCleanupHooks::isImageCached(const QImage &image)
+{
+    return const_cast<QImage &>(image).data_ptr()->is_cached;
+}
+
+bool QImagePixmapCleanupHooks::isPixmapCached(const QPixmap &pixmap)
+{
+    return const_cast<QPixmap&>(pixmap).data_ptr().data()->is_cached;
+}
+
+
+
 QT_END_NAMESPACE