From 4152e93bb7225a1781e95d22aec51f635c0f56b3 Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Wed, 18 Jul 2012 21:06:46 +0200 Subject: [PATCH] Add a cache for FilePath::icon(). --- src/core/FilePath.cpp | 23 ++++++++++++++++------- src/core/FilePath.h | 2 ++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/core/FilePath.cpp b/src/core/FilePath.cpp index 82e330d77..fd82de372 100644 --- a/src/core/FilePath.cpp +++ b/src/core/FilePath.cpp @@ -70,28 +70,37 @@ QIcon FilePath::applicationIcon() QIcon FilePath::icon(const QString& category, const QString& name, bool fromTheme) { - QIcon icon; + QString combinedName = category + "/" + name; + + QIcon icon = m_iconCache.value(combinedName); + + if (!icon.isNull()) { + return icon; + } if (fromTheme) { icon = QIcon::fromTheme(name); } if (icon.isNull()) { - QStringList pngSizes; - pngSizes << "16" << "22" << "24" << "32" << "48" << "64" << "128"; + QList pngSizes; + pngSizes << 16 << 22 << 24 << 32 << 48 << 64 << 128; QString filename; - Q_FOREACH (const QString& size, pngSizes) { - filename = QString("%1/icons/application/%2x%2/%3/%4.png").arg(m_dataPath, size, category, name); + Q_FOREACH (int size, pngSizes) { + filename = QString("%1/icons/application/%2x%2/%3.png").arg(m_dataPath, QString::number(size), + combinedName); if (QFile::exists(filename)) { - icon.addFile(filename); + icon.addFile(filename, QSize(size, size)); } } - filename = QString("%1/icons/application/scalable/%3/%4.svgz").arg(m_dataPath, category, name); + filename = QString("%1/icons/application/scalable/%3.svgz").arg(m_dataPath, combinedName); if (QFile::exists(filename)) { icon.addFile(filename); } } + m_iconCache.insert(combinedName, icon); + return icon; } diff --git a/src/core/FilePath.h b/src/core/FilePath.h index 5c5339d0d..d2d8c7390 100644 --- a/src/core/FilePath.h +++ b/src/core/FilePath.h @@ -18,6 +18,7 @@ #ifndef KEEPASSX_FILEPATH_H #define KEEPASSX_FILEPATH_H +#include #include #include @@ -40,6 +41,7 @@ private: static FilePath* m_instance; QString m_dataPath; + QHash m_iconCache; Q_DISABLE_COPY(FilePath) };