QMesageBox: add Q_ENUM and sync assertions

Add Q_ENUM to StandardButton and ButtonRole.
Add static assertion to enforce sync with QDialogButtonBox.

Task-number: QTBUG-118489
Pick-to: 6.6 6.5
Change-Id: I38a7367d6287ab7fa5e5ca0c94ea6daa0f95fc52
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Axel Spoerl 2023-11-23 12:02:20 +01:00
parent 9d3b55b2a8
commit 773f9ab018

View File

@ -6,6 +6,7 @@
#include <QtWidgets/qtwidgetsglobal.h>
#include <QtWidgets/qdialog.h>
#include <QtWidgets/qdialogbuttonbox.h>
QT_REQUIRE_CONFIG(messagebox);
@ -64,6 +65,10 @@ public:
NRoles
};
Q_ENUM(ButtonRole)
static_assert(static_cast<int>(ButtonRole::NRoles) ==
static_cast<int>(QDialogButtonBox::ButtonRole::NRoles),
"QMessageBox::ButtonRole and QDialogButtonBox::ButtonRole out of sync!");
enum StandardButton {
// keep this in sync with QDialogButtonBox::StandardButton and QPlatformDialogHelper::StandardButton
@ -98,6 +103,12 @@ public:
FlagMask = 0x00000300, // obsolete
ButtonMask = ~FlagMask // obsolete
};
Q_ENUM(StandardButton);
static_assert(static_cast<int>(StandardButton::LastButton) ==
static_cast<int>(QDialogButtonBox::StandardButton::LastButton),
"QMessageBox::StandardButton and QDialogButtonBox::StandardButton out of sync!");
#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
typedef StandardButton Button;
#endif