diff options
| author | 2021-05-25 22:14:55 -0400 | |
|---|---|---|
| committer | 2021-06-01 17:22:06 -0400 | |
| commit | c17e1bd7a8df8c26ca1334faec3e41ce239a5650 (patch) | |
| tree | a7c58c2c58c2b8f5971e8ec473267266c07ef320 /src | |
| parent | yuzu: Add settings reset button to general configuration (diff) | |
| download | yuzu-c17e1bd7a8df8c26ca1334faec3e41ce239a5650.tar.gz yuzu-c17e1bd7a8df8c26ca1334faec3e41ce239a5650.tar.xz yuzu-c17e1bd7a8df8c26ca1334faec3e41ce239a5650.zip | |
yuzu qt: Use lambda and std::function for reset callback
Also makes use of std::move, and performs a clang-format cleanup.
This addresses review comments.
Co-authored-by: LC <mathew1800@gmail.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/yuzu/configuration/configure_dialog.cpp | 6 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_general.cpp | 13 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_general.h | 6 | ||||
| -rw-r--r-- | src/yuzu/main.cpp | 11 |
4 files changed, 17 insertions, 19 deletions
diff --git a/src/yuzu/configuration/configure_dialog.cpp b/src/yuzu/configuration/configure_dialog.cpp index 167323831..371bc01b1 100644 --- a/src/yuzu/configuration/configure_dialog.cpp +++ b/src/yuzu/configuration/configure_dialog.cpp | |||
| @@ -16,10 +16,6 @@ | |||
| 16 | #include "yuzu/configuration/configure_input_player.h" | 16 | #include "yuzu/configuration/configure_input_player.h" |
| 17 | #include "yuzu/hotkeys.h" | 17 | #include "yuzu/hotkeys.h" |
| 18 | 18 | ||
| 19 | static void CloseDialog(ConfigureDialog *dialog) { | ||
| 20 | dialog->close(); | ||
| 21 | } | ||
| 22 | |||
| 23 | ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry, | 19 | ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry, |
| 24 | InputCommon::InputSubsystem* input_subsystem) | 20 | InputCommon::InputSubsystem* input_subsystem) |
| 25 | : QDialog(parent), ui(new Ui::ConfigureDialog), registry(registry) { | 21 | : QDialog(parent), ui(new Ui::ConfigureDialog), registry(registry) { |
| @@ -31,7 +27,7 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry, | |||
| 31 | 27 | ||
| 32 | ui->inputTab->Initialize(input_subsystem); | 28 | ui->inputTab->Initialize(input_subsystem); |
| 33 | 29 | ||
| 34 | ui->generalTab->SetResetCallback(&CloseDialog, this); | 30 | ui->generalTab->SetResetCallback([&] { this->close(); }); |
| 35 | 31 | ||
| 36 | SetConfiguration(); | 32 | SetConfiguration(); |
| 37 | PopulateSelectionList(); | 33 | PopulateSelectionList(); |
diff --git a/src/yuzu/configuration/configure_general.cpp b/src/yuzu/configuration/configure_general.cpp index 28aaf47be..38edb4d8d 100644 --- a/src/yuzu/configuration/configure_general.cpp +++ b/src/yuzu/configuration/configure_general.cpp | |||
| @@ -2,6 +2,8 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <functional> | ||
| 6 | #include <utility> | ||
| 5 | #include <QCheckBox> | 7 | #include <QCheckBox> |
| 6 | #include <QMessageBox> | 8 | #include <QMessageBox> |
| 7 | #include <QSpinBox> | 9 | #include <QSpinBox> |
| @@ -57,10 +59,8 @@ void ConfigureGeneral::SetConfiguration() { | |||
| 57 | } | 59 | } |
| 58 | 60 | ||
| 59 | // Called to set the callback when resetting settings to defaults | 61 | // Called to set the callback when resetting settings to defaults |
| 60 | void ConfigureGeneral::SetResetCallback(void (*callback)(ConfigureDialog*), | 62 | void ConfigureGeneral::SetResetCallback(std::function<void()> callback) { |
| 61 | ConfigureDialog* param) { | 63 | reset_callback = std::move(callback); |
| 62 | ResetCallback = callback; | ||
| 63 | reset_callback_param = param; | ||
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | void ConfigureGeneral::ResetDefaults() { | 66 | void ConfigureGeneral::ResetDefaults() { |
| @@ -69,11 +69,12 @@ void ConfigureGeneral::ResetDefaults() { | |||
| 69 | tr("This reset all settings and remove all per-game configurations. This will not delete " | 69 | tr("This reset all settings and remove all per-game configurations. This will not delete " |
| 70 | "game directories, profiles, or input profiles. Proceed?"), | 70 | "game directories, profiles, or input profiles. Proceed?"), |
| 71 | QMessageBox::Yes | QMessageBox::No, QMessageBox::No); | 71 | QMessageBox::Yes | QMessageBox::No, QMessageBox::No); |
| 72 | if (answer == QMessageBox::No) | 72 | if (answer == QMessageBox::No) { |
| 73 | return; | 73 | return; |
| 74 | } | ||
| 74 | UISettings::values.reset_to_defaults = true; | 75 | UISettings::values.reset_to_defaults = true; |
| 75 | UISettings::values.is_game_list_reload_pending.exchange(true); | 76 | UISettings::values.is_game_list_reload_pending.exchange(true); |
| 76 | (*ResetCallback)(reset_callback_param); | 77 | reset_callback(); |
| 77 | } | 78 | } |
| 78 | 79 | ||
| 79 | void ConfigureGeneral::ApplyConfiguration() { | 80 | void ConfigureGeneral::ApplyConfiguration() { |
diff --git a/src/yuzu/configuration/configure_general.h b/src/yuzu/configuration/configure_general.h index 2a7741ad9..a0fd52492 100644 --- a/src/yuzu/configuration/configure_general.h +++ b/src/yuzu/configuration/configure_general.h | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <functional> | ||
| 7 | #include <memory> | 8 | #include <memory> |
| 8 | #include <QWidget> | 9 | #include <QWidget> |
| 9 | 10 | ||
| @@ -26,7 +27,7 @@ public: | |||
| 26 | explicit ConfigureGeneral(QWidget* parent = nullptr); | 27 | explicit ConfigureGeneral(QWidget* parent = nullptr); |
| 27 | ~ConfigureGeneral() override; | 28 | ~ConfigureGeneral() override; |
| 28 | 29 | ||
| 29 | void SetResetCallback(void (*callback)(ConfigureDialog*), ConfigureDialog *param); | 30 | void SetResetCallback(std::function<void()> callback); |
| 30 | void ResetDefaults(); | 31 | void ResetDefaults(); |
| 31 | void ApplyConfiguration(); | 32 | void ApplyConfiguration(); |
| 32 | 33 | ||
| @@ -38,8 +39,7 @@ private: | |||
| 38 | 39 | ||
| 39 | void SetupPerGameUI(); | 40 | void SetupPerGameUI(); |
| 40 | 41 | ||
| 41 | void (*ResetCallback)(ConfigureDialog*); | 42 | std::function<void()> reset_callback; |
| 42 | ConfigureDialog *reset_callback_param; | ||
| 43 | 43 | ||
| 44 | std::unique_ptr<Ui::ConfigureGeneral> ui; | 44 | std::unique_ptr<Ui::ConfigureGeneral> ui; |
| 45 | 45 | ||
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index e5a2fdf8c..c5dec215d 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp | |||
| @@ -2611,17 +2611,18 @@ void GMainWindow::OnConfigure() { | |||
| 2611 | LOG_WARNING(Frontend, "Failed to remove game metadata cache files"); | 2611 | LOG_WARNING(Frontend, "Failed to remove game metadata cache files"); |
| 2612 | } | 2612 | } |
| 2613 | 2613 | ||
| 2614 | // Explicitly save the game directories, since reinitializing config does not do so. | 2614 | // Explicitly save the game directories, since reinitializing config does not explicitly do |
| 2615 | QVector<UISettings::GameDir> old_game_dirs = UISettings::values.game_dirs; | 2615 | // so. |
| 2616 | QVector<u64> old_favorited_ids = UISettings::values.favorited_ids; | 2616 | QVector<UISettings::GameDir> old_game_dirs = std::move(UISettings::values.game_dirs); |
| 2617 | QVector<u64> old_favorited_ids = std::move(UISettings::values.favorited_ids); | ||
| 2617 | 2618 | ||
| 2618 | Settings::values.disabled_addons.clear(); | 2619 | Settings::values.disabled_addons.clear(); |
| 2619 | 2620 | ||
| 2620 | config = std::make_unique<Config>(); | 2621 | config = std::make_unique<Config>(); |
| 2621 | UISettings::values.reset_to_defaults = false; | 2622 | UISettings::values.reset_to_defaults = false; |
| 2622 | 2623 | ||
| 2623 | UISettings::values.game_dirs = old_game_dirs; | 2624 | UISettings::values.game_dirs = std::move(old_game_dirs); |
| 2624 | UISettings::values.favorited_ids = old_favorited_ids; | 2625 | UISettings::values.favorited_ids = std::move(old_favorited_ids); |
| 2625 | 2626 | ||
| 2626 | InitializeRecentFileMenuActions(); | 2627 | InitializeRecentFileMenuActions(); |
| 2627 | 2628 | ||