QMessageBox: Move enum static assertions to cpp file

Move static assertions for StandardButton and ButtonRole enums from
header to cpp file.

Use qToUnderlying instead of casting and assert types where possible.

Amends 773f9ab0189bbb439c3066695c947b11a20c484f.

Found in API-Review.

Change-Id: Ia52886e6e33a3b94b327d17d1453e18febe6dd50
Found-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Task-number: QTBUG-119952
Pick-to: 6.7 6.6 6.5
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
Axel Spoerl 2024-01-09 13:27:41 +01:00 committed by Marc Mutz
parent 2502e5a2cb
commit 4cd2baae9a
2 changed files with 14 additions and 7 deletions

View File

@ -56,6 +56,20 @@ HMENU qt_getWindowsSystemMenu(const QWidget *w)
} }
#endif #endif
static_assert(qToUnderlying(QMessageBox::ButtonRole::NRoles) ==
qToUnderlying(QDialogButtonBox::ButtonRole::NRoles),
"QMessageBox::ButtonRole and QDialogButtonBox::ButtonRole out of sync!");
static_assert(std::is_same_v<std::underlying_type_t<QMessageBox::ButtonRole>,
std::underlying_type_t<QDialogButtonBox::ButtonRole>>);
// StandardButton enums have different underlying types
// => qToUnderlying and std::is_same_v won't work
// ### Qt 7: make them have the same underlying type
static_assert(static_cast<int>(QMessageBox::StandardButton::LastButton) ==
static_cast<int>(QDialogButtonBox::StandardButton::LastButton),
"QMessageBox::StandardButton and QDialogButtonBox::StandardButton out of sync!");
enum Button { Old_Ok = 1, Old_Cancel = 2, Old_Yes = 3, Old_No = 4, Old_Abort = 5, Old_Retry = 6, enum Button { Old_Ok = 1, Old_Cancel = 2, Old_Yes = 3, Old_No = 4, Old_Abort = 5, Old_Retry = 6,
Old_Ignore = 7, Old_YesAll = 8, Old_NoAll = 9, Old_ButtonMask = 0xFF, Old_Ignore = 7, Old_YesAll = 8, Old_NoAll = 9, Old_ButtonMask = 0xFF,
NewButtonMask = 0xFFFFFC00 }; NewButtonMask = 0xFFFFFC00 };

View File

@ -66,9 +66,6 @@ public:
NRoles NRoles
}; };
Q_ENUM(ButtonRole) 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 { enum StandardButton {
// keep this in sync with QDialogButtonBox::StandardButton and QPlatformDialogHelper::StandardButton // keep this in sync with QDialogButtonBox::StandardButton and QPlatformDialogHelper::StandardButton
@ -104,10 +101,6 @@ public:
ButtonMask = ~FlagMask // obsolete ButtonMask = ~FlagMask // obsolete
}; };
Q_ENUM(StandardButton); 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) #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
typedef StandardButton Button; typedef StandardButton Button;