mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-09-08 09:10:57 +02:00
Merge pull request #13911 from Dentomologist/gamelist_gridview_sorting
GameList: Use List View's sorting for Grid View
This commit is contained in:
@@ -122,12 +122,19 @@ GameList::GameList(QWidget* parent) : QStackedWidget(parent), m_model(this)
|
||||
m_list_proxy->setSortRole(GameListModel::SORT_ROLE);
|
||||
m_list_proxy->setSourceModel(&m_model);
|
||||
m_grid_proxy = new GridProxyModel(this);
|
||||
m_grid_proxy->setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||
m_grid_proxy->setSortRole(GameListModel::SORT_ROLE);
|
||||
m_grid_proxy->setSourceModel(&m_model);
|
||||
|
||||
MakeListView();
|
||||
MakeGridView();
|
||||
MakeEmptyView();
|
||||
|
||||
// Use List View's sorting for Grid View too.
|
||||
m_grid_proxy->sort(m_list_proxy->sortColumn(), m_list_proxy->sortOrder());
|
||||
connect(m_list->horizontalHeader(), &QHeaderView::sortIndicatorChanged, m_grid_proxy,
|
||||
&GridProxyModel::sort);
|
||||
|
||||
if (Settings::GetQSettings().contains(QStringLiteral("gridview/scale")))
|
||||
m_model.SetScale(Settings::GetQSettings().value(QStringLiteral("gridview/scale")).toFloat());
|
||||
|
||||
|
@@ -18,8 +18,7 @@ const QSize LARGE_BANNER_SIZE(144, 48);
|
||||
|
||||
GridProxyModel::GridProxyModel(QObject* parent) : QSortFilterProxyModel(parent)
|
||||
{
|
||||
setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||
sort(static_cast<int>(GameListModel::Column::Title));
|
||||
setDynamicSortFilter(true);
|
||||
}
|
||||
|
||||
QVariant GridProxyModel::data(const QModelIndex& i, int role) const
|
||||
@@ -76,3 +75,24 @@ bool GridProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_
|
||||
GameListModel* glm = qobject_cast<GameListModel*>(sourceModel());
|
||||
return glm->ShouldDisplayGameListItem(source_row);
|
||||
}
|
||||
|
||||
bool GridProxyModel::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;
|
||||
}
|
||||
|
@@ -14,5 +14,8 @@ class GridProxyModel final : public QSortFilterProxyModel
|
||||
public:
|
||||
explicit GridProxyModel(QObject* parent = nullptr);
|
||||
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
protected:
|
||||
bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;
|
||||
bool lessThan(const QModelIndex& left, const QModelIndex& right) const override;
|
||||
};
|
||||
|
Reference in New Issue
Block a user