Qt 4.8
Public Functions | Static Public Functions | Private Types | Properties | List of all members
QPMCache Class Reference
Inheritance diagram for QPMCache:
QObject QCache< QPixmapCache::Key, QPixmapCacheEntry >

Public Functions

QList< QPair< QString, QPixmap > > allPixmaps () const
 
void clear ()
 
QPixmapCache::Key createKey ()
 
bool flushDetachedPixmaps (bool nt)
 
bool insert (const QString &key, const QPixmap &pixmap, int cost)
 
QPixmapCache::Key insert (const QPixmap &pixmap, int cost)
 
QPixmapobject (const QString &key) const
 
QPixmapobject (const QPixmapCache::Key &key) const
 
 QPMCache ()
 
void releaseKey (const QPixmapCache::Key &key)
 
bool remove (const QString &key)
 
bool remove (const QPixmapCache::Key &key)
 
bool replace (const QPixmapCache::Key &key, const QPixmap &pixmap, int cost)
 
void resizeKeyArray (int size)
 
void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
 ~QPMCache ()
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 
- Public Functions inherited from QCache< QPixmapCache::Key, QPixmapCacheEntry >
void clear ()
 
bool contains (const QPixmapCache::Key &key) const
 
int count () const
 
bool insert (const QPixmapCache::Key &key, QPixmapCacheEntry *object, int cost=1)
 
bool isEmpty () const
 
QList< QPixmapCache::Keykeys () const
 
int maxCost () const
 
QPixmapCacheEntryobject (const QPixmapCache::Key &key) const
 
QPixmapCacheEntryoperator[] (const QPixmapCache::Key &key) const
 
 QCache (int maxCost=100)
 
bool remove (const QPixmapCache::Key &key)
 
void setMaxCost (int m)
 
int size () const
 
QPixmapCacheEntrytake (const QPixmapCache::Key &key)
 
int totalCost () const
 
 ~QCache ()
 

Static Public Functions

static QPixmapCache::KeyDataget (const QPixmapCache::Key &key)
 
static QPixmapCache::KeyDatagetKeyData (QPixmapCache::Key *key)
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 

Private Types

enum  { soon_time = 10000, flush_time = 30000 }
 

Properties

QHash< QString, QPixmapCache::KeycacheKeys
 
int freeKey
 
int * keyArray
 
int keyArraySize
 
int ps
 
bool t
 
int theid
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 180 of file qpixmapcache.cpp.

Enumerations

◆ anonymous enum

anonymous enum
private
Enumerator
soon_time 
flush_time 

Definition at line 211 of file qpixmapcache.cpp.

Constructors and Destructors

◆ QPMCache()

QPMCache::QPMCache ( )

Definition at line 230 of file qpixmapcache.cpp.

231  : QObject(0),
233  keyArray(0), theid(0), ps(0), keyArraySize(0), freeKey(0), t(false)
234 {
235 }
int * keyArray
int keyArraySize
static int cache_limit
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753

◆ ~QPMCache()

QPMCache::~QPMCache ( )

Definition at line 236 of file qpixmapcache.cpp.

237 {
238  clear();
239  free(keyArray);
240 }
int * keyArray
void clear()

Functions

◆ allPixmaps()

QList< QPair< QString, QPixmap > > QPMCache::allPixmaps ( ) const

Definition at line 451 of file qpixmapcache.cpp.

452 {
455  while (it != cacheKeys.end()) {
457  if (ptr)
459  ++it;
460  }
461  return r;
462 }
T * object(const Key &key) const
Definition: qcache.h:147
#define it(className, varName)
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
const T * ptr(const T &t)
QHash< QString, QPixmapCache::Key > cacheKeys
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
const Key key(const T &value) const
Returns the first key mapped to value.
Definition: qhash.h:674
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:464
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ clear()

void QPMCache::clear ( )

Definition at line 431 of file qpixmapcache.cpp.

Referenced by ~QPMCache().

432 {
433  free(keyArray);
434  keyArray = 0;
435  freeKey = 0;
436  keyArraySize = 0;
437  //Mark all keys as invalid
439  for (int i = 0; i < keys.size(); ++i)
440  keys.at(i).d->isValid = false;
442 }
int * keyArray
int keyArraySize
void clear()
Definition: qcache.h:138
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QList< QPixmapCache::Key > keys() const
Definition: qcache.h:112
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ createKey()

