Qt 4.8
|
The QPixmapCache class provides an application-wide cache for pixmaps. More...
#include <qpixmapcache.h>
Classes | |
class | Key |
The QPixmapCache::Key class can be used for efficient access to the QPixmapCache. More... | |
class | KeyData |
Static Public Functions | |
static int | cacheLimit () |
Returns the cache limit (in kilobytes). More... | |
static void | clear () |
Removes all pixmaps from the cache. More... | |
static QPixmap * | find (const QString &key) |
static bool | find (const QString &key, QPixmap &pixmap) |
static bool | find (const QString &key, QPixmap *pixmap) |
Looks for a cached pixmap associated with the given key in the cache. More... | |
static bool | find (const Key &key, QPixmap *pixmap) |
Looks for a cached pixmap associated with the given key in the cache. More... | |
static bool | insert (const QString &key, const QPixmap &pixmap) |
Inserts a copy of the pixmap pixmap associated with the key into the cache. More... | |
static Key | insert (const QPixmap &pixmap) |
Inserts a copy of the given pixmap into the cache and returns a key that can be used to retrieve it. More... | |
static void | remove (const QString &key) |
Removes the pixmap associated with key from the cache. More... | |
static void | remove (const Key &key) |
Removes the pixmap associated with key from the cache and releases the key for a future insertion. More... | |
static bool | replace (const Key &key, const QPixmap &pixmap) |
Replaces the pixmap associated with the given key with the pixmap specified. More... | |
static void | setCacheLimit (int) |
Sets the cache limit to n kilobytes. More... | |
The QPixmapCache class provides an application-wide cache for pixmaps.
This class is a tool for optimized drawing with QPixmap. You can use it to store temporary pixmaps that are expensive to generate without using more storage space than cacheLimit(). Use insert() to insert pixmaps, find() to find them, and clear() to empty the cache.
QPixmapCache contains no member data, only static functions to access the global pixmap cache. It creates an internal QCache object for caching the pixmaps.
The cache associates a pixmap with a user-provided string as a key, or with a QPixmapCache::Key that the cache generates. Using QPixmapCache::Key for keys is faster than using strings. The string API is very convenient for complex keys but the QPixmapCache::Key API will be very efficient and convenient for a one-to-one object-to-pixmap mapping in this case, you can store the keys as members of an object.
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 QHash and QCache classes.
The cache becomes full when the total size of all pixmaps in the cache exceeds cacheLimit(). 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 setCacheLimit() with the required value. A pixmap takes roughly (width * height * depth)/8 bytes of memory.
The Qt Quarterly article Optimizing with QPixmapCache explains how to use QPixmapCache to speed up applications by caching the results of painting.
Definition at line 57 of file qpixmapcache.h.
|
static |
Returns the cache limit (in kilobytes).
The default cache limit is 2048 KB on embedded platforms, 10240 KB on desktop platforms.
Definition at line 620 of file qpixmapcache.cpp.
Referenced by QItemDelegate::selected().
|
static |
Removes all pixmaps from the cache.
Definition at line 666 of file qpixmapcache.cpp.
Referenced by qt_cleanup(), QGtkStyle::unpolish(), and QGtkStyleUpdateScheduler::updateTheme().
Example:
Definition at line 493 of file qpixmapcache.cpp.
Referenced by QGraphicsEffectSource::draw(), QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(), QMacStylePrivate::drawColorlessButton(), QMacStylePrivate::drawCombobox(), QPlastiqueStyle::drawComplexControl(), QCleanlooksStyle::drawComplexControl(), QWindowsVistaStyle::drawControl(), QPlastiqueStyle::drawControl(), QCleanlooksStyle::drawControl(), QGraphicsScenePrivate::drawItemHelper(), QWindowsVistaStyle::drawPrimitive(), QPlastiqueStyle::drawPrimitive(), QWindowsStyle::drawPrimitive(), QGtkStyle::drawPrimitive(), QMacStylePrivate::drawTableHeader(), QDeclarativeRectangle::generateBorderedRect(), QDeclarativeRectangle::generateRoundedRect(), generateWavyPixmap(), QFileIconProviderPrivate::getWinIcon(), QPixmap::load(), QGtkPainter::paintArrow(), QGtkPainter::paintBox(), QGtkPainter::paintBoxGap(), QGtkPainter::paintCheckbox(), QGtkPainter::paintExpander(), QGtkPainter::paintExtention(), QGtkPainter::paintFlatBox(), QGtkPainter::paintFocus(), QGtkPainter::paintHandle(), QGtkPainter::paintHline(), QGtkPainter::paintOption(), QGtkPainter::paintResizeGrip(), QGtkPainter::paintShadow(), QGtkPainter::paintSlider(), QGtkPainter::paintVline(), QSvgIconEngine::pixmap(), QGraphicsEffectSource::pixmap(), PixmapEntry::pixmap(), QPixmapIconEngine::pixmap(), qBrushDark(), qBrushLight(), qBrushSetAlphaF(), qDrawPlainRect(), qt_mac_constructQIconFromIconRef(), qt_patternForAlpha(), qt_pixmapForBrush(), qt_plastique_draw_gradient(), QGraphicsItem::scroll(), and QItemDelegate::selected().
Looks for a cached pixmap associated with the given key in the cache.
If the pixmap is found, the function sets pixmap to that pixmap and returns true; otherwise it leaves pixmap alone and returns false.
Example:
Definition at line 521 of file qpixmapcache.cpp.
Looks for a cached pixmap associated with the given key in the cache.
If the pixmap is found, the function sets pixmap to that pixmap and returns true; otherwise it leaves pixmap alone and returns false. If the pixmap is not found, it means that the key is no longer valid, so it will be released for the next insertion.
Definition at line 538 of file qpixmapcache.cpp.
Inserts a copy of the pixmap pixmap associated with the key into the cache.
All pixmaps inserted by the Qt library have a key starting with "$qt", so your own pixmap keys should never begin "$qt".
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.
The oldest pixmaps (least recently accessed in the cache) are deleted when more space is needed.
The function returns true if the object was inserted into the cache; otherwise it returns false.
Definition at line 569 of file qpixmapcache.cpp.
Referenced by QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(), QMacStylePrivate::drawColorlessButton(), QMacStylePrivate::drawCombobox(), QPlastiqueStyle::drawComplexControl(), QCleanlooksStyle::drawComplexControl(), QWindowsVistaStyle::drawControl(), QPlastiqueStyle::drawControl(), QCleanlooksStyle::drawControl(), QGraphicsScenePrivate::drawItemHelper(), QWindowsVistaStyle::drawPrimitive(), QPlastiqueStyle::drawPrimitive(), QWindowsStyle::drawPrimitive(), QGtkStyle::drawPrimitive(), QMacStylePrivate::drawTableHeader(), QDeclarativeRectangle::generateBorderedRect(), QDeclarativeRectangle::generateRoundedRect(), generateWavyPixmap(), QFileIconProviderPrivate::getWinIcon(), QPixmap::load(), QGtkPainter::paintArrow(), QGtkPainter::paintBox(), QGtkPainter::paintBoxGap(), QGtkPainter::paintCheckbox(), QGtkPainter::paintExpander(), QGtkPainter::paintExtention(), QGtkPainter::paintFlatBox(), QGtkPainter::paintFocus(), QGtkPainter::paintHandle(), QGtkPainter::paintHline(), QGtkPainter::paintOption(), QGtkPainter::paintResizeGrip(), QGtkPainter::paintShadow(), QGtkPainter::paintSlider(), QGtkPainter::paintVline(), QSvgIconEngine::pixmap(), QGraphicsEffectSource::pixmap(), PixmapEntry::pixmap(), QPixmapIconEngine::pixmap(), qBrushDark(), qBrushLight(), qBrushSetAlphaF(), qDrawPlainRect(), qt_mac_constructQIconFromIconRef(), qt_patternForAlpha(), qt_pixmapForBrush(), qt_plastique_draw_gradient(), QGraphicsItem::scroll(), and QItemDelegate::selected().
|
static |
Inserts a copy of the given pixmap into the cache and returns a key that can be used to retrieve it.
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.
The oldest pixmaps (least recently accessed in the cache) are deleted when more space is needed.
Definition at line 589 of file qpixmapcache.cpp.
|
static |
Removes the pixmap associated with key from the cache.
Definition at line 643 of file qpixmapcache.cpp.
Referenced by QGraphicsScenePrivate::drawItemHelper(), QGraphicsEffectSourcePrivate::invalidateCache(), QGraphicsItemCache::purge(), and QGraphicsItem::scroll().
|
static |
Removes the pixmap associated with key from the cache and releases the key for a future insertion.
Definition at line 654 of file qpixmapcache.cpp.
Replaces the pixmap associated with the given key with the pixmap specified.
Returns true if the pixmap has been correctly inserted into the cache; otherwise returns false.
Definition at line 603 of file qpixmapcache.cpp.
|
static |
Sets the cache limit to n kilobytes.
The default setting is 2048 KB on embedded platforms, 10240 KB on desktop platforms.
Definition at line 634 of file qpixmapcache.cpp.
Referenced by QItemDelegate::selected().