src/gui/image/qimagepixmapcleanuphooks.cpp
changeset 7 f7bc934e204c
parent 3 41300fa6a67c
equal deleted inserted replaced
3:41300fa6a67c 7:f7bc934e204c
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     8 **
     8 **
    60 QImagePixmapCleanupHooks *QImagePixmapCleanupHooks::instance()
    60 QImagePixmapCleanupHooks *QImagePixmapCleanupHooks::instance()
    61 {
    61 {
    62     return qt_image_and_pixmap_cleanup_hooks();
    62     return qt_image_and_pixmap_cleanup_hooks();
    63 }
    63 }
    64 
    64 
    65 void QImagePixmapCleanupHooks::addPixmapModificationHook(_qt_pixmap_cleanup_hook_pm hook)
    65 void QImagePixmapCleanupHooks::addPixmapDataModificationHook(_qt_pixmap_cleanup_hook_pmd hook)
    66 {
    66 {
    67     pixmapModificationHooks.append(hook);
    67     pixmapModificationHooks.append(hook);
    68 }
    68 }
    69 
    69 
    70 void QImagePixmapCleanupHooks::addPixmapDestructionHook(_qt_pixmap_cleanup_hook_pm hook)
    70 void QImagePixmapCleanupHooks::addPixmapDataDestructionHook(_qt_pixmap_cleanup_hook_pmd hook)
    71 {
    71 {
    72     pixmapDestructionHooks.append(hook);
    72     pixmapDestructionHooks.append(hook);
    73 }
    73 }
    74 
    74 
    75 
    75 
    76 void QImagePixmapCleanupHooks::addImageHook(_qt_image_cleanup_hook_64 hook)
    76 void QImagePixmapCleanupHooks::addImageHook(_qt_image_cleanup_hook_64 hook)
    77 {
    77 {
    78     imageHooks.append(hook);
    78     imageHooks.append(hook);
    79 }
    79 }
    80 
    80 
    81 void QImagePixmapCleanupHooks::removePixmapModificationHook(_qt_pixmap_cleanup_hook_pm hook)
    81 void QImagePixmapCleanupHooks::removePixmapDataModificationHook(_qt_pixmap_cleanup_hook_pmd hook)
    82 {
    82 {
    83     pixmapModificationHooks.removeAll(hook);
    83     pixmapModificationHooks.removeAll(hook);
    84 }
    84 }
    85 
    85 
    86 void QImagePixmapCleanupHooks::removePixmapDestructionHook(_qt_pixmap_cleanup_hook_pm hook)
    86 void QImagePixmapCleanupHooks::removePixmapDataDestructionHook(_qt_pixmap_cleanup_hook_pmd hook)
    87 {
    87 {
    88     pixmapDestructionHooks.removeAll(hook);
    88     pixmapDestructionHooks.removeAll(hook);
    89 }
    89 }
    90 
    90 
    91 void QImagePixmapCleanupHooks::removeImageHook(_qt_image_cleanup_hook_64 hook)
    91 void QImagePixmapCleanupHooks::removeImageHook(_qt_image_cleanup_hook_64 hook)
    92 {
    92 {
    93     imageHooks.removeAll(hook);
    93     imageHooks.removeAll(hook);
    94 }
    94 }
    95 
    95 
    96 void QImagePixmapCleanupHooks::executePixmapModificationHooks(QPixmap* pm)
    96 void QImagePixmapCleanupHooks::executePixmapDataModificationHooks(QPixmapData* pmd)
    97 {
    97 {
    98     QImagePixmapCleanupHooks *h = qt_image_and_pixmap_cleanup_hooks();
    98     QImagePixmapCleanupHooks *h = qt_image_and_pixmap_cleanup_hooks();
       
    99     // the global destructor for the pixmap and image hooks might have
       
   100     // been called already if the app is "leaking" global
       
   101     // pixmaps/images
       
   102     if (!h)
       
   103         return;
    99     for (int i = 0; i < h->pixmapModificationHooks.count(); ++i)
   104     for (int i = 0; i < h->pixmapModificationHooks.count(); ++i)
   100         h->pixmapModificationHooks[i](pm);
   105         h->pixmapModificationHooks[i](pmd);
   101 
   106 
   102     if (qt_pixmap_cleanup_hook_64)
   107     if (qt_pixmap_cleanup_hook_64)
   103         qt_pixmap_cleanup_hook_64(pm->cacheKey());
   108         qt_pixmap_cleanup_hook_64(pmd->cacheKey());
   104 }
   109 }
   105 
   110 
   106 void QImagePixmapCleanupHooks::executePixmapDestructionHooks(QPixmap* pm)
   111 void QImagePixmapCleanupHooks::executePixmapDataDestructionHooks(QPixmapData* pmd)
   107 {
   112 {
   108     QImagePixmapCleanupHooks *h = qt_image_and_pixmap_cleanup_hooks();
   113     QImagePixmapCleanupHooks *h = qt_image_and_pixmap_cleanup_hooks();
       
   114     // the global destructor for the pixmap and image hooks might have
       
   115     // been called already if the app is "leaking" global
       
   116     // pixmaps/images
       
   117     if (!h)
       
   118         return;
   109     for (int i = 0; i < h->pixmapDestructionHooks.count(); ++i)
   119     for (int i = 0; i < h->pixmapDestructionHooks.count(); ++i)
   110         h->pixmapDestructionHooks[i](pm);
   120         h->pixmapDestructionHooks[i](pmd);
   111 
   121 
   112     if (qt_pixmap_cleanup_hook_64)
   122     if (qt_pixmap_cleanup_hook_64)
   113         qt_pixmap_cleanup_hook_64(pm->cacheKey());
   123         qt_pixmap_cleanup_hook_64(pmd->cacheKey());
   114 }
   124 }
   115 
   125 
   116 void QImagePixmapCleanupHooks::executeImageHooks(qint64 key)
   126 void QImagePixmapCleanupHooks::executeImageHooks(qint64 key)
   117 {
   127 {
   118     for (int i = 0; i < qt_image_and_pixmap_cleanup_hooks()->imageHooks.count(); ++i)
   128     for (int i = 0; i < qt_image_and_pixmap_cleanup_hooks()->imageHooks.count(); ++i)
   120 
   130 
   121     if (qt_image_cleanup_hook_64)
   131     if (qt_image_cleanup_hook_64)
   122         qt_image_cleanup_hook_64(key);
   132         qt_image_cleanup_hook_64(key);
   123 }
   133 }
   124 
   134 
   125 void QImagePixmapCleanupHooks::enableCleanupHooks(const QPixmap &pixmap)
       
   126 {
       
   127     enableCleanupHooks(const_cast<QPixmap &>(pixmap).data_ptr().data());
       
   128 }
       
   129 
   135 
   130 void QImagePixmapCleanupHooks::enableCleanupHooks(QPixmapData *pixmapData)
   136 void QImagePixmapCleanupHooks::enableCleanupHooks(QPixmapData *pixmapData)
   131 {
   137 {
   132     pixmapData->is_cached = true;
   138     pixmapData->is_cached = true;
       
   139 }
       
   140 
       
   141 void QImagePixmapCleanupHooks::enableCleanupHooks(const QPixmap &pixmap)
       
   142 {
       
   143     enableCleanupHooks(const_cast<QPixmap &>(pixmap).data_ptr().data());
   133 }
   144 }
   134 
   145 
   135 void QImagePixmapCleanupHooks::enableCleanupHooks(const QImage &image)
   146 void QImagePixmapCleanupHooks::enableCleanupHooks(const QImage &image)
   136 {
   147 {
   137     const_cast<QImage &>(image).data_ptr()->is_cached = true;
   148     const_cast<QImage &>(image).data_ptr()->is_cached = true;
   138 }
   149 }
   139 
   150 
       
   151 bool QImagePixmapCleanupHooks::isImageCached(const QImage &image)
       
   152 {
       
   153     return const_cast<QImage &>(image).data_ptr()->is_cached;
       
   154 }
       
   155 
       
   156 bool QImagePixmapCleanupHooks::isPixmapCached(const QPixmap &pixmap)
       
   157 {
       
   158     return const_cast<QPixmap&>(pixmap).data_ptr().data()->is_cached;
       
   159 }
       
   160 
       
   161 
       
   162 
   140 QT_END_NAMESPACE
   163 QT_END_NAMESPACE