QPixmapCache::Key QPMCache::createKey ( )

Definition at line 408 of file qpixmapcache.cpp.

Referenced by insert(), and replace().

409 {
410  if (freeKey == keyArraySize)
412  int id = freeKey;
413  freeKey = keyArray[id];
416  d->key = ++id;
417  return key;
418 }
double d
Definition: qnumeric_p.h:62
int * keyArray
int keyArraySize
void resizeKeyArray(int size)
static QPixmapCache::KeyData * getKeyData(QPixmapCache::Key *key)
The QPixmapCache::Key class can be used for efficient access to the QPixmapCache. ...
Definition: qpixmapcache.h:61
int key

◆ flushDetachedPixmaps()

bool QPMCache::flushDetachedPixmaps ( bool  nt)

Definition at line 256 of file qpixmapcache.cpp.

Referenced by timerEvent().

257 {
258  int mc = maxCost();
259  setMaxCost(nt ? totalCost() * 3 / 4 : totalCost() -1);
260  setMaxCost(mc);
261  ps = totalCost();
262 
263  bool any = false;
265  while (it != cacheKeys.end()) {
266  if (!contains(it.value())) {
267  releaseKey(it.value());
268  it = cacheKeys.erase(it);
269  any = true;
270  } else {
271  ++it;
272  }
273  }
274 
275  return any;
276 }
#define it(className, varName)
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
void releaseKey(const QPixmapCache::Key &key)
#define nt(var, enu)
QHash< QString, QPixmapCache::Key > cacheKeys
bool contains(const QPixmapCache::Key &key) const
Definition: qcache.h:118
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:464
iterator erase(iterator it)
Removes the (key, value) pair associated with the iterator pos from the hash, and returns an iterator...
Definition: qhash.h:827

◆ get()

static QPixmapCache::KeyData* QPMCache::get ( const QPixmapCache::Key key)
inlinestatic

Definition at line 202 of file qpixmapcache.cpp.

Referenced by qHash().

203  {return key.d;}

◆ getKeyData()

QPixmapCache::KeyData * QPMCache::getKeyData ( QPixmapCache::Key key)
static

Definition at line 444 of file qpixmapcache.cpp.

Referenced by createKey().

445 {
446  if (!key->d)
447  key->d = new QPixmapCache::KeyData;
448  return key->d;
449 }

◆ insert() [1/2]

bool QPMCache::insert ( const QString key,
const QPixmap pixmap,
int  cost 
)

Definition at line 317 of file qpixmapcache.cpp.

318 {
319  QPixmapCache::Key cacheKey;
320  QPixmapCache::Key oldCacheKey = cacheKeys.value(key);
321  //If for the same key we add already a pixmap we should delete it
322  if (oldCacheKey.d) {
324  cacheKeys.remove(key);
325  }
326 
327  //we create a new key the old one has been removed
328  cacheKey = createKey();
329 
330  bool success = QCache<QPixmapCache::Key, QPixmapCacheEntry>::insert(cacheKey, new QPixmapCacheEntry(cacheKey, pixmap), cost);
331  if (success) {
332  cacheKeys.insert(key, cacheKey);
333  if (!theid) {
335  t = false;
336  }
337  } else {
338  //Insertion failed we released the new allocated key
339  releaseKey(cacheKey);
340  }
341  return success;
342 }
int startTimer(int interval)
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer...
Definition: qobject.cpp:1623
int remove(const Key &key)
Removes all the items that have the key from the hash.
Definition: qhash.h:784
QPixmapCache::Key createKey()
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
void releaseKey(const QPixmapCache::Key &key)
QHash< QString, QPixmapCache::Key > cacheKeys
bool insert(const Key &key, T *object, int cost=1)
Definition: qcache.h:181
The QPixmapCache::Key class can be used for efficient access to the QPixmapCache. ...
Definition: qpixmapcache.h:61
bool remove(const Key &key)
Definition: qcache.h:155

◆ insert() [2/2]

