From 3114bcbd8dffd60f158dd5a164f5192ed8323f96 Mon Sep 17 00:00:00 2001 From: Silarn Date: Fri, 27 Apr 2018 20:21:42 -0500 Subject: Fix ESL index display and sorting by index --- src/pluginlist.cpp | 23 +++++++++++++++++++++-- src/pluginlist.h | 1 + src/pluginlistsortproxy.cpp | 4 ++-- 3 files changed, 24 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/pluginlist.cpp b/src/pluginlist.cpp index bd863f52..7642c87f 100644 --- a/src/pluginlist.cpp +++ b/src/pluginlist.cpp @@ -485,6 +485,25 @@ int PluginList::enabledCount() const return enabled; } +int PluginList::getIndexPriority(int index) const +{ + int numESLs = 0; + std::vector sortESPs(m_ESPs); + std::sort(sortESPs.begin(), sortESPs.end()); + for (auto sortedESP : sortESPs) { + if (sortedESP.m_LoadOrder == m_ESPs[index].m_LoadOrder) + break; + if ((sortedESP.m_IsLight || sortedESP.m_IsLightFlagged) && sortedESP.m_LoadOrder != -1) + ++numESLs; + } + if (m_ESPs[index].m_IsLight || m_ESPs[index].m_IsLightFlagged) { + int ESLpos = 254 + ((numESLs + 1) / 2048); + return ESLpos + (numESLs % 2048); + } else { + return m_ESPs[index].m_LoadOrder - numESLs; + } +} + bool PluginList::isESPLocked(int index) const { return m_LockedOrder.find(m_ESPs.at(index).m_Name.toLower()) != m_LockedOrder.end(); @@ -802,8 +821,8 @@ QVariant PluginList::data(const QModelIndex &modelIndex, int role) const ++numESLs; } if (m_ESPs[index].m_IsLight || m_ESPs[index].m_IsLightFlagged) { - int ESLpos = 254 + ((numESLs+1) / 4096); - return QString("%1:%2").arg(ESLpos, 2, 16, QChar('0')).arg((numESLs)%4096).toUpper(); + int ESLpos = 254 + ((numESLs+1) / 2048); + return QString("%1:%2").arg(ESLpos, 2, 16, QChar('0')).arg((numESLs)%2048, 3, 16, QChar('0')).toUpper(); } else { return QString("%1").arg(m_ESPs[index].m_LoadOrder - numESLs, 2, 16, QChar('0')).toUpper(); } diff --git a/src/pluginlist.h b/src/pluginlist.h index f9173810..6a53614a 100644 --- a/src/pluginlist.h +++ b/src/pluginlist.h @@ -194,6 +194,7 @@ public: QString getName(int index) const { return m_ESPs.at(index).m_Name; } int getPriority(int index) const { return m_ESPs.at(index).m_Priority; } + int getIndexPriority(int index) const; bool isESPLocked(int index) const; void lockESPIndex(int index, bool lock); diff --git a/src/pluginlistsortproxy.cpp b/src/pluginlistsortproxy.cpp index 342b3744..b844e1d8 100644 --- a/src/pluginlistsortproxy.cpp +++ b/src/pluginlistsortproxy.cpp @@ -100,8 +100,8 @@ bool PluginListSortProxy::lessThan(const QModelIndex &left, } } break; case PluginList::COL_MODINDEX: { - int leftVal = plugins->isEnabled(left.row()) ? plugins->getPriority(left.row()) : -1; - int rightVal = plugins->isEnabled(right.row()) ? plugins->getPriority(right.row()) : -1; + int leftVal = plugins->isEnabled(left.row()) ? plugins->getIndexPriority(left.row()) : -1; + int rightVal = plugins->isEnabled(right.row()) ? plugins->getIndexPriority(right.row()) : -1; return leftVal < rightVal; } break; default: { -- cgit v1.3.1