Retain space setting

Change-Id: I4584de9ba51610907c917a0e0ddf5f6f28d304a0
Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
Kurt Pattyn 2013-12-22 12:33:33 +01:00 committed by The Qt Project
parent 954bb6c35f
commit a2131d6c2f

View File

@ -174,6 +174,7 @@ template <class T>
inline QDebug operator<<(QDebug debug, const QList<T> &list) inline QDebug operator<<(QDebug debug, const QList<T> &list)
#endif #endif
{ {
const bool oldSetting = debug.autoInsertSpaces();
debug.nospace() << '('; debug.nospace() << '(';
for (typename QList<T>::size_type i = 0; i < list.count(); ++i) { for (typename QList<T>::size_type i = 0; i < list.count(); ++i) {
if (i) if (i)
@ -181,7 +182,8 @@ inline QDebug operator<<(QDebug debug, const QList<T> &list)
debug << list.at(i); debug << list.at(i);
} }
debug << ')'; debug << ')';
return debug.space(); debug.setAutoInsertSpaces(oldSetting);
return debug.maybeSpace();
} }
#if defined(FORCE_UREF) #if defined(FORCE_UREF)
@ -192,7 +194,9 @@ template <typename T>
inline QDebug operator<<(QDebug debug, const QVector<T> &vec) inline QDebug operator<<(QDebug debug, const QVector<T> &vec)
#endif #endif
{ {
const bool oldSetting = debug.autoInsertSpaces();
debug.nospace() << "QVector"; debug.nospace() << "QVector";
debug.setAutoInsertSpaces(oldSetting);
return operator<<(debug, vec.toList()); return operator<<(debug, vec.toList());
} }
@ -204,13 +208,15 @@ template <class aKey, class aT>
inline QDebug operator<<(QDebug debug, const QMap<aKey, aT> &map) inline QDebug operator<<(QDebug debug, const QMap<aKey, aT> &map)
#endif #endif
{ {
const bool oldSetting = debug.autoInsertSpaces();
debug.nospace() << "QMap("; debug.nospace() << "QMap(";
for (typename QMap<aKey, aT>::const_iterator it = map.constBegin(); for (typename QMap<aKey, aT>::const_iterator it = map.constBegin();
it != map.constEnd(); ++it) { it != map.constEnd(); ++it) {
debug << '(' << it.key() << ", " << it.value() << ')'; debug << '(' << it.key() << ", " << it.value() << ')';
} }
debug << ')'; debug << ')';
return debug.space(); debug.setAutoInsertSpaces(oldSetting);
return debug.maybeSpace();
} }
#if defined(FORCE_UREF) #if defined(FORCE_UREF)
@ -221,12 +227,14 @@ template <class aKey, class aT>
inline QDebug operator<<(QDebug debug, const QHash<aKey, aT> &hash) inline QDebug operator<<(QDebug debug, const QHash<aKey, aT> &hash)
#endif #endif
{ {
const bool oldSetting = debug.autoInsertSpaces();
debug.nospace() << "QHash("; debug.nospace() << "QHash(";
for (typename QHash<aKey, aT>::const_iterator it = hash.constBegin(); for (typename QHash<aKey, aT>::const_iterator it = hash.constBegin();
it != hash.constEnd(); ++it) it != hash.constEnd(); ++it)
debug << '(' << it.key() << ", " << it.value() << ')'; debug << '(' << it.key() << ", " << it.value() << ')';
debug << ')'; debug << ')';
return debug.space(); debug.setAutoInsertSpaces(oldSetting);
return debug.maybeSpace();
} }
#if defined(FORCE_UREF) #if defined(FORCE_UREF)
@ -237,14 +245,18 @@ template <class T1, class T2>
inline QDebug operator<<(QDebug debug, const QPair<T1, T2> &pair) inline QDebug operator<<(QDebug debug, const QPair<T1, T2> &pair)
#endif #endif
{ {
const bool oldSetting = debug.autoInsertSpaces();
debug.nospace() << "QPair(" << pair.first << ',' << pair.second << ')'; debug.nospace() << "QPair(" << pair.first << ',' << pair.second << ')';
return debug.space(); debug.setAutoInsertSpaces(oldSetting);
return debug.maybeSpace();
} }
template <typename T> template <typename T>
inline QDebug operator<<(QDebug debug, const QSet<T> &set) inline QDebug operator<<(QDebug debug, const QSet<T> &set)
{ {
const bool oldSetting = debug.autoInsertSpaces();
debug.nospace() << "QSet"; debug.nospace() << "QSet";
debug.setAutoInsertSpaces(oldSetting);
return operator<<(debug, set.toList()); return operator<<(debug, set.toList());
} }
@ -256,6 +268,7 @@ template <class T>
inline QDebug operator<<(QDebug debug, const QContiguousCache<T> &cache) inline QDebug operator<<(QDebug debug, const QContiguousCache<T> &cache)
#endif #endif
{ {
const bool oldSetting = debug.autoInsertSpaces();
debug.nospace() << "QContiguousCache("; debug.nospace() << "QContiguousCache(";
for (int i = cache.firstIndex(); i <= cache.lastIndex(); ++i) { for (int i = cache.firstIndex(); i <= cache.lastIndex(); ++i) {
debug << cache[i]; debug << cache[i];
@ -263,7 +276,8 @@ inline QDebug operator<<(QDebug debug, const QContiguousCache<T> &cache)
debug << ", "; debug << ", ";
} }
debug << ')'; debug << ')';
return debug.space(); debug.setAutoInsertSpaces(oldSetting);
return debug.maybeSpace();
} }
#if defined(FORCE_UREF) #if defined(FORCE_UREF)
@ -274,6 +288,7 @@ template <class T>
inline QDebug operator<<(QDebug debug, const QFlags<T> &flags) inline QDebug operator<<(QDebug debug, const QFlags<T> &flags)
#endif #endif
{ {
const bool oldSetting = debug.autoInsertSpaces();
debug.nospace() << "QFlags("; debug.nospace() << "QFlags(";
bool needSeparator = false; bool needSeparator = false;
for (uint i = 0; i < sizeof(T) * 8; ++i) { for (uint i = 0; i < sizeof(T) * 8; ++i) {
@ -286,7 +301,8 @@ inline QDebug operator<<(QDebug debug, const QFlags<T> &flags)
} }
} }
debug << ')'; debug << ')';
return debug.space(); debug.setAutoInsertSpaces(oldSetting);
return debug.maybeSpace();
} }
QT_END_NAMESPACE QT_END_NAMESPACE