Commit c413d543 authored by Ahmad Samir's avatar Ahmad Samir
Browse files

Fix QDialogButtonBox connections in the edit profile dialog

KPageDialog already creates the accepted()/rejected() connections, since
the code here created another connection, the accept() slot was being
called twice for each OK button click, with e.g. the profile name empty,
clicking Ok:
- the first time isProfileNameValid() would return false, and the saving
  would abort, as it should
- the second time around, isProfileNameValid() would return true since
  the name has been reverted to the original value in the Name line edit

The same goes for the reject() slot.

Also use a lambda instead of apply(), it's a very small method and this
was the code is more readable, since we don't need to jump back and forth.
parent 1c8db8a3
......@@ -77,17 +77,16 @@ EditProfileDialog::EditProfileDialog(QWidget *parent)
_buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Apply);
setButtonBox(_buttonBox);
QPushButton *okButton = _buttonBox->button(QDialogButtonBox::Ok);
okButton->setDefault(true);
connect(_buttonBox, &QDialogButtonBox::accepted, this, &Konsole::EditProfileDialog::accept);
connect(_buttonBox, &QDialogButtonBox::rejected, this, &Konsole::EditProfileDialog::reject);
// disable the apply button , since no modification has been made
_buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
connect(_buttonBox->button(QDialogButtonBox::Apply),
&QPushButton::clicked, this,
&Konsole::EditProfileDialog::apply);
_buttonBox->button(QDialogButtonBox::Ok)->setDefault(true);
auto *applyButton = _buttonBox->button(QDialogButtonBox::Apply);
// Disable it, since no modifications have been made yet
applyButton->setEnabled(false);
connect(applyButton, &QPushButton::clicked, this, [this]() {
if (isProfileNameValid()) {
save();
}
});
connect(_delayedPreviewTimer, &QTimer::timeout, this,
&Konsole::EditProfileDialog::delayedPreviewActivate);
......@@ -259,25 +258,11 @@ void EditProfileDialog::reject()
void EditProfileDialog::accept()
{
// if the Apply button is disabled then no settings were changed
// or the changes have already been saved by apply()
if (_buttonBox->button(QDialogButtonBox::Apply)->isEnabled()) {
if (!isProfileNameValid()) {
return;
}
if (isProfileNameValid()) {
save();
unpreviewAll();
QDialog::accept();
}
unpreviewAll();
QDialog::accept();
}
void EditProfileDialog::apply()
{
if (!isProfileNameValid()) {
return;
}
save();
}
void EditProfileDialog::setMessageGeneralPage(const QString &msg)
......
......@@ -94,8 +94,6 @@ public Q_SLOTS:
// reimplemented
void reject() override;
void apply();
protected:
bool eventFilter(QObject *watched, QEvent *event) override;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment