From 58b6e0eb48b4d4b201613f1062796a9af68fe454 Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Wed, 20 Jan 2021 18:16:20 +0100 Subject: Increase robustness of mods priority in profile. --- src/modlist.cpp | 60 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 31 deletions(-) (limited to 'src/modlist.cpp') diff --git a/src/modlist.cpp b/src/modlist.cpp index ffa841ed..4518f2e9 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -223,8 +223,7 @@ QVariant ModList::data(const QModelIndex &modelIndex, int role) const return version; } else if (column == COL_PRIORITY) { - int priority = modInfo->getFixedPriority(); - if (priority != INT_MIN) { + if (modInfo->isBackup() || modInfo->isOverwrite()) { return QVariant(); // hide priority for mods where it's fixed } else { @@ -337,9 +336,11 @@ QVariant ModList::data(const QModelIndex &modelIndex, int role) const } } else if (column == COL_PRIORITY) { - int priority = modInfo->getFixedPriority(); - if (priority != INT_MIN) { - return priority; + if (modInfo->isBackup()) { + return ModInfo::BACKUP_PRIORITY; + } + else if (modInfo->isOverwrite()) { + return ModInfo::OVERWRITE_PRIORITY; } else { return m_Profile->getModPriority(modIndex); @@ -365,9 +366,11 @@ QVariant ModList::data(const QModelIndex &modelIndex, int role) const return modInfo->gameName(); } else if (role == PriorityRole) { - int priority = modInfo->getFixedPriority(); - if (priority != std::numeric_limits::min()) { - return priority; + if (modInfo->isBackup()) { + return ModInfo::BACKUP_PRIORITY; + } + else if (modInfo->isOverwrite()) { + return ModInfo::OVERWRITE_PRIORITY; } else { return m_Profile->getModPriority(modIndex); @@ -687,7 +690,7 @@ Qt::ItemFlags ModList::flags(const QModelIndex &modelIndex) const } if (modelIndex.isValid()) { ModInfo::Ptr modInfo = ModInfo::getByIndex(modelIndex.row()); - if (modInfo->getFixedPriority() == INT_MIN) { + if (!modInfo->isFixedPriority()) { result |= Qt::ItemIsDragEnabled; result |= Qt::ItemIsUserCheckable; if ((modelIndex.column() == COL_PRIORITY) || @@ -743,8 +746,9 @@ void ModList::changeModPriority(std::vector sourceIndices, int newPriority) iter != sourceIndices.end(); ++iter) { int oldPriority = m_Profile->getModPriority(*iter); if (oldPriority > newPriority) { - m_Profile->setModPriority(*iter, newPriority); - m_ModMoved(ModInfo::getByIndex(*iter)->name(), oldPriority, newPriority); + if (m_Profile->setModPriority(*iter, newPriority)) { + m_ModMoved(ModInfo::getByIndex(*iter)->name(), oldPriority, newPriority); + } } } @@ -770,8 +774,9 @@ void ModList::changeModPriority(std::vector sourceIndices, int newPriority) iter != sourceIndices.end(); ++iter) { int oldPriority = m_Profile->getModPriority(*iter); if (oldPriority < newPriority) { - m_Profile->setModPriority(*iter, newPriority); - m_ModMoved(ModInfo::getByIndex(*iter)->name(), oldPriority, newPriority); + if (m_Profile->setModPriority(*iter, newPriority)) { + m_ModMoved(ModInfo::getByIndex(*iter)->name(), oldPriority, newPriority); + } } } @@ -901,11 +906,8 @@ QStringList ModList::allModsByProfilePriority(MOBase::IProfile* profile) const m_Organizer->currentProfile() : static_cast(profile); QStringList res; - for (int i = mo2Profile->getPriorityMinimum(); - i < mo2Profile->getPriorityMinimum() + (int)mo2Profile->numRegularMods(); - ++i) { - int modIndex = mo2Profile->modIndexByPriority(i); - auto modInfo = ModInfo::getByIndex(modIndex); + for (auto& [priority, index] : mo2Profile->getAllIndexesByPriority()) { + auto modInfo = ModInfo::getByIndex(index); if (!modInfo->isBackup() && !modInfo->isOverwrite()) { res.push_back(modInfo->internalName()); } @@ -1008,16 +1010,13 @@ int ModList::priority(const QString &name) const bool ModList::setPriority(const QString &name, int newPriority) { - if ((newPriority < 0) || (newPriority >= static_cast(m_Profile->numRegularMods()))) { - return false; - } - - unsigned int modIndex = ModInfo::getIndex(name); - if (modIndex == UINT_MAX) { + unsigned int index = ModInfo::getIndex(name); + if (index == UINT_MAX) { return false; } else { - m_Profile->setModPriority(modIndex, newPriority); - notifyChange(modIndex); + if (m_Profile->setModPriority(index, newPriority)) { + notifyChange(index); + } return true; } } @@ -1074,14 +1073,14 @@ int ModList::dropPriority(int row, const QModelIndex& parent) const int newPriority = 0; { - if ((row < 0) || (row > static_cast(m_Profile->numRegularMods()))) { - newPriority = m_Profile->numRegularMods() + 1; + if (row < 0 || row >= rowCount()) { + newPriority = std::numeric_limits::max(); } else { newPriority = m_Profile->getModPriority(row); } if (newPriority == -1) { - newPriority = m_Profile->numRegularMods() + 1; + newPriority = std::numeric_limits::max(); } } @@ -1408,8 +1407,7 @@ void ModList::shiftModsPriority(const QModelIndexList& indices, int offset) std::vector notify; for (auto index : allIndex) { int newPriority = m_Profile->getModPriority(index) + offset; - if ((newPriority >= 0) && (newPriority < static_cast(m_Profile->numRegularMods()))) { - m_Profile->setModPriority(index, newPriority); + if (m_Profile->setModPriority(index, newPriority)) { notify.push_back(index); } } -- cgit v1.3.1 From 0e7fed0e32cf7cd6ff342493621287e0040e51ad Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Wed, 20 Jan 2021 21:01:49 +0100 Subject: Move backup and overwrite priority to ModList. --- src/modinfo.h | 6 ------ src/modlist.cpp | 8 ++++---- src/modlist.h | 9 +++++++-- 3 files changed, 11 insertions(+), 12 deletions(-) (limited to 'src/modlist.cpp') diff --git a/src/modinfo.h b/src/modinfo.h index 621a0443..0fbcd1c0 100644 --- a/src/modinfo.h +++ b/src/modinfo.h @@ -103,12 +103,6 @@ public: // Type definitions: MOD_CC }; - // the priority of backups and overwrite from a mod list point of - // view, these do not correspond to the actual priority in the profile - // - static constexpr int BACKUP_PRIORITY = -1; - static constexpr int OVERWRITE_PRIORITY = std::numeric_limits::max(); - public: // Static functions: diff --git a/src/modlist.cpp b/src/modlist.cpp index 4518f2e9..073dbfd3 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -337,10 +337,10 @@ QVariant ModList::data(const QModelIndex &modelIndex, int role) const } else if (column == COL_PRIORITY) { if (modInfo->isBackup()) { - return ModInfo::BACKUP_PRIORITY; + return BACKUP_PRIORITY; } else if (modInfo->isOverwrite()) { - return ModInfo::OVERWRITE_PRIORITY; + return OVERWRITE_PRIORITY; } else { return m_Profile->getModPriority(modIndex); @@ -367,10 +367,10 @@ QVariant ModList::data(const QModelIndex &modelIndex, int role) const } else if (role == PriorityRole) { if (modInfo->isBackup()) { - return ModInfo::BACKUP_PRIORITY; + return BACKUP_PRIORITY; } else if (modInfo->isOverwrite()) { - return ModInfo::OVERWRITE_PRIORITY; + return OVERWRITE_PRIORITY; } else { return m_Profile->getModPriority(modIndex); diff --git a/src/modlist.h b/src/modlist.h index 5c7f28ee..8d0a2384 100644 --- a/src/modlist.h +++ b/src/modlist.h @@ -366,10 +366,15 @@ private: // int dropPriority(int row, const QModelIndex& parent) const; -private slots: - private: + // the priority of backups and overwrite for sorting (and display, although + // those are not displayed), these do not correspond to the actual priority + // in the mod list + // + static constexpr int BACKUP_PRIORITY = -1; + static constexpr int OVERWRITE_PRIORITY = std::numeric_limits::max(); + struct TModInfo { TModInfo(unsigned int index, ModInfo::Ptr modInfo) : modInfo(modInfo), nameOrder(index), priorityOrder(0), modIDOrder(0), categoryOrder(0) {} -- cgit v1.3.1 From 7c9d3777c28f79b1ae7cdbda107493493ca1ba2a Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Wed, 20 Jan 2021 21:04:49 +0100 Subject: Remove unused/undefined ModList functions. --- src/modlist.cpp | 26 -------------------------- src/modlist.h | 7 ------- 2 files changed, 33 deletions(-) (limited to 'src/modlist.cpp') diff --git a/src/modlist.cpp b/src/modlist.cpp index 073dbfd3..a9a4781e 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -128,32 +128,6 @@ QString ModList::makeInternalName(ModInfo::Ptr info, QString name) const return name; } -QVariant ModList::getOverwriteData(int column, int role) const -{ - switch (role) { - case Qt::DisplayRole: { - if (column == 0) { - return "Overwrite"; - } else { - return QVariant(); - } - } break; - case Qt::CheckStateRole: { - if (column == 0) { - return Qt::Checked; - } else { - return QVariant(); - } - } break; - case Qt::TextAlignmentRole: return QVariant(Qt::AlignCenter | Qt::AlignVCenter); - case GroupingRole: return -1; - case Qt::ForegroundRole: return QBrush(Qt::red); - case Qt::ToolTipRole: return tr("This entry contains files that have been created inside the virtual data tree (i.e. by the construction kit)"); - default: return QVariant(); - } -} - - QString ModList::getFlagText(ModInfo::EFlag flag, ModInfo::Ptr modInfo) const { switch (flag) { diff --git a/src/modlist.h b/src/modlist.h index 8d0a2384..242d185f 100644 --- a/src/modlist.h +++ b/src/modlist.h @@ -341,19 +341,12 @@ private: QString getDisplayName(ModInfo::Ptr info) const; QString makeInternalName(ModInfo::Ptr info, QString name) const; - QVariant getOverwriteData(int column, int role) const; - QString getFlagText(ModInfo::EFlag flag, ModInfo::Ptr modInfo) const; QString getConflictFlagText(ModInfo::EConflictFlag flag, ModInfo::Ptr modInfo) const; QString getColumnToolTip(int column) const; - ModList::EColumn getEnabledColumn(int index) const; - - QVariant categoryData(int categoryID, int column, int role) const; - QVariant modData(int modID, int modelColumn, int role) const; - bool renameMod(int index, const QString &newName); MOBase::IModList::ModStates state(unsigned int modIndex) const; -- cgit v1.3.1 From 0803920486ff62cccd79374b9b68084b880f010c Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Thu, 21 Jan 2021 19:20:24 +0100 Subject: Add method to retrieve priority of mods in ModList. --- src/modlist.cpp | 34 ++++++++++++++++------------------ src/modlist.h | 22 +++++++++++++++------- 2 files changed, 31 insertions(+), 25 deletions(-) (limited to 'src/modlist.cpp') diff --git a/src/modlist.cpp b/src/modlist.cpp index a9a4781e..c82aa802 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -168,6 +168,20 @@ QString ModList::getConflictFlagText(ModInfo::EConflictFlag flag, ModInfo::Ptr m } } +int ModList::modPriority(unsigned int index) const +{ + auto info = ModInfo::getByIndex(index); + if (info->isBackup()) { + return BACKUP_PRIORITY; + } + else if (info->isOverwrite()) { + return OVERWRITE_PRIORITY; + } + else { + return m_Profile->getModPriority(index); + } +} + QVariant ModList::data(const QModelIndex &modelIndex, int role) const { if (m_Profile == nullptr) return QVariant(); @@ -310,15 +324,7 @@ QVariant ModList::data(const QModelIndex &modelIndex, int role) const } } else if (column == COL_PRIORITY) { - if (modInfo->isBackup()) { - return BACKUP_PRIORITY; - } - else if (modInfo->isOverwrite()) { - return OVERWRITE_PRIORITY; - } - else { - return m_Profile->getModPriority(modIndex); - } + return modPriority(modIndex); } else { return modInfo->nexusId(); @@ -340,15 +346,7 @@ QVariant ModList::data(const QModelIndex &modelIndex, int role) const return modInfo->gameName(); } else if (role == PriorityRole) { - if (modInfo->isBackup()) { - return BACKUP_PRIORITY; - } - else if (modInfo->isOverwrite()) { - return OVERWRITE_PRIORITY; - } - else { - return m_Profile->getModPriority(modIndex); - } + return modPriority(modIndex); } else if (role == Qt::FontRole) { QFont result; diff --git a/src/modlist.h b/src/modlist.h index 242d185f..68316613 100644 --- a/src/modlist.h +++ b/src/modlist.h @@ -335,6 +335,21 @@ signals: private: + // the priority of backups and overwrite for sorting (and display, although + // those are not displayed), these do not correspond to the actual priority + // in the mod list + // + static constexpr int BACKUP_PRIORITY = -1; + static constexpr int OVERWRITE_PRIORITY = std::numeric_limits::max(); + + // retrieve the priority of a mod for the purpose of display (i.e. sorting + // or grouping) + // + // this can be different from the priority in the profile (e.g. for backups + // or overwrite) + // + int modPriority(unsigned int index) const; + // retrieve the display name of a mod or convert from a user-provided // name to internal name // @@ -361,13 +376,6 @@ private: private: - // the priority of backups and overwrite for sorting (and display, although - // those are not displayed), these do not correspond to the actual priority - // in the mod list - // - static constexpr int BACKUP_PRIORITY = -1; - static constexpr int OVERWRITE_PRIORITY = std::numeric_limits::max(); - struct TModInfo { TModInfo(unsigned int index, ModInfo::Ptr modInfo) : modInfo(modInfo), nameOrder(index), priorityOrder(0), modIDOrder(0), categoryOrder(0) {} -- cgit v1.3.1 From ffb820c701617721b82515be330a3f604b26dd7b Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Thu, 21 Jan 2021 19:21:07 +0100 Subject: Use isFixedPriority() when appropriate. --- src/modlist.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/modlist.cpp') diff --git a/src/modlist.cpp b/src/modlist.cpp index c82aa802..f83acc9c 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -211,7 +211,7 @@ QVariant ModList::data(const QModelIndex &modelIndex, int role) const return version; } else if (column == COL_PRIORITY) { - if (modInfo->isBackup() || modInfo->isOverwrite()) { + if (modInfo->isFixedPriority()) { return QVariant(); // hide priority for mods where it's fixed } else { -- cgit v1.3.1 From f8943ee477e1cb5821e6208ee2d177c26c4b4ad3 Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Thu, 21 Jan 2021 19:38:53 +0100 Subject: Use range-loop instead of old-style iterators. --- src/modlist.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'src/modlist.cpp') diff --git a/src/modlist.cpp b/src/modlist.cpp index f83acc9c..5cbc6c9f 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -714,12 +714,11 @@ void ModList::changeModPriority(std::vector sourceIndices, int newPriority) }); // move mods that are decreasing in priority - for (std::vector::const_iterator iter = sourceIndices.begin(); - iter != sourceIndices.end(); ++iter) { - int oldPriority = m_Profile->getModPriority(*iter); + for (const auto& index : sourceIndices) { + int oldPriority = m_Profile->getModPriority(index); if (oldPriority > newPriority) { - if (m_Profile->setModPriority(*iter, newPriority)) { - m_ModMoved(ModInfo::getByIndex(*iter)->name(), oldPriority, newPriority); + if (m_Profile->setModPriority(index, newPriority)) { + m_ModMoved(ModInfo::getByIndex(index)->name(), oldPriority, newPriority); } } } @@ -732,9 +731,8 @@ void ModList::changeModPriority(std::vector sourceIndices, int newPriority) // if at least one mod 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::const_iterator iter = sourceIndices.begin(); - iter != sourceIndices.end(); ++iter) { - int oldPriority = m_Profile->getModPriority(*iter); + for (const auto& index : sourceIndices) { + int oldPriority = m_Profile->getModPriority(index); if (oldPriority < newPriority) { --newPriority; break; @@ -742,12 +740,11 @@ void ModList::changeModPriority(std::vector sourceIndices, int newPriority) } // move mods that are increasing in priority - for (std::vector::const_iterator iter = sourceIndices.begin(); - iter != sourceIndices.end(); ++iter) { - int oldPriority = m_Profile->getModPriority(*iter); + for (const auto& index : sourceIndices) { + int oldPriority = m_Profile->getModPriority(index); if (oldPriority < newPriority) { - if (m_Profile->setModPriority(*iter, newPriority)) { - m_ModMoved(ModInfo::getByIndex(*iter)->name(), oldPriority, newPriority); + if (m_Profile->setModPriority(index, newPriority)) { + m_ModMoved(ModInfo::getByIndex(index)->name(), oldPriority, newPriority); } } } -- cgit v1.3.1 From 0a069709900fe37c265d8645554ae19e25bea06a Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Thu, 21 Jan 2021 20:21:57 +0100 Subject: Expose proper priority in ModList and sort in the sort proxy. --- src/modlist.cpp | 22 +--------------------- src/modlist.h | 15 --------------- src/modlistsortproxy.cpp | 7 ++++++- 3 files changed, 7 insertions(+), 37 deletions(-) (limited to 'src/modlist.cpp') diff --git a/src/modlist.cpp b/src/modlist.cpp index 5cbc6c9f..6637f48a 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -168,20 +168,6 @@ QString ModList::getConflictFlagText(ModInfo::EConflictFlag flag, ModInfo::Ptr m } } -int ModList::modPriority(unsigned int index) const -{ - auto info = ModInfo::getByIndex(index); - if (info->isBackup()) { - return BACKUP_PRIORITY; - } - else if (info->isOverwrite()) { - return OVERWRITE_PRIORITY; - } - else { - return m_Profile->getModPriority(index); - } -} - QVariant ModList::data(const QModelIndex &modelIndex, int role) const { if (m_Profile == nullptr) return QVariant(); @@ -323,9 +309,6 @@ QVariant ModList::data(const QModelIndex &modelIndex, int role) const return QVariant(); } } - else if (column == COL_PRIORITY) { - return modPriority(modIndex); - } else { return modInfo->nexusId(); } @@ -346,7 +329,7 @@ QVariant ModList::data(const QModelIndex &modelIndex, int role) const return modInfo->gameName(); } else if (role == PriorityRole) { - return modPriority(modIndex); + return m_Profile->getModPriority(modIndex); } else if (role == Qt::FontRole) { QFont result; @@ -580,9 +563,6 @@ bool ModList::setData(const QModelIndex &index, const QVariant &value, int role) case COL_PRIORITY: { bool ok = false; int newPriority = value.toInt(&ok); - if (ok && newPriority < 0) { - newPriority = 0; - } if (ok) { changeModPriority(modID, newPriority); result = true; diff --git a/src/modlist.h b/src/modlist.h index 68316613..e201de27 100644 --- a/src/modlist.h +++ b/src/modlist.h @@ -335,21 +335,6 @@ signals: private: - // the priority of backups and overwrite for sorting (and display, although - // those are not displayed), these do not correspond to the actual priority - // in the mod list - // - static constexpr int BACKUP_PRIORITY = -1; - static constexpr int OVERWRITE_PRIORITY = std::numeric_limits::max(); - - // retrieve the priority of a mod for the purpose of display (i.e. sorting - // or grouping) - // - // this can be different from the priority in the profile (e.g. for backups - // or overwrite) - // - int modPriority(unsigned int index) const; - // retrieve the display name of a mod or convert from a user-provided // name to internal name // diff --git a/src/modlistsortproxy.cpp b/src/modlistsortproxy.cpp index 18e91e6e..fc7f3270 100644 --- a/src/modlistsortproxy.cpp +++ b/src/modlistsortproxy.cpp @@ -215,7 +215,12 @@ bool ModListSortProxy::lessThan(const QModelIndex &left, } } break; case ModList::COL_PRIORITY: { - // nop, already compared by priority + if (leftMod->isBackup() != rightMod->isBackup()) { + lt = leftMod->isBackup(); + } + else if (leftMod->isOverwrite() != rightMod->isOverwrite()) { + lt = rightMod->isOverwrite(); + } } break; default: { log::warn("Sorting is not defined for column {}", left.column()); -- cgit v1.3.1 From d81fb09f33f8cd668db20b6120c481580c6c938e Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Thu, 21 Jan 2021 21:20:01 +0100 Subject: Replace isFixedPriority by hasAutomaticPriority. --- src/modinfo.h | 5 +++-- src/modlist.cpp | 4 ++-- src/profile.cpp | 8 ++++---- 3 files changed, 9 insertions(+), 8 deletions(-) (limited to 'src/modlist.cpp') diff --git a/src/modinfo.h b/src/modinfo.h index ff6c4001..f93296d2 100644 --- a/src/modinfo.h +++ b/src/modinfo.h @@ -602,9 +602,10 @@ public: // Methods after this do not come from IModInterface: */ virtual void ignoreUpdate(bool ignore) = 0; - // check if this mod has a fixed priority (i.e. that cannot be modified by users) + // check if the priority of this mod is not user-modifiable (i.e. + // computed by MO2 automatically) // - bool isFixedPriority() const { return isBackup() || isOverwrite(); } + bool hasAutomaticPriority() const { return isBackup() || isOverwrite(); } // check if this mod should always be enabled or disabled // diff --git a/src/modlist.cpp b/src/modlist.cpp index 6637f48a..e2a443bd 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -197,7 +197,7 @@ QVariant ModList::data(const QModelIndex &modelIndex, int role) const return version; } else if (column == COL_PRIORITY) { - if (modInfo->isFixedPriority()) { + if (modInfo->hasAutomaticPriority()) { return QVariant(); // hide priority for mods where it's fixed } else { @@ -642,7 +642,7 @@ Qt::ItemFlags ModList::flags(const QModelIndex &modelIndex) const } if (modelIndex.isValid()) { ModInfo::Ptr modInfo = ModInfo::getByIndex(modelIndex.row()); - if (!modInfo->isFixedPriority()) { + if (!modInfo->hasAutomaticPriority()) { result |= Qt::ItemIsDragEnabled; result |= Qt::ItemIsUserCheckable; if ((modelIndex.column() == COL_PRIORITY) || diff --git a/src/profile.cpp b/src/profile.cpp index 66c23ea1..2546661b 100644 --- a/src/profile.cpp +++ b/src/profile.cpp @@ -234,7 +234,7 @@ void Profile::doWriteModlist() // the priority order was inverted on load so it has to be inverted again const auto index = iter->second; ModInfo::Ptr modInfo = ModInfo::getByIndex(index); - if (!modInfo->isFixedPriority()) { + if (!modInfo->hasAutomaticPriority()) { if (modInfo->isForeign()) { file->write("*"); } else if (m_ModStatus[index].m_Enabled) { @@ -460,7 +460,7 @@ void Profile::refreshModStatus() // find the mod and check that this is a regular mod (and not a backup) ModInfo::Ptr info = ModInfo::getByIndex(modIndex); - if (modIndex < m_ModStatus.size() && !info->isFixedPriority()) { + if (modIndex < m_ModStatus.size() && !info->hasAutomaticPriority()) { m_ModStatus[modIndex].m_Enabled = enabled; if (m_ModStatus[modIndex].m_Priority == -1) { if (static_cast(index) >= m_ModStatus.size()) { @@ -527,7 +527,7 @@ void Profile::refreshModStatus() int offset = topInsert * -1; for (size_t i = 0; i < m_ModStatus.size(); ++i) { ModInfo::Ptr modInfo = ModInfo::getByIndex(static_cast(i)); - if (modInfo->isFixedPriority()) { + if (modInfo->hasAutomaticPriority()) { continue; } @@ -674,7 +674,7 @@ int Profile::getModPriority(unsigned int index) const bool Profile::setModPriority(unsigned int index, int &newPriority) { - if (ModInfo::getByIndex(index)->isFixedPriority()) { + if (ModInfo::getByIndex(index)->hasAutomaticPriority()) { // can't change priority of overwrite/backups return false; } -- cgit v1.3.1 From b1795f83cd500b5b58928efa5e170de8338178d5 Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Thu, 21 Jan 2021 21:56:08 +0100 Subject: Refresh data tab when mods are enabled or moved. --- src/mainwindow.cpp | 6 ++++++ src/modlist.cpp | 2 ++ 2 files changed, 8 insertions(+) (limited to 'src/modlist.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index a79aca2f..d6391677 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -313,6 +313,12 @@ MainWindow::MainWindow(Settings &settings setupModList(); ui->espList->setup(m_OrganizerCore, this, ui); + connect(m_OrganizerCore.modList(), &ModList::modPrioritiesChanged, [this]() { + m_DataTab->updateTree(); + }); + connect(m_OrganizerCore.modList(), &ModList::modStatesChanged, [this]() { + m_DataTab->updateTree(); + }); ui->bsaList->setLocalMoveOnly(true); ui->bsaList->setHeaderHidden(true); diff --git a/src/modlist.cpp b/src/modlist.cpp index e2a443bd..13b2298f 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -1433,4 +1433,6 @@ void ModList::setActive(const QModelIndexList& indices, bool active) else { m_Profile->setModsEnabled({}, mods); } + + emit modStatesChanged(indices); } -- cgit v1.3.1 From 7864fc0950729621c0297389f5b47d27e4d41d8f Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Fri, 22 Jan 2021 21:18:54 +0100 Subject: Use constant for minimum/maximum priorities. --- src/modlist.cpp | 5 +---- src/modlistbypriorityproxy.cpp | 2 +- src/modlistviewactions.cpp | 6 +++--- src/profile.h | 12 ++++++++++-- 4 files changed, 15 insertions(+), 10 deletions(-) (limited to 'src/modlist.cpp') diff --git a/src/modlist.cpp b/src/modlist.cpp index 13b2298f..81dc91bf 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -1023,14 +1023,11 @@ int ModList::dropPriority(int row, const QModelIndex& parent) const int newPriority = 0; { if (row < 0 || row >= rowCount()) { - newPriority = std::numeric_limits::max(); + newPriority = Profile::MaximumPriority; } else { newPriority = m_Profile->getModPriority(row); } - if (newPriority == -1) { - newPriority = std::numeric_limits::max(); - } } return newPriority; diff --git a/src/modlistbypriorityproxy.cpp b/src/modlistbypriorityproxy.cpp index d1d045fc..24e58ed0 100644 --- a/src/modlistbypriorityproxy.cpp +++ b/src/modlistbypriorityproxy.cpp @@ -234,7 +234,7 @@ bool ModListByPriorityProxy::canDropMimeData(const QMimeData* data, Qt::DropActi bool hasSeparator = false; unsigned int firstRowIndex = -1; - int firstRowPriority = std::numeric_limits::max(); + int firstRowPriority = Profile::MaximumPriority; for (auto sourceRow : dropInfo.rows()) { hasSeparator = hasSeparator || ModInfo::getByIndex(sourceRow)->isSeparator(); if (m_sortOrder == Qt::AscendingOrder && m_profile->getModPriority(sourceRow) < firstRowPriority diff --git a/src/modlistviewactions.cpp b/src/modlistviewactions.cpp index e7e74b16..647aac0b 100644 --- a/src/modlistviewactions.cpp +++ b/src/modlistviewactions.cpp @@ -539,12 +539,12 @@ void ModListViewActions::displayModInformation(ModInfo::Ptr modInfo, unsigned in void ModListViewActions::sendModsToTop(const QModelIndexList& indexes) const { - m_core.modList()->changeModsPriority(indexes, 0); + m_core.modList()->changeModsPriority(indexes, Profile::MinimumPriority); } void ModListViewActions::sendModsToBottom(const QModelIndexList& indexes) const { - m_core.modList()->changeModsPriority(indexes, std::numeric_limits::max()); + m_core.modList()->changeModsPriority(indexes, Profile::MaximumPriority); } void ModListViewActions::sendModsToPriority(const QModelIndexList& indexes) const @@ -580,7 +580,7 @@ void ModListViewActions::sendModsToSeparator(const QModelIndexList& indexes) con if (!result.isEmpty()) { result += "_separator"; - int newPriority = std::numeric_limits::max(); + int newPriority = Profile::MaximumPriority; bool foundSection = false; for (auto mod : m_core.modList()->allModsByProfilePriority()) { unsigned int modIndex = ModInfo::getIndex(mod); diff --git a/src/profile.h b/src/profile.h index d1e3f104..672a2c13 100644 --- a/src/profile.h +++ b/src/profile.h @@ -52,7 +52,14 @@ class Profile : public QObject, public MOBase::IProfile public: - typedef boost::shared_ptr Ptr; + using Ptr = boost::shared_ptr; + +public: + + // the minimum and maximum priority achievable by mods + // + static constexpr int MinimumPriority = 0; + static constexpr int MaximumPriority = std::numeric_limits::max(); public: @@ -283,7 +290,8 @@ public: // [old priority, new priority] such that no gaps are possible // // the priority is clamped in the range of valid priority (>= 0, and lower than - // the number of "regular" mods) + // the number of "regular" mods), you should use MinimumPriority or MaximumPriority + // to send a mod to the "top" or "bottom" of the priority list // // the function returns true if the priority was changed, or false if the mod // was already at the given priority (or if the priority of the mod cannot be -- cgit v1.3.1 From 54744c04b25454440c6d9a590a9ae2f36226bc03 Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Fri, 22 Jan 2021 21:19:35 +0100 Subject: Use proper naming convention for constants. --- src/downloadlist.cpp | 2 +- src/modlist.cpp | 2 +- src/modlistdropinfo.cpp | 4 ++-- src/modlistdropinfo.h | 4 ++-- src/settingsdialogplugins.cpp | 30 +++++++++++++++--------------- src/settingsdialogplugins.h | 8 +++++--- 6 files changed, 26 insertions(+), 24 deletions(-) (limited to 'src/modlist.cpp') diff --git a/src/downloadlist.cpp b/src/downloadlist.cpp index 93f8538c..9f29f475 100644 --- a/src/downloadlist.cpp +++ b/src/downloadlist.cpp @@ -99,7 +99,7 @@ Qt::ItemFlags DownloadList::flags(const QModelIndex& idx) const QMimeData* DownloadList::mimeData(const QModelIndexList& indexes) const { QMimeData* result = QAbstractItemModel::mimeData(indexes); - result->setData("text/plain", ModListDropInfo::DOWNLOAD_TEXT); + result->setData("text/plain", ModListDropInfo::DownloadText); return result; } diff --git a/src/modlist.cpp b/src/modlist.cpp index 81dc91bf..de24fbbd 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -677,7 +677,7 @@ QStringList ModList::mimeTypes() const QMimeData *ModList::mimeData(const QModelIndexList &indexes) const { QMimeData *result = QAbstractItemModel::mimeData(indexes); - result->setData("text/plain", ModListDropInfo::MOD_TEXT); + result->setData("text/plain", ModListDropInfo::ModText); return result; } diff --git a/src/modlistdropinfo.cpp b/src/modlistdropinfo.cpp index 62a103a4..a247194f 100644 --- a/src/modlistdropinfo.cpp +++ b/src/modlistdropinfo.cpp @@ -48,8 +48,8 @@ ModListDropInfo::ModListDropInfo(const QMimeData* mimeData, OrganizerCore& core) } } - if (mimeData->text() != ModListDropInfo::MOD_TEXT) { - if (mimeData->text() == ModListDropInfo::DOWNLOAD_TEXT && m_rows.size() == 1) { + if (mimeData->text() != ModListDropInfo::ModText) { + if (mimeData->text() == ModListDropInfo::DownloadText && m_rows.size() == 1) { m_download = m_rows[0]; } m_rows = {}; diff --git a/src/modlistdropinfo.h b/src/modlistdropinfo.h index 14a21691..5d2af92f 100644 --- a/src/modlistdropinfo.h +++ b/src/modlistdropinfo.h @@ -18,8 +18,8 @@ public: // text value for the mime-data for the various possible // origin (not for external drops) // - static constexpr const char* MOD_TEXT = "mod"; - static constexpr const char* DOWNLOAD_TEXT = "download"; + static constexpr const char* ModText = "mod"; + static constexpr const char* DownloadText = "download"; public: diff --git a/src/settingsdialogplugins.cpp b/src/settingsdialogplugins.cpp index 16f6fb0a..2f7f3985 100644 --- a/src/settingsdialogplugins.cpp +++ b/src/settingsdialogplugins.cpp @@ -40,18 +40,18 @@ PluginsSettingsTab::PluginsSettingsTab(Settings& s, PluginContainer* pluginConta QTreeWidgetItem* listItem = new QTreeWidgetItem( topItems.at(m_pluginContainer->topImplementedInterface(plugin))); listItem->setData(0, Qt::DisplayRole, plugin->localizedName()); - listItem->setData(0, ROLE_PLUGIN, QVariant::fromValue((void*)plugin)); - listItem->setData(0, ROLE_SETTINGS, settings().plugins().settings(plugin->name())); - listItem->setData(0, ROLE_DESCRIPTIONS, settings().plugins().descriptions(plugin->name())); + listItem->setData(0, PluginRole, QVariant::fromValue((void*)plugin)); + listItem->setData(0, SettingsRole, settings().plugins().settings(plugin->name())); + listItem->setData(0, DescriptionsRole, settings().plugins().descriptions(plugin->name())); // Handle child item: auto children = m_pluginContainer->requirements(plugin).children(); for (auto* child : children) { QTreeWidgetItem* childItem = new QTreeWidgetItem(listItem); childItem->setData(0, Qt::DisplayRole, child->localizedName()); - childItem->setData(0, ROLE_PLUGIN, QVariant::fromValue((void*)child)); - childItem->setData(0, ROLE_SETTINGS, settings().plugins().settings(child->name())); - childItem->setData(0, ROLE_DESCRIPTIONS, settings().plugins().descriptions(child->name())); + childItem->setData(0, PluginRole, QVariant::fromValue((void*)child)); + childItem->setData(0, SettingsRole, settings().plugins().settings(child->name())); + childItem->setData(0, DescriptionsRole, settings().plugins().descriptions(child->name())); handledNames.insert(child->name()); } @@ -174,7 +174,7 @@ void PluginsSettingsTab::filterPluginList() IPlugin* PluginsSettingsTab::plugin(QTreeWidgetItem* pluginItem) const { - return static_cast(qvariant_cast(pluginItem->data(0, ROLE_PLUGIN))); + return static_cast(qvariant_cast(pluginItem->data(0, PluginRole))); } void PluginsSettingsTab::update() @@ -185,7 +185,7 @@ void PluginsSettingsTab::update() for (int j = 0; j < topLevelItem->childCount(); ++j) { auto* item = topLevelItem->child(j); settings().plugins().setSettings( - plugin(item)->name(), item->data(0, ROLE_SETTINGS).toMap()); + plugin(item)->name(), item->data(0, SettingsRole).toMap()); } } @@ -209,7 +209,7 @@ void PluginsSettingsTab::on_checkboxEnabled_clicked(bool checked) { // Retrieve the plugin: auto *item = ui->pluginsList->currentItem(); - if (!item || !item->data(0, ROLE_PLUGIN).isValid()) { + if (!item || !item->data(0, PluginRole).isValid()) { return; } IPlugin* plugin = this->plugin(item); @@ -278,7 +278,7 @@ void PluginsSettingsTab::on_pluginsList_currentItemChanged(QTreeWidgetItem *curr { storeSettings(previous); - if (!current->data(0, ROLE_PLUGIN).isValid()) { + if (!current->data(0, PluginRole).isValid()) { return; } @@ -325,8 +325,8 @@ void PluginsSettingsTab::on_pluginsList_currentItemChanged(QTreeWidgetItem *curr } } - QVariantMap settings = current->data(0, ROLE_SETTINGS).toMap(); - QVariantMap descriptions = current->data(0, ROLE_DESCRIPTIONS).toMap(); + QVariantMap settings = current->data(0, SettingsRole).toMap(); + QVariantMap descriptions = current->data(0, DescriptionsRole).toMap(); ui->pluginSettingsList->setEnabled(settings.count() != 0); for (auto iter = settings.begin(); iter != settings.end(); ++iter) { QTreeWidgetItem *newItem = new QTreeWidgetItem(QStringList(iter.key())); @@ -359,14 +359,14 @@ void PluginsSettingsTab::deleteBlacklistItem() void PluginsSettingsTab::storeSettings(QTreeWidgetItem *pluginItem) { - if (pluginItem != nullptr && pluginItem->data(0, ROLE_PLUGIN).isValid()) { - QVariantMap settings = pluginItem->data(0, ROLE_SETTINGS).toMap(); + if (pluginItem != nullptr && pluginItem->data(0, PluginRole).isValid()) { + QVariantMap settings = pluginItem->data(0, SettingsRole).toMap(); for (int i = 0; i < ui->pluginSettingsList->topLevelItemCount(); ++i) { const QTreeWidgetItem *item = ui->pluginSettingsList->topLevelItem(i); settings[item->text(0)] = item->data(1, Qt::DisplayRole); } - pluginItem->setData(0, ROLE_SETTINGS, settings); + pluginItem->setData(0, SettingsRole, settings); } } diff --git a/src/settingsdialogplugins.h b/src/settingsdialogplugins.h index 3de0d7dc..c784b83e 100644 --- a/src/settingsdialogplugins.h +++ b/src/settingsdialogplugins.h @@ -39,9 +39,11 @@ private slots: */ MOBase::IPlugin* plugin(QTreeWidgetItem *pluginItem) const; - constexpr static int ROLE_PLUGIN = Qt::UserRole; - constexpr static int ROLE_SETTINGS = Qt::UserRole + 1; - constexpr static int ROLE_DESCRIPTIONS = Qt::UserRole + 2; + enum { + PluginRole = Qt::UserRole, + SettingsRole = Qt::UserRole + 1, + DescriptionsRole = Qt::UserRole + 2 + }; private: -- cgit v1.3.1