class KPixmapCache


Module kdeui
Namespace
Class KPixmapCache
Inherits
General-purpose pixmap cache for KDE.

The pixmap cache can be used to store pixmaps which can later be loaded from the cache very quickly.

It's most common use is storing SVG images which might be expensive to render every time they are used. With the cache you can render each SVG only once and later use the stored version unless the SVG file or requested pixmap size changes.

KPixmapCache's API is similar to that of the QPixmapCache so if you're already using the latter then all you need to do is creating a KPixmapCache object (unlike QPixmapCache, KPixmapCache doesn't have many static methods) and calling insert() and find() method on that object:

// Create KPixmapCache object
KPixmapCache* cache = new KPixmapCache("myapp-pixmaps");
// Load a pixmap
QPixmap pix;
if (!cache->find("pixmap-1", pix)) {
// Pixmap isn't in the cache, create it and insert to cache
pix = createPixmapFromData();
cache->insert("pixmap-1", pix);
}
// Use pix

The above example illustrates that you can also cache pixmaps created from some data. In case such data is updated, you might need to discard cache contents using discard() method:

// Discard the cache if it's too old
if (cache->timestamp() < mydataTimestamp()) {
cache->discard();
}
// Now the cache contains up-to-date data
As demonstrated, you can use cache's timestamp() method to see when the cache was created. If necessary, you can also change the timestamp using setTimestamp() method.


enums

enum details

methods