Core: Delay use of style to fetch icons for unknown files

Up to infinity on platforms that don't use it.

Change-Id: Ia732904886b1e850460759aa0097729cd65f3ad3
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2019-01-28 14:18:20 +01:00
parent 7e65693e31
commit e648c079b8

View File

@@ -68,7 +68,6 @@ class FileIconProviderImplementation : public QFileIconProvider
{ {
public: public:
FileIconProviderImplementation() FileIconProviderImplementation()
: m_unknownFileIcon(QApplication::style()->standardIcon(QStyle::SP_FileIcon))
{} {}
QIcon icon(const QFileInfo &info) const override; QIcon icon(const QFileInfo &info) const override;
@@ -103,8 +102,6 @@ public:
// Mapping of file suffix to icon. // Mapping of file suffix to icon.
mutable QHash<QString, QIcon> m_suffixCache; mutable QHash<QString, QIcon> m_suffixCache;
QHash<QString, QIcon> m_filenameCache; QHash<QString, QIcon> m_filenameCache;
QIcon m_unknownFileIcon;
}; };
FileIconProviderImplementation *instance() FileIconProviderImplementation *instance()
@@ -139,10 +136,12 @@ QIcon FileIconProviderImplementation::icon(const QFileInfo &fileInfo) const
// Get icon from OS (and cache it based on suffix!) // Get icon from OS (and cache it based on suffix!)
QIcon icon; QIcon icon;
if (HostOsInfo::isWindowsHost() || HostOsInfo::isMacHost()) if (HostOsInfo::isWindowsHost() || HostOsInfo::isMacHost()) {
icon = QFileIconProvider::icon(fileInfo); icon = QFileIconProvider::icon(fileInfo);
else // File icons are unknown on linux systems. } else { // File icons are unknown on linux systems.
icon = isDir ? QFileIconProvider::icon(fileInfo) : m_unknownFileIcon; static const QIcon unknownFileIcon(QApplication::style()->standardIcon(QStyle::SP_FileIcon));
icon = isDir ? QFileIconProvider::icon(fileInfo) : unknownFileIcon;
}
if (!isDir && !suffix.isEmpty()) if (!isDir && !suffix.isEmpty())
m_suffixCache.insert(suffix, icon); m_suffixCache.insert(suffix, icon);
return icon; return icon;