source: trunk/doc/html/qpixmapcache.html@ 208

Last change on this file since 208 was 190, checked in by rudi, 14 years ago

reference documentation added

File size: 9.9 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/kernel/qpixmapcache.cpp:45 -->
3<html>
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6<title>QPixmapCache Class</title>
7<style type="text/css"><!--
8fn { margin-left: 1cm; text-indent: -1cm; }
9a:link { color: #004faf; text-decoration: none }
10a:visited { color: #672967; text-decoration: none }
11body { background: #ffffff; color: black; }
12--></style>
13</head>
14<body>
15
16<table border="0" cellpadding="0" cellspacing="0" width="100%">
17<tr bgcolor="#E5E5E5">
18<td valign=center>
19 <a href="index.html">
20<font color="#004faf">Home</font></a>
21 | <a href="classes.html">
22<font color="#004faf">All&nbsp;Classes</font></a>
23 | <a href="mainclasses.html">
24<font color="#004faf">Main&nbsp;Classes</font></a>
25 | <a href="annotated.html">
26<font color="#004faf">Annotated</font></a>
27 | <a href="groups.html">
28<font color="#004faf">Grouped&nbsp;Classes</font></a>
29 | <a href="functions.html">
30<font color="#004faf">Functions</font></a>
31</td>
32<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QPixmapCache Class Reference</h1>
33
34<p>The QPixmapCache class provides an application-global cache for
35pixmaps.
36<a href="#details">More...</a>
37<p><tt>#include &lt;<a href="qpixmapcache-h.html">qpixmapcache.h</a>&gt;</tt>
38<p><a href="qpixmapcache-members.html">List of all member functions.</a>
39<h2>Static Public Members</h2>
40<ul>
41<li class=fn>int <a href="#cacheLimit"><b>cacheLimit</b></a> ()</li>
42<li class=fn>void <a href="#setCacheLimit"><b>setCacheLimit</b></a> ( int&nbsp;n )</li>
43<li class=fn>QPixmap * <a href="#find"><b>find</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;key )</li>
44<li class=fn>bool <a href="#find-2"><b>find</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;key, QPixmap&nbsp;&amp;&nbsp;pm )</li>
45<li class=fn>bool insert ( const&nbsp;QString&nbsp;&amp;&nbsp;key, QPixmap&nbsp;*&nbsp;pm ) &nbsp;<em>(obsolete)</em></li>
46<li class=fn>bool <a href="#insert"><b>insert</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;key, const&nbsp;QPixmap&nbsp;&amp;&nbsp;pm )</li>
47<li class=fn>void <a href="#remove"><b>remove</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;key )</li>
48<li class=fn>void <a href="#clear"><b>clear</b></a> ()</li>
49</ul>
50<hr><a name="details"></a><h2>Detailed Description</h2>
51
52
53<p> The QPixmapCache class provides an application-global cache for
54pixmaps.
55<p>
56
57
58<p> This class is a tool for optimized drawing with <a href="qpixmap.html">QPixmap</a>. You can
59use it to store temporary pixmaps that are expensive to generate
60without using more storage space than <a href="#cacheLimit">cacheLimit</a>(). Use <a href="#insert">insert</a>()
61to insert pixmaps, <a href="#find">find</a>() to find them and <a href="#clear">clear</a>() to empty the
62cache.
63<p> For example, <a href="qradiobutton.html">QRadioButton</a> has a non-trivial visual representation
64so we don't want to regenerate a pixmap whenever a radio button is
65displayed or changes state. In the function
66<a href="qbutton.html#drawButton">QRadioButton::drawButton</a>(), we do not draw the radio button
67directly. Instead, we first check the global pixmap cache for a
68pixmap with the key "$qt_radio_nnn_", where <tt>nnn</tt> is a numerical
69value that specifies the the radio button state. If a pixmap is
70found, we <a href="qimage.html#bitBlt">bitBlt</a>() it onto the widget and return. Otherwise, we
71create a new pixmap, draw the radio button in the pixmap, and
72finally insert the pixmap in the global pixmap cache, using the
73key above. The bitBlt() is ten times faster than drawing the
74radio button. All radio buttons in the program share the cached
75pixmap since QPixmapCache is application-global.
76<p> QPixmapCache contains no member data, only static functions to
77access the global pixmap cache. It creates an internal <a href="qcache.html">QCache</a> for
78caching the pixmaps.
79<p> The cache associates a pixmap with a string (key). If two pixmaps
80are inserted into the cache using equal keys, then the last pixmap
81will hide the first pixmap. The <a href="qdict.html">QDict</a> and QCache classes do
82exactly the same.
83<p> The cache becomes full when the total size of all pixmaps in the
84cache exceeds <a href="#cacheLimit">cacheLimit</a>(). The initial cache limit is 1024 KByte
85(1 MByte); it is changed with <a href="#setCacheLimit">setCacheLimit</a>(). A pixmap takes
86roughly width*height*depth/8 bytes of memory.
87<p> See the <a href="qcache.html">QCache</a> documentation for more details about the cache
88mechanism.
89<p>See also <a href="environment.html">Environment Classes</a>, <a href="graphics.html">Graphics Classes</a>, and <a href="images.html">Image Processing Classes</a>.
90
91<hr><h2>Member Function Documentation</h2>
92<h3 class=fn>int <a name="cacheLimit"></a>QPixmapCache::cacheLimit ()<tt> [static]</tt>
93</h3>
94Returns the cache limit (in kilobytes).
95<p> The default setting is 1024 kilobytes.
96<p> <p>See also <a href="#setCacheLimit">setCacheLimit</a>().
97
98<h3 class=fn>void <a name="clear"></a>QPixmapCache::clear ()<tt> [static]</tt>
99</h3>
100Removes all pixmaps from the cache.
101
102<h3 class=fn><a href="qpixmap.html">QPixmap</a>&nbsp;* <a name="find"></a>QPixmapCache::find ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;key )<tt> [static]</tt>
103</h3>
104Returns the pixmap associated with the <em>key</em> in the cache, or
105null if there is no such pixmap.
106<p> <b>Warning:</b> If valid, you should copy the pixmap immediately (this is
107fast). Subsequent insertions into the cache could cause the
108pointer to become invalid. For this reason, we recommend you use
109<a href="#find">find</a>(const <a href="qstring.html">QString</a>&, <a href="qpixmap.html">QPixmap</a>&) instead.
110<p> Example:
111<pre>
112 <a href="qpixmap.html">QPixmap</a>* pp;
113 <a href="qpixmap.html">QPixmap</a> p;
114 if ( (pp=QPixmapCache::<a href="#find">find</a>("my_big_image", pm)) ) {
115 p = *pp;
116 } else {
117 p.<a href="qpixmap.html#load">load</a>("bigimage.png");
118 QPixmapCache::<a href="#insert">insert</a>("my_big_image", new <a href="qpixmap.html">QPixmap</a>(p));
119 }
120 painter-&gt;drawPixmap(0, 0, p);
121 </pre>
122
123
124<h3 class=fn>bool <a name="find-2"></a>QPixmapCache::find ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;key, <a href="qpixmap.html">QPixmap</a>&nbsp;&amp;&nbsp;pm )<tt> [static]</tt>
125</h3>
126This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
127<p> Looks for a cached pixmap associated with the <em>key</em> in the cache.
128If a pixmap is found, the function sets <em>pm</em> to that pixmap and
129returns TRUE; otherwise leaves <em>pm</em> alone and returns FALSE.
130<p> Example:
131<pre>
132 <a href="qpixmap.html">QPixmap</a> p;
133 if ( !QPixmapCache::find("my_big_image", pm) ) {
134 pm.load("bigimage.png");
135 QPixmapCache::<a href="#insert">insert</a>("my_big_image", pm);
136 }
137 painter-&gt;drawPixmap(0, 0, p);
138 </pre>
139
140
141<h3 class=fn>bool <a name="insert"></a>QPixmapCache::insert ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;key, const&nbsp;<a href="qpixmap.html">QPixmap</a>&nbsp;&amp;&nbsp;pm )<tt> [static]</tt>
142</h3>
143Inserts a copy of the pixmap <em>pm</em> associated with the <em>key</em> into
144the cache.
145<p> All pixmaps inserted by the Qt library have a key starting with
146"$qt", so your own pixmap keys should never begin "$qt".
147<p> When a pixmap is inserted and the cache is about to exceed its
148limit, it removes pixmaps until there is enough room for the
149pixmap to be inserted.
150<p> The oldest pixmaps (least recently accessed in the cache) are
151deleted when more space is needed.
152<p> <p>See also <a href="#setCacheLimit">setCacheLimit</a>().
153
154<h3 class=fn>bool <a name="insert-2"></a>QPixmapCache::insert ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;key, <a href="qpixmap.html">QPixmap</a>&nbsp;*&nbsp;pm )<tt> [static]</tt>
155</h3>
156<b>This function is obsolete.</b> It is provided to keep old source working. We strongly advise against using it in new code.
157<p> Inserts the pixmap <em>pm</em> associated with <em>key</em> into the cache.
158Returns TRUE if successful, or FALSE if the pixmap is too big for the cache.
159<p> <strong>
160Note: <em>pm</em> must be allocated on the heap (using <tt>new</tt>).
161<p> If this function returns FALSE, you must delete <em>pm</em> yourself.
162<p> If this function returns TRUE, do not use <em>pm</em> afterwards or
163keep references to it because any other insertions into the cache,
164whether from anywhere in the application or within Qt itself, could cause
165the pixmap to be discarded from the cache and the pointer to
166become invalid.
167<p> Due to these dangers, we strongly recommend that you use
168<a href="#insert">insert</a>(const <a href="qstring.html">QString</a>&, const <a href="qpixmap.html">QPixmap</a>&) instead.
169</strong>
170
171<h3 class=fn>void <a name="remove"></a>QPixmapCache::remove ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;key )<tt> [static]</tt>
172</h3>
173Removes the pixmap associated with <em>key</em> from the cache.
174
175<h3 class=fn>void <a name="setCacheLimit"></a>QPixmapCache::setCacheLimit ( int&nbsp;n )<tt> [static]</tt>
176</h3>
177Sets the cache limit to <em>n</em> kilobytes.
178<p> The default setting is 1024 kilobytes.
179<p> <p>See also <a href="#cacheLimit">cacheLimit</a>().
180
181<!-- eof -->
182<hr><p>
183This file is part of the <a href="index.html">Qt toolkit</a>.
184Copyright &copy; 1995-2007
185<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
186<table width=100% cellspacing=0 border=0><tr>
187<td>Copyright &copy; 2007
188<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
189<td align=right><div align=right>Qt 3.3.8</div>
190</table></div></address></body>
191</html>
Note: See TracBrowser for help on using the repository browser.