1QPixmapCache(3qt) QPixmapCache(3qt)
2
3
4
6 QPixmapCache - Application-global cache for pixmaps
7
9 #include <qpixmapcache.h>
10
11 Static Public Members
12 <li class=fn>int cacheLimit () <li class=fn>void setCacheLimit ( int n
13 ) <li class=fn>QPixmap * find ( const QString & key ) <li class=fn>bool
14 find ( const QString & key, QPixmap & pm ) <li class=fn>bool insert (
15 const QString & key, QPixmap * pm ) (obsolete) <li class=fn>bool insert
16 ( const QString & key, const QPixmap & pm ) <li class=fn>void remove (
17 const QString & key ) <li class=fn>void clear ()
18
20 The QPixmapCache class provides an application-global cache for
21 pixmaps.
22
23 This class is a tool for optimized drawing with QPixmap. You can use it
24 to store temporary pixmaps that are expensive to generate without using
25 more storage space than cacheLimit(). Use insert() to insert pixmaps,
26 find() to find them and clear() to empty the cache.
27
28 For example, QRadioButton has a non-trivial visual representation so we
29 don't want to regenerate a pixmap whenever a radio button is displayed
30 or changes state. In the function QRadioButton::drawButton(), we do not
31 draw the radio button directly. Instead, we first check the global
32 pixmap cache for a pixmap with the key "$qt_radio_nnn_", where nnn is a
33 numerical value that specifies the the radio button state. If a pixmap
34 is found, we bitBlt() it onto the widget and return. Otherwise, we
35 create a new pixmap, draw the radio button in the pixmap, and finally
36 insert the pixmap in the global pixmap cache, using the key above. The
37 bitBlt() is ten times faster than drawing the radio button. All radio
38 buttons in the program share the cached pixmap since QPixmapCache is
39 application-global.
40
41 QPixmapCache contains no member data, only static functions to access
42 the global pixmap cache. It creates an internal QCache for caching the
43 pixmaps.
44
45 The cache associates a pixmap with a string (key). If two pixmaps are
46 inserted into the cache using equal keys, then the last pixmap will
47 hide the first pixmap. The QDict and QCache classes do exactly the
48 same.
49
50 The cache becomes full when the total size of all pixmaps in the cache
51 exceeds cacheLimit(). The initial cache limit is 1024 KByte (1 MByte);
52 it is changed with setCacheLimit(). A pixmap takes roughly
53 width*height*depth/8 bytes of memory.
54
55 See the QCache documentation for more details about the cache
56 mechanism.
57
58 See also Environment Classes, Graphics Classes, and Image Processing
59 Classes.
60
63 Returns the cache limit (in kilobytes).
64
65 The default setting is 1024 kilobytes.
66
67 See also setCacheLimit().
68
70 Removes all pixmaps from the cache.
71
73 Returns the pixmap associated with the key in the cache, or null if
74 there is no such pixmap.
75
76 Warning: If valid, you should copy the pixmap immediately (this is
77 fast). Subsequent insertions into the cache could cause the pointer to
78 become invalid. For this reason, we recommend you use find(const
79 QString&, QPixmap&) instead.
80
81 Example:
82
83 QPixmap* pp;
84 QPixmap p;
85 if ( (pp=QPixmapCache::find("my_big_image", pm)) ) {
86 p = *pp;
87 } else {
88 p.load("bigimage.png");
89 QPixmapCache::insert("my_big_image", new QPixmap(p));
90 }
91 painter->drawPixmap(0, 0, p);
92
94 This is an overloaded member function, provided for convenience. It
95 behaves essentially like the above function.
96
97 Looks for a cached pixmap associated with the key in the cache. If a
98 pixmap is found, the function sets pm to that pixmap and returns TRUE;
99 otherwise leaves pm alone and returns FALSE.
100
101 Example:
102
103 QPixmap p;
104 if ( !QPixmapCache::find("my_big_image", pm) ) {
105 pm.load("bigimage.png");
106 QPixmapCache::insert("my_big_image", pm);
107 }
108 painter->drawPixmap(0, 0, p);
109
111
112 Inserts a copy of the pixmap pm associated with the key into the cache.
113
114 All pixmaps inserted by the Qt library have a key starting with" $qt",
115 so your own pixmap keys should never begin "$qt".
116
117 When a pixmap is inserted and the cache is about to exceed its limit,
118 it removes pixmaps until there is enough room for the pixmap to be
119 inserted.
120
121 The oldest pixmaps (least recently accessed in the cache) are deleted
122 when more space is needed.
123
124 See also setCacheLimit().
125
127 This function is obsolete. It is provided to keep old source working.
128 We strongly advise against using it in new code.
129
130 Inserts the pixmap pm associated with key into the cache. Returns TRUE
131 if successful, or FALSE if the pixmap is too big for the cache.
132
133 Note: pm must be allocated on the heap (using new).
134
135 If this function returns FALSE, you must delete pm yourself.
136
137 If this function returns TRUE, do not use pm afterwards or keep
138 references to it because any other insertions into the cache, whether
139 from anywhere in the application or within Qt itself, could cause the
140 pixmap to be discarded from the cache and the pointer to become
141 invalid.
142
143 Due to these dangers, we strongly recommend that you use insert(const
144 QString&, const QPixmap&) instead.
145
147 Removes the pixmap associated with key from the cache.
148
150 Sets the cache limit to n kilobytes.
151
152 The default setting is 1024 kilobytes.
153
154 See also cacheLimit().
155
156
158 http://doc.trolltech.com/qpixmapcache.html
159 http://www.trolltech.com/faq/tech.html
160
162 Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the
163 license file included in the distribution for a complete license
164 statement.
165
167 Generated automatically from the source code.
168
170 If you find a bug in Qt, please report it as described in
171 http://doc.trolltech.com/bughowto.html. Good bug reports help us to
172 help you. Thank you.
173
174 The definitive Qt documentation is provided in HTML format; it is
175 located at $QTDIR/doc/html and can be read using Qt Assistant or with a
176 web browser. This man page is provided as a convenience for those users
177 who prefer man pages, although this format is not officially supported
178 by Trolltech.
179
180 If you find errors in this manual page, please report them to qt-
181 bugs@trolltech.com. Please include the name of the manual page
182 (qpixmapcache.3qt) and the Qt version (3.3.8).
183
184
185
186Trolltech AS 2 February 2007 QPixmapCache(3qt)