From kde-commits Sat May 22 00:44:57 2010 From: Michael Pyne Date: Sat, 22 May 2010 00:44:57 +0000 To: kde-commits Subject: KDE/kdelibs/kdeui/icons Message-Id: <20100522004457.56FF8AC8BC () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=127448914711853 SVN commit 1129340 by mpyne: When we cache "unknown" icons, only cache the image, do not cache the path. By doing this we can properly handle the "canReturnNull" parameter if it changes on a later call to loadIcon. This should fix the unit tests for KIconLoader (they all pass for me now) CCMAIL:dfaure@kde.org M +21 -1 kiconloader.cpp --- trunk/KDE/kdelibs/kdeui/icons/kiconloader.cpp #1129339:1129340 @@ -790,7 +790,7 @@ // Not a SVG or SVGZ img = QImage(path, ext.toLatin1()); - if (size != 0) { + if (size != 0 && !img.isNull()) { img = img.scaled(size, size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); } } @@ -1217,12 +1217,21 @@ // See if the image is already cached. QString key = d->makeCacheKey(name, group, overlays, size, state); QPixmap pix; + bool iconWasUnknown = false; K3Icon icon; if (d->findCachedPixmapWithPath(key, pix, icon.path)) { + // We cache the pixmap for the event of trying to find an unknown icon + // with canReturnNull set to false, but if we *can* return null then + // we should do so when necessary. + if (canReturnNull && icon.path.isEmpty()) { + return QPixmap(); + } + if (path_store) { *path_store = icon.path; } + return pix; } @@ -1260,6 +1269,7 @@ // We keep going in the function so we can ensure this result gets cached. if (icon.path.isEmpty() && !canReturnNull) { icon.path = d->unknownIconPath(size); + iconWasUnknown = true; } QImage img = d->createIconImage(icon.path, size); @@ -1293,8 +1303,18 @@ // have to transfer so much to the graphics card. d->drawOverlays(this, group, state, pix, overlays); + // Don't add the path to our unknown icon to the cache, only cache the + // actual image. + if (iconWasUnknown) { + icon.path = QString(); + } + d->insertCachedPixmapWithPath(key, pix, icon.path); + if (path_store) { + *path_store = icon.path; + } + return pix; }