summaryrefslogtreecommitdiff
path: root/src/modlistsortproxy.cpp
diff options
context:
space:
mode:
authorSilarn <jrim@rimpo.org>2019-12-23 23:16:36 -0600
committerJeremy Rimpo <jeremy.rimpo@servermonkey.com>2023-09-21 17:03:43 -0500
commit127db7799ed4847b151a35a16cefab6c494128ef (patch)
treedd31c995fee70d2fd0367eeaa6ad916755060256 /src/modlistsortproxy.cpp
parent4fd45b937c0577a0c5c1699726e8132b97be8f5d (diff)
WIP: Category QObj refactor
Diffstat (limited to 'src/modlistsortproxy.cpp')
-rw-r--r--src/modlistsortproxy.cpp185
1 files changed, 89 insertions, 96 deletions
diff --git a/src/modlistsortproxy.cpp b/src/modlistsortproxy.cpp
index 704ec10b..1d54dfa4 100644
--- a/src/modlistsortproxy.cpp
+++ b/src/modlistsortproxy.cpp
@@ -125,111 +125,104 @@ bool ModListSortProxy::lessThan(const QModelIndex& left, const QModelIndex& righ
right.data(ModList::PriorityRole).toInt();
switch (left.column()) {
- case ModList::COL_FLAGS: {
- std::vector<ModInfo::EFlag> leftFlags = leftMod->getFlags();
- std::vector<ModInfo::EFlag> rightFlags = rightMod->getFlags();
- if (leftFlags.size() != rightFlags.size()) {
- lt = leftFlags.size() < rightFlags.size();
- } else {
- lt = flagsId(leftFlags) < flagsId(rightFlags);
- }
- } break;
- case ModList::COL_CONFLICTFLAGS: {
- std::vector<ModInfo::EConflictFlag> leftFlags = leftMod->getConflictFlags();
- std::vector<ModInfo::EConflictFlag> rightFlags = rightMod->getConflictFlags();
- if (leftFlags.size() != rightFlags.size()) {
- lt = leftFlags.size() < rightFlags.size();
- } else {
- lt = conflictFlagsId(leftFlags) < conflictFlagsId(rightFlags);
- }
- } break;
- case ModList::COL_CONTENT: {
- const auto& lContents = leftMod->getContents();
- const auto& rContents = rightMod->getContents();
- unsigned int lValue = 0;
- unsigned int rValue = 0;
- m_Organizer->modDataContents().forEachContentIn(
+ case ModList::COL_FLAGS: {
+ std::vector<ModInfo::EFlag> leftFlags = leftMod->getFlags();
+ std::vector<ModInfo::EFlag> rightFlags = rightMod->getFlags();
+ if (leftFlags.size() != rightFlags.size()) {
+ lt = leftFlags.size() < rightFlags.size();
+ } else {
+ lt = flagsId(leftFlags) < flagsId(rightFlags);
+ }
+ } break;
+ case ModList::COL_CONFLICTFLAGS: {
+ std::vector<ModInfo::EConflictFlag> leftFlags = leftMod->getConflictFlags();
+ std::vector<ModInfo::EConflictFlag> rightFlags = rightMod->getConflictFlags();
+ if (leftFlags.size() != rightFlags.size()) {
+ lt = leftFlags.size() < rightFlags.size();
+ } else {
+ lt = conflictFlagsId(leftFlags) < conflictFlagsId(rightFlags);
+ }
+ } break;
+ case ModList::COL_CONTENT: {
+ const auto& lContents = leftMod->getContents();
+ const auto& rContents = rightMod->getContents();
+ unsigned int lValue = 0;
+ unsigned int rValue = 0;
+ m_Organizer->modDataContents().forEachContentIn(
lContents, [&lValue](auto const& content) {
lValue += 2U << static_cast<unsigned int>(content.id());
});
- m_Organizer->modDataContents().forEachContentIn(
+ m_Organizer->modDataContents().forEachContentIn(
rContents, [&rValue](auto const& content) {
rValue += 2U << static_cast<unsigned int>(content.id());
- });
- lt = lValue < rValue;
- } break;
- case ModList::COL_NAME: {
- int comp = QString::compare(leftMod->name(), rightMod->name(), Qt::CaseInsensitive);
- if (comp != 0)
- lt = comp < 0;
- } break;
- case ModList::COL_CATEGORY: {
- if (leftMod->primaryCategory() != rightMod->primaryCategory()) {
- if (leftMod->primaryCategory() < 0)
- lt = false;
- else if (rightMod->primaryCategory() < 0)
- lt = true;
- else {
- try {
- CategoryFactory& categories = CategoryFactory::instance();
- QString leftCatName = categories.getCategoryName(
- categories.getCategoryIndex(leftMod->primaryCategory()));
- QString rightCatName = categories.getCategoryName(
- categories.getCategoryIndex(rightMod->primaryCategory()));
- lt = leftCatName < rightCatName;
- } catch (const std::exception& e) {
- log::error("failed to compare categories: {}", e.what());
- }
- }
- }
- } break;
- case ModList::COL_MODID: {
- if (leftMod->nexusId() != rightMod->nexusId())
- lt = leftMod->nexusId() < rightMod->nexusId();
- } break;
- case ModList::COL_VERSION: {
- if (leftMod->version() != rightMod->version())
- lt = leftMod->version() < rightMod->version();
- } break;
- case ModList::COL_INSTALLTIME: {
- QDateTime leftTime = left.data().toDateTime();
- QDateTime rightTime = right.data().toDateTime();
- if (leftTime != rightTime)
- return leftTime < rightTime;
- } break;
- case ModList::COL_GAME: {
- if (leftMod->gameName() != rightMod->gameName()) {
- lt = leftMod->gameName() < rightMod->gameName();
- } else {
- int comp =
- QString::compare(leftMod->name(), rightMod->name(), Qt::CaseInsensitive);
+ });
+ lt = lValue < rValue;
+ } break;
+ case ModList::COL_NAME: {
+ int comp = QString::compare(leftMod->name(), rightMod->name(), Qt::CaseInsensitive);
if (comp != 0)
lt = comp < 0;
- }
- } break;
- case ModList::COL_NOTES: {
- QString leftComments = leftMod->comments();
- QString rightComments = rightMod->comments();
- if (leftComments != rightComments) {
- if (leftComments.isEmpty()) {
- lt = sortOrder() == Qt::DescendingOrder;
- } else if (rightComments.isEmpty()) {
- lt = sortOrder() == Qt::AscendingOrder;
+ } break;
+ case ModList::COL_CATEGORY: {
+ if (leftMod->primaryCategory() != rightMod->primaryCategory()) {
+ if (leftMod->primaryCategory() < 0)
+ lt = false;
+ else if (rightMod->primaryCategory() < 0)
+ lt = true;
+ else {
+ try {
+ CategoryFactory* categories = CategoryFactory::instance();
+ QString leftCatName = categories->getCategoryName(categories->getCategoryIndex(leftMod->primaryCategory()));
+ QString rightCatName = categories->getCategoryName(categories->getCategoryIndex(rightMod->primaryCategory()));
+ lt = leftCatName < rightCatName;
+ } catch (const std::exception& e) {
+ log::error("failed to compare categories: {}", e.what());
+ }
+ }
+ }
+ } break;
+ case ModList::COL_MODID: {
+ if (leftMod->nexusId() != rightMod->nexusId())
+ lt = leftMod->nexusId() < rightMod->nexusId();
+ } break;
+ case ModList::COL_VERSION: {
+ if (leftMod->version() != rightMod->version())
+ lt = leftMod->version() < rightMod->version();
+ } break;
+ case ModList::COL_INSTALLTIME: {
+ QDateTime leftTime = left.data().toDateTime();
+ QDateTime rightTime = right.data().toDateTime();
+ if (leftTime != rightTime)
+ return leftTime < rightTime;
+ } break;
+ case ModList::COL_GAME: {
+ if (leftMod->gameName() != rightMod->gameName()) {
+ lt = leftMod->gameName() < rightMod->gameName();
} else {
- lt = leftComments < rightComments;
+ int comp = QString::compare(leftMod->name(), rightMod->name(), Qt::CaseInsensitive);
+ if (comp != 0)
+ lt = comp < 0;
+ }
+ } break;
+ case ModList::COL_NOTES: {
+ QString leftComments = leftMod->comments();
+ QString rightComments = rightMod->comments();
+ if (leftComments != rightComments) {
+ if (leftComments.isEmpty()) {
+ lt = sortOrder() == Qt::DescendingOrder;
+ } else if (rightComments.isEmpty()) {
+ lt = sortOrder() == Qt::AscendingOrder;
+ } else {
+ lt = leftComments < rightComments;
+ }
}
- }
- } break;
- case ModList::COL_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());
- } break;
+ } break;
+ case ModList::COL_PRIORITY: {
+ // nop, already compared by priority
+ } break;
+ default: {
+ log::warn("Sorting is not defined for column {}", left.column());
+ } break;
}
return lt;
}