Browse Source

[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
Andrey Filipenkov 1 month ago
parent
commit
80f353f954

+ 25 - 0
launcher/modManager/modstateitemmodel_moc.cpp

@@ -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)
 {

+ 2 - 0
launcher/modManager/modstateitemmodel_moc.h

@@ -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);