QMetaType: extract the signedness of a QFlags enum type

The documentation was correct, but it looks like it was because we just
failed to extract the information into the QMetaTypeInterface.

Drive-by firm-up the documentation.

Change-Id: I8a96935cf6c742259c9dfffd17e95974d153aea1
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
This commit is contained in:
Thiago Macieira 2024-08-06 21:58:10 -07:00
parent bac583d090
commit b957400b64
2 changed files with 11 additions and 4 deletions

View File

@ -2979,8 +2979,13 @@ bool QMetaType::hasRegisteredDataStreamOperators() const
If this metatype represents an enumeration, this method returns a
metatype of a numeric class of the same signedness and size as the
enums underlying type.
If it represents a QFlags type, it returns QMetaType::Int.
If it represents a QFlags type, it returns a metatype of a numeric class
with the same signedness and size as that \l QFlags::Int type.
In all other cases an invalid QMetaType is returned.
Do note the metatype is synthesized from size and signedness and may thus
not match the actual underlying type of the enum itself. That is, it will
never return the metatype for \c{char}, \c{long}, \c{unsigned long}.
*/
QMetaType QMetaType::underlyingType() const
{

View File

@ -1267,10 +1267,12 @@ namespace QtPrivate {
template<typename T>
inline constexpr bool IsQmlListType = false;
template<typename T, bool = std::is_enum<T>::value>
template<typename T, bool = std::is_enum<T>::value, bool = QtPrivate::IsQFlags<T>::value>
constexpr bool IsUnsignedEnum = false;
template<typename T>
constexpr bool IsUnsignedEnum<T, true> = !std::is_signed_v<std::underlying_type_t<T>>;
template<typename T> constexpr bool IsUnsignedEnum<T, true, false> =
!std::is_signed_v<std::underlying_type_t<T>>;
template<typename T> constexpr bool IsUnsignedEnum<T, false, true> =
!std::is_signed_v<std::underlying_type_t<typename T::enum_type>>;
template<typename T>
struct QMetaTypeTypeFlags