From 145fbff79b0e30da050b6007b5f90aabd81af587 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Thu, 31 Oct 2024 20:13:43 +1000 Subject: [PATCH] Qt: Add log level/channels to debug menu --- src/duckstation-qt/mainwindow.cpp | 124 +++++------------------ src/duckstation-qt/mainwindow.h | 4 +- src/duckstation-qt/mainwindow.ui | 23 +++++ src/duckstation-qt/settingwidgetbinder.h | 40 ++++++++ 4 files changed, 87 insertions(+), 104 deletions(-) diff --git a/src/duckstation-qt/mainwindow.cpp b/src/duckstation-qt/mainwindow.cpp index d2312dc1d..31ea3c094 100644 --- a/src/duckstation-qt/mainwindow.cpp +++ b/src/duckstation-qt/mainwindow.cpp @@ -1617,58 +1617,14 @@ void MainWindow::setupAdditionalUi() m_ui.actionGridViewShowTitles->setChecked(m_game_list_widget->isShowingGridCoverTitles()); - updateDebugMenuVisibility(); - - for (u32 i = 0; i < static_cast(CPUExecutionMode::Count); i++) - { - const CPUExecutionMode mode = static_cast(i); - QAction* action = - m_ui.menuCPUExecutionMode->addAction(QString::fromUtf8(Settings::GetCPUExecutionModeDisplayName(mode))); - action->setCheckable(true); - connect(action, &QAction::triggered, [this, mode]() { - Host::SetBaseStringSettingValue("CPU", "ExecutionMode", Settings::GetCPUExecutionModeName(mode)); - Host::CommitBaseSettingChanges(); - g_emu_thread->applySettings(); - updateDebugMenuCPUExecutionMode(); - }); - } - updateDebugMenuCPUExecutionMode(); - - for (u32 i = 0; i < static_cast(GPURenderer::Count); i++) - { - const GPURenderer renderer = static_cast(i); - QAction* action = m_ui.menuRenderer->addAction(QString::fromUtf8(Settings::GetRendererDisplayName(renderer))); - action->setCheckable(true); - connect(action, &QAction::triggered, [this, renderer]() { - Host::SetBaseStringSettingValue("GPU", "Renderer", Settings::GetRendererName(renderer)); - Host::CommitBaseSettingChanges(); - g_emu_thread->applySettings(); - updateDebugMenuGPURenderer(); - }); - } - updateDebugMenuGPURenderer(); - - for (u32 i = 0; i < static_cast(DisplayCropMode::Count); i++) - { - const DisplayCropMode crop_mode = static_cast(i); - QAction* action = - m_ui.menuCropMode->addAction(QString::fromUtf8(Settings::GetDisplayCropModeDisplayName(crop_mode))); - action->setCheckable(true); - connect(action, &QAction::triggered, [this, crop_mode]() { - Host::SetBaseStringSettingValue("Display", "CropMode", Settings::GetDisplayCropModeName(crop_mode)); - Host::CommitBaseSettingChanges(); - g_emu_thread->applySettings(); - updateDebugMenuCropMode(); - }); - } - updateDebugMenuCropMode(); - for (u32 scale = 1; scale <= 10; scale++) { QAction* action = m_ui.menuWindowSize->addAction(tr("%1x Scale").arg(scale)); connect(action, &QAction::triggered, [scale]() { g_emu_thread->requestDisplaySize(scale); }); } + updateDebugMenuVisibility(); + #ifdef ENABLE_RAINTEGRATION if (Achievements::IsUsingRAIntegration()) { @@ -2064,6 +2020,21 @@ void MainWindow::connectSignals() connect(m_game_list_widget, &GameListWidget::addGameDirectoryRequested, this, [this]() { getSettingsWindow()->getGameListSettingsWidget()->addSearchDirectory(this); }); + SettingWidgetBinder::BindMenuToEnumSetting(m_ui.menuCPUExecutionMode, "CPU", "ExecutionMode", + &Settings::ParseCPUExecutionMode, &Settings::GetCPUExecutionModeName, + &Settings::GetCPUExecutionModeDisplayName, + Settings::DEFAULT_CPU_EXECUTION_MODE, CPUExecutionMode::Count); + SettingWidgetBinder::BindMenuToEnumSetting(m_ui.menuRenderer, "GPU", "Renderer", &Settings::ParseRendererName, + &Settings::GetRendererName, &Settings::GetRendererDisplayName, + Settings::DEFAULT_GPU_RENDERER, GPURenderer::Count); + SettingWidgetBinder::BindMenuToEnumSetting( + m_ui.menuCropMode, "Display", "CropMode", &Settings::ParseDisplayCropMode, &Settings::GetDisplayCropModeName, + &Settings::GetDisplayCropModeDisplayName, Settings::DEFAULT_DISPLAY_CROP_MODE, DisplayCropMode::Count); + SettingWidgetBinder::BindMenuToEnumSetting(m_ui.menuLogLevel, "Logging", "LogLevel", &Settings::ParseLogLevelName, + &Settings::GetLogLevelName, &Settings::GetLogLevelDisplayName, + Settings::DEFAULT_LOG_LEVEL, Log::Level::MaxCount); + connect(m_ui.menuLogChannels, &QMenu::aboutToShow, this, &MainWindow::onDebugLogChannelsMenuAboutToShow); + SettingWidgetBinder::BindWidgetToBoolSetting(nullptr, m_ui.actionDisableAllEnhancements, "Main", "DisableAllEnhancements", false); SettingWidgetBinder::BindWidgetToBoolSetting(nullptr, m_ui.actionDebugDumpCPUtoVRAMCopies, "Debug", @@ -2155,9 +2126,6 @@ void MainWindow::onSettingsResetToDefault(bool system, bool controller) doControllerSettings(ControllerSettingsWindow::Category::GlobalSettings); } - updateDebugMenuCPUExecutionMode(); - updateDebugMenuGPURenderer(); - updateDebugMenuCropMode(); updateDebugMenuVisibility(); } @@ -2292,58 +2260,6 @@ void MainWindow::openInputProfileEditor(const std::string_view name) dlg->switchProfile(name); } -void MainWindow::updateDebugMenuCPUExecutionMode() -{ - std::optional current_mode = - Settings::ParseCPUExecutionMode(Host::GetBaseStringSettingValue("CPU", "ExecutionMode").c_str()); - if (!current_mode.has_value()) - return; - - const QString current_mode_display_name = - QString::fromUtf8(Settings::GetCPUExecutionModeDisplayName(current_mode.value())); - for (QObject* obj : m_ui.menuCPUExecutionMode->children()) - { - QAction* action = qobject_cast(obj); - if (action) - action->setChecked(action->text() == current_mode_display_name); - } -} - -void MainWindow::updateDebugMenuGPURenderer() -{ - // update the menu with the new selected renderer - std::optional current_renderer = - Settings::ParseRendererName(Host::GetBaseStringSettingValue("GPU", "Renderer").c_str()); - if (!current_renderer.has_value()) - return; - - const QString current_renderer_display_name = - QString::fromUtf8(Settings::GetRendererDisplayName(current_renderer.value())); - for (QObject* obj : m_ui.menuRenderer->children()) - { - QAction* action = qobject_cast(obj); - if (action) - action->setChecked(action->text() == current_renderer_display_name); - } -} - -void MainWindow::updateDebugMenuCropMode() -{ - std::optional current_crop_mode = - Settings::ParseDisplayCropMode(Host::GetBaseStringSettingValue("Display", "CropMode").c_str()); - if (!current_crop_mode.has_value()) - return; - - const QString current_crop_mode_display_name = - QString::fromUtf8(Settings::GetDisplayCropModeDisplayName(current_crop_mode.value())); - for (QObject* obj : m_ui.menuCropMode->children()) - { - QAction* action = qobject_cast(obj); - if (action) - action->setChecked(action->text() == current_crop_mode_display_name); - } -} - void MainWindow::showEvent(QShowEvent* event) { QMainWindow::showEvent(event); @@ -2833,6 +2749,12 @@ void MainWindow::onUpdateCheckComplete() m_auto_updater_dialog = nullptr; } +void MainWindow::onDebugLogChannelsMenuAboutToShow() +{ + m_ui.menuLogChannels->clear(); + LogWindow::populateFilterMenu(m_ui.menuLogChannels); +} + MainWindow::SystemLock MainWindow::pauseAndLockSystem() { // To switch out of fullscreen when displaying a popup, or not to? diff --git a/src/duckstation-qt/mainwindow.h b/src/duckstation-qt/mainwindow.h index 31e3bb510..4c0d24932 100644 --- a/src/duckstation-qt/mainwindow.h +++ b/src/duckstation-qt/mainwindow.h @@ -194,6 +194,7 @@ private Q_SLOTS: void onUpdateCheckComplete(); + void onDebugLogChannelsMenuAboutToShow(); void openCPUDebugger(); protected: @@ -247,9 +248,6 @@ private: void openGamePropertiesForCurrentGame(const char* category = nullptr); void doControllerSettings(ControllerSettingsWindow::Category category = ControllerSettingsWindow::Category::Count); - void updateDebugMenuCPUExecutionMode(); - void updateDebugMenuGPURenderer(); - void updateDebugMenuCropMode(); std::string getDeviceDiscPath(const QString& title); void setGameListEntryCoverImage(const GameList::Entry* entry); void clearGameListEntryPlayTime(const GameList::Entry* entry); diff --git a/src/duckstation-qt/mainwindow.ui b/src/duckstation-qt/mainwindow.ui index 687312e91..4fece997d 100644 --- a/src/duckstation-qt/mainwindow.ui +++ b/src/duckstation-qt/mainwindow.ui @@ -153,11 +153,24 @@ Switch Crop Mode + + + Log Level + + + + + Log Channels + + + + + @@ -918,6 +931,16 @@ Capture GPU Frame + + + asdf + + + + + aaa + + diff --git a/src/duckstation-qt/settingwidgetbinder.h b/src/duckstation-qt/settingwidgetbinder.h index 5fc342adf..03e75a44e 100644 --- a/src/duckstation-qt/settingwidgetbinder.h +++ b/src/duckstation-qt/settingwidgetbinder.h @@ -13,9 +13,11 @@ #include "common/assert.h" #include "common/file_system.h" #include "common/path.h" +#include "common/small_string.h" #include #include +#include #include #include #include @@ -27,6 +29,7 @@ #include #include #include +#include #include #include @@ -1133,6 +1136,43 @@ static void BindWidgetToEnumSetting(SettingsInterface* sif, WidgetType* widget, } } +template +static void BindMenuToEnumSetting(QMenu* menu, std::string section, std::string key, + std::optional (*from_string_function)(const char* str), + const char* (*to_string_function)(DataType value), + const char* (*to_display_name_function)(DataType value), DataType default_value, + ValueCountType value_count) +{ + QActionGroup* group = new QActionGroup(menu); + + const std::optional typed_value = from_string_function( + Host::GetBaseSmallStringSettingValue(section.c_str(), key.c_str(), to_string_function(default_value)).c_str()); + + // need a shared pointer, otherwise we dupe it a ton... + struct CallbackData + { + std::string section; + std::string key; + }; + std::shared_ptr data = std::make_shared(); + data->section = std::move(section); + data->key = std::move(key); + + for (u32 i = 0; i < static_cast(value_count); i++) + { + QAction* action = group->addAction(QString::fromUtf8(to_display_name_function(static_cast(i)))); + action->setCheckable(true); + action->setChecked(typed_value.has_value() && typed_value.value() == static_cast(i)); + menu->addAction(action); + QObject::connect(action, &QAction::triggered, menu, [data, to_string_function, i]() { + Host::SetBaseStringSettingValue(data->section.c_str(), data->key.c_str(), + to_string_function(static_cast(i))); + Host::CommitBaseSettingChanges(); + g_emu_thread->applySettings(); + }); + } +} + template static void BindWidgetToEnumSetting(SettingsInterface* sif, WidgetType* widget, std::string section, std::string key, const char** enum_names, DataType default_value)