QPixmapCache::Key QPMCache::insert ( const QPixmap pixmap,
int  cost 
)

Definition at line 344 of file qpixmapcache.cpp.

345 {
346  QPixmapCache::Key cacheKey = createKey();
347  bool success = QCache<QPixmapCache::Key, QPixmapCacheEntry>::insert(cacheKey, new QPixmapCacheEntry(cacheKey, pixmap), cost);
348  if (success) {
349  if (!theid) {
351  t = false;
352  }
353  } else {
354  //Insertion failed we released the key and return an invalid one
355  releaseKey(cacheKey);
356  }
357  return cacheKey;
358 }
int startTimer(int interval)
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer...
Definition: qobject.cpp:1623
QPixmapCache::Key createKey()
void releaseKey(const QPixmapCache::Key &key)
bool insert(const Key &key, T *object, int cost=1)
Definition: qcache.h:181
The QPixmapCache::Key class can be used for efficient access to the QPixmapCache. ...
Definition: qpixmapcache.h:61

◆ object() [1/2]

QPixmap * QPMCache::object ( const QString key) const

Definition at line 292 of file qpixmapcache.cpp.

293 {
294  QPixmapCache::Key cacheKey = cacheKeys.value(key);
295  if (!cacheKey.d || !cacheKey.d->isValid) {
296  const_cast<QPMCache *>(this)->cacheKeys.remove(key);
297  return 0;
298  }
300  //We didn't find the pixmap in the cache, the key is not valid anymore
301  if (!ptr) {
302  const_cast<QPMCache *>(this)->cacheKeys.remove(key);
303  }
304  return ptr;
305 }
T * object(const Key &key) const
Definition: qcache.h:147
int remove(const Key &key)
Removes all the items that have the key from the hash.
Definition: qhash.h:784
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
const T * ptr(const T &t)
QHash< QString, QPixmapCache::Key > cacheKeys
The QPixmapCache::Key class can be used for efficient access to the QPixmapCache. ...
Definition: qpixmapcache.h:61
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71

◆ object() [2/2]

QPixmap * QPMCache::object ( const QPixmapCache::Key key) const

Definition at line 307 of file qpixmapcache.cpp.

308 {
309  Q_ASSERT(key.d->isValid);
311  //We didn't find the pixmap in the cache, the key is not valid anymore
312  if (!ptr)
313  const_cast<QPMCache *>(this)->releaseKey(key);
314  return ptr;
315 }
T * object(const Key &key) const
Definition: qcache.h:147
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void releaseKey(const QPixmapCache::Key &key)
const T * ptr(const T &t)
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71

◆ releaseKey()

void QPMCache::releaseKey ( const QPixmapCache::Key key)

Definition at line 420 of file qpixmapcache.cpp.

Referenced by flushDetachedPixmaps(), insert(), object(), and replace().

421 {
422  if (key.d->key > keyArraySize || key.d->key <= 0)
423  return;
424  key.d->key--;
425  keyArray[key.d->key] = freeKey;
426  freeKey = key.d->key;
427  key.d->isValid = false;
428  key.d->key = 0;
429 }
int * keyArray
int keyArraySize

◆ remove() [1/2]

bool QPMCache::remove ( const QString key)

Definition at line 382 of file qpixmapcache.cpp.

383 {
384  QPixmapCache::Key cacheKey = cacheKeys.value(key);
385  //The key was not in the cache
386  if (!cacheKey.d)
387  return false;
388  cacheKeys.remove(key);
390 }
int remove(const Key &key)
Removes all the items that have the key from the hash.
Definition: qhash.h:784
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
QHash< QString, QPixmapCache::Key > cacheKeys
The QPixmapCache::Key class can be used for efficient access to the QPixmapCache. ...
Definition: qpixmapcache.h:61
bool remove(const Key &key)
Definition: qcache.h:155

◆ remove() [2/2]

bool QPMCache::remove ( const QPixmapCache::Key key)

Definition at line 392 of file qpixmapcache.cpp.

393 {
395 }
bool remove(const Key &key)
Definition: qcache.h:155

◆ replace()

