diff --git a/Source/Core/DolphinQt2/CMakeLists.txt b/Source/Core/DolphinQt2/CMakeLists.txt index 66ba436282..104ca2ffd3 100644 --- a/Source/Core/DolphinQt2/CMakeLists.txt +++ b/Source/Core/DolphinQt2/CMakeLists.txt @@ -63,6 +63,7 @@ set(SRCS GameList/GameListModel.cpp GameList/GameTracker.cpp GameList/ListProxyModel.cpp + GameList/TableProxyModel.cpp QtUtils/DoubleClickEventFilter.cpp QtUtils/ElidedButton.cpp QtUtils/ListTabWidget.cpp diff --git a/Source/Core/DolphinQt2/DolphinQt2.vcxproj b/Source/Core/DolphinQt2/DolphinQt2.vcxproj index e51b6c9006..18af6e387d 100644 --- a/Source/Core/DolphinQt2/DolphinQt2.vcxproj +++ b/Source/Core/DolphinQt2/DolphinQt2.vcxproj @@ -84,6 +84,7 @@ + @@ -125,6 +126,7 @@ + @@ -177,6 +179,7 @@ + diff --git a/Source/Core/DolphinQt2/GameList/GameList.cpp b/Source/Core/DolphinQt2/GameList/GameList.cpp index 0586462a45..7e68a2ddfd 100644 --- a/Source/Core/DolphinQt2/GameList/GameList.cpp +++ b/Source/Core/DolphinQt2/GameList/GameList.cpp @@ -26,6 +26,7 @@ #include "DolphinQt2/Config/PropertiesDialog.h" #include "DolphinQt2/GameList/GameList.h" #include "DolphinQt2/GameList/ListProxyModel.h" +#include "DolphinQt2/GameList/TableProxyModel.h" #include "DolphinQt2/QtUtils/DoubleClickEventFilter.h" #include "DolphinQt2/Settings.h" @@ -34,7 +35,7 @@ static bool CompressCB(const std::string&, float, void*); GameList::GameList(QWidget* parent) : QStackedWidget(parent) { m_model = new GameListModel(this); - m_table_proxy = new QSortFilterProxyModel(this); + m_table_proxy = new TableProxyModel(this); m_table_proxy->setSortCaseSensitivity(Qt::CaseInsensitive); m_table_proxy->setSortRole(Qt::InitialSortOrderRole); m_table_proxy->setSourceModel(m_model); @@ -446,6 +447,12 @@ void GameList::OnColumnVisibilityToggled(const QString& row, bool visible) m_table->setColumnHidden(rowname_to_col_index[row], !visible); } +void GameList::OnGameListVisibilityChanged() +{ + m_table_proxy->invalidate(); + m_list_proxy->invalidate(); +} + static bool CompressCB(const std::string& text, float percent, void* ptr) { if (ptr == nullptr) diff --git a/Source/Core/DolphinQt2/GameList/GameList.h b/Source/Core/DolphinQt2/GameList/GameList.h index 09c8c57d73..1aab2a3299 100644 --- a/Source/Core/DolphinQt2/GameList/GameList.h +++ b/Source/Core/DolphinQt2/GameList/GameList.h @@ -25,6 +25,7 @@ public: void SetListView() { SetPreferredView(false); } void SetViewColumn(int col, bool view) { m_table->setColumnHidden(col, !view); } void OnColumnVisibilityToggled(const QString& row, bool visible); + void OnGameListVisibilityChanged(); signals: void GameSelected(); diff --git a/Source/Core/DolphinQt2/GameList/GameListModel.cpp b/Source/Core/DolphinQt2/GameList/GameListModel.cpp index 78f13928fb..ecd9683133 100644 --- a/Source/Core/DolphinQt2/GameList/GameListModel.cpp +++ b/Source/Core/DolphinQt2/GameList/GameListModel.cpp @@ -3,7 +3,7 @@ // Refer to the license.txt file included. #include "DolphinQt2/GameList/GameListModel.h" - +#include "Core/ConfigManager.h" #include "DiscIO/Enums.h" #include "DolphinQt2/Resources.h" #include "DolphinQt2/Settings.h" @@ -138,6 +138,63 @@ int GameListModel::columnCount(const QModelIndex& parent) const return NUM_COLS; } +bool GameListModel::ShouldDisplayGameListItem(int index) const +{ + QSharedPointer game = m_games[index]; + + const bool show_platform = [&game] { + switch (game->GetPlatformID()) + { + case DiscIO::Platform::GAMECUBE_DISC: + return SConfig::GetInstance().m_ListGC; + case DiscIO::Platform::WII_DISC: + return SConfig::GetInstance().m_ListWii; + case DiscIO::Platform::WII_WAD: + return SConfig::GetInstance().m_ListWad; + case DiscIO::Platform::ELF_DOL: + return SConfig::GetInstance().m_ListElfDol; + default: + return false; + } + }(); + + if (!show_platform) + return false; + + switch (game->GetCountryID()) + { + case DiscIO::Country::COUNTRY_AUSTRALIA: + return SConfig::GetInstance().m_ListAustralia; + case DiscIO::Country::COUNTRY_EUROPE: + return SConfig::GetInstance().m_ListPal; + case DiscIO::Country::COUNTRY_FRANCE: + return SConfig::GetInstance().m_ListFrance; + case DiscIO::Country::COUNTRY_GERMANY: + return SConfig::GetInstance().m_ListGermany; + case DiscIO::Country::COUNTRY_ITALY: + return SConfig::GetInstance().m_ListItaly; + case DiscIO::Country::COUNTRY_JAPAN: + return SConfig::GetInstance().m_ListJap; + case DiscIO::Country::COUNTRY_KOREA: + return SConfig::GetInstance().m_ListKorea; + case DiscIO::Country::COUNTRY_NETHERLANDS: + return SConfig::GetInstance().m_ListNetherlands; + case DiscIO::Country::COUNTRY_RUSSIA: + return SConfig::GetInstance().m_ListRussia; + case DiscIO::Country::COUNTRY_SPAIN: + return SConfig::GetInstance().m_ListSpain; + case DiscIO::Country::COUNTRY_TAIWAN: + return SConfig::GetInstance().m_ListTaiwan; + case DiscIO::Country::COUNTRY_USA: + return SConfig::GetInstance().m_ListUsa; + case DiscIO::Country::COUNTRY_WORLD: + return SConfig::GetInstance().m_ListWorld; + case DiscIO::Country::COUNTRY_UNKNOWN: + default: + return SConfig::GetInstance().m_ListUnknown; + } +} + void GameListModel::UpdateGame(QSharedPointer game) { QString path = game->GetFilePath(); diff --git a/Source/Core/DolphinQt2/GameList/GameListModel.h b/Source/Core/DolphinQt2/GameList/GameListModel.h index 3f54bfc636..da807cc83c 100644 --- a/Source/Core/DolphinQt2/GameList/GameListModel.h +++ b/Source/Core/DolphinQt2/GameList/GameListModel.h @@ -27,6 +27,7 @@ public: // Path of the Game at the specified index. QString GetPath(int index) const { return m_games[index]->GetFilePath(); } + bool ShouldDisplayGameListItem(int index) const; enum { COL_PLATFORM = 0, diff --git a/Source/Core/DolphinQt2/GameList/ListProxyModel.cpp b/Source/Core/DolphinQt2/GameList/ListProxyModel.cpp index 27394d6ab8..1dcc7b5b38 100644 --- a/Source/Core/DolphinQt2/GameList/ListProxyModel.cpp +++ b/Source/Core/DolphinQt2/GameList/ListProxyModel.cpp @@ -34,3 +34,9 @@ QVariant ListProxyModel::data(const QModelIndex& i, int role) const } return QVariant(); } + +bool ListProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const +{ + GameListModel* glm = qobject_cast(sourceModel()); + return glm->ShouldDisplayGameListItem(source_row); +} diff --git a/Source/Core/DolphinQt2/GameList/ListProxyModel.h b/Source/Core/DolphinQt2/GameList/ListProxyModel.h index 235c4bd7af..3d984e828e 100644 --- a/Source/Core/DolphinQt2/GameList/ListProxyModel.h +++ b/Source/Core/DolphinQt2/GameList/ListProxyModel.h @@ -15,4 +15,5 @@ class ListProxyModel final : public QSortFilterProxyModel public: explicit ListProxyModel(QObject* parent = nullptr); QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; + bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override; }; diff --git a/Source/Core/DolphinQt2/GameList/TableProxyModel.cpp b/Source/Core/DolphinQt2/GameList/TableProxyModel.cpp new file mode 100644 index 0000000000..30b1b6d093 --- /dev/null +++ b/Source/Core/DolphinQt2/GameList/TableProxyModel.cpp @@ -0,0 +1,16 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "DolphinQt2/GameList/TableProxyModel.h" +#include "DolphinQt2/GameList/GameListModel.h" + +TableProxyModel::TableProxyModel(QObject* parent) : QSortFilterProxyModel(parent) +{ +} + +bool TableProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const +{ + GameListModel* glm = qobject_cast(sourceModel()); + return glm->ShouldDisplayGameListItem(source_row); +} diff --git a/Source/Core/DolphinQt2/GameList/TableProxyModel.h b/Source/Core/DolphinQt2/GameList/TableProxyModel.h new file mode 100644 index 0000000000..ec7c1f1d1c --- /dev/null +++ b/Source/Core/DolphinQt2/GameList/TableProxyModel.h @@ -0,0 +1,15 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include + +// This subclass of QSortFilterProxyModel allows the data to be filtered by the view. +class TableProxyModel final : public QSortFilterProxyModel +{ + Q_OBJECT + +public: + explicit TableProxyModel(QObject* parent = nullptr); + bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override; +}; diff --git a/Source/Core/DolphinQt2/MainWindow.cpp b/Source/Core/DolphinQt2/MainWindow.cpp index 0ed3447a48..44cc7413f0 100644 --- a/Source/Core/DolphinQt2/MainWindow.cpp +++ b/Source/Core/DolphinQt2/MainWindow.cpp @@ -199,6 +199,10 @@ void MainWindow::ConnectMenuBar() connect(m_menu_bar, &MenuBar::ShowList, m_game_list, &GameList::SetListView); connect(m_menu_bar, &MenuBar::ColumnVisibilityToggled, m_game_list, &GameList::OnColumnVisibilityToggled); + connect(m_menu_bar, &MenuBar::GameListPlatformVisibilityToggled, m_game_list, + &GameList::OnGameListVisibilityChanged); + connect(m_menu_bar, &MenuBar::GameListRegionVisibilityToggled, m_game_list, + &GameList::OnGameListVisibilityChanged); connect(m_menu_bar, &MenuBar::ShowAboutDialog, this, &MainWindow::ShowAboutDialog); connect(this, &MainWindow::EmulationStarted, m_menu_bar, &MenuBar::EmulationStarted); diff --git a/Source/Core/DolphinQt2/MenuBar.cpp b/Source/Core/DolphinQt2/MenuBar.cpp index d67aef4047..413624526f 100644 --- a/Source/Core/DolphinQt2/MenuBar.cpp +++ b/Source/Core/DolphinQt2/MenuBar.cpp @@ -191,6 +191,9 @@ void MenuBar::AddViewMenu() AddGameListTypeSection(view_menu); view_menu->addSeparator(); AddTableColumnsMenu(view_menu); + view_menu->addSeparator(); + AddShowPlatformsMenu(view_menu); + AddShowRegionsMenu(view_menu); } void MenuBar::AddOptionsMenu() @@ -273,6 +276,66 @@ void MenuBar::AddTableColumnsMenu(QMenu* view_menu) } } +void MenuBar::AddShowPlatformsMenu(QMenu* view_menu) +{ + static const QMap platform_map{ + {tr("Show Wii"), &SConfig::GetInstance().m_ListWii}, + {tr("Show GameCube"), &SConfig::GetInstance().m_ListGC}, + {tr("Show WAD"), &SConfig::GetInstance().m_ListWad}, + {tr("Show ELF/DOL"), &SConfig::GetInstance().m_ListElfDol}}; + + QActionGroup* platform_group = new QActionGroup(this); + QMenu* plat_menu = view_menu->addMenu(tr("Show Platforms")); + platform_group->setExclusive(false); + + for (const auto& key : platform_map.keys()) + { + bool* config = platform_map[key]; + QAction* action = platform_group->addAction(plat_menu->addAction(key)); + action->setCheckable(true); + action->setChecked(*config); + connect(action, &QAction::toggled, [this, config, key](bool value) { + *config = value; + emit GameListPlatformVisibilityToggled(key, value); + }); + } +} + +void MenuBar::AddShowRegionsMenu(QMenu* view_menu) +{ + static const QMap region_map{ + {tr("Show JAP"), &SConfig::GetInstance().m_ListJap}, + {tr("Show PAL"), &SConfig::GetInstance().m_ListPal}, + {tr("Show USA"), &SConfig::GetInstance().m_ListUsa}, + {tr("Show Australia"), &SConfig::GetInstance().m_ListAustralia}, + {tr("Show France"), &SConfig::GetInstance().m_ListFrance}, + {tr("Show Germany"), &SConfig::GetInstance().m_ListGermany}, + {tr("Show Italy"), &SConfig::GetInstance().m_ListItaly}, + {tr("Show Korea"), &SConfig::GetInstance().m_ListKorea}, + {tr("Show Netherlands"), &SConfig::GetInstance().m_ListNetherlands}, + {tr("Show Russia"), &SConfig::GetInstance().m_ListRussia}, + {tr("Show Spain"), &SConfig::GetInstance().m_ListSpain}, + {tr("Show Taiwan"), &SConfig::GetInstance().m_ListTaiwan}, + {tr("Show World"), &SConfig::GetInstance().m_ListWorld}, + {tr("Show Unknown"), &SConfig::GetInstance().m_ListUnknown}}; + + QActionGroup* region_group = new QActionGroup(this); + QMenu* region_menu = view_menu->addMenu(tr("Show Regions")); + region_group->setExclusive(false); + + for (const auto& key : region_map.keys()) + { + bool* config = region_map[key]; + QAction* action = region_group->addAction(region_menu->addAction(key)); + action->setCheckable(true); + action->setChecked(*config); + connect(action, &QAction::toggled, [this, config, key](bool value) { + *config = value; + emit GameListRegionVisibilityToggled(key, value); + }); + } +} + void MenuBar::UpdateToolsMenu(bool emulation_started) { m_boot_sysmenu->setEnabled(!emulation_started); diff --git a/Source/Core/DolphinQt2/MenuBar.h b/Source/Core/DolphinQt2/MenuBar.h index b1093308aa..2843f17d67 100644 --- a/Source/Core/DolphinQt2/MenuBar.h +++ b/Source/Core/DolphinQt2/MenuBar.h @@ -63,6 +63,8 @@ signals: void ShowTable(); void ShowList(); void ColumnVisibilityToggled(const QString& row, bool visible); + void GameListPlatformVisibilityToggled(const QString& row, bool visible); + void GameListRegionVisibilityToggled(const QString& row, bool visible); void ShowAboutDialog(); @@ -77,6 +79,8 @@ private: void AddViewMenu(); void AddGameListTypeSection(QMenu* view_menu); void AddTableColumnsMenu(QMenu* view_menu); + void AddShowPlatformsMenu(QMenu* view_menu); + void AddShowRegionsMenu(QMenu* view_menu); void AddOptionsMenu(); void AddToolsMenu();