From 00eb61543df10d8b5f8d11bb17f93adb9a16bb34 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 20 May 2020 22:53:42 +0800 Subject: [PATCH 1/3] Make the icon cache a class variable --- src/gui/uithememanager.cpp | 14 +++++++------- src/gui/uithememanager.h | 2 ++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/gui/uithememanager.cpp b/src/gui/uithememanager.cpp index 43d076e6f..15cf93fe4 100644 --- a/src/gui/uithememanager.cpp +++ b/src/gui/uithememanager.cpp @@ -31,7 +31,6 @@ #include #include -#include #include #include #include @@ -127,14 +126,15 @@ QIcon UIThemeManager::getIcon(const QString &iconId, const QString &fallback) co return icon; } #endif - // cache to avoid rescaling svg icons - static QHash iconCache; - const auto iter = iconCache.find(iconId); - if (iter != iconCache.end()) + + // Cache to avoid rescaling svg icons + // And don't cache system icons because users might change them at run time + const auto iter = m_iconCache.find(iconId); + if (iter != m_iconCache.end()) return *iter; const QIcon icon {getIconPathFromResources(iconId, fallback)}; - iconCache[iconId] = icon; + m_iconCache[iconId] = icon; return icon; } @@ -153,7 +153,7 @@ QString UIThemeManager::getIconPath(const QString &iconId) const { #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) if (m_useSystemTheme) { - QString path = Utils::Fs::tempPath() + iconId + ".png"; + QString path = Utils::Fs::tempPath() + iconId + QLatin1String(".png"); if (!QFile::exists(path)) { const QIcon icon = QIcon::fromTheme(iconId); if (!icon.isNull()) diff --git a/src/gui/uithememanager.h b/src/gui/uithememanager.h index 95166d918..3eb3b0a21 100644 --- a/src/gui/uithememanager.h +++ b/src/gui/uithememanager.h @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -60,6 +61,7 @@ private: static UIThemeManager *m_instance; QHash m_colors; + mutable QHash m_iconCache; const bool m_useCustomTheme; #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) bool m_useSystemTheme; From 99a1802dbb473a1dd7207da40edda608504165a8 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sat, 23 May 2020 21:11:19 +0800 Subject: [PATCH 2/3] Make class variable const --- src/gui/uithememanager.cpp | 7 +++---- src/gui/uithememanager.h | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/gui/uithememanager.cpp b/src/gui/uithememanager.cpp index 15cf93fe4..3343cfaa5 100644 --- a/src/gui/uithememanager.cpp +++ b/src/gui/uithememanager.cpp @@ -76,6 +76,9 @@ void UIThemeManager::initInstance() UIThemeManager::UIThemeManager() : m_useCustomTheme(Preferences::instance()->useCustomUITheme()) +#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) + , m_useSystemTheme(Preferences::instance()->useSystemIconTheme()) +#endif { const Preferences *const pref = Preferences::instance(); if (m_useCustomTheme) { @@ -87,10 +90,6 @@ UIThemeManager::UIThemeManager() applyPalette(); } } - -#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) - m_useSystemTheme = pref->useSystemIconTheme(); -#endif } UIThemeManager *UIThemeManager::instance() diff --git a/src/gui/uithememanager.h b/src/gui/uithememanager.h index 3eb3b0a21..dca86193b 100644 --- a/src/gui/uithememanager.h +++ b/src/gui/uithememanager.h @@ -64,6 +64,6 @@ private: mutable QHash m_iconCache; const bool m_useCustomTheme; #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) - bool m_useSystemTheme; + const bool m_useSystemTheme; #endif }; From ba2db3f139f5eb5ae9cad9d14591340415b1af2f Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sat, 23 May 2020 21:16:46 +0800 Subject: [PATCH 3/3] Avoid overuse of QStringLiteral This code path doesn't look like frequently used. --- src/gui/rss/feedlistwidget.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/gui/rss/feedlistwidget.cpp b/src/gui/rss/feedlistwidget.cpp index 3e4693e16..beb287eca 100644 --- a/src/gui/rss/feedlistwidget.cpp +++ b/src/gui/rss/feedlistwidget.cpp @@ -85,13 +85,13 @@ void FeedListWidget::handleFeedStateChanged(RSS::Feed *feed) QIcon icon; if (feed->isLoading()) - icon = UIThemeManager::instance()->getIcon(QStringLiteral("loading")); + icon = UIThemeManager::instance()->getIcon(QLatin1String("loading")); else if (feed->hasError()) - icon = UIThemeManager::instance()->getIcon(QStringLiteral("unavailable")); + icon = UIThemeManager::instance()->getIcon(QLatin1String("unavailable")); else if (!feed->iconPath().isEmpty()) icon = QIcon(feed->iconPath()); else - icon = UIThemeManager::instance()->getIcon(QStringLiteral("application-rss+xml")); + icon = UIThemeManager::instance()->getIcon(QLatin1String("application-rss+xml")); item->setData(0, Qt::DecorationRole, icon); } @@ -237,14 +237,14 @@ QTreeWidgetItem *FeedListWidget::createItem(RSS::Item *rssItem, QTreeWidgetItem if (feed->isLoading()) icon = UIThemeManager::instance()->getIcon(QLatin1String("loading")); else if (feed->hasError()) - icon = UIThemeManager::instance()->getIcon(QStringLiteral("unavailable")); + icon = UIThemeManager::instance()->getIcon(QLatin1String("unavailable")); else if (!feed->iconPath().isEmpty()) icon = QIcon(feed->iconPath()); else - icon = UIThemeManager::instance()->getIcon(QStringLiteral("application-rss+xml")); + icon = UIThemeManager::instance()->getIcon(QLatin1String("application-rss+xml")); } else { - icon = UIThemeManager::instance()->getIcon("inode-directory"); + icon = UIThemeManager::instance()->getIcon(QLatin1String("inode-directory")); } item->setData(0, Qt::DecorationRole, icon);