summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAxel Spoerl <[email protected]>2024-01-09 13:27:41 +0100
committerQt Cherry-pick Bot <[email protected]>2024-02-11 11:18:45 +0000
commit54c3530a758284a0d38f548bf334ff00db274f09 (patch)
tree1b616b2f2c9ac603b57afee559b9bb92cc96cb34
parent4e18431165c962245b2cc92e98011b7179c99794 (diff)
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 <[email protected]> Task-number: QTBUG-119952 Reviewed-by: Marc Mutz <[email protected]> (cherry picked from commit 4cd2baae9abc07200c70cb007ce12b800a786927) Reviewed-by: Qt Cherry-pick Bot <[email protected]> (cherry picked from commit 9ed3cc0b510f0bd1c3dd7dc3c78a893e0a3c90a4) (cherry picked from commit 714bc6c4032c99c7e091e6047ab1ace0c0b1cdd6)
-rw-r--r--src/widgets/dialogs/qmessagebox.cpp14
-rw-r--r--src/widgets/dialogs/qmessagebox.h7
2 files changed, 14 insertions, 7 deletions
diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp
index 46a6e871b14..08cf212af4c 100644
--- a/src/widgets/dialogs/qmessagebox.cpp
+++ b/src/widgets/dialogs/qmessagebox.cpp
@@ -49,6 +49,20 @@ HMENU qt_getWindowsSystemMenu(const QWidget *w)
}
#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,
Old_Ignore = 7, Old_YesAll = 8, Old_NoAll = 9, Old_ButtonMask = 0xFF,
NewButtonMask = 0xFFFFFC00 };
diff --git a/src/widgets/dialogs/qmessagebox.h b/src/widgets/dialogs/qmessagebox.h
index 419fd23af8a..c2e31abc64e 100644
--- a/src/widgets/dialogs/qmessagebox.h
+++ b/src/widgets/dialogs/qmessagebox.h
@@ -60,9 +60,6 @@ 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,10 +95,6 @@ public:
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;