diff options
| author | Mikaël Capelle <capelle.mikael@gmail.com> | 2022-05-17 11:47:01 +0200 |
|---|---|---|
| committer | Mikaël Capelle <capelle.mikael@gmail.com> | 2023-07-09 17:20:40 +0200 |
| commit | d13f6bb870cdda71257f665367be8ef9fca86255 (patch) | |
| tree | 52e214718478f1e52856572f5aa1a2ac58537f9f /src/pluginlist.cpp | |
| parent | 86bb01ba9eac879d3685c439ac9da0028bc4bc80 (diff) | |
Apply clang-format.
Diffstat (limited to 'src/pluginlist.cpp')
| -rw-r--r-- | src/pluginlist.cpp | 638 |
1 files changed, 328 insertions, 310 deletions
diff --git a/src/pluginlist.cpp b/src/pluginlist.cpp index a4742529..6e54b46d 100644 --- a/src/pluginlist.cpp +++ b/src/pluginlist.cpp @@ -18,41 +18,40 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. */ #include "pluginlist.h" -#include "settings.h" -#include "scopeguard.h" #include "modinfo.h" #include "modlist.h" -#include "viewmarkingscrollbar.h" +#include "scopeguard.h" +#include "settings.h" #include "shared/directoryentry.h" -#include "shared/filesorigin.h" #include "shared/fileentry.h" +#include "shared/filesorigin.h" +#include "viewmarkingscrollbar.h" -#include <utility.h> -#include <iplugingame.h> +#include "shared/windows_error.h" #include <espfile.h> +#include <gameplugins.h> +#include <iplugingame.h> #include <report.h> -#include "shared/windows_error.h" #include <safewritefile.h> -#include <gameplugins.h> +#include <utility.h> -#include <QtDebug> -#include <QMessageBox> -#include <QMimeData> +#include <QApplication> #include <QCoreApplication> #include <QDateTime> #include <QDir> #include <QFile> #include <QFileInfo> -#include <QFileInfo> +#include <QKeyEvent> #include <QListWidgetItem> +#include <QMessageBox> +#include <QMimeData> #include <QRegularExpression> -#include <QString> -#include <QApplication> -#include <QKeyEvent> #include <QSortFilterProxyModel> +#include <QString> +#include <QtDebug> -#include <ctime> #include <algorithm> +#include <ctime> #include <stdexcept> #include "organizercore.h" @@ -60,7 +59,6 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. using namespace MOBase; using namespace MOShared; - static QString TruncateString(const QString& text) { QString new_text = text; @@ -73,11 +71,8 @@ static QString TruncateString(const QString& text) return new_text; } - PluginList::PluginList(OrganizerCore& organizer) - : QAbstractItemModel(&organizer) - , m_Organizer(organizer) - , m_FontMetrics(QFont()) + : QAbstractItemModel(&organizer), m_Organizer(organizer), m_FontMetrics(QFont()) { connect(this, SIGNAL(writePluginsList()), this, SLOT(generatePluginIndexes())); m_LastCheck.start(); @@ -93,34 +88,43 @@ PluginList::~PluginList() QString PluginList::getColumnName(int column) { switch (column) { - case COL_NAME: return tr("Name"); - case COL_PRIORITY: return tr("Priority"); - case COL_MODINDEX: return tr("Mod Index"); - case COL_FLAGS: return tr("Flags"); - default: return tr("unknown"); + case COL_NAME: + return tr("Name"); + case COL_PRIORITY: + return tr("Priority"); + case COL_MODINDEX: + return tr("Mod Index"); + case COL_FLAGS: + return tr("Flags"); + default: + return tr("unknown"); } } - QString PluginList::getColumnToolTip(int column) { switch (column) { - case COL_NAME: return tr("Name of the plugin"); - case COL_FLAGS: return tr("Emblems to highlight things that might require attention."); - case COL_PRIORITY: return tr("Load priority of plugins. The higher, the more \"important\" it is and thus " - "overwrites data from plugins with lower priority."); - case COL_MODINDEX: return tr("Determines the formids of objects originating from this mods."); - default: return tr("unknown"); + case COL_NAME: + return tr("Name of the plugin"); + case COL_FLAGS: + return tr("Emblems to highlight things that might require attention."); + case COL_PRIORITY: + return tr( + "Load priority of plugins. The higher, the more \"important\" it is and thus " + "overwrites data from plugins with lower priority."); + case COL_MODINDEX: + return tr("Determines the formids of objects originating from this mods."); + default: + return tr("unknown"); } } -void PluginList::highlightPlugins( - const std::vector<unsigned int>& modIndices, - const MOShared::DirectoryEntry &directoryEntry) +void PluginList::highlightPlugins(const std::vector<unsigned int>& modIndices, + const MOShared::DirectoryEntry& directoryEntry) { auto* profile = m_Organizer.currentProfile(); - for (auto &esp : m_ESPs) { + for (auto& esp : m_ESPs) { esp.modSelected = false; } @@ -128,14 +132,20 @@ void PluginList::highlightPlugins( ModInfo::Ptr selectedMod = ModInfo::getByIndex(modIndex); if (!selectedMod.isNull() && profile->modEnabled(modIndex)) { QDir dir(selectedMod->absolutePath()); - QStringList plugins = dir.entryList(QStringList() << "*.esp" << "*.esm" << "*.esl"); - const MOShared::FilesOrigin& origin = directoryEntry.getOriginByName(selectedMod->internalName().toStdWString()); + QStringList plugins = dir.entryList(QStringList() << "*.esp" + << "*.esm" + << "*.esl"); + const MOShared::FilesOrigin& origin = + directoryEntry.getOriginByName(selectedMod->internalName().toStdWString()); if (plugins.size() > 0) { for (auto plugin : plugins) { MOShared::FileEntryPtr file = directoryEntry.findFile(plugin.toStdWString()); if (file && file->getOrigin() != origin.getID()) { const auto alternatives = file->getAlternatives(); - if (std::find_if(alternatives.begin(), alternatives.end(), [&](const FileAlternative& element) { return element.originID() == origin.getID(); }) == alternatives.end()) + if (std::find_if(alternatives.begin(), alternatives.end(), + [&](const FileAlternative& element) { + return element.originID() == origin.getID(); + }) == alternatives.end()) continue; } std::map<QString, int>::iterator iter = m_ESPsByName.find(plugin); @@ -147,13 +157,13 @@ void PluginList::highlightPlugins( } } - emit dataChanged(this->index(0, 0), this->index(static_cast<int>(m_ESPs.size()) - 1, this->columnCount() - 1)); + emit dataChanged(this->index(0, 0), this->index(static_cast<int>(m_ESPs.size()) - 1, + this->columnCount() - 1)); } -void PluginList::refresh(const QString &profileName - , const DirectoryEntry &baseDirectory - , const QString &lockedOrderFile - , bool force) +void PluginList::refresh(const QString& profileName, + const DirectoryEntry& baseDirectory, + const QString& lockedOrderFile, bool force) { TimeThis tt("PluginList::refresh()"); @@ -166,8 +176,9 @@ void PluginList::refresh(const QString &profileName ChangeBracket<PluginList> layoutChange(this); QStringList primaryPlugins = m_GamePlugin->primaryPlugins(); - GamePlugins *gamePlugins = m_GamePlugin->feature<GamePlugins>(); - const bool lightPluginsAreSupported = gamePlugins ? gamePlugins->lightPluginsAreSupported() : false; + GamePlugins* gamePlugins = m_GamePlugin->feature<GamePlugins>(); + const bool lightPluginsAreSupported = + gamePlugins ? gamePlugins->lightPluginsAreSupported() : false; m_CurrentProfile = profileName; @@ -191,51 +202,57 @@ void PluginList::refresh(const QString &profileName } bool forceEnabled = Settings::instance().game().forceEnableCoreFiles() && - primaryPlugins.contains(filename, Qt::CaseInsensitive); + primaryPlugins.contains(filename, Qt::CaseInsensitive); bool archive = false; try { - FilesOrigin &origin = baseDirectory.getOriginByID(current->getOrigin(archive)); + FilesOrigin& origin = baseDirectory.getOriginByID(current->getOrigin(archive)); - //name without extension + // name without extension QString baseName = QFileInfo(filename).completeBaseName(); QString iniPath = baseName + ".ini"; - bool hasIni = baseDirectory.findFile(ToWString(iniPath)).get() != nullptr; + bool hasIni = baseDirectory.findFile(ToWString(iniPath)).get() != nullptr; std::set<QString> loadedArchives; QString candidateName; for (FileEntryPtr archiveCandidate : files) { candidateName = ToQString(archiveCandidate->getName()); if (candidateName.startsWith(baseName, Qt::CaseInsensitive) && - (candidateName.endsWith(".bsa", Qt::CaseInsensitive) || - candidateName.endsWith(".ba2", Qt::CaseInsensitive))) { + (candidateName.endsWith(".bsa", Qt::CaseInsensitive) || + candidateName.endsWith(".ba2", Qt::CaseInsensitive))) { loadedArchives.insert(candidateName); } } - QString originName = ToQString(origin.getName()); + QString originName = ToQString(origin.getName()); unsigned int modIndex = ModInfo::getIndex(originName); if (modIndex != UINT_MAX) { ModInfo::Ptr modInfo = ModInfo::getByIndex(modIndex); - originName = modInfo->name(); + originName = modInfo->name(); } - m_ESPs.push_back(ESPInfo(filename, forceEnabled, originName, ToQString(current->getFullPath()), hasIni, loadedArchives, lightPluginsAreSupported)); + m_ESPs.push_back(ESPInfo(filename, forceEnabled, originName, + ToQString(current->getFullPath()), hasIni, + loadedArchives, lightPluginsAreSupported)); m_ESPs.rbegin()->priority = -1; - } catch (const std::exception &e) { - reportError(tr("failed to update esp info for file %1 (source id: %2), error: %3").arg(filename).arg(current->getOrigin(archive)).arg(e.what())); + } catch (const std::exception& e) { + reportError( + tr("failed to update esp info for file %1 (source id: %2), error: %3") + .arg(filename) + .arg(current->getOrigin(archive)) + .arg(e.what())); } } } - for (const auto &espName : m_ESPsByName) { + for (const auto& espName : m_ESPsByName) { if (!availablePlugins.contains(espName.first, Qt::CaseInsensitive)) { m_ESPs[espName.second].name = ""; } } m_ESPs.erase(std::remove_if(m_ESPs.begin(), m_ESPs.end(), - [](const ESPInfo &info) -> bool { + [](const ESPInfo& info) -> bool { return info.name.isEmpty(); }), m_ESPs.end()); @@ -276,8 +293,8 @@ void PluginList::fixPrimaryPlugins() // This function ensures that the primary plugins are first and in the correct order QStringList primaryPlugins = m_Organizer.managedGame()->primaryPlugins(); - int prio = 0; - bool somethingChanged = false; + int prio = 0; + bool somethingChanged = false; for (QString plugin : primaryPlugins) { std::map<QString, int>::iterator iter = m_ESPsByName.find(plugin); // Plugin is present? @@ -304,8 +321,7 @@ void PluginList::fixPluginRelationships() // Count the types of plugins int masterCount = 0; for (auto plugin : m_ESPs) { - if (plugin.hasLightExtension || - plugin.hasMasterExtension || + if (plugin.hasLightExtension || plugin.hasMasterExtension || plugin.isMasterFlagged) { masterCount++; } @@ -314,15 +330,13 @@ void PluginList::fixPluginRelationships() // Ensure masters are up top and normal plugins are down below for (int i = 0; i < m_ESPs.size(); i++) { ESPInfo& plugin = m_ESPs[i]; - if (plugin.hasLightExtension || - plugin.hasMasterExtension || + if (plugin.hasLightExtension || plugin.hasMasterExtension || plugin.isMasterFlagged) { if (plugin.priority > masterCount) { int newPriority = masterCount + 1; setPluginPriority(i, newPriority); } - } - else { + } else { if (plugin.priority < masterCount) { int newPriority = masterCount + 1; setPluginPriority(i, newPriority); @@ -359,7 +373,7 @@ void PluginList::fixPriorities() } std::sort(espPrios.begin(), espPrios.end(), - [](const std::pair<int, int> &lhs, const std::pair<int, int> &rhs) { + [](const std::pair<int, int>& lhs, const std::pair<int, int>& rhs) { return lhs.first < rhs.first; }); @@ -368,18 +382,17 @@ void PluginList::fixPriorities() } } -void PluginList::enableESP(const QString &name, bool enable) +void PluginList::enableESP(const QString& name, bool enable) { std::map<QString, int>::iterator iter = m_ESPsByName.find(name); if (iter != m_ESPsByName.end()) { - auto enabled = m_ESPs[iter->second].enabled; - m_ESPs[iter->second].enabled = - enable || m_ESPs[iter->second].forceEnabled; + auto enabled = m_ESPs[iter->second].enabled; + m_ESPs[iter->second].enabled = enable || m_ESPs[iter->second].forceEnabled; emit writePluginsList(); if (enabled != m_ESPs[iter->second].enabled) { - pluginStatesChanged({ name }, state(name)); + pluginStatesChanged({name}, state(name)); } } else { reportError(tr("Plugin not found: %1").arg(qUtf8Printable(name))); @@ -388,7 +401,7 @@ void PluginList::enableESP(const QString &name, bool enable) int PluginList::findPluginByPriority(int priority) { - for (int i = 0; i < m_ESPs.size(); i++ ) { + for (int i = 0; i < m_ESPs.size(); i++) { if (m_ESPs[i].priority == priority) { return i; } @@ -408,15 +421,15 @@ void PluginList::setEnabled(const QModelIndexList& indices, bool enabled) } if (!dirty.isEmpty()) { emit writePluginsList(); - pluginStatesChanged(dirty, - enabled ? IPluginList::PluginState::STATE_ACTIVE : IPluginList::PluginState::STATE_INACTIVE); + pluginStatesChanged(dirty, enabled ? IPluginList::PluginState::STATE_ACTIVE + : IPluginList::PluginState::STATE_INACTIVE); } } void PluginList::setEnabledAll(bool enabled) { QStringList dirty; - for (ESPInfo &info : m_ESPs) { + for (ESPInfo& info : m_ESPs) { if (info.enabled != enabled) { info.enabled = enabled; dirty.append(info.name); @@ -424,8 +437,8 @@ void PluginList::setEnabledAll(bool enabled) } if (!dirty.isEmpty()) { emit writePluginsList(); - pluginStatesChanged(dirty, - enabled ? IPluginList::PluginState::STATE_ACTIVE : IPluginList::PluginState::STATE_INACTIVE); + pluginStatesChanged(dirty, enabled ? IPluginList::PluginState::STATE_ACTIVE + : IPluginList::PluginState::STATE_INACTIVE); } } @@ -453,7 +466,7 @@ void PluginList::shiftPluginsPriority(const QModelIndexList& indices, int offset std::sort(allIndex.begin(), allIndex.end(), [=](int lhs, int rhs) { bool cmp = m_ESPs[lhs].priority < m_ESPs[rhs].priority; return offset > 0 ? !cmp : cmp; - }); + }); for (auto index : allIndex) { int newPriority = m_ESPs[index].priority + offset; @@ -476,13 +489,14 @@ void PluginList::toggleState(const QModelIndexList& indices) maxRow = idx; } int oldState = idx.data(Qt::CheckStateRole).toInt(); - setData(idx, oldState == Qt::Unchecked ? Qt::Checked : Qt::Unchecked, Qt::CheckStateRole); + setData(idx, oldState == Qt::Unchecked ? Qt::Checked : Qt::Unchecked, + Qt::CheckStateRole); } emit dataChanged(minRow, maxRow); } -bool PluginList::isEnabled(const QString &name) +bool PluginList::isEnabled(const QString& name) { std::map<QString, int>::iterator iter = m_ESPsByName.find(name); @@ -493,7 +507,7 @@ bool PluginList::isEnabled(const QString &name) } } -void PluginList::clearInformation(const QString &name) +void PluginList::clearInformation(const QString& name) { std::map<QString, int>::iterator iter = m_ESPsByName.find(name); @@ -507,7 +521,7 @@ void PluginList::clearAdditionalInformation() m_AdditionalInfo.clear(); } -void PluginList::addInformation(const QString &name, const QString &message) +void PluginList::addInformation(const QString& name, const QString& message) { std::map<QString, int>::iterator iter = m_ESPsByName.find(name); @@ -534,7 +548,7 @@ bool PluginList::isEnabled(int index) return m_ESPs.at(index).enabled; } -void PluginList::readLockedOrderFrom(const QString &fileName) +void PluginList::readLockedOrderFrom(const QString& fileName) { m_LockedOrder.clear(); @@ -546,39 +560,36 @@ void PluginList::readLockedOrderFrom(const QString &fileName) file.open(QIODevice::ReadOnly); int lineNumber = 0; - while (!file.atEnd()) - { + while (!file.atEnd()) { QByteArray line = file.readLine(); ++lineNumber; // Skip empty lines or commented out lines (#) - if ((line.size() <= 0) || (line.at(0) == '#')) - { + if ((line.size() <= 0) || (line.at(0) == '#')) { continue; } QList<QByteArray> fields = line.split('|'); - if (fields.count() != 2) - { + if (fields.count() != 2) { // Don't know how to parse this so run away - log::error("locked order file: invalid line #{}: {}", lineNumber, QString::fromUtf8(line).trimmed()); + log::error("locked order file: invalid line #{}: {}", lineNumber, + QString::fromUtf8(line).trimmed()); continue; } // Read the plugin name and priority QString pluginName = QString::fromUtf8(fields.at(0)); - int priority = fields.at(1).trimmed().toInt(); - if (priority < 0) - { + int priority = fields.at(1).trimmed().toInt(); + if (priority < 0) { // WTF do you mean a negative priority? - log::error("locked order file: invalid line #{}: {}", lineNumber, QString::fromUtf8(line).trimmed()); + log::error("locked order file: invalid line #{}: {}", lineNumber, + QString::fromUtf8(line).trimmed()); continue; } // Determine the index of the plugin auto it = m_ESPsByName.find(pluginName); - if (it == m_ESPsByName.end()) - { + if (it == m_ESPsByName.end()) { // Plugin does not exist in the current set of plugins m_LockedOrder[pluginName] = priority; continue; @@ -586,42 +597,41 @@ void PluginList::readLockedOrderFrom(const QString &fileName) int pluginIndex = it->second; // Do not allow locking forced plugins - if (m_ESPs[pluginIndex].forceEnabled) - { + if (m_ESPs[pluginIndex].forceEnabled) { continue; } // If the priority is larger than the number of plugins, just keep it locked - if (priority >= m_ESPsByPriority.size()) - { + if (priority >= m_ESPsByPriority.size()) { m_LockedOrder[pluginName] = priority; continue; } // These are some helper functions for figuring out what is already locked - auto findLocked = [&](const std::pair<QString, int>& a) { return a.second == priority; }; - auto alreadyLocked = [&](){ return std::find_if(m_LockedOrder.begin(), m_LockedOrder.end(), findLocked) != m_LockedOrder.end(); }; + auto findLocked = [&](const std::pair<QString, int>& a) { + return a.second == priority; + }; + auto alreadyLocked = [&]() { + return std::find_if(m_LockedOrder.begin(), m_LockedOrder.end(), findLocked) != + m_LockedOrder.end(); + }; // See if we can just set the given priority - if (!m_ESPs[m_ESPsByPriority.at(priority)].forceEnabled && !alreadyLocked()) - { + if (!m_ESPs[m_ESPsByPriority.at(priority)].forceEnabled && !alreadyLocked()) { m_LockedOrder[pluginName] = priority; continue; } // Find the next higher priority we can set the plugin to - while (++priority < m_ESPs.size()) - { - if (!m_ESPs[m_ESPsByPriority.at(priority)].forceEnabled && !alreadyLocked()) - { + while (++priority < m_ESPs.size()) { + if (!m_ESPs[m_ESPsByPriority.at(priority)].forceEnabled && !alreadyLocked()) { m_LockedOrder[pluginName] = priority; break; } } // See if we walked off the end of the plugin list - if (priority >= m_ESPs.size()) - { + if (priority >= m_ESPs.size()) { // I guess go ahead and lock it here at the end of the list? m_LockedOrder[pluginName] = priority; continue; @@ -630,21 +640,22 @@ void PluginList::readLockedOrderFrom(const QString &fileName) file.close(); } -void PluginList::writeLockedOrder(const QString &fileName) const +void PluginList::writeLockedOrder(const QString& fileName) const { SafeWriteFile file(fileName); file->resize(0); - file->write(QString("# This file was automatically generated by Mod Organizer.\r\n").toUtf8()); + file->write(QString("# This file was automatically generated by Mod Organizer.\r\n") + .toUtf8()); for (auto iter = m_LockedOrder.begin(); iter != m_LockedOrder.end(); ++iter) { file->write(QString("%1|%2\r\n").arg(iter->first).arg(iter->second).toUtf8()); } file.commit(); } -void PluginList::saveTo(const QString &lockedOrderFileName) const +void PluginList::saveTo(const QString& lockedOrderFileName) const { - GamePlugins *gamePlugins = m_GamePlugin->feature<GamePlugins>(); + GamePlugins* gamePlugins = m_GamePlugin->feature<GamePlugins>(); if (gamePlugins) { gamePlugins->writePluginLists(m_Organizer.managedGameOrganizer()->pluginList()); } @@ -652,8 +663,7 @@ void PluginList::saveTo(const QString &lockedOrderFileName) const writeLockedOrder(lockedOrderFileName); } - -bool PluginList::saveLoadOrder(DirectoryEntry &directoryStructure) +bool PluginList::saveLoadOrder(DirectoryEntry& directoryStructure) { if (m_GamePlugin->loadOrderMechanism() != IPluginGame::LoadOrderMechanism::FileTime) { // nothing to do @@ -662,8 +672,8 @@ bool PluginList::saveLoadOrder(DirectoryEntry &directoryStructure) log::debug("setting file times on esps"); - for (ESPInfo &esp : m_ESPs) { - std::wstring espName = ToWString(esp.name); + for (ESPInfo& esp : m_ESPs) { + std::wstring espName = ToWString(esp.name); const FileEntryPtr fileEntry = directoryStructure.findFile(espName); if (fileEntry.get() != nullptr) { QString fileName; @@ -671,31 +681,37 @@ bool PluginList::saveLoadOrder(DirectoryEntry &directoryStructure) int originid = fileEntry->getOrigin(archive); fileName = QString("%1\\%2") - .arg(QDir::toNativeSeparators(ToQString(directoryStructure.getOriginByID(originid).getPath()))) - .arg(esp.name); + .arg(QDir::toNativeSeparators(ToQString( + directoryStructure.getOriginByID(originid).getPath()))) + .arg(esp.name); - HANDLE file = ::CreateFile(ToWString(fileName).c_str(), GENERIC_READ | GENERIC_WRITE, - 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); + HANDLE file = + ::CreateFile(ToWString(fileName).c_str(), GENERIC_READ | GENERIC_WRITE, 0, + nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); if (file == INVALID_HANDLE_VALUE) { if (::GetLastError() == ERROR_SHARING_VIOLATION) { // file is locked, probably the game is running return false; } else { - throw windows_error(QObject::tr("failed to access %1").arg(fileName).toUtf8().constData()); + throw windows_error( + QObject::tr("failed to access %1").arg(fileName).toUtf8().constData()); } } ULONGLONG temp = 0; - temp = (145731ULL + esp.priority) * 24 * 60 * 60 * 10000000ULL; + temp = (145731ULL + esp.priority) * 24 * 60 * 60 * 10000000ULL; FILETIME newWriteTime; newWriteTime.dwLowDateTime = (DWORD)(temp & 0xFFFFFFFF); newWriteTime.dwHighDateTime = (DWORD)(temp >> 32); - esp.time = newWriteTime; + esp.time = newWriteTime; fileEntry->setFileTime(newWriteTime); if (!::SetFileTime(file, nullptr, nullptr, &newWriteTime)) { - throw windows_error(QObject::tr("failed to set file time %1").arg(fileName).toUtf8().constData()); + throw windows_error(QObject::tr("failed to set file time %1") + .arg(fileName) + .toUtf8() + .constData()); } CloseHandle(file); @@ -707,7 +723,7 @@ bool PluginList::saveLoadOrder(DirectoryEntry &directoryStructure) int PluginList::enabledCount() const { int enabled = 0; - for (const auto &info : m_ESPs) { + for (const auto& info : m_ESPs) { if (info.enabled) { ++enabled; } @@ -762,10 +778,11 @@ void PluginList::refreshLoadOrder() // set priorities according to locked load order std::map<int, QString> lockedLoadOrder; std::for_each(m_LockedOrder.begin(), m_LockedOrder.end(), - [&lockedLoadOrder] (const std::pair<QString, int> &ele) { - lockedLoadOrder[ele.second] = ele.first; }); + [&lockedLoadOrder](const std::pair<QString, int>& ele) { + lockedLoadOrder[ele.second] = ele.first; + }); - int targetPrio = 0; + int targetPrio = 0; bool savePluginsList = false; // this is guaranteed to iterate from lowest key (load order) to highest for (auto iter = lockedLoadOrder.begin(); iter != lockedLoadOrder.end(); ++iter) { @@ -783,7 +800,7 @@ void PluginList::refreshLoadOrder() continue; } - int temp = targetPrio; + int temp = targetPrio; int index = nameIter->second; if (m_ESPs[index].priority != temp) { setPluginPriority(index, temp); @@ -798,7 +815,8 @@ void PluginList::refreshLoadOrder() } } -void PluginList::disconnectSlots() { +void PluginList::disconnectSlots() +{ m_PluginMoved.disconnect_all_slots(); m_Refreshed.disconnect_all_slots(); m_PluginStateChanged.disconnect_all_slots(); @@ -813,48 +831,50 @@ QStringList PluginList::pluginNames() const { QStringList result; - for (const ESPInfo &info : m_ESPs) { + for (const ESPInfo& info : m_ESPs) { result.append(info.name); } return result; } -IPluginList::PluginStates PluginList::state(const QString &name) const +IPluginList::PluginStates PluginList::state(const QString& name) const { auto iter = m_ESPsByName.find(name); if (iter == m_ESPsByName.end()) { return IPluginList::STATE_MISSING; } else { - return m_ESPs[iter->second].enabled ? IPluginList::STATE_ACTIVE : IPluginList::STATE_INACTIVE; + return m_ESPs[iter->second].enabled ? IPluginList::STATE_ACTIVE + : IPluginList::STATE_INACTIVE; } } -void PluginList::setState(const QString &name, PluginStates state) { +void PluginList::setState(const QString& name, PluginStates state) +{ auto iter = m_ESPsByName.find(name); if (iter != m_ESPsByName.end()) { - m_ESPs[iter->second].enabled = (state == IPluginList::STATE_ACTIVE) || - m_ESPs[iter->second].forceEnabled; + m_ESPs[iter->second].enabled = + (state == IPluginList::STATE_ACTIVE) || m_ESPs[iter->second].forceEnabled; } else { log::warn("Plugin not found: {}", name); } } -void PluginList::setLoadOrder(const QStringList &pluginList) +void PluginList::setLoadOrder(const QStringList& pluginList) { - for (ESPInfo &info : m_ESPs) { + for (ESPInfo& info : m_ESPs) { info.priority = -1; } int maxPriority = 0; - for (const QString &plugin : pluginList) { + for (const QString& plugin : pluginList) { auto iter = m_ESPsByName.find(plugin); - if (iter !=m_ESPsByName.end()) { + if (iter != m_ESPsByName.end()) { m_ESPs[iter->second].priority = maxPriority++; } } // use old priorities - for (ESPInfo &info : m_ESPs) { + for (ESPInfo& info : m_ESPs) { if (info.priority == -1) { info.priority = maxPriority++; } @@ -862,7 +882,7 @@ void PluginList::setLoadOrder(const QStringList &pluginList) updateIndices(); } -int PluginList::priority(const QString &name) const +int PluginList::priority(const QString& name) const { auto iter = m_ESPsByName.find(name); if (iter == m_ESPsByName.end()) { @@ -872,7 +892,8 @@ int PluginList::priority(const QString &name) const } } -bool PluginList::setPriority(const QString& name, int newPriority) { +bool PluginList::setPriority(const QString& name, int newPriority) +{ if (newPriority < 0 || newPriority >= static_cast<int>(m_ESPsByPriority.size())) { return false; @@ -890,12 +911,12 @@ bool PluginList::setPriority(const QString& name, int newPriority) { if (oldPriority < newPriority) { newPriority += 1; } - changePluginPriority({ rowIndex }, newPriority); + changePluginPriority({rowIndex}, newPriority); return true; } -int PluginList::loadOrder(const QString &name) const +int PluginList::loadOrder(const QString& name) const { auto iter = m_ESPsByName.find(name); if (iter == m_ESPsByName.end()) { @@ -905,21 +926,21 @@ int PluginList::loadOrder(const QString &name) const } } -QStringList PluginList::masters(const QString &name) const +QStringList PluginList::masters(const QString& name) const { auto iter = m_ESPsByName.find(name); if (iter == m_ESPsByName.end()) { return QStringList(); } else { QStringList result; - for (const QString &master : m_ESPs[iter->second].masters) { + for (const QString& master : m_ESPs[iter->second].masters) { result.append(master); } return result; } } -QString PluginList::origin(const QString &name) const +QString PluginList::origin(const QString& name) const { auto iter = m_ESPsByName.find(name); if (iter == m_ESPsByName.end()) { @@ -934,8 +955,7 @@ bool PluginList::hasMasterExtension(const QString& name) const auto iter = m_ESPsByName.find(name); if (iter == m_ESPsByName.end()) { return false; - } - else { + } else { return m_ESPs[iter->second].hasMasterExtension; } } @@ -945,8 +965,7 @@ bool PluginList::hasLightExtension(const QString& name) const auto iter = m_ESPsByName.find(name); if (iter == m_ESPsByName.end()) { return false; - } - else { + } else { return m_ESPs[iter->second].hasLightExtension; } } @@ -956,8 +975,7 @@ bool PluginList::isMasterFlagged(const QString& name) const auto iter = m_ESPsByName.find(name); if (iter == m_ESPsByName.end()) { return false; - } - else { + } else { return m_ESPs[iter->second].isMasterFlagged; } } @@ -967,18 +985,20 @@ bool PluginList::isLightFlagged(const QString& name) const auto iter = m_ESPsByName.find(name); if (iter == m_ESPsByName.end()) { return false; - } - else { + } else { return m_ESPs[iter->second].isLightFlagged; } } -boost::signals2::connection PluginList::onPluginStateChanged(const std::function<void(const std::map<QString, PluginStates>&)>& func) +boost::signals2::connection PluginList::onPluginStateChanged( + const std::function<void(const std::map<QString, PluginStates>&)>& func) { return m_PluginStateChanged.connect(func); } -void PluginList::pluginStatesChanged(QStringList const& pluginNames, PluginStates state) const { +void PluginList::pluginStatesChanged(QStringList const& pluginNames, + PluginStates state) const +{ if (pluginNames.isEmpty()) { return; } @@ -989,12 +1009,14 @@ void PluginList::pluginStatesChanged(QStringList const& pluginNames, PluginState m_PluginStateChanged(infos); } -boost::signals2::connection PluginList::onRefreshed(const std::function<void ()> &callback) +boost::signals2::connection +PluginList::onRefreshed(const std::function<void()>& callback) { return m_Refreshed.connect(callback); } -boost::signals2::connection PluginList::onPluginMoved(const std::function<void (const QString &, int, int)> &func) +boost::signals2::connection +PluginList::onPluginMoved(const std::function<void(const QString&, int, int)>& func) { return m_PluginMoved.connect(func); } @@ -1012,7 +1034,7 @@ void PluginList::updateIndices() log::error("invalid plugin priority: {}", m_ESPs[i].priority); continue; } - m_ESPsByName[m_ESPs[i].name] = i; + m_ESPsByName[m_ESPs[i].name] = i; m_ESPsByPriority.at(static_cast<size_t>(m_ESPs[i].priority)) = i; } @@ -1021,11 +1043,12 @@ void PluginList::updateIndices() void PluginList::generatePluginIndexes() { - int numESLs = 0; + int numESLs = 0; int numSkipped = 0; GamePlugins* gamePlugins = m_GamePlugin->feature<GamePlugins>(); - const bool lightPluginsSupported = gamePlugins ? gamePlugins->lightPluginsAreSupported() : false; + const bool lightPluginsSupported = + gamePlugins ? gamePlugins->lightPluginsAreSupported() : false; for (int l = 0; l < m_ESPs.size(); ++l) { int i = m_ESPsByPriority.at(l); @@ -1034,18 +1057,23 @@ void PluginList::generatePluginIndexes() ++numSkipped; continue; } - if (lightPluginsSupported && (m_ESPs[i].hasLightExtension || m_ESPs[i].isLightFlagged)) { - int ESLpos = 254 + ((numESLs + 1) / 4096); - m_ESPs[i].index = QString("%1:%2").arg(ESLpos, 2, 16, QChar('0')).arg((numESLs) % 4096, 3, 16, QChar('0')).toUpper(); + if (lightPluginsSupported && + (m_ESPs[i].hasLightExtension || m_ESPs[i].isLightFlagged)) { + int ESLpos = 254 + ((numESLs + 1) / 4096); + m_ESPs[i].index = QString("%1:%2") + .arg(ESLpos, 2, 16, QChar('0')) + .arg((numESLs) % 4096, 3, 16, QChar('0')) + .toUpper(); ++numESLs; } else { - m_ESPs[i].index = QString("%1").arg(l - numESLs - numSkipped, 2, 16, QChar('0')).toUpper(); + m_ESPs[i].index = + QString("%1").arg(l - numESLs - numSkipped, 2, 16, QChar('0')).toUpper(); } } emit esplist_changed(); } -int PluginList::rowCount(const QModelIndex &parent) const +int PluginList::rowCount(const QModelIndex& parent) const { if (!parent.isValid()) { return static_cast<int>(m_ESPs.size()); @@ -1054,7 +1082,7 @@ int PluginList::rowCount(const QModelIndex &parent) const } } -int PluginList::columnCount(const QModelIndex &) const +int PluginList::columnCount(const QModelIndex&) const { return COL_LASTCOLUMN + 1; } @@ -1062,16 +1090,16 @@ int PluginList::columnCount(const QModelIndex &) const void PluginList::testMasters() { std::set<QString, FileNameComparator> enabledMasters; - for (const auto& iter: m_ESPs) { + for (const auto& iter : m_ESPs) { if (iter.enabled) { enabledMasters.insert(iter.name); } } - for (auto& iter: m_ESPs) { + for (auto& iter : m_ESPs) { iter.masterUnset.clear(); if (iter.enabled) { - for (const auto& master: iter.masters) { + for (const auto& master : iter.masters) { if (enabledMasters.find(master) == enabledMasters.end()) { iter.masterUnset.insert(master); } @@ -1080,7 +1108,7 @@ void PluginList::testMasters() } } -QVariant PluginList::data(const QModelIndex &modelIndex, int role) const +QVariant PluginList::data(const QModelIndex& modelIndex, int role) const { int index = modelIndex.row(); @@ -1104,27 +1132,26 @@ QVariant PluginList::data(const QModelIndex &modelIndex, int role) const return QVariant(); } -QVariant PluginList::displayData(const QModelIndex &modelIndex) const +QVariant PluginList::displayData(const QModelIndex& modelIndex) const { const int index = modelIndex.row(); - switch (modelIndex.column()) - { - case COL_NAME: - return m_ESPs[index].name; + switch (modelIndex.column()) { + case COL_NAME: + return m_ESPs[index].name; - case COL_PRIORITY: - return m_ESPs[index].priority; + case COL_PRIORITY: + return m_ESPs[index].priority; - case COL_MODINDEX: - return m_ESPs[index].index; + case COL_MODINDEX: + return m_ESPs[index].index; - default: - return {}; + default: + return {}; } } -QVariant PluginList::checkstateData(const QModelIndex &modelIndex) const +QVariant PluginList::checkstateData(const QModelIndex& modelIndex) const { const int index = modelIndex.row(); @@ -1135,7 +1162,7 @@ QVariant PluginList::checkstateData(const QModelIndex &modelIndex) const return m_ESPs[index].enabled ? Qt::Checked : Qt::Unchecked; } -QVariant PluginList::foregroundData(const QModelIndex &modelIndex) const +QVariant PluginList::foregroundData(const QModelIndex& modelIndex) const { const int index = modelIndex.row(); @@ -1146,7 +1173,7 @@ QVariant PluginList::foregroundData(const QModelIndex &modelIndex) const return {}; } -QVariant PluginList::backgroundData(const QModelIndex &modelIndex) const +QVariant PluginList::backgroundData(const QModelIndex& modelIndex) const { const int index = modelIndex.row(); @@ -1157,14 +1184,13 @@ QVariant PluginList::backgroundData(const QModelIndex &modelIndex) const return {}; } -QVariant PluginList::fontData(const QModelIndex &modelIndex) const +QVariant PluginList::fontData(const QModelIndex& modelIndex) const { const int index = modelIndex.row(); QFont result; - if (m_ESPs[index].hasMasterExtension || - m_ESPs[index].isMasterFlagged || + if (m_ESPs[index].hasMasterExtension || m_ESPs[index].isMasterFlagged || m_ESPs[index].hasLightExtension) { result.setItalic(true); result.setWeight(QFont::Bold); @@ -1175,7 +1201,7 @@ QVariant PluginList::fontData(const QModelIndex &modelIndex) const return result; } -QVariant PluginList::alignmentData(const QModelIndex &modelIndex) const +QVariant PluginList::alignmentData(const QModelIndex& modelIndex) const { const int index = modelIndex.row(); @@ -1186,7 +1212,7 @@ QVariant PluginList::alignmentData(const QModelIndex &modelIndex) const } } -QVariant PluginList::tooltipData(const QModelIndex &modelIndex) const +QVariant PluginList::tooltipData(const QModelIndex& modelIndex) const { const int index = modelIndex.row(); const auto& esp = m_ESPs[index]; @@ -1196,69 +1222,65 @@ QVariant PluginList::tooltipData(const QModelIndex &modelIndex) const toolTip += "<b>" + tr("Origin") + "</b>: " + esp.originName; if (esp.forceEnabled) { - toolTip += - "<br><b><i>" + - tr("This plugin can't be disabled (enforced by the game).") + - "</i></b>"; + toolTip += "<br><b><i>" + + tr("This plugin can't be disabled (enforced by the game).") + "</i></b>"; } else { if (!esp.author.isEmpty()) { - toolTip += - "<br><b>" + tr("Author") + "</b>: " + - TruncateString(esp.author); + toolTip += "<br><b>" + tr("Author") + "</b>: " + TruncateString(esp.author); } if (esp.description.size() > 0) { toolTip += - "<br><b>" + tr("Description") + "</b>: " + - TruncateString(esp.description); + "<br><b>" + tr("Description") + "</b>: " + TruncateString(esp.description); } if (esp.masterUnset.size() > 0) { toolTip += - "<br><b>" + tr("Missing Masters") + "</b>: " + - "<b>" + TruncateString(QStringList(esp.masterUnset.begin(), esp.masterUnset.end()).join(", ")) + "</b>"; + "<br><b>" + tr("Missing Masters") + "</b>: " + "<b>" + + TruncateString( + QStringList(esp.masterUnset.begin(), esp.masterUnset.end()).join(", ")) + + "</b>"; } std::set<QString> enabledMasters; - std::set_difference(esp.masters.begin(), esp.masters.end(), - esp.masterUnset.begin(), esp.masterUnset.end(), - std::inserter(enabledMasters, enabledMasters.end())); + std::set_difference(esp.masters.begin(), esp.masters.end(), esp.masterUnset.begin(), + esp.masterUnset.end(), + std::inserter(enabledMasters, enabledMasters.end())); if (!enabledMasters.empty()) { - toolTip += - "<br><b>" + tr("Enabled Masters") + "</b>: " + - TruncateString(SetJoin(enabledMasters, ", ")); + toolTip += "<br><b>" + tr("Enabled Masters") + + "</b>: " + TruncateString(SetJoin(enabledMasters, ", ")); } if (!esp.archives.empty()) { toolTip += - "<br><b>" + tr("Loads Archives") + "</b>: " + - TruncateString(QStringList(esp.archives.begin(), esp.archives.end()).join(", ")) + - "<br>" + tr( - "There are Archives connected to this plugin. Their assets will be " - "added to your game, overwriting in case of conflicts following the " - "plugin order. Loose files will always overwrite assets from " - "Archives. (This flag only checks for Archives from the same mod as " - "the plugin)"); + "<br><b>" + tr("Loads Archives") + "</b>: " + + TruncateString( + QStringList(esp.archives.begin(), esp.archives.end()).join(", ")) + + "<br>" + + tr("There are Archives connected to this plugin. Their assets will be " + "added to your game, overwriting in case of conflicts following the " + "plugin order. Loose files will always overwrite assets from " + "Archives. (This flag only checks for Archives from the same mod as " + "the plugin)"); } if (esp.hasIni) { toolTip += - "<br><b>" + tr("Loads INI settings") + "</b>: " - "<br>" + tr( - "There is an ini file connected to this plugin. Its settings will " - "be added to your game settings, overwriting in case of conflicts."); + "<br><b>" + tr("Loads INI settings") + + "</b>: " + "<br>" + + tr("There is an ini file connected to this plugin. Its settings will " + "be added to your game settings, overwriting in case of conflicts."); } if (esp.isLightFlagged && !esp.hasLightExtension) { - toolTip += - "<br><br>" + tr( - "This ESP is flagged as an ESL. It will adhere to the ESP load " - "order but the records will be loaded in ESL space."); + toolTip += "<br><br>" + + tr("This ESP is flagged as an ESL. It will adhere to the ESP load " + "order but the records will be loaded in ESL space."); } } - // additional info auto itor = m_AdditionalInfo.find(esp.name); @@ -1285,10 +1307,10 @@ QString PluginList::makeLootTooltip(const Loot::Plugin& loot) const QString s; for (auto&& f : loot.incompatibilities) { - s += - "<li>" + tr("Incompatible with %1") - .arg(f.displayName.isEmpty() ? f.name : f.displayName) + - "</li>"; + s += "<li>" + + tr("Incompatible with %1") + .arg(f.displayName.isEmpty() ? f.name : f.displayName) + + "</li>"; } for (auto&& m : loot.missingMasters) { @@ -1298,21 +1320,20 @@ QString PluginList::makeLootTooltip(const Loot::Plugin& loot) const for (auto&& m : loot.messages) { s += "<li>"; - switch (m.type) - { - case log::Warning: - s += tr("Warning") + ": "; - break; + switch (m.type) { + case log::Warning: + s += tr("Warning") + ": "; + break; - case log::Error: - s += tr("Error") + ": "; - break; + case log::Error: + s += tr("Error") + ": "; + break; - case log::Info: // fall-through - case log::Debug: - default: - // nothing - break; + case log::Info: // fall-through + case log::Debug: + default: + // nothing + break; } s += m.text + "</li>"; @@ -1327,17 +1348,16 @@ QString PluginList::makeLootTooltip(const Loot::Plugin& loot) const } if (!s.isEmpty()) { - s = - "<hr>" - "<ul style=\"margin-top:0px; padding-top:0px; margin-left:15px; -qt-list-indent: 0;\">" + - s + - "</ul>"; + s = "<hr>" + "<ul style=\"margin-top:0px; padding-top:0px; margin-left:15px; " + "-qt-list-indent: 0;\">" + + s + "</ul>"; } return s; } -QVariant PluginList::iconData(const QModelIndex &modelIndex) const +QVariant PluginList::iconData(const QModelIndex& modelIndex) const { int index = modelIndex.row(); @@ -1417,9 +1437,9 @@ bool PluginList::hasInfo(const ESPInfo& esp, const AdditionalInfo* info) const return false; } -bool PluginList::setData(const QModelIndex &modIndex, const QVariant &value, int role) +bool PluginList::setData(const QModelIndex& modIndex, const QVariant& value, int role) { - QString modName = modIndex.data().toString(); + QString modName = modIndex.data().toString(); IPluginList::PluginStates oldState = state(modName); bool result = false; @@ -1436,7 +1456,7 @@ bool PluginList::setData(const QModelIndex &modIndex, const QVariant &value, int result = true; } else if (role == Qt::EditRole) { if (modIndex.column() == COL_PRIORITY) { - bool ok = false; + bool ok = false; int newPriority = value.toInt(&ok); if (ok) { setPluginPriority(modIndex.row(), newPriority); @@ -1450,12 +1470,11 @@ bool PluginList::setData(const QModelIndex &modIndex, const QVariant &value, int IPluginList::PluginStates newState = state(modName); if (oldState != newState) { try { - pluginStatesChanged({ modName }, newState); + pluginStatesChanged({modName}, newState); testMasters(); - emit dataChanged( - this->index(0, 0), - this->index(static_cast<int>(m_ESPs.size()), columnCount())); - } catch (const std::exception &e) { + emit dataChanged(this->index(0, 0), + this->index(static_cast<int>(m_ESPs.size()), columnCount())); + } catch (const std::exception& e) { log::error("failed to invoke state changed notification: {}", e.what()); } catch (...) { log::error("failed to invoke state changed notification: unknown exception"); @@ -1466,7 +1485,7 @@ bool PluginList::setData(const QModelIndex &modIndex, const QVariant &value, int } QVariant PluginList::headerData(int section, Qt::Orientation orientation, - int role) const + int role) const { if (orientation == Qt::Horizontal) { if (role == Qt::DisplayRole) { @@ -1478,12 +1497,12 @@ QVariant PluginList::headerData(int section, Qt::Orientation orientation, return QAbstractItemModel::headerData(section, orientation, role); } -Qt::ItemFlags PluginList::flags(const QModelIndex &modelIndex) const +Qt::ItemFlags PluginList::flags(const QModelIndex& modelIndex) const { - int index = modelIndex.row(); + int index = modelIndex.row(); Qt::ItemFlags result = QAbstractItemModel::flags(modelIndex); - if (modelIndex.isValid()) { + if (modelIndex.isValid()) { if (!m_ESPs[index].forceEnabled) { result |= Qt::ItemIsUserCheckable | Qt::ItemIsDragEnabled; } @@ -1498,7 +1517,7 @@ Qt::ItemFlags PluginList::flags(const QModelIndex &modelIndex) const return result; } -void PluginList::setPluginPriority(int row, int &newPriority, bool isForced) +void PluginList::setPluginPriority(int row, int& newPriority, bool isForced) { int newPriorityTemp = newPriority; @@ -1508,14 +1527,13 @@ void PluginList::setPluginPriority(int row, int &newPriority, bool isForced) else if (newPriorityTemp >= static_cast<int>(m_ESPsByPriority.size())) newPriorityTemp = static_cast<int>(m_ESPsByPriority.size()) - 1; - if (!m_ESPs[row].isMasterFlagged && - !m_ESPs[row].hasLightExtension && + if (!m_ESPs[row].isMasterFlagged && !m_ESPs[row].hasLightExtension && !m_ESPs[row].hasMasterExtension) { // don't allow esps to be moved above esms while ((newPriorityTemp < static_cast<int>(m_ESPsByPriority.size() - 1)) && - (m_ESPs.at(m_ESPsByPriority.at(newPriorityTemp)).isMasterFlagged || - m_ESPs.at(m_ESPsByPriority.at(newPriorityTemp)).hasLightExtension || - m_ESPs.at(m_ESPsByPriority.at(newPriorityTemp)).hasMasterExtension)) { + (m_ESPs.at(m_ESPsByPriority.at(newPriorityTemp)).isMasterFlagged || + m_ESPs.at(m_ESPsByPriority.at(newPriorityTemp)).hasLightExtension || + m_ESPs.at(m_ESPsByPriority.at(newPriorityTemp)).hasMasterExtension)) { ++newPriorityTemp; } } else { @@ -1534,20 +1552,18 @@ void PluginList::setPluginPriority(int row, int &newPriority, bool isForced) } int oldPriority = m_ESPs.at(row).priority; - if (newPriorityTemp < oldPriority) { // moving up + if (newPriorityTemp < oldPriority) { // moving up // don't allow plugins to be moved above their masters for (auto master : m_ESPs[row].masters) { auto iter = m_ESPsByName.find(master); if (iter != m_ESPsByName.end()) { int masterPriority = m_ESPs[iter->second].priority; - if (masterPriority >= newPriorityTemp) - { + if (masterPriority >= newPriorityTemp) { newPriorityTemp = masterPriority + 1; } } } - } - else if (newPriorityTemp > oldPriority) { // moving down + } else if (newPriorityTemp > oldPriority) { // moving down // don't allow masters to be moved below their children for (int i = oldPriority + 1; i <= newPriorityTemp; i++) { PluginList::ESPInfo* otherInfo = &m_ESPs.at(m_ESPsByPriority[i]); @@ -1567,13 +1583,14 @@ void PluginList::setPluginPriority(int row, int &newPriority, bool isForced) for (int i = oldPriority + 1; i <= newPriorityTemp; ++i) { --m_ESPs.at(m_ESPsByPriority.at(i)).priority; } - emit dataChanged(index(oldPriority + 1, 0), index(newPriorityTemp, columnCount())); - } - else { + emit dataChanged(index(oldPriority + 1, 0), + index(newPriorityTemp, columnCount())); + } else { for (int i = newPriorityTemp; i < oldPriority; ++i) { ++m_ESPs.at(m_ESPsByPriority.at(i)).priority; } - emit dataChanged(index(newPriorityTemp, 0), index(oldPriority - 1, columnCount())); + emit dataChanged(index(newPriorityTemp, 0), + index(oldPriority - 1, columnCount())); ++newPriority; } @@ -1591,14 +1608,14 @@ void PluginList::setPluginPriority(int row, int &newPriority, bool isForced) void PluginList::changePluginPriority(std::vector<int> rows, int newPriority) { ChangeBracket<PluginList> layoutChange(this); - const std::vector<ESPInfo> &esp = m_ESPs; + const std::vector<ESPInfo>& esp = m_ESPs; int minPriority = INT_MAX; int maxPriority = INT_MIN; // don't try to move plugins before force-enabled plugins - for (std::vector<ESPInfo>::const_iterator iter = m_ESPs.begin(); - iter != m_ESPs.end(); ++iter) { + for (std::vector<ESPInfo>::const_iterator iter = m_ESPs.begin(); iter != m_ESPs.end(); + ++iter) { if (iter->forceEnabled) { newPriority = std::max(newPriority, iter->priority + 1); } @@ -1611,22 +1628,22 @@ void PluginList::changePluginPriority(std::vector<int> rows, int newPriority) newPriority = std::max(newPriority, minPriority); // sort the moving plugins by ascending priorities - std::sort(rows.begin(), rows.end(), - [&esp](const int &LHS, const int &RHS) { + std::sort(rows.begin(), rows.end(), [&esp](const int& LHS, const int& RHS) { return esp[LHS].priority < esp[RHS].priority; }); // if at least on plugin is increasing in priority, the target index is // that of the row BELOW the dropped location, otherwise it's the one above - for (std::vector<int>::const_iterator iter = rows.begin(); - iter != rows.end(); ++iter) { + for (std::vector<int>::const_iterator iter = rows.begin(); iter != rows.end(); + ++iter) { if (m_ESPs[*iter].priority < newPriority) { --newPriority; break; } } - for (std::vector<int>::const_iterator iter = rows.begin(); iter != rows.end(); ++iter) { + for (std::vector<int>::const_iterator iter = rows.begin(); iter != rows.end(); + ++iter) { setPluginPriority(*iter, newPriority); } @@ -1635,7 +1652,8 @@ void PluginList::changePluginPriority(std::vector<int> rows, int newPriority) emit writePluginsList(); } -bool PluginList::dropMimeData(const QMimeData *mimeData, Qt::DropAction action, int row, int, const QModelIndex &parent) +bool PluginList::dropMimeData(const QMimeData* mimeData, Qt::DropAction action, int row, + int, const QModelIndex& parent) { if (action == Qt::IgnoreAction) { return true; @@ -1648,9 +1666,9 @@ bool PluginList::dropMimeData(const QMimeData *mimeData, Qt::DropAction action, while (!stream.atEnd()) { int sourceRow, col; - QMap<int, QVariant> roleDataMap; + QMap<int, QVariant> roleDataMap; stream >> sourceRow >> col >> roleDataMap; - if (col == 0) { // only add each row once + if (col == 0) { // only add each row once sourceRows.push_back(sourceRow); } } @@ -1661,8 +1679,7 @@ bool PluginList::dropMimeData(const QMimeData *mimeData, Qt::DropAction action, int newPriority; - if ((row < 0) || - (row >= static_cast<int>(m_ESPs.size()))) { + if ((row < 0) || (row >= static_cast<int>(m_ESPs.size()))) { newPriority = static_cast<int>(m_ESPs.size()); } else { newPriority = m_ESPs[row].priority; @@ -1685,37 +1702,38 @@ QModelIndex PluginList::parent(const QModelIndex&) const return QModelIndex(); } -PluginList::ESPInfo::ESPInfo(const QString &name, bool enabled, - const QString &originName, const QString &fullPath, - bool hasIni, std::set<QString> archives, bool lightPluginsAreSupported) - : name(name), fullPath(fullPath), enabled(enabled), forceEnabled(enabled), - priority(0), loadOrder(-1), originName(originName), hasIni(hasIni), - archives(archives.begin(), archives.end()), modSelected(false) +PluginList::ESPInfo::ESPInfo(const QString& name, bool enabled, + const QString& originName, const QString& fullPath, + bool hasIni, std::set<QString> archives, + bool lightPluginsAreSupported) + : name(name), fullPath(fullPath), enabled(enabled), forceEnabled(enabled), + priority(0), loadOrder(-1), originName(originName), hasIni(hasIni), + archives(archives.begin(), archives.end()), modSelected(false) { try { ESP::File file(ToWString(fullPath)); - auto extension = name.right(3).toLower(); + auto extension = name.right(3).toLower(); hasMasterExtension = (extension == "esm"); - hasLightExtension = lightPluginsAreSupported && (extension == "esl"); - isMasterFlagged = file.isMaster(); - isLightFlagged = lightPluginsAreSupported && file.isLight(); + hasLightExtension = lightPluginsAreSupported && (extension == "esl"); + isMasterFlagged = file.isMaster(); + isLightFlagged = lightPluginsAreSupported && file.isLight(); - author = QString::fromLatin1(file.author().c_str()); + author = QString::fromLatin1(file.author().c_str()); description = QString::fromLatin1(file.description().c_str()); for (auto&& m : file.masters()) { masters.insert(QString::fromStdString(m)); } - } catch (const std::exception &e) { + } catch (const std::exception& e) { log::error("failed to parse plugin file {}: {}", fullPath, e.what()); hasMasterExtension = false; - hasLightExtension = false; - isMasterFlagged = false; - isLightFlagged = false; + hasLightExtension = false; + isMasterFlagged = false; + isLightFlagged = false; } } -void PluginList::managedGameChanged(const IPluginGame *gamePlugin) +void PluginList::managedGameChanged(const IPluginGame* gamePlugin) { m_GamePlugin = gamePlugin; } |
