summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/io/qdebug.cpp17
-rw-r--r--src/corelib/io/qdebug.h4
-rw-r--r--tests/auto/corelib/io/qdebug/tst_qdebug.cpp19
3 files changed, 37 insertions, 3 deletions
diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp
index 038e9cb0a3..ef9c654266 100644
--- a/src/corelib/io/qdebug.cpp
+++ b/src/corelib/io/qdebug.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 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.
@@ -152,6 +152,21 @@ QDebug::~QDebug()
*/
/*!
+ Resets the stream formatting options, bringing it back to its original constructed state.
+
+ \sa space(), quote()
+ \since 5.4
+*/
+QDebug &QDebug::resetFormat()
+{
+ stream->ts.reset();
+ stream->space = true;
+ if (stream->context.version > 1)
+ stream->flags = 0;
+ return *this;
+}
+
+/*!
\fn QDebug &QDebug::space()
Writes a space character to the debug stream and returns a reference to
diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h
index 0bbb617c1f..d224359724 100644
--- a/src/corelib/io/qdebug.h
+++ b/src/corelib/io/qdebug.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 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.
@@ -93,6 +93,8 @@ public:
~QDebug();
inline void swap(QDebug &other) { qSwap(stream, other.stream); }
+ QDebug &resetFormat();
+
inline QDebug &space() { stream->space = true; stream->ts << ' '; return *this; }
inline QDebug &nospace() { stream->space = false; return *this; }
inline QDebug &maybeSpace() { if (stream->space) stream->ts << ' '; return *this; }
diff --git a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp
index 9b761bc63d..2143a8874c 100644
--- a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp
+++ b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the test suite of the Qt Toolkit.
@@ -64,6 +64,7 @@ private slots:
void qDebugQLatin1String() const;
void qDebugQByteArray() const;
void textStreamModifiers() const;
+ void resetFormat() const;
void defaultMessagehandler() const;
void threadSafety() const;
};
@@ -383,6 +384,22 @@ void tst_QDebug::textStreamModifiers() const
QCOMPARE(QString::fromLatin1(s_function), function);
}
+void tst_QDebug::resetFormat() const
+{
+ MessageHandlerSetter mhs(myMessageHandler);
+ {
+ QDebug d = qDebug();
+ d.nospace().noquote() << hex << int(0xf);
+ d.resetFormat() << int(0xf) << QStringLiteral("foo");
+ }
+ QString file = __FILE__; int line = __LINE__ - 4; QString function = Q_FUNC_INFO;
+ QCOMPARE(s_msgType, QtDebugMsg);
+ QCOMPARE(s_msg, QString::fromLatin1("f15 \"foo\""));
+ QCOMPARE(QString::fromLatin1(s_file), file);
+ QCOMPARE(s_line, line);
+ QCOMPARE(QString::fromLatin1(s_function), function);
+}
+
void tst_QDebug::defaultMessagehandler() const
{
MessageHandlerSetter mhs(0); // set 0, should set default handler