From e06bc69870d1ef79466557dd716ec1edb0e48fee Mon Sep 17 00:00:00 2001 From: Harald Fernengel Date: Fri, 21 May 2010 16:14:38 +0200 Subject: QDebug operator for QFlags Output the flags one by one instead of just an integer Reviewed-by: Robert Griebl --- src/corelib/io/qdebug.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h index bc68599..093312f 100644 --- a/src/corelib/io/qdebug.h +++ b/src/corelib/io/qdebug.h @@ -254,6 +254,29 @@ inline QDebug operator<<(QDebug debug, const QContiguousCache &cache) return debug.space(); } +#if defined(FORCE_UREF) +template +inline QDebug &operator<<(QDebug debug, const QFlags &flags) +#else +template +inline QDebug operator<<(QDebug debug, const QFlags &flags) +#endif +{ + debug.nospace() << "QFlags("; + bool needSeparator = false; + for (uint i = 0; i < sizeof(T) * 8; ++i) { + if (flags.testFlag(T(1 << i))) { + if (needSeparator) + debug.nospace() << '|'; + else + needSeparator = true; + debug.nospace() << "0x" << QByteArray::number(T(1 << i), 16).constData(); + } + } + debug << ')'; + return debug.space(); +} + #if !defined(QT_NO_DEBUG_STREAM) Q_CORE_EXPORT_INLINE QDebug qDebug() { return QDebug(QtDebugMsg); } -- cgit v0.12