Qt 4.8
qimagepixmapcleanuphooks.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
43 #include "private/qpixmapdata_p.h"
44 #include "private/qimage_p.h"
45 
46 
48 
49 // Legacy, single instance hooks: ### Qt 5: remove
50 typedef void (*_qt_pixmap_cleanup_hook)(int);
52 typedef void (*_qt_image_cleanup_hook)(int);
57 
58 Q_GLOBAL_STATIC(QImagePixmapCleanupHooks, qt_image_and_pixmap_cleanup_hooks)
59 
61 {
62  return qt_image_and_pixmap_cleanup_hooks();
63 }
64 
66 {
68 }
69 
71 {
73 }
74 
75 
77 {
78  imageHooks.append(hook);
79 }
80 
82 {
84 }
85 
87 {
89 }
90 
92 {
93  imageHooks.removeAll(hook);
94 }
95 
97 {
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;
104  for (int i = 0; i < h->pixmapModificationHooks.count(); ++i)
105  h->pixmapModificationHooks[i](pmd);
106 
109 }
110 
112 {
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;
119  for (int i = 0; i < h->pixmapDestructionHooks.count(); ++i)
120  h->pixmapDestructionHooks[i](pmd);
121 
124 }
125 
127 {
128  for (int i = 0; i < qt_image_and_pixmap_cleanup_hooks()->imageHooks.count(); ++i)
129  qt_image_and_pixmap_cleanup_hooks()->imageHooks[i](key);
130 
133 }
134 
135 
137 {
138  pixmapData->is_cached = true;
139 }
140 
142 {
143  enableCleanupHooks(const_cast<QPixmap &>(pixmap).data_ptr().data());
144 }
145 
147 {
148  const_cast<QImage &>(image).data_ptr()->is_cached = true;
149 }
150 
152 {
153  return const_cast<QImage &>(image).data_ptr()->is_cached;
154 }
155 
157 {
158  return const_cast<QPixmap&>(pixmap).data_ptr().data()->is_cached;
159 }
160 
161 
162 
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void addPixmapDataModificationHook(_qt_pixmap_cleanup_hook_pmd)
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
QList< _qt_pixmap_cleanup_hook_pmd > pixmapModificationHooks
Q_GUI_EXPORT _qt_image_cleanup_hook qt_image_cleanup_hook
static void enableCleanupHooks(const QImage &image)
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
Q_GUI_EXPORT _qt_pixmap_cleanup_hook_64 qt_pixmap_cleanup_hook_64
static void executePixmapDataDestructionHooks(QPixmapData *)
void removePixmapDataModificationHook(_qt_pixmap_cleanup_hook_pmd)
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
static void executeImageHooks(qint64 key)
void(* _qt_image_cleanup_hook_64)(qint64)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void addPixmapDataDestructionHook(_qt_pixmap_cleanup_hook_pmd)
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
Definition: qglobal.h:1968
void(* _qt_pixmap_cleanup_hook)(int)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
static const char * data(const QByteArray &arr)
void(* _qt_image_cleanup_hook)(int)
void(* _qt_pixmap_cleanup_hook_64)(qint64)
__int64 qint64
Definition: qglobal.h:942
void removePixmapDataDestructionHook(_qt_pixmap_cleanup_hook_pmd)
QList< _qt_image_cleanup_hook_64 > imageHooks
static void executePixmapDataModificationHooks(QPixmapData *)
static bool isPixmapCached(const QPixmap &pixmap)
void * data_ptr(const QTransform &t)
Definition: qpainter_p.h:81
int key
void removeImageHook(_qt_image_cleanup_hook_64)
Q_GUI_EXPORT _qt_image_cleanup_hook_64 qt_image_cleanup_hook_64
QList< _qt_pixmap_cleanup_hook_pmd > pixmapDestructionHooks
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
void(* _qt_pixmap_cleanup_hook_pmd)(QPixmapData *)
static bool isImageCached(const QImage &image)
qint64 cacheKey() const
Q_GUI_EXPORT _qt_pixmap_cleanup_hook qt_pixmap_cleanup_hook
int removeAll(const T &t)
Removes all occurrences of value in the list and returns the number of entries removed.
Definition: qlist.h:770
void addImageHook(_qt_image_cleanup_hook_64)