From fcbbe7b927508ab345d1551f591bcfcbfc08a44d Mon Sep 17 00:00:00 2001 From: pm3g19 Date: Wed, 3 Aug 2022 15:28:08 +0100 Subject: [PATCH] Add Apply option to preferences dialog (cherry picked from commit f6fc90829aea0432abff9a1b0a23a97e66a833a7) --- app/dialog/configbase/configdialogbase.cpp | 9 +++++---- app/dialog/configbase/configdialogbase.h | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/dialog/configbase/configdialogbase.cpp b/app/dialog/configbase/configdialogbase.cpp index 13bbafbb54..b1d1db2c0f 100644 --- a/app/dialog/configbase/configdialogbase.cpp +++ b/app/dialog/configbase/configdialogbase.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include "core.h" @@ -46,12 +47,13 @@ ConfigDialogBase::ConfigDialogBase(QWidget* parent) : QDialogButtonBox* button_box = new QDialogButtonBox(this); button_box->setOrientation(Qt::Horizontal); - button_box->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok); + button_box->setStandardButtons(QDialogButtonBox::Apply | QDialogButtonBox::Cancel|QDialogButtonBox::Ok); layout->addWidget(button_box); - connect(button_box, &QDialogButtonBox::accepted, this, &ConfigDialogBase::accept); + connect(button_box, &QDialogButtonBox::accepted, this, [this]() {apply(); QDialog::accept();});; connect(button_box, &QDialogButtonBox::rejected, this, &ConfigDialogBase::reject); + connect(button_box, &QDialogButtonBox::clicked, this, [this, button_box](QAbstractButton* btn) {if (button_box->buttonRole(btn) == QDialogButtonBox::ApplyRole) apply();}); connect(list_widget_, &QListWidget::currentRowChanged, @@ -59,7 +61,7 @@ ConfigDialogBase::ConfigDialogBase(QWidget* parent) : &QStackedWidget::setCurrentIndex); } -void ConfigDialogBase::accept() +void ConfigDialogBase::apply() { foreach (ConfigDialogBaseTab* tab, tabs_) { if (!tab->Validate()) { @@ -77,7 +79,6 @@ void ConfigDialogBase::accept() AcceptEvent(); - QDialog::accept(); } void ConfigDialogBase::AddTab(ConfigDialogBaseTab *tab, const QString &title) diff --git a/app/dialog/configbase/configdialogbase.h b/app/dialog/configbase/configdialogbase.h index 35592175e9..b1b2f63299 100644 --- a/app/dialog/configbase/configdialogbase.h +++ b/app/dialog/configbase/configdialogbase.h @@ -39,7 +39,8 @@ private slots: /** * @brief Override of accept to save preferences to Config. */ - virtual void accept() override; + virtual void apply(); + protected: void AddTab(ConfigDialogBaseTab* tab, const QString& title);