From 051cbf1962e8add8127c0f3c39f84e9113792d00 Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Sat, 27 May 2017 18:48:04 -0700 Subject: [PATCH 1/3] GameListModel: invert role-column choice tree --- .../DolphinQt2/GameList/GameListModel.cpp | 49 ++++++++++++------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/Source/Core/DolphinQt2/GameList/GameListModel.cpp b/Source/Core/DolphinQt2/GameList/GameListModel.cpp index 30aaa9d77b..4d00a2e3df 100644 --- a/Source/Core/DolphinQt2/GameList/GameListModel.cpp +++ b/Source/Core/DolphinQt2/GameList/GameListModel.cpp @@ -21,17 +21,24 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const return QVariant(); QSharedPointer game = m_games[index.row()]; - if (role == Qt::DecorationRole) + + switch (index.column()) { - switch (index.column()) - { - case COL_PLATFORM: + case COL_PLATFORM: + if (role == Qt::DecorationRole) return Resources::GetPlatform(static_cast(game->GetPlatformID())); - case COL_COUNTRY: + break; + case COL_COUNTRY: + if (role == Qt::DecorationRole) return Resources::GetCountry(static_cast(game->GetCountryID())); - case COL_RATING: + break; + case COL_RATING: + if (role == Qt::DecorationRole) return Resources::GetRating(game->GetRating()); - case COL_BANNER: + break; + case COL_BANNER: + if (role == Qt::DecorationRole) + { // GameCube banners are 96x32, but Wii banners are 192x64. // TODO: use custom banners from rom directory like DolphinWX? QPixmap banner = game->GetBanner(); @@ -39,23 +46,29 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const banner.height() / GAMECUBE_BANNER_SIZE.height())); return banner; } - } - if (role == Qt::DisplayRole) - { - switch (index.column()) - { - case COL_TITLE: + break; + case COL_TITLE: + if (role == Qt::DisplayRole) return game->GetLongName(); - case COL_ID: + break; + case COL_ID: + if (role == Qt::DisplayRole) return game->GetGameID(); - case COL_DESCRIPTION: + break; + case COL_DESCRIPTION: + if (role == Qt::DisplayRole) return game->GetDescription(); - case COL_MAKER: + break; + case COL_MAKER: + if (role == Qt::DisplayRole) return game->GetMaker(); - case COL_SIZE: + break; + case COL_SIZE: + if (role == Qt::DisplayRole) return FormatSize(game->GetFileSize()); - } + break; } + return QVariant(); } From 8bbc31e0a27c81a2e2ea4f07f11fac4602aa57f7 Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Sat, 27 May 2017 18:58:27 -0700 Subject: [PATCH 2/3] GameList: sort case-insensitively --- Source/Core/DolphinQt2/GameList/GameList.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Core/DolphinQt2/GameList/GameList.cpp b/Source/Core/DolphinQt2/GameList/GameList.cpp index 4a1c3d3278..10bbd128a9 100644 --- a/Source/Core/DolphinQt2/GameList/GameList.cpp +++ b/Source/Core/DolphinQt2/GameList/GameList.cpp @@ -30,6 +30,7 @@ GameList::GameList(QWidget* parent) : QStackedWidget(parent) { m_model = new GameListModel(this); m_table_proxy = new QSortFilterProxyModel(this); + m_table_proxy->setSortCaseSensitivity(Qt::CaseInsensitive); m_table_proxy->setSourceModel(m_model); m_list_proxy = new ListProxyModel(this); m_list_proxy->setSourceModel(m_model); From 1a7210aa74cda4d6c7533c718159b0263cf74d91 Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Sat, 27 May 2017 18:59:19 -0700 Subject: [PATCH 3/3] GameListModel: provide Qt::InitialSortOrderRole for sorting Fixes regression where pixmap columns can't be sorted by default. --- Source/Core/DolphinQt2/GameList/GameList.cpp | 1 + .../Core/DolphinQt2/GameList/GameListModel.cpp | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Source/Core/DolphinQt2/GameList/GameList.cpp b/Source/Core/DolphinQt2/GameList/GameList.cpp index 10bbd128a9..41a063322d 100644 --- a/Source/Core/DolphinQt2/GameList/GameList.cpp +++ b/Source/Core/DolphinQt2/GameList/GameList.cpp @@ -31,6 +31,7 @@ GameList::GameList(QWidget* parent) : QStackedWidget(parent) m_model = new GameListModel(this); m_table_proxy = new QSortFilterProxyModel(this); m_table_proxy->setSortCaseSensitivity(Qt::CaseInsensitive); + m_table_proxy->setSortRole(Qt::InitialSortOrderRole); m_table_proxy->setSourceModel(m_model); m_list_proxy = new ListProxyModel(this); m_list_proxy->setSourceModel(m_model); diff --git a/Source/Core/DolphinQt2/GameList/GameListModel.cpp b/Source/Core/DolphinQt2/GameList/GameListModel.cpp index 4d00a2e3df..ad2a291908 100644 --- a/Source/Core/DolphinQt2/GameList/GameListModel.cpp +++ b/Source/Core/DolphinQt2/GameList/GameListModel.cpp @@ -27,14 +27,20 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const case COL_PLATFORM: if (role == Qt::DecorationRole) return Resources::GetPlatform(static_cast(game->GetPlatformID())); + if (role == Qt::InitialSortOrderRole) + return static_cast(game->GetPlatformID()); break; case COL_COUNTRY: if (role == Qt::DecorationRole) return Resources::GetCountry(static_cast(game->GetCountryID())); + if (role == Qt::InitialSortOrderRole) + return static_cast(game->GetCountryID()); break; case COL_RATING: if (role == Qt::DecorationRole) return Resources::GetRating(game->GetRating()); + if (role == Qt::InitialSortOrderRole) + return game->GetRating(); break; case COL_BANNER: if (role == Qt::DecorationRole) @@ -48,24 +54,26 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const } break; case COL_TITLE: - if (role == Qt::DisplayRole) + if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole) return game->GetLongName(); break; case COL_ID: - if (role == Qt::DisplayRole) + if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole) return game->GetGameID(); break; case COL_DESCRIPTION: - if (role == Qt::DisplayRole) + if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole) return game->GetDescription(); break; case COL_MAKER: - if (role == Qt::DisplayRole) + if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole) return game->GetMaker(); break; case COL_SIZE: if (role == Qt::DisplayRole) return FormatSize(game->GetFileSize()); + if (role == Qt::InitialSortOrderRole) + return game->GetFileSize(); break; }