From e4e26a9113464e8360a53e277c6347c87c9ddb2c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= <thorbjorn.lindeijer@nokia.com>
Date: Thu, 29 Jan 2009 15:19:34 +0100
Subject: [PATCH] Optimized qrc editor in case of large images

Prevented it from re-generating an icon for the large image every time
it needed to be drawn.
---
 src/shared/qrceditor/resourcefile.cpp | 21 +++++++++++----------
 src/shared/qrceditor/resourcefile_p.h |  2 ++
 2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/src/shared/qrceditor/resourcefile.cpp b/src/shared/qrceditor/resourcefile.cpp
index d6aa452cdcf..ae003d31532 100644
--- a/src/shared/qrceditor/resourcefile.cpp
+++ b/src/shared/qrceditor/resourcefile.cpp
@@ -619,12 +619,12 @@ QVariant ResourceModel::data(const QModelIndex &index, int role) const
     if (!index.isValid())
         return QVariant();
 
-    void * const internalPointer = index.internalPointer();
-    Node * const node = reinterpret_cast<Node *>(internalPointer);
-    Prefix const * const prefix = node->prefix();
-    File const * const file = node->file();
+    const void *internalPointer = index.internalPointer();
+    const Node *node = reinterpret_cast<const Node *>(internalPointer);
+    const Prefix *prefix = node->prefix();
+    File *file = node->file();
     Q_ASSERT(prefix);
-    bool const isFileNode = (prefix != node);
+    const bool isFileNode = (prefix != node);
 
     QVariant result;
 
@@ -654,12 +654,13 @@ QVariant ResourceModel::data(const QModelIndex &index, int role) const
         if (isFileNode) {
             // File node
             Q_ASSERT(file);
-            const QString path = m_resource_file.absolutePath(file->name);
-            if (iconFileExtension(path)) {
-                const QIcon icon(path);
-                if (!icon.isNull())
-                    result = icon;
+            if (file->icon.isNull()) {
+                const QString path = m_resource_file.absolutePath(file->name);
+                if (iconFileExtension(path))
+                    file->icon = QIcon(path);
             }
+            if (!file->icon.isNull())
+                result = file->icon;
         }
         break;
     default:
diff --git a/src/shared/qrceditor/resourcefile_p.h b/src/shared/qrceditor/resourcefile_p.h
index 00d999c90c6..4a7d510dc48 100644
--- a/src/shared/qrceditor/resourcefile_p.h
+++ b/src/shared/qrceditor/resourcefile_p.h
@@ -40,6 +40,7 @@
 #include <QtCore/QMap>
 #include <QtCore/QString>
 #include <QtCore/QStringList>
+#include <QtGui/QIcon>
 
 #include "shared_global_p.h"
 
@@ -89,6 +90,7 @@ struct File : public Node {
     bool operator != (const File &other) const { return name != other.name; }
     QString name;
     QString alias;
+    QIcon icon;
 };
 
 class FileList : public QList<File *>
-- 
GitLab