Skip to content

Commit

Permalink
Add Apply option to preferences dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
pm3g19 committed Aug 3, 2022
1 parent dd9dcf7 commit f6fc908
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
9 changes: 5 additions & 4 deletions app/dialog/configbase/configdialogbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <QDialogButtonBox>
#include <QSplitter>
#include <QVBoxLayout>
#include <QAbstractButton>

#include "core.h"

Expand All @@ -46,20 +47,21 @@ 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,
preference_pane_stack_,
&QStackedWidget::setCurrentIndex);
}

void ConfigDialogBase::accept()
void ConfigDialogBase::apply()
{
foreach (ConfigDialogBaseTab* tab, tabs_) {
if (!tab->Validate()) {
Expand All @@ -77,7 +79,6 @@ void ConfigDialogBase::accept()

AcceptEvent();

QDialog::accept();
}

void ConfigDialogBase::AddTab(ConfigDialogBaseTab *tab, const QString &title)
Expand Down
3 changes: 2 additions & 1 deletion app/dialog/configbase/configdialogbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f6fc908

Please sign in to comment.