Add method for checking of QPixmapCache::Key validity
We need a method to check whether a specified pixmap is still cached without touching the recently-accessed list for this pixmap. [ChangeLog][QtGui][QPixmapCache] Added QPixmapCache::Key::isValid(). Change-Id: I90fa4f67b569099b67b6207e78494beb3111b68e Reviewed-by: aavit <eirik.aavitsland@theqtcompany.com>
This commit is contained in:
parent
0d3464428e
commit
8f68d15789
@ -155,6 +155,16 @@ bool QPixmapCache::Key::operator ==(const Key &key) const
|
||||
\since 5.6
|
||||
*/
|
||||
|
||||
/*!
|
||||
Returns \c true if there is a cached pixmap associated with this key.
|
||||
Otherwise, if pixmap was flushed, the key is no longer valid.
|
||||
\since 5.7
|
||||
*/
|
||||
bool QPixmapCache::Key::isValid() const Q_DECL_NOTHROW
|
||||
{
|
||||
return d && d->isValid;
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
*/
|
||||
|
@ -59,6 +59,7 @@ public:
|
||||
Key &operator =(const Key &other);
|
||||
|
||||
void swap(Key &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
|
||||
bool isValid() const Q_DECL_NOTHROW;
|
||||
|
||||
private:
|
||||
KeyData *d;
|
||||
|
@ -147,7 +147,7 @@ void tst_QPixmapCache::setCacheLimit()
|
||||
QVERIFY(QPixmapCache::find(key, p1) == 0);
|
||||
QPixmapCache::setCacheLimit(1000);
|
||||
key = QPixmapCache::insert(*p1);
|
||||
QCOMPARE(getPrivate(key)->isValid, true);
|
||||
QVERIFY(key.isValid());
|
||||
QCOMPARE(getPrivate(key)->key, 1);
|
||||
|
||||
delete p1;
|
||||
@ -189,7 +189,7 @@ void tst_QPixmapCache::setCacheLimit()
|
||||
key2 = QPixmapCache::insert(*p1);
|
||||
QCOMPARE(getPrivate(key2)->key, 1);
|
||||
//This old key is not valid anymore after the flush
|
||||
QCOMPARE(getPrivate(key)->isValid, false);
|
||||
QVERIFY(!key.isValid());
|
||||
QVERIFY(QPixmapCache::find(key, &p2) == 0);
|
||||
delete p1;
|
||||
}
|
||||
@ -233,7 +233,7 @@ void tst_QPixmapCache::find()
|
||||
|
||||
//at that time the first key has been erase because no more place in the cache
|
||||
QVERIFY(QPixmapCache::find(key, &p1) == 0);
|
||||
QCOMPARE(getPrivate(key)->isValid, false);
|
||||
QVERIFY(!key.isValid());
|
||||
}
|
||||
|
||||
void tst_QPixmapCache::insert()
|
||||
@ -313,7 +313,7 @@ void tst_QPixmapCache::replace()
|
||||
p2.fill(Qt::yellow);
|
||||
|
||||
QPixmapCache::Key key = QPixmapCache::insert(p1);
|
||||
QCOMPARE(getPrivate(key)->isValid, true);
|
||||
QVERIFY(key.isValid());
|
||||
|
||||
QPixmap p3;
|
||||
QVERIFY(QPixmapCache::find(key, &p3) == 1);
|
||||
@ -321,7 +321,7 @@ void tst_QPixmapCache::replace()
|
||||
QPixmapCache::replace(key, p2);
|
||||
|
||||
QVERIFY(QPixmapCache::find(key, &p3) == 1);
|
||||
QCOMPARE(getPrivate(key)->isValid, true);
|
||||
QVERIFY(key.isValid());
|
||||
QCOMPARE(getPrivate(key)->key, 1);
|
||||
|
||||
QCOMPARE(p3.width(), 10);
|
||||
@ -438,7 +438,7 @@ void tst_QPixmapCache::clear()
|
||||
|
||||
for (int k = 0; k < numberOfKeys; ++k) {
|
||||
QVERIFY(QPixmapCache::find(keys.at(k), &p1) == 0);
|
||||
QCOMPARE(getPrivate(keys[k])->isValid, false);
|
||||
QVERIFY(!keys[k].isValid());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user