QtCore: Use QDebugStateSaver in (almost) all QDebug operator<<
Unify the behavior of the different operator<< by always using QDebugStateSaver (appending an optional space at exit), and making sure that the space(), nospace() setting isn't 'leaked'. Change-Id: I38e4f82fa6f7419d8b5edfc4dc37495af497e8ac Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
This commit is contained in:
parent
6389160f04
commit
868201155f
@ -3904,8 +3904,9 @@ QDataStream &operator>>(QDataStream &in, QUrl &url)
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
QDebug operator<<(QDebug d, const QUrl &url)
|
||||
{
|
||||
d.maybeSpace() << "QUrl(" << url.toDisplayString() << ')';
|
||||
return d.space();
|
||||
QDebugStateSaver saver(d);
|
||||
d.nospace() << "QUrl(" << url.toDisplayString() << ')';
|
||||
return d;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||
** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the QtCore module of the Qt Toolkit.
|
||||
@ -449,9 +449,10 @@ bool QPersistentModelIndex::isValid() const
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
QDebug operator<<(QDebug dbg, const QModelIndex &idx)
|
||||
{
|
||||
QDebugStateSaver saver(dbg);
|
||||
dbg.nospace() << "QModelIndex(" << idx.row() << ',' << idx.column()
|
||||
<< ',' << idx.internalPointer() << ',' << idx.model() << ')';
|
||||
return dbg.space();
|
||||
return dbg;
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug dbg, const QPersistentModelIndex &idx)
|
||||
|
@ -1849,9 +1849,10 @@ void QItemSelectionModel::emitSelectionChanged(const QItemSelection &newSelectio
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
QDebug operator<<(QDebug dbg, const QItemSelectionRange &range)
|
||||
{
|
||||
QDebugStateSaver saver(dbg);
|
||||
dbg.nospace() << "QItemSelectionRange(" << range.topLeft()
|
||||
<< ',' << range.bottomRight() << ')';
|
||||
return dbg.space();
|
||||
return dbg;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1154,6 +1154,7 @@ void QJsonArray::compact()
|
||||
#if !defined(QT_NO_DEBUG_STREAM) && !defined(QT_JSON_READONLY)
|
||||
QDebug operator<<(QDebug dbg, const QJsonArray &a)
|
||||
{
|
||||
QDebugStateSaver saver(dbg);
|
||||
if (!a.a) {
|
||||
dbg << "QJsonArray()";
|
||||
return dbg;
|
||||
@ -1163,7 +1164,7 @@ QDebug operator<<(QDebug dbg, const QJsonArray &a)
|
||||
dbg.nospace() << "QJsonArray("
|
||||
<< json.constData() // print as utf-8 string without extra quotation marks
|
||||
<< ")";
|
||||
return dbg.space();
|
||||
return dbg;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -561,6 +561,7 @@ bool QJsonDocument::isNull() const
|
||||
#if !defined(QT_NO_DEBUG_STREAM) && !defined(QT_JSON_READONLY)
|
||||
QDebug operator<<(QDebug dbg, const QJsonDocument &o)
|
||||
{
|
||||
QDebugStateSaver saver(dbg);
|
||||
if (!o.d) {
|
||||
dbg << "QJsonDocument()";
|
||||
return dbg;
|
||||
@ -573,7 +574,7 @@ QDebug operator<<(QDebug dbg, const QJsonDocument &o)
|
||||
dbg.nospace() << "QJsonDocument("
|
||||
<< json.constData() // print as utf-8 string without extra quotation marks
|
||||
<< ")";
|
||||
return dbg.space();
|
||||
return dbg;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1111,6 +1111,7 @@ void QJsonObject::setValueAt(int i, const QJsonValue &val)
|
||||
#if !defined(QT_NO_DEBUG_STREAM) && !defined(QT_JSON_READONLY)
|
||||
QDebug operator<<(QDebug dbg, const QJsonObject &o)
|
||||
{
|
||||
QDebugStateSaver saver(dbg);
|
||||
if (!o.o) {
|
||||
dbg << "QJsonObject()";
|
||||
return dbg;
|
||||
@ -1120,7 +1121,7 @@ QDebug operator<<(QDebug dbg, const QJsonObject &o)
|
||||
dbg.nospace() << "QJsonObject("
|
||||
<< json.constData() // print as utf-8 string without extra quotation marks
|
||||
<< ")";
|
||||
return dbg.space();
|
||||
return dbg;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||
** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the QtCore module of the Qt Toolkit.
|
||||
@ -709,12 +709,13 @@ QJsonValue QJsonValueRef::toValue() const
|
||||
#if !defined(QT_NO_DEBUG_STREAM) && !defined(QT_JSON_READONLY)
|
||||
QDebug operator<<(QDebug dbg, const QJsonValue &o)
|
||||
{
|
||||
QDebugStateSaver saver(dbg);
|
||||
switch (o.t) {
|
||||
case QJsonValue::Undefined:
|
||||
dbg.nospace() << "QJsonValue(undefined)";
|
||||
dbg << "QJsonValue(undefined)";
|
||||
break;
|
||||
case QJsonValue::Null:
|
||||
dbg.nospace() << "QJsonValue(null)";
|
||||
dbg << "QJsonValue(null)";
|
||||
break;
|
||||
case QJsonValue::Bool:
|
||||
dbg.nospace() << "QJsonValue(bool, " << o.toBool() << ")";
|
||||
@ -727,16 +728,16 @@ QDebug operator<<(QDebug dbg, const QJsonValue &o)
|
||||
break;
|
||||
case QJsonValue::Array:
|
||||
dbg.nospace() << "QJsonValue(array, ";
|
||||
dbg.nospace() << o.toArray();
|
||||
dbg.nospace() << ")";
|
||||
dbg << o.toArray();
|
||||
dbg << ")";
|
||||
break;
|
||||
case QJsonValue::Object:
|
||||
dbg.nospace() << "QJsonValue(object, ";
|
||||
dbg.nospace() << o.toObject();
|
||||
dbg.nospace() << ")";
|
||||
dbg << o.toObject();
|
||||
dbg << ")";
|
||||
break;
|
||||
}
|
||||
return dbg.space();
|
||||
return dbg;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1041,8 +1041,9 @@ QString decodeMSG(const MSG& msg)
|
||||
|
||||
QDebug operator<<(QDebug dbg, const MSG &msg)
|
||||
{
|
||||
QDebugStateSaver saver(dbg);
|
||||
dbg << decodeMSG(msg);
|
||||
return dbg.nospace();
|
||||
return dbg;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -260,7 +260,8 @@ QVariant QPpsAttribute::toVariant() const
|
||||
|
||||
QDebug operator<<(QDebug dbg, const QPpsAttribute &attribute)
|
||||
{
|
||||
dbg << "QPpsAttribute(";
|
||||
QDebugStateSaver saver(dbg);
|
||||
dbg.nospace() << "QPpsAttribute(";
|
||||
|
||||
switch (attribute.type()) {
|
||||
case QPpsAttribute::Number:
|
||||
|
@ -207,11 +207,13 @@ static timespec roundToMillisecond(timespec val)
|
||||
#ifdef QTIMERINFO_DEBUG
|
||||
QDebug operator<<(QDebug s, timeval tv)
|
||||
{
|
||||
QDebugStateSaver saver(s);
|
||||
s.nospace() << tv.tv_sec << "." << qSetFieldWidth(6) << qSetPadChar(QChar(48)) << tv.tv_usec << reset;
|
||||
return s.space();
|
||||
return s;
|
||||
}
|
||||
QDebug operator<<(QDebug s, Qt::TimerType t)
|
||||
{
|
||||
QDebugStateSaver saver(s);
|
||||
s << (t == Qt::PreciseTimer ? "P" :
|
||||
t == Qt::CoarseTimer ? "C" : "VC");
|
||||
return s;
|
||||
|
@ -3424,10 +3424,11 @@ bool QVariant::isNull() const
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
QDebug operator<<(QDebug dbg, const QVariant &v)
|
||||
{
|
||||
QDebugStateSaver saver(dbg);
|
||||
const uint typeId = v.d.type;
|
||||
dbg.nospace() << "QVariant(";
|
||||
if (typeId != QMetaType::UnknownType) {
|
||||
dbg.nospace() << QMetaType::typeName(typeId) << ", ";
|
||||
dbg << QMetaType::typeName(typeId) << ", ";
|
||||
bool userStream = false;
|
||||
bool canConvertToString = false;
|
||||
if (typeId >= QMetaType::User) {
|
||||
@ -3439,19 +3440,20 @@ QDebug operator<<(QDebug dbg, const QVariant &v)
|
||||
else if (!userStream)
|
||||
handlerManager[typeId]->debugStream(dbg, v);
|
||||
} else {
|
||||
dbg.nospace() << "Invalid";
|
||||
dbg << "Invalid";
|
||||
}
|
||||
dbg.nospace() << ')';
|
||||
return dbg.space();
|
||||
dbg << ')';
|
||||
return dbg;
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug dbg, const QVariant::Type p)
|
||||
{
|
||||
QDebugStateSaver saver(dbg);
|
||||
dbg.nospace() << "QVariant::"
|
||||
<< (int(p) != int(QMetaType::UnknownType)
|
||||
? QMetaType::typeName(p)
|
||||
: "Invalid");
|
||||
return dbg.space();
|
||||
return dbg;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -993,8 +993,9 @@ QUuid QUuid::createUuid()
|
||||
*/
|
||||
QDebug operator<<(QDebug dbg, const QUuid &id)
|
||||
{
|
||||
QDebugStateSaver saver(dbg);
|
||||
dbg.nospace() << "QUuid(" << id.toString() << ')';
|
||||
return dbg.space();
|
||||
return dbg;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -772,18 +772,19 @@ QDataStream &operator>>(QDataStream &in, QBitArray &ba)
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
QDebug operator<<(QDebug dbg, const QBitArray &array)
|
||||
{
|
||||
QDebugStateSaver saver(dbg);
|
||||
dbg.nospace() << "QBitArray(";
|
||||
for (int i = 0; i < array.size();) {
|
||||
if (array.testBit(i))
|
||||
dbg.nospace() << '1';
|
||||
dbg << '1';
|
||||
else
|
||||
dbg.nospace() << '0';
|
||||
dbg << '0';
|
||||
i += 1;
|
||||
if (!(i % 4) && (i < array.size()))
|
||||
dbg.nospace() << ' ';
|
||||
dbg << ' ';
|
||||
}
|
||||
dbg.nospace() << ')';
|
||||
return dbg.space();
|
||||
dbg << ')';
|
||||
return dbg;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -5006,18 +5006,21 @@ QDataStream &operator>>(QDataStream &in, QDateTime &dateTime)
|
||||
#if !defined(QT_NO_DEBUG_STREAM) && !defined(QT_NO_DATESTRING)
|
||||
QDebug operator<<(QDebug dbg, const QDate &date)
|
||||
{
|
||||
QDebugStateSaver saver(dbg);
|
||||
dbg.nospace() << "QDate(" << date.toString(Qt::ISODate) << ')';
|
||||
return dbg.space();
|
||||
return dbg;
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug dbg, const QTime &time)
|
||||
{
|
||||
QDebugStateSaver saver(dbg);
|
||||
dbg.nospace() << "QTime(" << time.toString(QStringLiteral("HH:mm:ss.zzz")) << ')';
|
||||
return dbg.space();
|
||||
return dbg;
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug dbg, const QDateTime &date)
|
||||
{
|
||||
QDebugStateSaver saver(dbg);
|
||||
QString spec;
|
||||
switch (date.d->m_spec) {
|
||||
case Qt::UTC:
|
||||
@ -5037,7 +5040,7 @@ QDebug operator<<(QDebug dbg, const QDateTime &date)
|
||||
}
|
||||
QString output = date.toString(QStringLiteral("yyyy-MM-dd HH:mm:ss.zzz t")) + spec;
|
||||
dbg.nospace() << "QDateTime(" << output << ')';
|
||||
return dbg.space();
|
||||
return dbg;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1417,6 +1417,7 @@ qreal QEasingCurve::valueForProgress(qreal progress) const
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
QDebug operator<<(QDebug debug, const QEasingCurve &item)
|
||||
{
|
||||
QDebugStateSaver saver(debug);
|
||||
debug << "type:" << item.d_ptr->type
|
||||
<< "func:" << item.d_ptr->func;
|
||||
if (item.d_ptr->config) {
|
||||
|
@ -3583,10 +3583,12 @@ QString QLocale::nativeCountryName() const
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
QDebug operator<<(QDebug dbg, const QLocale &l)
|
||||
{
|
||||
dbg.nospace() << "QLocale(" << qPrintable(QLocale::languageToString(l.language()))
|
||||
<< ", " << qPrintable(QLocale::scriptToString(l.script()))
|
||||
<< ", " << qPrintable(QLocale::countryToString(l.country())) << ')';
|
||||
return dbg.space();
|
||||
QDebugStateSaver saver(dbg);
|
||||
dbg.nospace().noquote()
|
||||
<< "QLocale(" << QLocale::languageToString(l.language())
|
||||
<< ", " << QLocale::scriptToString(l.script())
|
||||
<< ", " << QLocale::countryToString(l.country()) << ')';
|
||||
return dbg;
|
||||
}
|
||||
#endif
|
||||
QT_END_NAMESPACE
|
||||
|
@ -432,9 +432,10 @@ QDataStream &operator>>(QDataStream &s, QMargins &m)
|
||||
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
QDebug operator<<(QDebug dbg, const QMargins &m) {
|
||||
QDebugStateSaver saver(dbg);
|
||||
dbg.nospace() << "QMargins(" << m.left() << ", "
|
||||
<< m.top() << ", " << m.right() << ", " << m.bottom() << ')';
|
||||
return dbg.space();
|
||||
return dbg;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -764,9 +765,10 @@ QDataStream &operator>>(QDataStream &s, QMarginsF &m)
|
||||
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
QDebug operator<<(QDebug dbg, const QMarginsF &m) {
|
||||
QDebugStateSaver saver(dbg);
|
||||
dbg.nospace() << "QMarginsF(" << m.left() << ", "
|
||||
<< m.top() << ", " << m.right() << ", " << m.bottom() << ')';
|
||||
return dbg.space();
|
||||
return dbg;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -4577,9 +4577,10 @@ QDataStream &operator>>(QDataStream &in, QRegExp ®Exp)
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
QDebug operator<<(QDebug dbg, const QRegExp &r)
|
||||
{
|
||||
QDebugStateSaver saver(dbg);
|
||||
dbg.nospace() << "QRegExp(patternSyntax=" << r.patternSyntax()
|
||||
<< ", pattern='"<< r.pattern() << "')";
|
||||
return dbg.space();
|
||||
return dbg;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -2444,8 +2444,9 @@ QDataStream &operator>>(QDataStream &in, QRegularExpression &re)
|
||||
*/
|
||||
QDebug operator<<(QDebug debug, const QRegularExpression &re)
|
||||
{
|
||||
QDebugStateSaver saver(debug);
|
||||
debug.nospace() << "QRegularExpression(" << re.pattern() << ", " << re.patternOptions() << ")";
|
||||
return debug.space();
|
||||
return debug;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -2458,6 +2459,7 @@ QDebug operator<<(QDebug debug, const QRegularExpression &re)
|
||||
*/
|
||||
QDebug operator<<(QDebug debug, QRegularExpression::PatternOptions patternOptions)
|
||||
{
|
||||
QDebugStateSaver saver(debug);
|
||||
QByteArray flags;
|
||||
|
||||
if (patternOptions == QRegularExpression::NoPatternOption) {
|
||||
@ -2487,7 +2489,7 @@ QDebug operator<<(QDebug debug, QRegularExpression::PatternOptions patternOption
|
||||
|
||||
debug.nospace() << "QRegularExpression::PatternOptions(" << flags << ")";
|
||||
|
||||
return debug.space();
|
||||
return debug;
|
||||
}
|
||||
/*!
|
||||
\relates QRegularExpressionMatch
|
||||
@ -2499,11 +2501,12 @@ QDebug operator<<(QDebug debug, QRegularExpression::PatternOptions patternOption
|
||||
*/
|
||||
QDebug operator<<(QDebug debug, const QRegularExpressionMatch &match)
|
||||
{
|
||||
QDebugStateSaver saver(debug);
|
||||
debug.nospace() << "QRegularExpressionMatch(";
|
||||
|
||||
if (!match.isValid()) {
|
||||
debug << "Invalid)";
|
||||
return debug.space();
|
||||
return debug;
|
||||
}
|
||||
|
||||
debug << "Valid";
|
||||
@ -2528,7 +2531,7 @@ QDebug operator<<(QDebug debug, const QRegularExpressionMatch &match)
|
||||
|
||||
debug << ")";
|
||||
|
||||
return debug.space();
|
||||
return debug;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -980,9 +980,10 @@ QDataStream &operator>>(QDataStream &ds, QTimeZone &tz)
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
QDebug operator<<(QDebug dbg, const QTimeZone &tz)
|
||||
{
|
||||
QDebugStateSaver saver(dbg);
|
||||
//TODO Include backend and data version details?
|
||||
dbg.nospace() << "QTimeZone(" << QString::fromUtf8(tz.id()) << ')';
|
||||
return dbg.space();
|
||||
return dbg;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -458,8 +458,9 @@ QDataStream& operator>>(QDataStream &in, QVersionNumber &version)
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
QDebug operator<<(QDebug debug, const QVersionNumber &version)
|
||||
{
|
||||
QDebugStateSaver saver(debug);
|
||||
debug.noquote() << version.toString();
|
||||
return debug.quote();
|
||||
return debug;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -2204,13 +2204,13 @@ void tst_QtJson::testDebugStream()
|
||||
array.append(1);
|
||||
array.append(QLatin1String("foo"));
|
||||
value = QJsonValue(array); // array
|
||||
QTest::ignoreMessage(QtDebugMsg, "QJsonValue(array, QJsonArray([1,\"foo\"]) )");
|
||||
QTest::ignoreMessage(QtDebugMsg, "QJsonValue(array, QJsonArray([1,\"foo\"]))");
|
||||
qDebug() << value;
|
||||
|
||||
QJsonObject object;
|
||||
object.insert(QLatin1String("foo"), QLatin1String("bar"));
|
||||
value = QJsonValue(object); // object
|
||||
QTest::ignoreMessage(QtDebugMsg, "QJsonValue(object, QJsonObject({\"foo\":\"bar\"}) )");
|
||||
QTest::ignoreMessage(QtDebugMsg, "QJsonValue(object, QJsonObject({\"foo\":\"bar\"}))");
|
||||
qDebug() << value;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user