summaryrefslogtreecommitdiff
path: root/src/gui/graphicsview/qgraphicsitem.cpp
diff options
context:
space:
mode:
authorAlexis Menard <alexis.menard@nokia.com>2009-05-18 11:23:05 +0200
committerAlexis Menard <alexis.menard@nokia.com>2009-05-18 11:23:05 +0200
commit60a17320d39eed9cd82f38d07495161b2b2d5e42 (patch)
tree8b6b36806c35e2e384162bacf884e432ae919dc2 /src/gui/graphicsview/qgraphicsitem.cpp
parent3cc966afd45ac727126ea89bafa7c1aa1295226b (diff)
downloadqt4-tools-60a17320d39eed9cd82f38d07495161b2b2d5e42.tar.gz
Add an extension to QPixmapCache to get rid of strings.
This commit add a new API to add/find/remove pixmaps into QPixmapCache. This new extension is based on a key that the cache give you during the insertion. This key is internally a int which makes all operations in the cache much more faster that the string approach. Auto-tests has been extended as well and a benchmark has been added to compare both approach. I also depecrate the find method for the string API to have a method pointer based and not reference based like the Qt policy says. Reviewed-by: bnilsen Reviewed-by: andreas Followed-deeply-by: trond
Diffstat (limited to 'src/gui/graphicsview/qgraphicsitem.cpp')
-rw-r--r--src/gui/graphicsview/qgraphicsitem.cpp11
1 files changed, 3 insertions, 8 deletions
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp
index ec08aaf442..72b832a455 100644
--- a/src/gui/graphicsview/qgraphicsitem.cpp
+++ b/src/gui/graphicsview/qgraphicsitem.cpp
@@ -978,6 +978,7 @@ void QGraphicsItemPrivate::initStyleOption(QStyleOptionGraphicsItem *option, con
void QGraphicsItemCache::purge()
{
QPixmapCache::remove(key);
+ key = QPixmapCache::Key();
QMutableMapIterator<QPaintDevice *, DeviceData> it(deviceData);
while (it.hasNext()) {
DeviceData &data = it.next().value();
@@ -1426,12 +1427,6 @@ void QGraphicsItem::setCacheMode(CacheMode mode, const QSize &logicalCacheSize)
cache->purge();
if (mode == ItemCoordinateCache) {
- if (cache->key.isEmpty()) {
- // Generate new simple pixmap cache key.
- QString tmp;
- tmp.sprintf("qgv-%p", this);
- cache->key = tmp;
- }
if (lastMode == mode && cache->fixedSize == logicalCacheSize)
noVisualChange = true;
cache->fixedSize = logicalCacheSize;
@@ -4205,7 +4200,7 @@ void QGraphicsItem::scroll(qreal dx, qreal dy, const QRectF &rect)
&& (d->cacheMode == ItemCoordinateCache && !c->fixedSize.isValid());
if (scrollCache) {
QPixmap pix;
- if (QPixmapCache::find(c->key, pix)) {
+ if (QPixmapCache::find(c->key, &pix)) {
// Adjust with 2 pixel margin. Notice the loss of precision
// when converting to QRect.
int adjust = 2;
@@ -4214,7 +4209,7 @@ void QGraphicsItem::scroll(qreal dx, qreal dy, const QRectF &rect)
_q_scrollPixmap(&pix, irect, dx, dy);
- QPixmapCache::insert(c->key, pix);
+ QPixmapCache::replace(c->key, pix);
// Translate the existing expose.
foreach (QRectF exposedRect, c->exposed)