summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gui/image/qpixmapcache.cpp10
-rw-r--r--src/gui/image/qpixmapcache.h1
-rw-r--r--tests/auto/gui/image/qpixmapcache/tst_qpixmapcache.cpp12
3 files changed, 17 insertions, 6 deletions
diff --git a/src/gui/image/qpixmapcache.cpp b/src/gui/image/qpixmapcache.cpp
index 71a79745e8..04e1d442b0 100644
--- a/src/gui/image/qpixmapcache.cpp
+++ b/src/gui/image/qpixmapcache.cpp
@@ -156,6 +156,16 @@ bool QPixmapCache::Key::operator ==(const Key &key) const
*/
/*!
+ 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
*/
QPixmapCache::Key &QPixmapCache::Key::operator =(const Key &other)
diff --git a/src/gui/image/qpixmapcache.h b/src/gui/image/qpixmapcache.h
index 37a0588e06..ca18f299a7 100644
--- a/src/gui/image/qpixmapcache.h
+++ b/src/gui/image/qpixmapcache.h
@@ -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;
diff --git a/tests/auto/gui/image/qpixmapcache/tst_qpixmapcache.cpp b/tests/auto/gui/image/qpixmapcache/tst_qpixmapcache.cpp
index a3cf66da18..d1f76e8742 100644
--- a/tests/auto/gui/image/qpixmapcache/tst_qpixmapcache.cpp
+++ b/tests/auto/gui/image/qpixmapcache/tst_qpixmapcache.cpp
@@ -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());
}
}