Merge pull request #6726 from spycrab/qt_sort_alpha

Qt/GameList: Always sort games alphabetically
This commit is contained in:
Mat M 2018-05-03 13:13:09 -04:00 committed by GitHub
commit 54a6b0f50a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -15,3 +15,20 @@ bool ListProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_
GameListModel* glm = qobject_cast<GameListModel*>(sourceModel()); GameListModel* glm = qobject_cast<GameListModel*>(sourceModel());
return glm->ShouldDisplayGameListItem(source_row); return glm->ShouldDisplayGameListItem(source_row);
} }
bool ListProxyModel::lessThan(const QModelIndex& left, const QModelIndex& right) const
{
if (left.data(Qt::InitialSortOrderRole) != right.data(Qt::InitialSortOrderRole))
return !QSortFilterProxyModel::lessThan(left, right);
// If two items are otherwise equal, compare them by their title
const auto right_title =
sourceModel()->index(right.row(), GameListModel::COL_TITLE).data().toString();
const auto left_title =
sourceModel()->index(left.row(), GameListModel::COL_TITLE).data().toString();
if (sortOrder() == Qt::AscendingOrder)
return left_title < right_title;
return right_title < left_title;
}

View File

@ -14,4 +14,7 @@ class ListProxyModel final : public QSortFilterProxyModel
public: public:
explicit ListProxyModel(QObject* parent = nullptr); explicit ListProxyModel(QObject* parent = nullptr);
bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override; bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;
protected:
bool lessThan(const QModelIndex& left, const QModelIndex& right) const override;
}; };