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(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(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(GameListModel::Column::Title)) + .data() + .toString(); + const auto left_title = sourceModel() + ->index(left.row(), static_cast(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; };