bool QPMCache::replace ( const QPixmapCache::Key key,
const QPixmap pixmap,
int  cost 
)

Definition at line 360 of file qpixmapcache.cpp.

361 {
362  Q_ASSERT(key.d->isValid);
363  //If for the same key we had already an entry so we should delete the pixmap and use the new one
365 
366  QPixmapCache::Key cacheKey = createKey();
367 
368  bool success = QCache<QPixmapCache::Key, QPixmapCacheEntry>::insert(cacheKey, new QPixmapCacheEntry(cacheKey, pixmap), cost);
369  if (success) {
370  if(!theid) {
372  t = false;
373  }
374  const_cast<QPixmapCache::Key&>(key) = cacheKey;
375  } else {
376  //Insertion failed we released the key
377  releaseKey(cacheKey);
378  }
379  return success;
380 }
int startTimer(int interval)
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer...
Definition: qobject.cpp:1623
QPixmapCache::Key createKey()
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void releaseKey(const QPixmapCache::Key &key)
bool insert(const Key &key, T *object, int cost=1)
Definition: qcache.h:181
The QPixmapCache::Key class can be used for efficient access to the QPixmapCache. ...
Definition: qpixmapcache.h:61
int key
bool remove(const Key &key)
Definition: qcache.h:155

◆ resizeKeyArray()

void QPMCache::resizeKeyArray ( int  size)

Definition at line 397 of file qpixmapcache.cpp.

Referenced by createKey().

398 {
399  if (size <= keyArraySize || size == 0)
400  return;
401  keyArray = q_check_ptr(reinterpret_cast<int *>(realloc(keyArray,
402  size * sizeof(int))));
403  for (int i = keyArraySize; i != size; ++i)
404  keyArray[i] = i + 1;
405  keyArraySize = size;
406 }
T * q_check_ptr(T *p)
Definition: qglobal.h:1857
int * keyArray
int keyArraySize

◆ timerEvent()

void QPMCache::timerEvent ( QTimerEvent event)
virtual

This event handler can be reimplemented in a subclass to receive timer events for the object.

QTimer provides a higher-level interface to the timer functionality, and also more general information about timers. The timer event is passed in the event parameter.

See also
startTimer(), killTimer(), event()

Reimplemented from QObject.

Definition at line 278 of file qpixmapcache.cpp.

279 {
280  bool nt = totalCost() == ps;
281  if (!flushDetachedPixmaps(nt)) {
282  killTimer(theid);
283  theid = 0;
284  } else if (nt != t) {
285  killTimer(theid);
287  t = nt;
288  }
289 }
int startTimer(int interval)
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer...
Definition: qobject.cpp:1623
#define nt(var, enu)
bool flushDetachedPixmaps(bool nt)
void killTimer(int id)
Kills the timer with timer identifier, id.
Definition: qobject.cpp:1650

Properties

◆ cacheKeys

QHash<QString, QPixmapCache::Key> QPMCache::cacheKeys
private

Definition at line 217 of file qpixmapcache.cpp.

Referenced by allPixmaps(), flushDetachedPixmaps(), insert(), object(), and remove().

◆ freeKey

int QPMCache::freeKey
private

Definition at line 216 of file qpixmapcache.cpp.

Referenced by clear(), createKey(), and releaseKey().

◆ keyArray

int* QPMCache::keyArray
private

Definition at line 212 of file qpixmapcache.cpp.

Referenced by clear(), createKey(), releaseKey(), resizeKeyArray(), and ~QPMCache().

◆ keyArraySize

int QPMCache::keyArraySize
private

Definition at line 215 of file qpixmapcache.cpp.

Referenced by clear(), createKey(), releaseKey(), and resizeKeyArray().

◆ ps

int QPMCache::ps
private

Definition at line 214 of file qpixmapcache.cpp.

Referenced by flushDetachedPixmaps(), and timerEvent().

◆ t

bool QPMCache::t
private

Definition at line 218 of file qpixmapcache.cpp.

Referenced by insert(), replace(), and timerEvent().

◆ theid

int QPMCache::theid
private

Definition at line 213 of file qpixmapcache.cpp.

Referenced by insert(), replace(), and timerEvent().


The documentation for this class was generated from the following file: