Merge pull request #9210 from Dentomologist/regions-show-hide-all

DolphinQt: Add Show/Hide All options to gamelist region menu
This commit is contained in:
Léo Lam 2020-11-20 11:35:22 +01:00 committed by GitHub
commit c580a70a12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 11 deletions

View File

@ -701,20 +701,29 @@ void MenuBar::AddShowRegionsMenu(QMenu* view_menu)
{tr("Show World"), &SConfig::GetInstance().m_ListWorld}, {tr("Show World"), &SConfig::GetInstance().m_ListWorld},
{tr("Show Unknown"), &SConfig::GetInstance().m_ListUnknown}}; {tr("Show Unknown"), &SConfig::GetInstance().m_ListUnknown}};
QActionGroup* region_group = new QActionGroup(this); QMenu* const region_menu = view_menu->addMenu(tr("Show Regions"));
QMenu* region_menu = view_menu->addMenu(tr("Show Regions")); const QAction* const show_all_regions = region_menu->addAction(tr("Show All"));
region_group->setExclusive(false); const QAction* const hide_all_regions = region_menu->addAction(tr("Hide All"));
region_menu->addSeparator();
for (const auto& key : region_map.keys()) for (const auto& key : region_map.keys())
{ {
bool* config = region_map[key]; bool* const config = region_map[key];
QAction* action = region_group->addAction(region_menu->addAction(key)); QAction* const menu_item = region_menu->addAction(key);
action->setCheckable(true); menu_item->setCheckable(true);
action->setChecked(*config); menu_item->setChecked(*config);
connect(action, &QAction::toggled, [this, config, key](bool value) {
*config = value; const auto set_visibility = [this, config, key, menu_item](bool visibility) {
emit GameListRegionVisibilityToggled(key, value); menu_item->setChecked(visibility);
}); *config = visibility;
emit GameListRegionVisibilityToggled(key, visibility);
};
const auto set_visible = std::bind(set_visibility, true);
const auto set_hidden = std::bind(set_visibility, false);
connect(menu_item, &QAction::toggled, set_visibility);
connect(show_all_regions, &QAction::triggered, menu_item, set_visible);
connect(hide_all_regions, &QAction::triggered, menu_item, set_hidden);
} }
} }