diff options
| author | Tilka <tilkax@gmail.com> | 2025-08-30 02:56:18 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-30 02:56:18 +0100 |
| commit | 25be1cfe97de8b242f55f63f4f0c44631f3ed172 (patch) | |
| tree | 572ac942c4d9a655e9059dcc6eb5550af7094d71 | |
| parent | e0c72cd963bbde29f01fa33b06c22f7dff871e5d (diff) | |
| parent | 489fd643d38ff1481af4191704863888ac448728 (diff) | |
Merge pull request #13911 from Dentomologist/gamelist_gridview_sorting
GameList: Use List View's sorting for Grid View
| -rw-r--r-- | Source/Core/DolphinQt/GameList/GameList.cpp | 7 | ||||
| -rw-r--r-- | Source/Core/DolphinQt/GameList/GridProxyModel.cpp | 24 | ||||
| -rw-r--r-- | Source/Core/DolphinQt/GameList/GridProxyModel.h | 3 |
3 files changed, 32 insertions, 2 deletions
diff --git a/Source/Core/DolphinQt/GameList/GameList.cpp b/Source/Core/DolphinQt/GameList/GameList.cpp index c09ca07f52..9c39962e8c 100644 --- a/Source/Core/DolphinQt/GameList/GameList.cpp +++ b/Source/Core/DolphinQt/GameList/GameList.cpp @@ -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()); diff --git a/Source/Core/DolphinQt/GameList/GridProxyModel.cpp b/Source/Core/DolphinQt/GameList/GridProxyModel.cpp index a35340f3b7..6154e5838c 100644 --- a/Source/Core/DolphinQt/GameList/GridProxyModel.cpp +++ b/Source/Core/DolphinQt/GameList/GridProxyModel.cpp @@ -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; +} diff --git a/Source/Core/DolphinQt/GameList/GridProxyModel.h b/Source/Core/DolphinQt/GameList/GridProxyModel.h index 707dcb857e..c268ef2c97 100644 --- a/Source/Core/DolphinQt/GameList/GridProxyModel.h +++ b/Source/Core/DolphinQt/GameList/GridProxyModel.h @@ -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; }; |
