diff options
| author | Tor Arne Vestbø <[email protected]> | 2023-06-28 16:58:58 +0200 |
|---|---|---|
| committer | Tor Arne Vestbø <[email protected]> | 2023-06-29 18:49:46 +0200 |
| commit | 1f70c073d4325bc0eb9b0cec5156c3b89ce1b4df (patch) | |
| tree | e162a9fe518770210a7dedb1f091b0dbbef38103 /src/widgets/dialogs/qmessagebox.cpp | |
| parent | 4a4283e3e98d779e6eb6cb47d408fe4fd402cdf8 (diff) | |
QMessageBox: Respect clients overriding QDialog::done()
As a result of d8bbb5ee0e60d44a70d29306e607a59caf7fe5bc, we
were no longer calling QDialog::done(), which users may have
overridden.
We now pull out the dialog code to determine whether to
emit accepted/rejected directly in done(), so that we
can go back to calling QDialog::done().
Pick-to: 6.6 6.5
Change-Id: Ie08270123d61d9010acd8c989b66986f71960ad0
Reviewed-by: Volker Hilsheimer <[email protected]>
Diffstat (limited to 'src/widgets/dialogs/qmessagebox.cpp')
| -rw-r--r-- | src/widgets/dialogs/qmessagebox.cpp | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp index d40d35bea06..2c6b01a0d97 100644 --- a/src/widgets/dialogs/qmessagebox.cpp +++ b/src/widgets/dialogs/qmessagebox.cpp @@ -187,8 +187,6 @@ public: QAbstractButton *abstractButtonForId(int id) const; int execReturnCode(QAbstractButton *button); - int dialogCodeForButtonRole(QMessageBox::ButtonRole buttonRole) const; - void detectEscapeButton(); void updateSize(); int layoutMinimumWidth(); @@ -239,6 +237,7 @@ public: private: void initHelper(QPlatformDialogHelper *) override; void helperPrepareShow(QPlatformDialogHelper *) override; + int dialogCode() const override; }; void QMessageBoxPrivate::init(const QString &title, const QString &text) @@ -442,23 +441,24 @@ int QMessageBoxPrivate::execReturnCode(QAbstractButton *button) return ret; } -/*! - \internal +int QMessageBoxPrivate::dialogCode() const +{ + Q_Q(const QMessageBox); - Returns 0 for RejectedRole and NoRole, 1 for AcceptedRole and YesRole, -1 otherwise - */ -int QMessageBoxPrivate::dialogCodeForButtonRole(QMessageBox::ButtonRole buttonRole) const -{ - switch (buttonRole) { - case QMessageBox::AcceptRole: - case QMessageBox::YesRole: - return QDialog::Accepted; - case QMessageBox::RejectRole: - case QMessageBox::NoRole: - return QDialog::Rejected; - default: - return -1; + if (clickedButton) { + switch (q->buttonRole(clickedButton)) { + case QMessageBox::AcceptRole: + case QMessageBox::YesRole: + return QDialog::Accepted; + case QMessageBox::RejectRole: + case QMessageBox::NoRole: + return QDialog::Rejected; + default: + ; + } } + + return QDialogPrivate::dialogCode(); } void QMessageBoxPrivate::_q_buttonClicked(QAbstractButton *button) @@ -492,8 +492,7 @@ void QMessageBoxPrivate::setClickedButton(QAbstractButton *button) emit q->buttonClicked(clickedButton); auto resultCode = execReturnCode(button); - close(resultCode); - finalize(resultCode, dialogCodeForButtonRole(q->buttonRole(button))); + q->done(resultCode); } void QMessageBoxPrivate::_q_helperClicked(QPlatformDialogHelper::StandardButton helperButton, QPlatformDialogHelper::ButtonRole role) |
