blob: 968152234a5632152175faa2a31be9d89fde66c6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
// Copyright 2017 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "DolphinQt/GameList/ListProxyModel.h"
#include "DolphinQt/GameList/GameListModel.h"
ListProxyModel::ListProxyModel(QObject* parent) : QSortFilterProxyModel(parent)
{
setDynamicSortFilter(true);
}
bool ListProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
{
GameListModel* glm = qobject_cast<GameListModel*>(sourceModel());
return glm->ShouldDisplayGameListItem(source_row);
}
bool ListProxyModel::lessThan(const QModelIndex& left, const QModelIndex& right) const
{
if (left.data(GameListModel::SORT_ROLE) != right.data(GameListModel::SORT_ROLE))
return QSortFilterProxyModel::lessThan(left, right);
// If two items are otherwise equal, compare them by their title
const auto right_title = sourceModel()
->index(right.row(), static_cast<int>(GameListModel::Column::Title))
.data()
.toString();
const auto left_title = sourceModel()
->index(left.row(), static_cast<int>(GameListModel::Column::Title))
.data()
.toString();
if (sortOrder() == Qt::AscendingOrder)
return left_title < right_title;
return right_title < left_title;
}
|