~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to doc/html/qpixmapcache.html

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-11-02 18:30:08 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (15.2.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 88.
  • Revision ID: james.westby@ubuntu.com-20091102183008-b6a4gcs128mvfb3m
Tags: upstream-4.6.0~beta1
ImportĀ upstreamĀ versionĀ 4.6.0~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
<!DOCTYPE html
3
3
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
4
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
 
<!-- /fasttmp/mkdist-qt-4.5.2-1245473805/qt-x11-opensource-src-4.5.2/src/gui/image/qpixmapcache.cpp -->
 
5
<!-- qpixmapcache.cpp -->
6
6
<head>
7
 
  <title>Qt 4.5: QPixmapCache Class Reference</title>
 
7
  <title>Qt 4.6: QPixmapCache Class Reference</title>
8
8
  <link href="classic.css" rel="stylesheet" type="text/css" />
9
9
</head>
10
10
<body>
 
11
<a name="//apple_ref/cpp/cl//QPixmapCache" />
11
12
<table border="0" cellpadding="0" cellspacing="0" width="100%">
12
13
<tr>
13
 
<td align="left" valign="top" width="32"><a href="http://qtsoftware.com/products/qt"><img src="images/qt-logo.png" align="left" border="0" /></a></td>
14
 
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="namespaces.html"><font color="#004faf">All&nbsp;Namespaces</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="modules.html"><font color="#004faf">Modules</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
15
 
<td align="right" valign="top" width="230"></td></tr></table><h1 class="title">QPixmapCache Class Reference<br /><span class="small-subtitle">[<a href="qtgui.html">QtGui</a> module]</span>
 
14
<td align="left" valign="top" width="32"><a href="http://qt.nokia.com/"><img src="images/qt-logo.png" align="left" border="0" /></a></td>
 
15
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">All&nbsp;Functions</font></a>&nbsp;&middot; <a href="overviews.html"><font color="#004faf">Overviews</font></a></td><td class="searchBar" align="right" valign="center"><form action="http://www.google.com/cse" id="cse-search-box"><div><input type="hidden" name="cx" value="000136343326384750312:dhbxnqlakyu" /><input type="hidden" name="ie" value="UTF-8" /><input type="text" name="q" size="31" /><input type="submit" name="sa" value="Search" /></div></form></td>
 
16
</tr></table><h1 class="title">QPixmapCache Class Reference<br /><span class="small-subtitle">[<a href="qtgui.html">QtGui</a> module]</span>
16
17
</h1>
17
18
<p>The QPixmapCache class provides an application-wide cache for pixmaps. <a href="#details">More...</a></p>
18
19
<pre> #include &lt;QPixmapCache&gt;</pre><ul>
19
20
<li><a href="qpixmapcache-members.html">List of all members, including inherited members</a></li>
20
21
<li><a href="qpixmapcache-obsolete.html">Obsolete members</a></li>
21
22
</ul>
 
23
<hr />
 
24
<a name="public-types"></a>
 
25
<h2>Public Types</h2>
 
26
<table class="alignedsummary" border="0" cellpadding="0" cellspacing="0" width="100%">
 
27
<tr><td class="memItemLeft" align="right" valign="top">class </td><td class="memItemRight" valign="bottom"><b><a href="qpixmapcache-key.html">Key</a></b></td></tr>
 
28
</table>
 
29
<hr />
22
30
<a name="static-public-members"></a>
23
 
<h3>Static Public Members</h3>
24
 
<ul>
25
 
<li><div class="fn"></div>int <b><a href="qpixmapcache.html#cacheLimit">cacheLimit</a></b> ()</li>
26
 
<li><div class="fn"></div>void <b><a href="qpixmapcache.html#clear">clear</a></b> ()</li>
27
 
<li><div class="fn"></div>bool <b><a href="qpixmapcache.html#find">find</a></b> ( const QString &amp; <i>key</i>, QPixmap &amp; <i>pm</i> )</li>
28
 
<li><div class="fn"></div>bool <b><a href="qpixmapcache.html#insert">insert</a></b> ( const QString &amp; <i>key</i>, const QPixmap &amp; <i>pm</i> )</li>
29
 
<li><div class="fn"></div>void <b><a href="qpixmapcache.html#remove">remove</a></b> ( const QString &amp; <i>key</i> )</li>
30
 
<li><div class="fn"></div>void <b><a href="qpixmapcache.html#setCacheLimit">setCacheLimit</a></b> ( int <i>n</i> )</li>
31
 
</ul>
 
31
<h2>Static Public Members</h2>
 
32
<table class="alignedsummary" border="0" cellpadding="0" cellspacing="0" width="100%">
 
33
<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><b><a href="qpixmapcache.html#cacheLimit">cacheLimit</a></b> ()</td></tr>
 
34
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qpixmapcache.html#clear">clear</a></b> ()</td></tr>
 
35
<tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qpixmapcache.html#find">find</a></b> ( const QString &amp; <i>key</i>, QPixmap * <i>pixmap</i> )</td></tr>
 
36
<tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qpixmapcache.html#find-3">find</a></b> ( const Key &amp; <i>key</i>, QPixmap * <i>pixmap</i> )</td></tr>
 
37
<tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qpixmapcache.html#insert">insert</a></b> ( const QString &amp; <i>key</i>, const QPixmap &amp; <i>pixmap</i> )</td></tr>
 
38
<tr><td class="memItemLeft" align="right" valign="top">Key </td><td class="memItemRight" valign="bottom"><b><a href="qpixmapcache.html#insert-2">insert</a></b> ( const QPixmap &amp; <i>pixmap</i> )</td></tr>
 
39
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qpixmapcache.html#remove">remove</a></b> ( const QString &amp; <i>key</i> )</td></tr>
 
40
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qpixmapcache.html#remove-2">remove</a></b> ( const Key &amp; <i>key</i> )</td></tr>
 
41
<tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qpixmapcache.html#replace">replace</a></b> ( const Key &amp; <i>key</i>, const QPixmap &amp; <i>pixmap</i> )</td></tr>
 
42
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qpixmapcache.html#setCacheLimit">setCacheLimit</a></b> ( int <i>n</i> )</td></tr>
 
43
</table>
32
44
<a name="details"></a>
33
45
<hr />
34
46
<h2>Detailed Description</h2>
35
47
<p>The QPixmapCache class provides an application-wide cache for pixmaps.</p>
36
48
<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="qpixmapcache.html#cacheLimit">cacheLimit</a>(). Use <a href="qpixmapcache.html#insert">insert</a>() to insert pixmaps, <a href="qpixmapcache.html#find">find</a>() to find them, and <a href="qpixmapcache.html#clear">clear</a>() to empty the cache.</p>
37
49
<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> object for caching the pixmaps.</p>
38
 
<p>The cache associates a pixmap with a 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="qhash.html">QHash</a> and <a href="qcache.html">QCache</a> classes do exactly the same.</p>
39
 
<p>The cache becomes full when the total size of all pixmaps in the cache exceeds <a href="qpixmapcache.html#cacheLimit">cacheLimit</a>(). The initial cache limit is 1024 KB (1 MB); it is changed with <a href="qpixmapcache.html#setCacheLimit">setCacheLimit</a>(). A pixmap takes roughly (<i>width</i> * <i>height</i> * <i>depth</i>)/8 bytes of memory.</p>
40
 
<p>The <i>Qt Quarterly</i> article <a href="http://doc.trolltech.com/qq/qq12-qpixmapcache.html">Optimizing with QPixmapCache</a> explains how to use QPixmapCache to speed up applications by caching the results of painting.</p>
 
50
<p>The cache associates a pixmap with a user-provided string as a key, or with a <a href="qpixmapcache-key.html">QPixmapCache::Key</a> that the cache generates. Using <a href="qpixmapcache-key.html">QPixmapCache::Key</a> for keys is faster than using strings. The string API is very convenient for complex keys but the <a href="qpixmapcache-key.html">QPixmapCache::Key</a> API will be very efficient and convenient for a one-to-one object-to-pixmap mapping &mdash; in this case, you can store the keys as members of an object.</p>
 
51
<p>If two pixmaps are inserted into the cache using equal keys then the last pixmap will replace the first pixmap in the cache. This follows the behavior of the <a href="qhash.html">QHash</a> and <a href="qcache.html">QCache</a> classes.</p>
 
52
<p>The cache becomes full when the total size of all pixmaps in the cache exceeds <a href="qpixmapcache.html#cacheLimit">cacheLimit</a>(). The initial cache limit is 2048 KB (2 MB) on embedded platforms, 10240 KB (10 MB) on desktop platforms; you can change this by calling <a href="qpixmapcache.html#setCacheLimit">setCacheLimit</a>() with the required value. A pixmap takes roughly (<i>width</i> * <i>height</i> * <i>depth</i>)/8 bytes of memory.</p>
 
53
<p>The <i>Qt Quarterly</i> article <a href="http://qt.nokia.com/doc/qq/qq12-qpixmapcache.html">Optimizing with QPixmapCache</a> explains how to use QPixmapCache to speed up applications by caching the results of painting.</p>
41
54
<p>See also <a href="qcache.html">QCache</a> and <a href="qpixmap.html">QPixmap</a>.</p>
42
55
<hr />
43
56
<h2>Member Function Documentation</h2>
 
57
<a name="//apple_ref/cpp/clm/QPixmapCache/cacheLimit" />
44
58
<h3 class="fn"><a name="cacheLimit"></a>int QPixmapCache::cacheLimit ()&nbsp;&nbsp;<tt> [static]</tt></h3>
45
59
<p>Returns the cache limit (in kilobytes).</p>
46
 
<p>The default cache limit is 2048 KB for Embedded, 10240 KB for Desktops.</p>
 
60
<p>The default cache limit is 2048 KB on embedded platforms, 10240 KB on desktop platforms.</p>
47
61
<p>See also <a href="qpixmapcache.html#setCacheLimit">setCacheLimit</a>().</p>
 
62
<a name="//apple_ref/cpp/clm/QPixmapCache/clear" />
48
63
<h3 class="fn"><a name="clear"></a>void QPixmapCache::clear ()&nbsp;&nbsp;<tt> [static]</tt></h3>
49
64
<p>Removes all pixmaps from the cache.</p>
50
 
<h3 class="fn"><a name="find"></a>bool QPixmapCache::find ( const <a href="qstring.html">QString</a> &amp; <i>key</i>, <a href="qpixmap.html">QPixmap</a> &amp; <i>pm</i> )&nbsp;&nbsp;<tt> [static]</tt></h3>
51
 
<p>Looks for a cached pixmap associated with the <i>key</i> in the cache. If the pixmap is found, the function sets <i>pm</i> to that pixmap and returns true; otherwise it leaves <i>pm</i> alone and returns false.</p>
 
65
<a name="//apple_ref/cpp/clm/QPixmapCache/find" />
 
66
<h3 class="fn"><a name="find"></a>bool QPixmapCache::find ( const <a href="qstring.html">QString</a> &amp; <i>key</i>, <a href="qpixmap.html">QPixmap</a> * <i>pixmap</i> )&nbsp;&nbsp;<tt> [static]</tt></h3>
 
67
<p>Looks for a cached pixmap associated with the given <i>key</i> in the cache. If the pixmap is found, the function sets <i>pixmap</i> to that pixmap and returns true; otherwise it leaves <i>pixmap</i> alone and returns false.</p>
52
68
<p>Example:</p>
53
69
<pre> QPixmap pm;
54
 
 if (!QPixmapCache::find(&quot;my_big_image&quot;, pm)) {
 
70
 if (!QPixmapCache::find(&quot;my_big_image&quot;, &amp;pm)) {
55
71
     pm.load(&quot;bigimage.png&quot;);
56
72
     QPixmapCache::insert(&quot;my_big_image&quot;, pm);
57
73
 }
58
74
 painter-&gt;drawPixmap(0, 0, pm);</pre>
59
 
<h3 class="fn"><a name="insert"></a>bool QPixmapCache::insert ( const <a href="qstring.html">QString</a> &amp; <i>key</i>, const <a href="qpixmap.html">QPixmap</a> &amp; <i>pm</i> )&nbsp;&nbsp;<tt> [static]</tt></h3>
60
 
<p>Inserts a copy of the pixmap <i>pm</i> associated with the <i>key</i> into the cache.</p>
 
75
<p>This function was introduced in Qt 4.6.</p>
 
76
<h3 class="fn"><a name="find-3"></a>bool QPixmapCache::find ( const <a href="qpixmapcache-key.html">Key</a> &amp; <i>key</i>, <a href="qpixmap.html">QPixmap</a> * <i>pixmap</i> )&nbsp;&nbsp;<tt> [static]</tt></h3>
 
77
<p>Looks for a cached pixmap associated with the given <i>key</i> in the cache. If the pixmap is found, the function sets <i>pixmap</i> to that pixmap and returns true; otherwise it leaves <i>pixmap</i> alone and returns false. If the pixmap is not found, it means that the <i>key</i> is no longer valid, so it will be released for the next insertion.</p>
 
78
<p>This function was introduced in Qt 4.6.</p>
 
79
<a name="//apple_ref/cpp/clm/QPixmapCache/insert" />
 
80
<h3 class="fn"><a name="insert"></a>bool QPixmapCache::insert ( const <a href="qstring.html">QString</a> &amp; <i>key</i>, const <a href="qpixmap.html">QPixmap</a> &amp; <i>pixmap</i> )&nbsp;&nbsp;<tt> [static]</tt></h3>
 
81
<p>Inserts a copy of the pixmap <i>pixmap</i> associated with the <i>key</i> into the cache.</p>
61
82
<p>All pixmaps inserted by the Qt library have a key starting with &quot;$qt&quot;, so your own pixmap keys should never begin &quot;$qt&quot;.</p>
62
83
<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>
63
84
<p>The oldest pixmaps (least recently accessed in the cache) are deleted when more space is needed.</p>
64
85
<p>The function returns true if the object was inserted into the cache; otherwise it returns false.</p>
65
86
<p>See also <a href="qpixmapcache.html#setCacheLimit">setCacheLimit</a>().</p>
 
87
<h3 class="fn"><a name="insert-2"></a><a href="qpixmapcache-key.html">Key</a> QPixmapCache::insert ( const <a href="qpixmap.html">QPixmap</a> &amp; <i>pixmap</i> )&nbsp;&nbsp;<tt> [static]</tt></h3>
 
88
<p>Inserts a copy of the given <i>pixmap</i> into the cache and returns a key that can be used to retrieve it.</p>
 
89
<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>
 
90
<p>The oldest pixmaps (least recently accessed in the cache) are deleted when more space is needed.</p>
 
91
<p>This function was introduced in Qt 4.6.</p>
 
92
<p>See also <a href="qpixmapcache.html#setCacheLimit">setCacheLimit</a>() and <a href="qpixmapcache.html#replace">replace</a>().</p>
 
93
<a name="//apple_ref/cpp/clm/QPixmapCache/remove" />
66
94
<h3 class="fn"><a name="remove"></a>void QPixmapCache::remove ( const <a href="qstring.html">QString</a> &amp; <i>key</i> )&nbsp;&nbsp;<tt> [static]</tt></h3>
67
95
<p>Removes the pixmap associated with <i>key</i> from the cache.</p>
 
96
<h3 class="fn"><a name="remove-2"></a>void QPixmapCache::remove ( const <a href="qpixmapcache-key.html">Key</a> &amp; <i>key</i> )&nbsp;&nbsp;<tt> [static]</tt></h3>
 
97
<p>Removes the pixmap associated with <i>key</i> from the cache and releases the key for a future insertion.</p>
 
98
<p>This function was introduced in Qt 4.6.</p>
 
99
<a name="//apple_ref/cpp/clm/QPixmapCache/replace" />
 
100
<h3 class="fn"><a name="replace"></a>bool QPixmapCache::replace ( const <a href="qpixmapcache-key.html">Key</a> &amp; <i>key</i>, const <a href="qpixmap.html">QPixmap</a> &amp; <i>pixmap</i> )&nbsp;&nbsp;<tt> [static]</tt></h3>
 
101
<p>Replaces the pixmap associated with the given <i>key</i> with the <i>pixmap</i> specified. Returns true if the <i>pixmap</i> has been correctly inserted into the cache; otherwise returns false.</p>
 
102
<p>This function was introduced in Qt 4.6.</p>
 
103
<p>See also <a href="qpixmapcache.html#setCacheLimit">setCacheLimit</a>() and <a href="qpixmapcache.html#insert">insert</a>().</p>
 
104
<a name="//apple_ref/cpp/clm/QPixmapCache/setCacheLimit" />
68
105
<h3 class="fn"><a name="setCacheLimit"></a>void QPixmapCache::setCacheLimit ( int <i>n</i> )&nbsp;&nbsp;<tt> [static]</tt></h3>
69
106
<p>Sets the cache limit to <i>n</i> kilobytes.</p>
70
 
<p>The default setting is 2048 KB for Embedded, 10240 KB for Desktops.</p>
 
107
<p>The default setting is 2048 KB on embedded platforms, 10240 KB on desktop platforms.</p>
71
108
<p>See also <a href="qpixmapcache.html#cacheLimit">cacheLimit</a>().</p>
72
109
<p /><address><hr /><div align="center">
73
110
<table width="100%" cellspacing="0" border="0"><tr class="address">
74
 
<td width="30%" align="left">Copyright &copy; 2009 Nokia Corporation and/or its subsidiary(-ies)</td>
75
 
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
76
 
<td width="30%" align="right"><div align="right">Qt 4.5.2</div></td>
77
 
</tr></table></div></address></body>
 
111
<td width="40%" align="left">Copyright &copy; 2009 Nokia Corporation and/or its subsidiary(-ies)</td>
 
112
<td width="20%" align="center"><a href="trademarks.html">Trademarks</a></td>
 
113
<td width="40%" align="right"><div align="right">Qt 4.6.0</div></td>
 
114
<script type="text/javascript" src="http://www.google.com/jsapi"></script><script type="text/javascript">google.load("elements", "1", {packages: "transliteration"});</script><script type="text/javascript" src="http://www.google.com/coop/cse/t13n?form=cse-search-box&t13n_langs=en"></script><script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=cse-search-box&lang=en"></script></tr></table></div></address></body>
78
115
</html>