summaryrefslogtreecommitdiffstats
path: root/src/widgets/dialogs
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2023-06-27 19:27:05 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2023-06-29 18:49:46 +0200
commit6da1ecc8c2b9f7fd488194b6e81b41a314b678d5 (patch)
tree39d1d900a7fb41831a7af01aa6e166e62394d9a1 /src/widgets/dialogs
parentcd9ae49962bbadf20c4b6599187b5a1bb0d8dc8a (diff)
QMessageBox: Emit accepted/rejected for native message boxes
In d8bbb5ee0e60d44a70d29306e607a59caf7fe5bc we started respecting the button roles of buttons added to QMessageBox, by emitting accepted() and rejected() if the appropriate roles were found. Unfortunately this only touched the QMessageBoxPrivate::_q_buttonClicked code path, for non-native dialogs, leaving the code path for native dialogs in QMessageBoxPrivate::_q_clicked alone. We now follow the same approach for the native dialogs as for the non-native ones, by calling QMessageBoxPrivate::close() and QMessageBoxPrivate::finalize() explicitly, instead of going via QDialog::done(). This allows us to pass a dialog code to finalize(). One side effect of the original change was that overriding QDialog::done() for non-native dialogs no longer had any effect, as we were using lower level plumbing. Since we now align with the original change for native dialogs, we will adopt the same limitation, but this will be fixed in a follow up for both cases. The callback code for custom buttons in native dialogs could also use some alignment with the non-native path, but this is also left for a follow up. Fixes: QTBUG-113685 Pick-to: 6.5 6.6 Change-Id: Iea03a0007f884d6c7f11d2bd891446bdaa5ddc67 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Erik Verbruggen <erik.verbruggen@me.com>
Diffstat (limited to 'src/widgets/dialogs')
-rw-r--r--src/widgets/dialogs/qmessagebox.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp
index 551663a711..efc43ba396 100644
--- a/src/widgets/dialogs/qmessagebox.cpp
+++ b/src/widgets/dialogs/qmessagebox.cpp
@@ -187,7 +187,7 @@ public:
QAbstractButton *abstractButtonForId(int id) const;
int execReturnCode(QAbstractButton *button);
- int dialogCodeForButton(QAbstractButton *button) const;
+ int dialogCodeForButtonRole(QMessageBox::ButtonRole buttonRole) const;
void detectEscapeButton();
void updateSize();
@@ -447,11 +447,9 @@ int QMessageBoxPrivate::execReturnCode(QAbstractButton *button)
Returns 0 for RejectedRole and NoRole, 1 for AcceptedRole and YesRole, -1 otherwise
*/
-int QMessageBoxPrivate::dialogCodeForButton(QAbstractButton *button) const
+int QMessageBoxPrivate::dialogCodeForButtonRole(QMessageBox::ButtonRole buttonRole) const
{
- Q_Q(const QMessageBox);
-
- switch (q->buttonRole(button)) {
+ switch (buttonRole) {
case QMessageBox::AcceptRole:
case QMessageBox::YesRole:
return QDialog::Accepted;
@@ -495,7 +493,7 @@ void QMessageBoxPrivate::setClickedButton(QAbstractButton *button)
auto resultCode = execReturnCode(button);
close(resultCode);
- finalize(resultCode, dialogCodeForButton(button));
+ finalize(resultCode, dialogCodeForButtonRole(q->buttonRole(button)));
}
void QMessageBoxPrivate::_q_clicked(QPlatformDialogHelper::StandardButton button, QPlatformDialogHelper::ButtonRole role)
@@ -507,11 +505,13 @@ void QMessageBoxPrivate::_q_clicked(QPlatformDialogHelper::StandardButton button
clickedButton = static_cast<QAbstractButton *>(options->customButton(button)->button);
Q_ASSERT(clickedButton);
clickedButton->click();
- q->done(role);
+ close(role);
+ finalize(role, dialogCodeForButtonRole(q->buttonRole(clickedButton)));
} else {
clickedButton = q->button(QMessageBox::StandardButton(button));
Q_ASSERT(clickedButton);
- q->done(button);
+ close(button);
+ finalize(button, dialogCodeForButtonRole(static_cast<QMessageBox::ButtonRole>(role)));
}
}