1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-23 22:37:55 +02:00

[launcher] fix sorting mods by the Enabled column

if both mods have the same Enabled status, then Install status is checked and the last fallback is to name sorting
This commit is contained in:
Andrey Filipenkov
2025-10-30 00:41:39 +03:00
parent dc9fd90f3e
commit 80f353f954
2 changed files with 27 additions and 0 deletions

View File

@@ -320,6 +320,31 @@ bool CModFilterModel::filterAcceptsRow(int source_row, const QModelIndex & sourc
return false;
}
bool CModFilterModel::lessThan(const QModelIndex & source_left, const QModelIndex & source_right) const
{
if(source_left.column() != ModFields::STATUS_ENABLED)
return QSortFilterProxyModel::lessThan(source_left, source_right);
const auto leftMod = base->model->getMod(base->modIndexToName(source_left));
const auto rightMod = base->model->getMod(base->modIndexToName(source_right));
const auto isLeftEnabled = base->model->isModEnabled(leftMod.getID());
const auto isRightEnabled = base->model->isModEnabled(rightMod.getID());
if(!isLeftEnabled && isRightEnabled)
return true;
if(isLeftEnabled && !isRightEnabled)
return false;
const auto isLeftInstalled = leftMod.isInstalled();
const auto isRightInstalled = rightMod.isInstalled();
if(!isLeftInstalled && isRightInstalled)
return true;
if(isLeftInstalled && !isRightInstalled)
return false;
return QSortFilterProxyModel::lessThan(source_left.siblingAtColumn(ModFields::NAME), source_right.siblingAtColumn(ModFields::NAME));
}
CModFilterModel::CModFilterModel(ModStateItemModel * model, QObject * parent)
: QSortFilterProxyModel(parent), base(model), filterMask(ModFilterMask::ALL)
{

View File

@@ -97,6 +97,8 @@ class CModFilterModel final : public QSortFilterProxyModel
bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const override;
bool lessThan(const QModelIndex & source_left, const QModelIndex & source_right) const override;
public:
void setTypeFilter(ModFilterMask filterMask);