summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2018-12-19 20:13:02 +0100
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2019-01-23 16:12:52 +0000
commit237c3972fd8869698cea69ff57f751c982bec487 (patch)
tree758df079a672e1d85765f3a2fe13515d7795b753 /src
parent25fc90e48b279d61dfcedb3ecfe7818e29eca341 (diff)
Allow more fine grained control over QFlags debug output
Useful in contexts such as other QDebug operators, where the class is already known, and the full scope of the flags is not needed. Change-Id: I546381b1722c9c846e2412e56763563b8f625212 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/io/qdebug.cpp58
1 files changed, 54 insertions, 4 deletions
diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp
index cc77db28de..15c5e0ce96 100644
--- a/src/corelib/io/qdebug.cpp
+++ b/src/corelib/io/qdebug.cpp
@@ -976,17 +976,67 @@ QDebug qt_QMetaEnum_debugOperator(QDebug &dbg, int value, const QMetaObject *met
return dbg;
}
+/*!
+ \fn QDebug qt_QMetaEnum_flagDebugOperator(QDebug &, quint64 value, const QMetaObject *, const char *name)
+ \internal
+
+ Formats the given flag \a value for debug output.
+
+ The supported verbosity are:
+
+ 0: Just the key(s):
+
+ MyFlag1
+ MyFlag2|MyFlag3
+ MyScopedFlag(MyFlag2)
+ MyScopedFlag(MyFlag2|MyFlag3)
+
+ 1: Same as 0, but treating all flags as scoped:
+
+ MyFlag(MyFlag1)
+ MyFlag(MyFlag2|MyFlag3)
+ MyScopedFlag(MyFlag2)
+ MyScopedFlag(MyFlag2|MyFlag3)
+
+ 2: The QDebug default. Same as 1, and includes class/namespace scope:
+
+ QFlags<MyNamespace::MyClass::MyFlag>(MyFlag1)
+ QFlags<MyNamespace::MyClass::MyFlag>(MyFlag2|MyFlag3)
+ QFlags<MyNamespace::MyClass::MyScopedFlag>(MyFlag2)
+ QFlags<MyNamespace::MyClass::MyScopedFlag>(MyFlag2|MyFlag3)
+ */
QDebug qt_QMetaEnum_flagDebugOperator(QDebug &debug, quint64 value, const QMetaObject *meta, const char *name)
{
+ const int verbosity = debug.verbosity();
+
QDebugStateSaver saver(debug);
debug.resetFormat();
debug.noquote();
debug.nospace();
- debug << "QFlags<";
+
const QMetaEnum me = meta->enumerator(meta->indexOfEnumerator(name));
- if (const char *scope = me.scope())
- debug << scope << "::";
- debug << me.enumName() << ">(" << me.valueToKeys(value) << ')';
+
+ const bool classScope = verbosity >= QDebug::DefaultVerbosity;
+ if (classScope) {
+ debug << "QFlags<";
+
+ if (const char *scope = me.scope())
+ debug << scope << "::";
+ }
+
+ const bool enumScope = me.isScoped() || verbosity > QDebug::MinimumVerbosity;
+ if (enumScope) {
+ debug << me.enumName();
+ if (classScope)
+ debug << ">";
+ debug << "(";
+ }
+
+ debug << me.valueToKeys(value);
+
+ if (enumScope)
+ debug << ')';
+
return debug;
}
#endif // !QT_NO_QOBJECT