From 671d96383b2668ef773a49ba943328ddf0c98420 Mon Sep 17 00:00:00 2001 From: Tannin Date: Wed, 25 Feb 2015 17:48:37 +0100 Subject: icon delegates now use a pixmap cache to improve rendering performance --- src/genericicondelegate.cpp | 10 +++++----- src/genericicondelegate.h | 2 +- src/icondelegate.cpp | 13 +++++++++--- src/icondelegate.h | 2 +- src/modflagicondelegate.cpp | 34 ++++++++++++++++---------------- src/modflagicondelegate.h | 4 ++-- src/modinfo.cpp | 48 +++++++++++++++++++++++++++------------------ src/modlist.cpp | 23 +++++++++++----------- src/pluginlist.cpp | 10 +++++----- 9 files changed, 82 insertions(+), 64 deletions(-) (limited to 'src') diff --git a/src/genericicondelegate.cpp b/src/genericicondelegate.cpp index c3471735..3711b428 100644 --- a/src/genericicondelegate.cpp +++ b/src/genericicondelegate.cpp @@ -1,6 +1,7 @@ #include "genericicondelegate.h" #include "pluginlist.h" #include +#include GenericIconDelegate::GenericIconDelegate(QObject *parent, int role, int logicalIndex, int compactSize) @@ -19,14 +20,13 @@ void GenericIconDelegate::columnResized(int logicalIndex, int, int newSize) } } -QList GenericIconDelegate::getIcons(const QModelIndex &index) const +QList GenericIconDelegate::getIcons(const QModelIndex &index) const { - QList result; + QList result; if (index.isValid()) { foreach (const QVariant &var, index.data(m_Role).toList()) { - QIcon icon = var.value(); - if (!m_Compact || !icon.isNull()) { - result.append(icon); + if (!m_Compact || !var.toString().isEmpty()) { + result.append(var.toString()); } } } diff --git a/src/genericicondelegate.h b/src/genericicondelegate.h index 9842d09a..98605250 100644 --- a/src/genericicondelegate.h +++ b/src/genericicondelegate.h @@ -24,7 +24,7 @@ public: public slots: void columnResized(int logicalIndex, int oldSize, int newSize); private: - virtual QList getIcons(const QModelIndex &index) const; + virtual QList getIcons(const QModelIndex &index) const; virtual size_t getNumIcons(const QModelIndex &index) const; private: int m_Role; diff --git a/src/icondelegate.cpp b/src/icondelegate.cpp index 8c2fe5cc..794ac7f3 100644 --- a/src/icondelegate.cpp +++ b/src/icondelegate.cpp @@ -22,6 +22,7 @@ along with Mod Organizer. If not, see . #include #include #include +#include IconDelegate::IconDelegate(QObject *parent) @@ -34,7 +35,7 @@ void IconDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, { QStyledItemDelegate::paint(painter, option, index); - QList icons = getIcons(index); + QList icons = getIcons(index); int x = 4; painter->save(); @@ -43,8 +44,14 @@ void IconDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, iconWidth = std::min(16, iconWidth); painter->translate(option.rect.topLeft()); - for (auto iter = icons.begin(); iter != icons.end(); ++iter) { - painter->drawPixmap(x, 2, iconWidth, iconWidth, iter->pixmap(QSize(iconWidth, iconWidth))); + for (const QString &iconId : icons) { + QPixmap icon; + QString fullIconId = QString("%1_%2").arg(iconId).arg(iconWidth); + if (!QPixmapCache::find(fullIconId, &icon)) { + icon = QIcon(iconId).pixmap(iconWidth, iconWidth); + QPixmapCache::insert(fullIconId, icon); + } + painter->drawPixmap(x, 2, iconWidth, iconWidth, icon); x += iconWidth + 4; } diff --git a/src/icondelegate.h b/src/icondelegate.h index b24de102..39694481 100644 --- a/src/icondelegate.h +++ b/src/icondelegate.h @@ -40,7 +40,7 @@ public slots: private: - virtual QList getIcons(const QModelIndex &index) const = 0; + virtual QList getIcons(const QModelIndex &index) const = 0; virtual size_t getNumIcons(const QModelIndex &index) const = 0; diff --git a/src/modflagicondelegate.cpp b/src/modflagicondelegate.cpp index 96b2bd58..e4c11bc5 100644 --- a/src/modflagicondelegate.cpp +++ b/src/modflagicondelegate.cpp @@ -1,20 +1,20 @@ -#include "modflagicondelegate.h" + #include "modflagicondelegate.h" #include ModInfo::EFlag ModFlagIconDelegate::m_ConflictFlags[4] = { ModInfo::FLAG_CONFLICT_MIXED - , ModInfo::FLAG_CONFLICT_OVERWRITE - , ModInfo::FLAG_CONFLICT_OVERWRITTEN - , ModInfo::FLAG_CONFLICT_REDUNDANT }; + , ModInfo::FLAG_CONFLICT_OVERWRITE + , ModInfo::FLAG_CONFLICT_OVERWRITTEN + , ModInfo::FLAG_CONFLICT_REDUNDANT }; ModFlagIconDelegate::ModFlagIconDelegate(QObject *parent) : IconDelegate(parent) { } -QList ModFlagIconDelegate::getIcons(const QModelIndex &index) const +QList ModFlagIconDelegate::getIcons(const QModelIndex &index) const { - QList result; + QList result; QVariant modid = index.data(Qt::UserRole + 1); if (modid.isValid()) { ModInfo::Ptr info = ModInfo::getByIndex(modid.toInt()); @@ -26,7 +26,7 @@ QList ModFlagIconDelegate::getIcons(const QModelIndex &index) const result.append(getFlagIcon(*iter)); flags.erase(iter); } else { - result.append(QIcon()); + result.append(QString()); } } @@ -37,18 +37,18 @@ QList ModFlagIconDelegate::getIcons(const QModelIndex &index) const return result; } -QIcon ModFlagIconDelegate::getFlagIcon(ModInfo::EFlag flag) const +QString ModFlagIconDelegate::getFlagIcon(ModInfo::EFlag flag) const { switch (flag) { - case ModInfo::FLAG_BACKUP: return QIcon(":/MO/gui/emblem_backup"); - case ModInfo::FLAG_INVALID: return QIcon(":/MO/gui/emblem_problem"); - case ModInfo::FLAG_NOTENDORSED: return QIcon(":/MO/gui/emblem_notendorsed"); - case ModInfo::FLAG_NOTES: return QIcon(":/MO/gui/emblem_notes"); - case ModInfo::FLAG_CONFLICT_OVERWRITE: return QIcon(":/MO/gui/emblem_conflict_overwrite"); - case ModInfo::FLAG_CONFLICT_OVERWRITTEN: return QIcon(":/MO/gui/emblem_conflict_overwritten"); - case ModInfo::FLAG_CONFLICT_MIXED: return QIcon(":/MO/gui/emblem_conflict_mixed"); - case ModInfo::FLAG_CONFLICT_REDUNDANT: return QIcon(":MO/gui/emblem_conflict_redundant"); - default: return QIcon(); + case ModInfo::FLAG_BACKUP: return ":/MO/gui/emblem_backup"; + case ModInfo::FLAG_INVALID: return ":/MO/gui/emblem_problem"; + case ModInfo::FLAG_NOTENDORSED: return "MO/gui/emblem_notendorsed"; + case ModInfo::FLAG_NOTES: return ":/MO/gui/emblem_notes"; + case ModInfo::FLAG_CONFLICT_OVERWRITE: return ":/MO/gui/emblem_conflict_overwrite"; + case ModInfo::FLAG_CONFLICT_OVERWRITTEN: return ":/MO/gui/emblem_conflict_overwritten"; + case ModInfo::FLAG_CONFLICT_MIXED: return ":/MO/gui/emblem_conflict_mixed"; + case ModInfo::FLAG_CONFLICT_REDUNDANT: return ":MO/gui/emblem_conflict_redundant"; + default: return QString(); } } diff --git a/src/modflagicondelegate.h b/src/modflagicondelegate.h index cc652c06..b31a250b 100644 --- a/src/modflagicondelegate.h +++ b/src/modflagicondelegate.h @@ -9,10 +9,10 @@ public: explicit ModFlagIconDelegate(QObject *parent = 0); virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; private: - virtual QList getIcons(const QModelIndex &index) const; + virtual QList getIcons(const QModelIndex &index) const; virtual size_t getNumIcons(const QModelIndex &index) const; - QIcon getFlagIcon(ModInfo::EFlag flag) const; + QString getFlagIcon(ModInfo::EFlag flag) const; private: static ModInfo::EFlag m_ConflictFlags[4]; }; diff --git a/src/modinfo.cpp b/src/modinfo.cpp index 3b8d6b92..cf8fa5c5 100644 --- a/src/modinfo.cpp +++ b/src/modinfo.cpp @@ -859,28 +859,38 @@ std::vector ModInfoRegular::getFlags() const std::vector ModInfoRegular::getContents() const { - std::vector result; - QDir dir(absolutePath()); - if (dir.entryList(QStringList() << "*.esp" << "*.esm").size() > 0) { - result.push_back(CONTENT_PLUGIN); - } + QTime now = QTime::currentTime(); + if (m_LastContentCheck.isNull() || (m_LastContentCheck.secsTo(now) > 60)) { + m_CachedContent.clear(); + QDir dir(absolutePath()); + if (dir.entryList(QStringList() << "*.esp" << "*.esm").size() > 0) { + m_CachedContent.push_back(CONTENT_PLUGIN); + } + if (dir.entryList(QStringList() << "*.bsa").size() > 0) { + m_CachedContent.push_back(CONTENT_BSA); + } - ScriptExtender *extender = qApp->property("managed_game").value()->feature(); + ScriptExtender *extender = qApp->property("managed_game").value()->feature(); - if (extender != nullptr) { - QString sePluginPath = extender->name() + "/plugins"; - if (dir.exists(sePluginPath)) result.push_back(CONTENT_SKSE); + if (extender != nullptr) { + QString sePluginPath = extender->name() + "/plugins"; + if (dir.exists(sePluginPath)) m_CachedContent.push_back(CONTENT_SKSE); + } + if (dir.exists("textures")) m_CachedContent.push_back(CONTENT_TEXTURE); + if (dir.exists("meshes")) m_CachedContent.push_back(CONTENT_MESH); + if (dir.exists("interface") + || dir.exists("menus")) m_CachedContent.push_back(CONTENT_INTERFACE); + if (dir.exists("music")) m_CachedContent.push_back(CONTENT_MUSIC); + if (dir.exists("sound")) m_CachedContent.push_back(CONTENT_SOUND); + if (dir.exists("scripts")) m_CachedContent.push_back(CONTENT_SCRIPT); + if (dir.exists("strings")) m_CachedContent.push_back(CONTENT_STRING); + if (dir.exists("SkyProc Patchers")) m_CachedContent.push_back(CONTENT_SKYPROC); + + m_LastContentCheck = QTime::currentTime(); } - if (dir.exists("textures")) result.push_back(CONTENT_TEXTURE); - if (dir.exists("meshes")) result.push_back(CONTENT_MESH); - if (dir.exists("interface") - || dir.exists("menus")) result.push_back(CONTENT_INTERFACE); - if (dir.exists("music")) result.push_back(CONTENT_MUSIC); - if (dir.exists("sound")) result.push_back(CONTENT_SOUND); - if (dir.exists("scripts")) result.push_back(CONTENT_SCRIPT); - if (dir.exists("strings")) result.push_back(CONTENT_STRING); - if (dir.exists("SkyProc Patchers")) result.push_back(CONTENT_SKYPROC); - return result; + + return m_CachedContent; + } diff --git a/src/modlist.cpp b/src/modlist.cpp index 19c0ac8c..23b74300 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -58,16 +58,17 @@ ModList::ModList(QObject *parent) , m_FontMetrics(QFont()) , m_DropOnItems(false) { - m_ContentIcons[ModInfo::CONTENT_PLUGIN] = std::make_tuple(QIcon(":/MO/gui/content/plugin"), ":/MO/gui/content/plugin", tr("Game plugins (esp/esm)")); - m_ContentIcons[ModInfo::CONTENT_INTERFACE] = std::make_tuple(QIcon(":/MO/gui/content/interface"), ":/MO/gui/content/interface", tr("Interface")); - m_ContentIcons[ModInfo::CONTENT_MESH] = std::make_tuple(QIcon(":/MO/gui/content/mesh"), ":/MO/gui/content/mesh", tr("Meshes")); - m_ContentIcons[ModInfo::CONTENT_MUSIC] = std::make_tuple(QIcon(":/MO/gui/content/music"), ":/MO/gui/content/music", tr("Music")); - m_ContentIcons[ModInfo::CONTENT_SCRIPT] = std::make_tuple(QIcon(":/MO/gui/content/script"), ":/MO/gui/content/script", tr("Scripts (Papyrus)")); - m_ContentIcons[ModInfo::CONTENT_SKSE] = std::make_tuple(QIcon(":/MO/gui/content/skse"), ":/MO/gui/content/skse", tr("Script Extender Plugin")); - m_ContentIcons[ModInfo::CONTENT_SKYPROC] = std::make_tuple(QIcon(":/MO/gui/content/skyproc"), ":/MO/gui/content/skyproc", tr("SkyProc Patcher")); - m_ContentIcons[ModInfo::CONTENT_SOUND] = std::make_tuple(QIcon(":/MO/gui/content/sound"), ":/MO/gui/content/sound", tr("Sound")); - m_ContentIcons[ModInfo::CONTENT_STRING] = std::make_tuple(QIcon(":/MO/gui/content/string"), ":/MO/gui/content/string", tr("Strings")); - m_ContentIcons[ModInfo::CONTENT_TEXTURE] = std::make_tuple(QIcon(":/MO/gui/content/texture"), ":/MO/gui/content/texture", tr("Textures")); + m_ContentIcons[ModInfo::CONTENT_PLUGIN] = std::make_tuple(":/MO/gui/content/plugin", tr("Game plugins (esp/esm)")); + m_ContentIcons[ModInfo::CONTENT_INTERFACE] = std::make_tuple(":/MO/gui/content/interface", tr("Interface")); + m_ContentIcons[ModInfo::CONTENT_MESH] = std::make_tuple(":/MO/gui/content/mesh", tr("Meshes")); + m_ContentIcons[ModInfo::CONTENT_BSA] = std::make_tuple(":/MO/gui/content/bsa", tr("BSA")); + m_ContentIcons[ModInfo::CONTENT_MUSIC] = std::make_tuple(":/MO/gui/content/music", tr("Music")); + m_ContentIcons[ModInfo::CONTENT_SCRIPT] = std::make_tuple(":/MO/gui/content/script", tr("Scripts (Papyrus)")); + m_ContentIcons[ModInfo::CONTENT_SKSE] = std::make_tuple(":/MO/gui/content/skse", tr("Script Extender Plugin")); + m_ContentIcons[ModInfo::CONTENT_SKYPROC] = std::make_tuple(":/MO/gui/content/skyproc", tr("SkyProc Patcher")); + m_ContentIcons[ModInfo::CONTENT_SOUND] = std::make_tuple(":/MO/gui/content/sound", tr("Sound")); + m_ContentIcons[ModInfo::CONTENT_STRING] = std::make_tuple(":/MO/gui/content/string", tr("Strings")); + m_ContentIcons[ModInfo::CONTENT_TEXTURE] = std::make_tuple(":/MO/gui/content/texture", tr("Textures")); } ModList::~ModList() @@ -155,7 +156,7 @@ QVariantList ModList::contentsToIcons(const std::vector &cont if (contentsSet.find(iter->first) != contentsSet.end()) { result.append(std::get<0>(iter->second)); } else { - result.append(QIcon()); + result.append(QString()); } } return result; diff --git a/src/pluginlist.cpp b/src/pluginlist.cpp index 3c7af59f..f72ab690 100644 --- a/src/pluginlist.cpp +++ b/src/pluginlist.cpp @@ -866,22 +866,22 @@ QVariant PluginList::data(const QModelIndex &modelIndex, int role) const QVariantList result; QString nameLower = m_ESPs[index].m_Name.toLower(); if (m_ESPs[index].m_MasterUnset.size() > 0) { - result.append(QIcon(":/MO/gui/warning")); + result.append(":/MO/gui/warning"); } if (m_LockedOrder.find(nameLower) != m_LockedOrder.end()) { - result.append(QIcon(":/MO/gui/locked")); + result.append(":/MO/gui/locked"); } auto bossInfoIter = m_AdditionalInfo.find(nameLower); if (bossInfoIter != m_AdditionalInfo.end()) { if (!bossInfoIter->second.m_Messages.isEmpty()) { - result.append(QIcon(":/MO/gui/information")); + result.append(":/MO/gui/information"); } } if (m_ESPs[index].m_HasIni) { - result.append(QIcon(":/MO/gui/attachment")); + result.append(":/MO/gui/attachment"); } if (m_ESPs[index].m_IsDummy && m_ESPs[index].m_Enabled && !m_ESPs[index].m_HasIni) { - result.append(QIcon(":/MO/gui/edit_clear")); + result.append(":/MO/gui/edit_clear"); } return result; } -- cgit v1.3.1