Eneboo - Documentación para desarrolladores
Métodos públicos estáticos
Referencia de la Clase QPixmapCache

The QPixmapCache class provides an application-global cache for pixmaps. Más...

#include <qpixmapcache.h>

Lista de todos los miembros.

Métodos públicos estáticos

static int cacheLimit ()
static void setCacheLimit (int)
static QPixmapfind (const QString &key)
static bool find (const QString &key, QPixmap &)
static bool insert (const QString &key, QPixmap *)
static bool insert (const QString &key, const QPixmap &)
static void remove (const QString &key)
static void clear ()
static int cacheLimit ()
static void setCacheLimit (int)
static QPixmapfind (const QString &key)
static bool find (const QString &key, QPixmap &)
static bool insert (const QString &key, QPixmap *)
static bool insert (const QString &key, const QPixmap &)
static void remove (const QString &key)
static void clear ()

Descripción detallada

The QPixmapCache class provides an application-global 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.

For example, QRadioButton has a non-trivial visual representation so we don't want to regenerate a pixmap whenever a radio button is displayed or changes state. In the function QRadioButton::drawButton(), 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 nnn is a numerical value that specifies the the radio button state. If a pixmap is found, we bitBlt() 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 ten times faster than drawing the radio button. All radio buttons in the program share the cached pixmap since QPixmapCache is application-global.

QPixmapCache contains no member data, only static functions to access the global pixmap cache. It creates an internal QCache for caching the pixmaps.

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 QDict and QCache classes do exactly the same.

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 setCacheLimit(). A pixmap takes roughly width*height*depth/8 bytes of memory.

See the QCache documentation for more details about the cache mechanism.


Documentación de las funciones miembro

int QPixmapCache::cacheLimit ( ) [static]

Returns the cache limit (in kilobytes).

The default setting is 1024 kilobytes.

Ver también:
setCacheLimit().
static int QPixmapCache::cacheLimit ( ) [static]
void QPixmapCache::clear ( void  ) [static]

Removes all pixmaps from the cache.

static void QPixmapCache::clear ( ) [static]
bool QPixmapCache::find ( const QString key,
QPixmap pm 
) [static]

Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Looks for a cached pixmap associated with the key in the cache. If a pixmap is found, the function sets pm to that pixmap and returns TRUE; otherwise leaves pm alone and returns FALSE.

Example:

        QPixmap p;
        if ( !QPixmapCache::find("my_big_image", pm) ) {
            pm.load("bigimage.png");
            QPixmapCache::insert("my_big_image", pm);
        }
        painter->drawPixmap(0, 0, p);
static QPixmap* QPixmapCache::find ( const QString key) [static]
QPixmap * QPixmapCache::find ( const QString key) [static]

Returns the pixmap associated with the key in the cache, or null if there is no such pixmap.

Atención:
If valid, you should copy the pixmap immediately (this is fast). Subsequent insertions into the cache could cause the pointer to become invalid. For this reason, we recommend you use find(const QString&, QPixmap&) instead.

Example:

        QPixmap* pp;
        QPixmap p;
        if ( (pp=QPixmapCache::find("my_big_image", pm)) ) {
            p = *pp;
        } else {
            p.load("bigimage.png");
            QPixmapCache::insert("my_big_image", new QPixmap(p));
        }
        painter->drawPixmap(0, 0, p);
static bool QPixmapCache::find ( const QString key,
QPixmap  
) [static]
bool QPixmapCache::insert ( const QString key,
const QPixmap pm 
) [static]

Inserts a copy of the pixmap pm 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.

Ver también:
setCacheLimit().
static bool QPixmapCache::insert ( const QString key,
QPixmap  
) [static]
static bool QPixmapCache::insert ( const QString key,
const QPixmap  
) [static]
bool QPixmapCache::insert ( const QString key,
QPixmap pm 
) [static]

Inserts the pixmap pm associated with key into the cache. Returns TRUE if successful, or FALSE if the pixmap is too big for the cache.

Note: pm must be allocated on the heap (using new).

If this function returns FALSE, you must delete pm yourself.

If this function returns TRUE, do not use pm afterwards or keep references to it because any other insertions into the cache, whether 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.

Due to these dangers, we strongly recommend that you use insert(const QString&, const QPixmap&) instead.

static void QPixmapCache::remove ( const QString key) [static]
void QPixmapCache::remove ( const QString key) [static]

Removes the pixmap associated with key from the cache.

static void QPixmapCache::setCacheLimit ( int  ) [static]
void QPixmapCache::setCacheLimit ( int  n) [static]

Sets the cache limit to n kilobytes.

The default setting is 1024 kilobytes.

Ver también:
cacheLimit()

La documentación para esta clase fue generada a partir de los siguientes ficheros:
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'