forked from qt-creator/qt-creator
FileIconProvider: Use hash for cache, instead of list.
Change-Id: I5d633ca2d21b6352c59cdeb7cd85267ced1d2170 Reviewed-by: hjk <hjk121@nokiamail.com>
This commit is contained in:
@@ -37,7 +37,7 @@
|
|||||||
#include <QStyle>
|
#include <QStyle>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QPair>
|
#include <QHash>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#include <QFileIconProvider>
|
#include <QFileIconProvider>
|
||||||
@@ -68,9 +68,6 @@ namespace FileIconProvider {
|
|||||||
|
|
||||||
enum { debug = 0 };
|
enum { debug = 0 };
|
||||||
|
|
||||||
typedef QPair<QString, QIcon> StringIconPair;
|
|
||||||
typedef QList<StringIconPair> StringIconPairList;
|
|
||||||
|
|
||||||
class FileIconProviderImplementation : public QFileIconProvider
|
class FileIconProviderImplementation : public QFileIconProvider
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -89,15 +86,8 @@ public:
|
|||||||
QTC_ASSERT(!icon.isNull() && !suffix.isEmpty(), return);
|
QTC_ASSERT(!icon.isNull() && !suffix.isEmpty(), return);
|
||||||
|
|
||||||
const QPixmap fileIconPixmap = FileIconProvider::overlayIcon(QStyle::SP_FileIcon, icon, QSize(16, 16));
|
const QPixmap fileIconPixmap = FileIconProvider::overlayIcon(QStyle::SP_FileIcon, icon, QSize(16, 16));
|
||||||
|
|
||||||
// replace old icon, if it exists
|
// replace old icon, if it exists
|
||||||
for (int i = 0, n = m_cache.size(); i != n; ++i) {
|
m_cache.insert(suffix, fileIconPixmap);
|
||||||
if (m_cache.at(i).first == suffix) {
|
|
||||||
m_cache[i].second = fileIconPixmap;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m_cache.append(StringIconPair(suffix, fileIconPixmap));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void registerIconOverlayForMimeType(const QIcon &icon, const MimeType &mimeType)
|
void registerIconOverlayForMimeType(const QIcon &icon, const MimeType &mimeType)
|
||||||
@@ -107,7 +97,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Mapping of file suffix to icon.
|
// Mapping of file suffix to icon.
|
||||||
StringIconPairList m_cache;
|
QHash<QString, QIcon> m_cache;
|
||||||
|
|
||||||
QIcon m_unknownFileIcon;
|
QIcon m_unknownFileIcon;
|
||||||
};
|
};
|
||||||
@@ -130,10 +120,8 @@ QIcon FileIconProviderImplementation::icon(const QFileInfo &fileInfo) const
|
|||||||
// Check for cached overlay icons by file suffix.
|
// Check for cached overlay icons by file suffix.
|
||||||
if (!m_cache.isEmpty() && !fileInfo.isDir()) {
|
if (!m_cache.isEmpty() && !fileInfo.isDir()) {
|
||||||
const QString suffix = fileInfo.suffix();
|
const QString suffix = fileInfo.suffix();
|
||||||
if (!suffix.isEmpty()) {
|
if (!suffix.isEmpty() && m_cache.contains(suffix)) {
|
||||||
for (int i = 0, n = m_cache.size(); i != n; ++i)
|
return m_cache.value(suffix);
|
||||||
if (m_cache.at(i).first == suffix)
|
|
||||||
return m_cache[i].second;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Get icon from OS.
|
// Get icon from OS.
|
||||||
|
|||||||
Reference in New Issue
Block a user