summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2019-07-31 01:28:55 +0200
committerPetr Mrázek <peterix@gmail.com>2019-07-31 01:28:55 +0200
commit930d39b5f2c28bbc5d7156e6e1e20e0fa8194900 (patch)
tree8a4a31a09323b2b24a9e03323ffe54ce383b3086
parentbafcf93eb157760e510c7dcb2fa889e1032e7e39 (diff)
downloadMultiMC-930d39b5f2c28bbc5d7156e6e1e20e0fa8194900.tar
MultiMC-930d39b5f2c28bbc5d7156e6e1e20e0fa8194900.tar.gz
MultiMC-930d39b5f2c28bbc5d7156e6e1e20e0fa8194900.tar.lz
MultiMC-930d39b5f2c28bbc5d7156e6e1e20e0fa8194900.tar.xz
MultiMC-930d39b5f2c28bbc5d7156e6e1e20e0fa8194900.zip
GH-2550 soring of mods by enabled status, cascade sorting to name and version
-rw-r--r--application/pages/instance/ModFolderPage.cpp29
1 files changed, 22 insertions, 7 deletions
diff --git a/application/pages/instance/ModFolderPage.cpp b/application/pages/instance/ModFolderPage.cpp
index 951928e3..e923c4f4 100644
--- a/application/pages/instance/ModFolderPage.cpp
+++ b/application/pages/instance/ModFolderPage.cpp
@@ -67,22 +67,37 @@ protected:
// we are now guaranteed to have two valid indexes in the same column... we love the provided invariants unconditionally and proceed.
auto column = (SimpleModList::Columns) source_left.column();
+ bool invert = false;
switch(column) {
+ // GH-2550 - sort by enabled/disabled
+ case SimpleModList::ActiveColumn: {
+ auto dataL = source_left.data(Qt::CheckStateRole).toBool();
+ auto dataR = source_right.data(Qt::CheckStateRole).toBool();
+ if(dataL != dataR) {
+ return dataL > dataR;
+ }
+ // fallthrough
+ invert = sortOrder() == Qt::DescendingOrder;
+ }
// GH-2722 - sort mod names in a way that discards "The" prefixes
case SimpleModList::NameColumn: {
- auto dataL = source_left.data(Qt::DisplayRole).toString();
+ auto dataL = model->data(model->index(source_left.row(), SimpleModList::NameColumn)).toString();
RemoveThePrefix(dataL);
- auto dataR = source_right.data(Qt::DisplayRole).toString();
+ auto dataR = model->data(model->index(source_right.row(), SimpleModList::NameColumn)).toString();
RemoveThePrefix(dataR);
- auto less = dataL.compare(dataR, sortCaseSensitivity()) < 0;
- return less;
+ auto less = dataL.compare(dataR, sortCaseSensitivity());
+ if(less != 0) {
+ return invert ? (less > 0) : (less < 0);
+ }
+ // fallthrough
+ invert = sortOrder() == Qt::DescendingOrder;
}
// GH-2762 - sort versions by parsing them as versions
case SimpleModList::VersionColumn: {
- auto dataL = Version(source_left.data(Qt::DisplayRole).toString());
- auto dataR = Version(source_right.data(Qt::DisplayRole).toString());
- return dataL < dataR;
+ auto dataL = Version(model->data(model->index(source_left.row(), SimpleModList::VersionColumn)).toString());
+ auto dataR = Version(model->data(model->index(source_right.row(), SimpleModList::VersionColumn)).toString());
+ return invert ? (dataL > dataR) : (dataL < dataR);
}
default: {
return QSortFilterProxyModel::lessThan(source_left, source_right);