From 930d39b5f2c28bbc5d7156e6e1e20e0fa8194900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 31 Jul 2019 01:28:55 +0200 Subject: GH-2550 soring of mods by enabled status, cascade sorting to name and version --- application/pages/instance/ModFolderPage.cpp | 29 +++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'application') 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); -- cgit v1.2.3