From 6200d413487517eadb8f4696d92a38fc73ba737c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trond=20Kjern=C3=A5sen?= <trond@trolltech.com>
Date: Mon, 11 May 2009 16:40:33 +0200
Subject: Improved caching of QSvgIconEngine::actualSize() calls.

If an application calls QIcon::actualSize() for SVG based icons, before
the icon is drawn for the first time, the actualSize() call will
result in the SVG file being loaded and parsed for each call.
Instead of doing that, just render a pixmap of the queried size and
then the resulting actualSize() calls will used the size of the
cached pixmap.

Task-number: related to 251106
Reviewed-by: Kim
---
 src/plugins/iconengines/svgiconengine/qsvgiconengine.cpp | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/src/plugins/iconengines/svgiconengine/qsvgiconengine.cpp b/src/plugins/iconengines/svgiconengine/qsvgiconengine.cpp
index c7249d3..3273513 100644
--- a/src/plugins/iconengines/svgiconengine/qsvgiconengine.cpp
+++ b/src/plugins/iconengines/svgiconengine/qsvgiconengine.cpp
@@ -122,16 +122,10 @@ QSize QSvgIconEngine::actualSize(const QSize &size, QIcon::Mode mode,
             return size;
     }
 
-    QSvgRenderer renderer;
-    d->loadDataForModeAndState(&renderer, mode, state);
-    if (renderer.isValid()) {
-        QSize defaultSize = renderer.defaultSize();
-        if (!defaultSize.isNull())
-            defaultSize.scale(size, Qt::KeepAspectRatio);
-        return defaultSize;
-    } else {
+    QPixmap pm = pixmap(size, mode, state);
+    if (pm.isNull())
         return QSize();
-    }
+    return pm.size();
 }
 
 void QSvgIconEnginePrivate::loadDataForModeAndState(QSvgRenderer *renderer, QIcon::Mode mode, QIcon::State state)
-- 
cgit v0.12