Add debug output for single enum flags

They have a separate type that we can't recognize directly, but we
can check if we can recognize the QFlags<T> form, though we have to
add a lot of template-conditions to avoid triggering QFlags static
asserts.

Change-Id: I00853682c5376dd3cc411ff151f47bce2389e277
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
Allan Sandfeld Jensen 2018-07-26 17:14:07 +02:00
parent 9c9f98f2ff
commit 10a88b8149
2 changed files with 18 additions and 0 deletions

View File

@ -376,6 +376,19 @@ operator<<(QDebug dbg, T value)
return qt_QMetaEnum_debugOperator(dbg, typename QFlags<T>::Int(value), obj, name);
}
template<typename T,
typename A = typename std::enable_if<std::is_enum<T>::value, void>::type,
typename B = typename std::enable_if<sizeof(T) <= sizeof(int), void>::type,
typename C = typename std::enable_if<!QtPrivate::IsQEnumHelper<T>::Value, void>::type,
typename D = typename std::enable_if<QtPrivate::IsQEnumHelper<QFlags<T>>::Value, void>::type>
inline QDebug operator<<(QDebug dbg, T value)
{
typedef QFlags<T> FlagsT;
const QMetaObject *obj = qt_getEnumMetaObject(FlagsT());
const char *name = qt_getEnumName(FlagsT());
return qt_QMetaEnum_debugOperator(dbg, typename FlagsT::Int(value), obj, name);
}
template <class T>
inline typename std::enable_if<
QtPrivate::IsQEnumHelper<T>::Value || QtPrivate::IsQEnumHelper<QFlags<T> >::Value,

View File

@ -1767,6 +1767,11 @@ void tst_QMetaObject::enumDebugStream()
QTest::ignoreMessage(QtDebugMsg, "QFlags<MyNamespace::MyClass::MyScopedFlag>(MyFlag2|MyFlag3)");
f3 |= MyNamespace::MyClass::MyScopedFlag::MyFlag3;
qDebug() << f3;
// Single flag recognized as enum:
QTest::ignoreMessage(QtDebugMsg, "MyNamespace::MyClass::MyFlag1");
MyNamespace::MyClass::MyFlag f4 = MyNamespace::MyClass::MyFlag1;
qDebug() << f4;
}
void tst_QMetaObject::inherits_data()