mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-29 14:57:41 -05:00
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>
This commit is contained in:
parent
4a3d57e469
commit
c17e1bd7a8
4 changed files with 17 additions and 19 deletions
|
@ -16,10 +16,6 @@
|
||||||
#include "yuzu/configuration/configure_input_player.h"
|
#include "yuzu/configuration/configure_input_player.h"
|
||||||
#include "yuzu/hotkeys.h"
|
#include "yuzu/hotkeys.h"
|
||||||
|
|
||||||
static void CloseDialog(ConfigureDialog *dialog) {
|
|
||||||
dialog->close();
|
|
||||||
}
|
|
||||||
|
|
||||||
ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry,
|
ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry,
|
||||||
InputCommon::InputSubsystem* input_subsystem)
|
InputCommon::InputSubsystem* input_subsystem)
|
||||||
: QDialog(parent), ui(new Ui::ConfigureDialog), registry(registry) {
|
: QDialog(parent), ui(new Ui::ConfigureDialog), registry(registry) {
|
||||||
|
@ -31,7 +27,7 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry,
|
||||||
|
|
||||||
ui->inputTab->Initialize(input_subsystem);
|
ui->inputTab->Initialize(input_subsystem);
|
||||||
|
|
||||||
ui->generalTab->SetResetCallback(&CloseDialog, this);
|
ui->generalTab->SetResetCallback([&] { this->close(); });
|
||||||
|
|
||||||
SetConfiguration();
|
SetConfiguration();
|
||||||
PopulateSelectionList();
|
PopulateSelectionList();
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
#include <utility>
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
|
@ -57,10 +59,8 @@ void ConfigureGeneral::SetConfiguration() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called to set the callback when resetting settings to defaults
|
// Called to set the callback when resetting settings to defaults
|
||||||
void ConfigureGeneral::SetResetCallback(void (*callback)(ConfigureDialog*),
|
void ConfigureGeneral::SetResetCallback(std::function<void()> callback) {
|
||||||
ConfigureDialog* param) {
|
reset_callback = std::move(callback);
|
||||||
ResetCallback = callback;
|
|
||||||
reset_callback_param = param;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigureGeneral::ResetDefaults() {
|
void ConfigureGeneral::ResetDefaults() {
|
||||||
|
@ -69,11 +69,12 @@ void ConfigureGeneral::ResetDefaults() {
|
||||||
tr("This reset all settings and remove all per-game configurations. This will not delete "
|
tr("This reset all settings and remove all per-game configurations. This will not delete "
|
||||||
"game directories, profiles, or input profiles. Proceed?"),
|
"game directories, profiles, or input profiles. Proceed?"),
|
||||||
QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
|
QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
|
||||||
if (answer == QMessageBox::No)
|
if (answer == QMessageBox::No) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
UISettings::values.reset_to_defaults = true;
|
UISettings::values.reset_to_defaults = true;
|
||||||
UISettings::values.is_game_list_reload_pending.exchange(true);
|
UISettings::values.is_game_list_reload_pending.exchange(true);
|
||||||
(*ResetCallback)(reset_callback_param);
|
reset_callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigureGeneral::ApplyConfiguration() {
|
void ConfigureGeneral::ApplyConfiguration() {
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
@ -26,7 +27,7 @@ public:
|
||||||
explicit ConfigureGeneral(QWidget* parent = nullptr);
|
explicit ConfigureGeneral(QWidget* parent = nullptr);
|
||||||
~ConfigureGeneral() override;
|
~ConfigureGeneral() override;
|
||||||
|
|
||||||
void SetResetCallback(void (*callback)(ConfigureDialog*), ConfigureDialog *param);
|
void SetResetCallback(std::function<void()> callback);
|
||||||
void ResetDefaults();
|
void ResetDefaults();
|
||||||
void ApplyConfiguration();
|
void ApplyConfiguration();
|
||||||
|
|
||||||
|
@ -38,8 +39,7 @@ private:
|
||||||
|
|
||||||
void SetupPerGameUI();
|
void SetupPerGameUI();
|
||||||
|
|
||||||
void (*ResetCallback)(ConfigureDialog*);
|
std::function<void()> reset_callback;
|
||||||
ConfigureDialog *reset_callback_param;
|
|
||||||
|
|
||||||
std::unique_ptr<Ui::ConfigureGeneral> ui;
|
std::unique_ptr<Ui::ConfigureGeneral> ui;
|
||||||
|
|
||||||
|
|
|
@ -2611,17 +2611,18 @@ void GMainWindow::OnConfigure() {
|
||||||
LOG_WARNING(Frontend, "Failed to remove game metadata cache files");
|
LOG_WARNING(Frontend, "Failed to remove game metadata cache files");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Explicitly save the game directories, since reinitializing config does not do so.
|
// Explicitly save the game directories, since reinitializing config does not explicitly do
|
||||||
QVector<UISettings::GameDir> old_game_dirs = UISettings::values.game_dirs;
|
// so.
|
||||||
QVector<u64> old_favorited_ids = UISettings::values.favorited_ids;
|
QVector<UISettings::GameDir> old_game_dirs = std::move(UISettings::values.game_dirs);
|
||||||
|
QVector<u64> old_favorited_ids = std::move(UISettings::values.favorited_ids);
|
||||||
|
|
||||||
Settings::values.disabled_addons.clear();
|
Settings::values.disabled_addons.clear();
|
||||||
|
|
||||||
config = std::make_unique<Config>();
|
config = std::make_unique<Config>();
|
||||||
UISettings::values.reset_to_defaults = false;
|
UISettings::values.reset_to_defaults = false;
|
||||||
|
|
||||||
UISettings::values.game_dirs = old_game_dirs;
|
UISettings::values.game_dirs = std::move(old_game_dirs);
|
||||||
UISettings::values.favorited_ids = old_favorited_ids;
|
UISettings::values.favorited_ids = std::move(old_favorited_ids);
|
||||||
|
|
||||||
InitializeRecentFileMenuActions();
|
InitializeRecentFileMenuActions();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue