1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Qt Toolkit - QPixmapCache Class</title><style type="text/css"><!--
h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }body { background: white; color: black; }
--></style>
</head><body bgcolor="#ffffff">
<table width="100%">
<tr><td><a href="index.html">
<img width="100" height="100" src="qtlogo.png"
alt="Home" border="0"><img width="100"
height="100" src="face.png" alt="Home" border="0">
</a><td valign=top><div align=right><img src="dochead.png" width="472" height="27"><br>
<a href="classes.html"><b>Classes</b></a>
-<a href="annotated.html">Annotated</a>
- <a href="hierarchy.html">Tree</a>
-<a href="functions.html">Functions</a>
-<a href="index.html">Home</a>
-<a href="topicals.html"><b>Structure</b></a>
</div>
</table>
<h1 align=center>QPixmapCache Class Reference</h1><br clear="all">
<p>
The QPixmapCache class provides an application-global cache for pixmaps.
<a href="#details">More...</a>
<p>
<code>#include <<a href="qpixmapcache-h.html">qpixmapcache.h</a>></code>
<p><a href="qpixmapcache-members.html">List of all member functions.</a>
<h2>Static Public Members</h2>
<ul>
<li><div class="fn">int<a href="#8175e1"><b>cacheLimit</b></a>()</div>
<li><div class="fn">void<a href="#84a8fc"><b>setCacheLimit</b></a>(int)</div>
<li><div class="fn">QPixmap*<a href="#6f0a0b"><b>find</b></a>(constQString&key)</div>
<li><div class="fn">bool<a href="#920fbe"><b>find</b></a>(constQString&key, QPixmap&)</div>
<li><div class="fn">boolinsert(constQString&key, QPixmap*)<em>(obsolete)</em></div>
<li><div class="fn">void<a href="#bb65e8"><b>insert</b></a>(constQString&key, constQPixmap&)</div>
<li><div class="fn">void<a href="#225476"><b>clear</b></a>()</div>
</ul>
<hr><h2><a name="details"></a>Detailed Description</h2>
The QPixmapCache class provides an application-global cache for pixmaps.
<p>
This class is a tool for optimized drawing with <a href="qpixmap.html">QPixmap</a>. You can
use it to store temporary pixmaps that are expensive to generate,
without using more storage space than <a href="#8175e1">cacheLimit</a>(). Use <a href="#bb65e8">insert</a>() to
insert pixmaps, <a href="#6f0a0b">find</a>() to find them and <a href="#225476">clear</a>() to empty the cache.
<p>Here follows an example. <a href="qradiobutton.html">QRadioButton</a> has a non-trivial visual
representation. In the function <a href="qradiobutton.html#b82239">QRadioButton::drawButton</a>(), we do
not draw the radio button directly. Instead, we first check the
global pixmap cache for a pixmap with the key "$qt_radio_nnn_",
where <code>nnn</code> is a numerical value that specifies the the radio
button state. If a pixmap is found, we <a href="qpaintdevice.html#35ae2e">bitBlt</a>() it onto the widget
and return. Otherwise, we create a new pixmap, draw the radio button
in the pixmap and finally insert the pixmap in the global pixmap
cache, using the key above. The bitBlt() is 10 times faster than
drawing the radio button. All radio buttons in the program share
the cached pixmap since QPixmapCache is application-global.
<p>QPixmapCache contains no member data, only static functions to access
the global pixmap cache. It creates an internal <a href="qcache.html">QCache</a> for caching the
pixmaps.
<p>The cache associates a pixmap with a normal string (key). If two
pixmaps are inserted into the cache using equal keys, then the last
pixmap will hide the first pixmap. The <a href="qdict.html">QDict</a> and QCache classes do
exactly the same.
<p>The cache becomes full when the total size of all pixmaps in the
cache exceeds cacheLimit(). The initial cache limit is 1024 KByte
(1 MByte); it is changed with <a href="#84a8fc">setCacheLimit</a>(). A pixmap takes
roughly width*height*depth/8 bytes of memory.
<p>See the <a href="qcache.html">QCache</a> documentation for more details about the cache mechanism.
<hr><h2>Member Function Documentation</h2>
<h3 class="fn">int<a name="8175e1"></a>QPixmapCache::cacheLimit() <code>[static]</code></h3>
<p>Returns the cache limit (in kilobytes).
<p>The default setting is 1024 kilobytes.
<p>See also <a href="#84a8fc">setCacheLimit</a>().
<h3 class="fn">void<a name="225476"></a>QPixmapCache::clear() <code>[static]</code></h3>
<p>Removes all pixmaps from the cache.
<h3 class="fn"><a href="qpixmap.html">QPixmap</a>*<a name="6f0a0b"></a>QPixmapCache::find(const<a href="qstring.html">QString</a>&key) <code>[static]</code></h3>
<p>Returns the pixmap associated with <em>key</em> in the cache, or null if there
is no such pixmap.
<p><strong>
NOTE: if valid, you should copy the pixmap immediately (this is quick
since QPixmaps are <a href="shclass.html">implicitly shared</a>), because
subsequent insertions into the cache could cause the pointer to become
invalid. For this reason, we recommend you use
find(const <a href="qstring.html">QString</a>&, <a href="qpixmap.html">QPixmap</a>&) instead.
</strong>
<p>Example:
<pre> <a href="qpixmap.html">QPixmap</a>* pp;
<a href="qpixmap.html">QPixmap</a> p;
if ( (pp=QPixmapCache::find("my_previous_copy", pm)) ) {
p = *pp;
} else {
p.<a href="qpixmap.html#a728cf">load</a>("bigimage.png");
<a href="#bb65e8">QPixmapCache::insert</a>("my_previous_copy", new <a href="qpixmap.html">QPixmap</a>(p));
}
painter->drawPixmap(0, 0, p);
</pre>
<h3 class="fn">bool<a name="920fbe"></a>QPixmapCache::find(const<a href="qstring.html">QString</a>&key, <a href="qpixmap.html">QPixmap</a>&pm) <code>[static]</code></h3>
<p>Looks for a cached pixmap associated with <em>key</em> in the cache. If a
pixmap is found, the function sets <em>pm</em> to that pixmap and returns
TRUE. Otherwise, the function returns FALSE and does not change <em>pm.</em>
<p>Example:
<pre> <a href="qpixmap.html">QPixmap</a> p;
if ( !QPixmapCache::find("my_previous_copy", pm) ) {
pm.load("bigimage.png");
<a href="#bb65e8">QPixmapCache::insert</a>("my_previous_copy", pm);
}
painter->drawPixmap(0, 0, p);
</pre>
<h3 class="fn">bool<a name="edbcea"></a>QPixmapCache::insert(const<a href="qstring.html">QString</a>&key, <a href="qpixmap.html">QPixmap</a>*pm) <code>[static]</code></h3>
<p><b>This function is obsolete.</b> It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code.<p>
Inserts the pixmap <em>pm</em> associated with <em>key</em> into the cache.
Returns TRUE if successful, or FALSE if the pixmap is too big for the cache.
<p><strong>
NOTE: <em>pm</em> must be allocated on the heap (using <code>new).</code>
<p>If this function returns FALSE, you must delete <em>pm</em> yourself.
<p>If this function returns TRUE, do not use <em>pm</em> afterwards or
keep references to it, as any other insertions into the cache,
from anywhere in the application, or within Qt itself, could cause
the pixmap to be discarded from the cache, and the pointer to
become invalid.
<p>Due to these dangers, we strongly recommend that you use
<a href="#bb65e8">insert</a>(const <a href="qstring.html">QString</a>&, const <a href="qpixmap.html">QPixmap</a>&) instead.
</strong>
<h3 class="fn">void<a name="bb65e8"></a>QPixmapCache::insert(const<a href="qstring.html">QString</a>&key, const<a href="qpixmap.html">QPixmap</a>&pm) <code>[static]</code></h3>
<p>Inserts a copy of the pixmap <em>pm</em> associated with <em>key</em> into the cache.
<p>All pixmaps inserted by the Qt library have a key starting with "$qt..".
Use something else for your own pixmaps.
<p>When a pixmap is inserted and the cache is about to exceed its limit, it
removes pixmaps until there is enough room for the pixmap to be inserted.
<p>The oldest pixmaps (least recently accessed in the cache) are deleted
when more space is needed.
<p>See also <a href="#84a8fc">setCacheLimit</a>().
<h3 class="fn">void<a name="84a8fc"></a>QPixmapCache::setCacheLimit(int<a href="n.html">n</a>) <code>[static]</code></h3>
<p>Sets the cache limit to <em><a href="n.html">n</a></em> kilobytes.
<p>The default setting is 1024 kilobytes.
<p>See also <a href="#8175e1">cacheLimit</a>().
<hr><p>
Search the documentation, FAQ, qt-interest archive and more (uses
<a href="http://www.trolltech.com">www.trolltech.com</a>):<br>
<form method=post action="http://www.trolltech.com/search.cgi">
<input type=hidden name="version" value="2.3.2"><nobr>
<input size="50" name="search"><input type=submit value="Search">
</nobr></form><hr><p>
This file is part of the <a href="index.html">Qt toolkit</a>,
copyright © 1995-2001
<a href="http://www.trolltech.com">Trolltech</a>, all rights reserved.<p><address><hr><div align="center">
<table width="100%" cellspacing="0" border="0"><tr>
<td>Copyright 2001 Trolltech<td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a>
<td align="right"><div align="right">Qt version 2.3.2</div>
</table></div></address></body></html>
|