| Home · All Classes · Grouped Classes · Annotated · Functions |
The QGlobalPixmapCache class provides a system-wide cache for pixmaps. More...
#include <QGlobalPixmapCache>
The QGlobalPixmapCache class provides a system-wide cache for pixmaps.
This class is a tool for caching of pixmaps which are likely to be used by multiple processes, or are expensive to generate and may benefit from caching between application executions. For an application-wide QPixmap cache use QPixmapCache.
Use insert() to insert pixmaps, find() to find them, and remove() to remove them from the global cache.
QGlobalPixmapCache contains no member data, only static functions to access the global pixmap cache.
The global cache associates a pixmap with a string (key). If two pixmaps are inserted into the global cache using equal keys, then the last pixmap will hide the first pixmap.
When the global cache becomes full, insert() will fail until adequate space is made available by removing unneeded pixmaps from the global cache, or by deleting all references to the global pixmap's data.
See also QPixmapCache and QPixmap.
Looks for a cached pixmap associated with the key in the global cache. If the pixmap is found, the function sets pixmap to that pixmap and returns true; otherwise it leaves pixmap alone and returns false.
Internally the global cache ensures that the pixmap is not removed until the pixmap is destroyed, therefore pixmap is directly associated with the QPixmap in the global cache and should not be reused.
Example of correct use:
{
QPixmap pm;
if (!QGlobalPixmapCache::find("background_image", pm)) {
pm.load("backgroundimage.png");
QGlobalPixmapCache::insert("background_image", pm);
}
painter->drawPixmap(0, 0, pm);
}
{
QPixmap pm;
if (!QGlobalPixmapCache::find("wallpaper_image", pm)) {
pm.load("wallpaper.png");
QGlobalPixmapCache::insert("wallpaper_image", pm);
}
painter->drawPixmap(0, 0, pm);
}
Example of incorrect use:
QPixmap pm;
if (!QGlobalPixmapCache::find("background_image", pm)) {
pm.load("backgroundimage.png");
QGlobalPixmapCache::insert("background_image", pm);
}
painter->drawPixmap(0, 0, pm);
if (!QGlobalPixmapCache::find("wallpaper_image", pm)) {
pm.load("wallpaper.png");
QGlobalPixmapCache::insert("wallpaper_image", pm);
}
painter->drawPixmap(0, 0, pm);
Inserts the pixmap pixmap associated with the key into the global cache.
All pixmaps inserted by Qtopia have a key starting with "_$QTOPIA", so your own pixmap keys should never begin with "_$QTOPIA".
The function returns true if the object was inserted into the global cache; otherwise it returns false.
When the pixmap is no longer required in the global cache, remove() may be called to free space in the global cache.
If two pixmaps are inserted into the global cache using equal keys, then the last pixmap will hide the first pixmap.
Removes the pixmap associated with the key from the global cache.
Space in the global cache will not be reclaimed unless remove() is called on pixmaps that are not required or all pixmaps referencing the global pixmap data are deleted.
This constant is provided to aid memory management for systems with large, high bit per pixel(bpp) screens. If not defined otherwise this constant is defined as follows:
#include "custom.h"
#ifndef QGLOBAL_PIXMAP_CACHE_LIMIT
//You can override this in your device profile custom.h
#define QGLOBAL_PIXMAP_CACHE_LIMIT 1048576 // 1 Mb
#endif
Device profiles can override this constant via custom.h (refer to Device Profiles).
The Shared Memory Cache documentation provides further information about this macro.
| Copyright © 2007 Trolltech | Trademarks | Qtopia 4.3.0 |