From c1748b229a81390c3ee81a1b951455839204c572 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Tue, 9 May 2023 14:26:03 -0400 Subject: [PATCH] shared_widget: Make button creation static --- src/yuzu/configuration/shared_widget.cpp | 17 +++++++++-------- src/yuzu/configuration/shared_widget.h | 5 +++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/yuzu/configuration/shared_widget.cpp b/src/yuzu/configuration/shared_widget.cpp index 0676973a91..ba44d19735 100644 --- a/src/yuzu/configuration/shared_widget.cpp +++ b/src/yuzu/configuration/shared_widget.cpp @@ -14,10 +14,10 @@ namespace ConfigurationShared { -void Widget::CreateRestoreGlobalButton() { - QStyle* style = this->style(); +QPushButton* Widget::CreateRestoreGlobalButton(Settings::BasicSetting& setting, QWidget* parent) { + QStyle* style = parent->style(); QIcon* icon = new QIcon(style->standardIcon(QStyle::SP_DialogResetButton)); - restore_button = new QPushButton(*icon, QStringLiteral(""), this); + QPushButton* restore_button = new QPushButton(*icon, QStringLiteral(""), parent); restore_button->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding); QSizePolicy sp_retain = restore_button->sizePolicy(); @@ -26,6 +26,8 @@ void Widget::CreateRestoreGlobalButton() { restore_button->setEnabled(!setting.UsingGlobal()); restore_button->setVisible(!setting.UsingGlobal()); + + return restore_button; } void Widget::CreateCheckBox(const QString& label, std::function& load_func) { @@ -44,7 +46,7 @@ void Widget::CreateCheckBox(const QString& label, std::function& load_fu setting.LoadString(checkbox->checkState() == Qt::Checked ? "true" : "false"); }; } else { - CreateRestoreGlobalButton(); + restore_button = CreateRestoreGlobalButton(setting, this); layout->addWidget(restore_button); QObject::connect(checkbox, &QCheckBox::stateChanged, [&](int) { @@ -97,7 +99,7 @@ void Widget::CreateCombobox(const QString& label, bool managed, std::functioncurrentIndex())); }; } else if (managed) { - CreateRestoreGlobalButton(); + restore_button = CreateRestoreGlobalButton(setting, this); layout->addWidget(restore_button); QObject::connect(restore_button, &QAbstractButton::clicked, [&](bool) { @@ -144,7 +146,7 @@ void Widget::CreateLineEdit(const QString& label, bool managed, std::functionaddWidget(restore_button); QObject::connect(restore_button, &QAbstractButton::clicked, [&](bool) { @@ -207,7 +209,7 @@ void Widget::CreateSlider(const QString& name, bool reversed, float multiplier, if (Settings::IsConfiguringGlobal()) { load_func = [=]() { setting.LoadString(std::to_string(slider->value())); }; } else { - CreateRestoreGlobalButton(); + restore_button = CreateRestoreGlobalButton(setting, this); layout->addWidget(restore_button); QObject::connect(restore_button, &QAbstractButton::clicked, [=](bool) { @@ -340,7 +342,6 @@ Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translati } apply_funcs.push_front([load_func, setting_](bool powered_on) { - LOG_DEBUG(Frontend, "{}", setting_->GetLabel()); if (setting_->RuntimeModfiable() || !powered_on) { load_func(); } diff --git a/src/yuzu/configuration/shared_widget.h b/src/yuzu/configuration/shared_widget.h index 3d96805ed8..8d2d7f2691 100644 --- a/src/yuzu/configuration/shared_widget.h +++ b/src/yuzu/configuration/shared_widget.h @@ -37,6 +37,9 @@ public: bool Valid(); + [[nodiscard]] static QPushButton* CreateRestoreGlobalButton(Settings::BasicSetting& setting, + QWidget* parent); + QPushButton* restore_button{}; QLineEdit* line_edit{}; QCheckBox* checkbox{}; @@ -54,8 +57,6 @@ private: void CreateSlider(const QString& label, bool reversed, float multiplier, std::function& load_func); - void CreateRestoreGlobalButton(); - QWidget* parent; const TranslationMap& translations; Settings::BasicSetting& setting;