OSDN Git Service

QDebug rewrite to use QByteArray as internal buffer
authorIvailo Monev <xakepa10@gmail.com>
Sun, 13 Nov 2022 13:39:19 +0000 (15:39 +0200)
committerIvailo Monev <xakepa10@gmail.com>
Sun, 13 Nov 2022 13:54:04 +0000 (15:54 +0200)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
19 files changed:
src/core/io/qdatastream.cpp
src/core/io/qdatastream.h
src/core/io/qdebug.cpp
src/core/io/qdebug.h
src/core/tools/qbitarray.h
src/core/tools/qdatetime.h
src/gui/image/qkathandler.cpp
src/gui/kernel/qevent.cpp
src/gui/math3d/qgenericmatrix.h
src/gui/math3d/qmatrix4x4.cpp
src/gui/painting/qpaintengineex.cpp
src/gui/painting/qpainterpath.cpp
src/gui/text/qcssparser.cpp
src/tools/moc/CMakeLists.txt
src/tools/moc/generator.cpp
tests/auto/qfile/tst_qfile.cpp
tests/auto/qfileinfo/tst_qfileinfo.cpp
tests/auto/qnetworkinterface/tst_qnetworkinterface.cpp
tests/auto/qprocess/tst_qprocess.cpp

index 4c97c8d..7d0ef2b 100644 (file)
@@ -212,7 +212,6 @@ QT_BEGIN_NAMESPACE
 
     \sa setDevice()
 */
-
 QDataStream::QDataStream()
     : dev(nullptr),
     owndev(false),
@@ -233,7 +232,6 @@ QDataStream::QDataStream()
 
     \sa setDevice(), device()
 */
-
 QDataStream::QDataStream(QIODevice *device)
     : dev(device),
     owndev(false),
@@ -245,8 +243,6 @@ QDataStream::QDataStream(QIODevice *device)
 
 
 /*!
-    \fn QDataStream::QDataStream(QByteArray *a, QIODevice::OpenMode mode)
-
     Constructs a data stream that operates on a byte array, \a a. The
     \a mode describes how the device is to be used.
 
@@ -256,7 +252,6 @@ QDataStream::QDataStream(QIODevice *device)
     Since QByteArray is not a QIODevice subclass, internally a QBuffer
     is created to wrap the byte array.
 */
-
 QDataStream::QDataStream(QByteArray *a, QIODevice::OpenMode flags)
     : dev(nullptr),
     owndev(true),
@@ -304,14 +299,12 @@ QDataStream::QDataStream(const QByteArray &a)
     passed in the \e constructor, in which case the internal I/O device
     is destroyed.
 */
-
 QDataStream::~QDataStream()
 {
     if (owndev)
         delete dev;
 }
 
-
 /*!
     \fn QIODevice *QDataStream::device() const
 
@@ -329,7 +322,6 @@ QDataStream::~QDataStream()
 
     \sa device()
 */
-
 void QDataStream::setDevice(QIODevice *device)
 {
     if (owndev) {
@@ -340,15 +332,12 @@ void QDataStream::setDevice(QIODevice *device)
 }
 
 /*!
-    \fn bool QDataStream::atEnd() const
-
     Returns true if the I/O device has reached the end position (end of
     the stream or file) or if there is no I/O device set; otherwise
     returns false.
 
     \sa QIODevice::atEnd()
 */
-
 bool QDataStream::atEnd() const
 {
     return dev ? dev->atEnd() : true;
@@ -389,7 +378,6 @@ void QDataStream::setFloatingPointPrecision(QDataStream::FloatingPointPrecision
 
     \sa Status setStatus() resetStatus()
 */
-
 QDataStream::DataStatus QDataStream::status() const
 {
     return q_status;
@@ -439,7 +427,6 @@ void QDataStream::setStatus(DataStatus status)
 
     \sa byteOrder()
 */
-
 void QDataStream::setByteOrder(ByteOrder bo)
 {
     byteorder = bo;
@@ -461,7 +448,6 @@ void QDataStream::setByteOrder(ByteOrder bo)
     Reads a signed byte from the stream into \a i, and returns a
     reference to the stream.
 */
-
 QDataStream &QDataStream::operator>>(qint8 &i)
 {
     i = 0;
@@ -474,7 +460,6 @@ QDataStream &QDataStream::operator>>(qint8 &i)
     return *this;
 }
 
-
 /*!
     \fn QDataStream &QDataStream::operator>>(quint16 &i)
     \overload
@@ -489,7 +474,6 @@ QDataStream &QDataStream::operator>>(qint8 &i)
     Reads a signed 16-bit integer from the stream into \a i, and
     returns a reference to the stream.
 */
-
 QDataStream &QDataStream::operator>>(qint16 &i)
 {
     i = 0;
@@ -503,7 +487,6 @@ QDataStream &QDataStream::operator>>(qint16 &i)
     return *this;
 }
 
-
 /*!
     \fn QDataStream &QDataStream::operator>>(quint32 &i)
     \overload
@@ -518,7 +501,6 @@ QDataStream &QDataStream::operator>>(qint16 &i)
     Reads a signed 32-bit integer from the stream into \a i, and
     returns a reference to the stream.
 */
-
 QDataStream &QDataStream::operator>>(qint32 &i)
 {
     i = 0;
@@ -546,7 +528,6 @@ QDataStream &QDataStream::operator>>(qint32 &i)
     Reads a signed 64-bit integer from the stream into \a i, and
     returns a reference to the stream.
 */
-
 QDataStream &QDataStream::operator>>(qint64 &i)
 {
     i = qint64(0);
@@ -581,7 +562,6 @@ QDataStream &QDataStream::operator>>(bool &i)
 
     \sa setFloatingPointPrecision()
 */
-
 QDataStream &QDataStream::operator>>(float &f)
 {
     if (floatingPointPrecision() == QDataStream::DoublePrecision) {
@@ -616,7 +596,6 @@ QDataStream &QDataStream::operator>>(float &f)
 
     \sa setFloatingPointPrecision()
 */
-
 QDataStream &QDataStream::operator>>(double &f)
 {
     if (floatingPointPrecision() == QDataStream::SinglePrecision) {
@@ -650,7 +629,6 @@ QDataStream &QDataStream::operator>>(double &f)
 
     \sa QIODevice::read(), writeRawData()
 */
-
 int QDataStream::readRawData(char *s, int len)
 {
     CHECK_STREAM_PRECOND(-1)
@@ -685,7 +663,6 @@ QDataStream &QDataStream::operator<<(qint8 i)
     return *this;
 }
 
-
 /*!
     \fn QDataStream &QDataStream::operator<<(quint16 i)
     \overload
@@ -700,7 +677,6 @@ QDataStream &QDataStream::operator<<(qint8 i)
     Writes a signed 16-bit integer, \a i, to the stream and returns a
     reference to the stream.
 */
-
 QDataStream &QDataStream::operator<<(qint16 i)
 {
     CHECK_STREAM_WRITE_PRECOND(*this)
@@ -718,7 +694,6 @@ QDataStream &QDataStream::operator<<(qint16 i)
     Writes a signed 32-bit integer, \a i, to the stream and returns a
     reference to the stream.
 */
-
 QDataStream &QDataStream::operator<<(qint32 i)
 {
     CHECK_STREAM_WRITE_PRECOND(*this)
@@ -744,7 +719,6 @@ QDataStream &QDataStream::operator<<(qint32 i)
     Writes a signed 64-bit integer, \a i, to the stream and returns a
     reference to the stream.
 */
-
 QDataStream &QDataStream::operator<<(qint64 i)
 {
     CHECK_STREAM_WRITE_PRECOND(*this)
@@ -768,7 +742,6 @@ QDataStream &QDataStream::operator<<(qint64 i)
     Writes a boolean value, \a i, to the stream. Returns a reference
     to the stream.
 */
-
 QDataStream &QDataStream::operator<<(bool i)
 {
     CHECK_STREAM_WRITE_PRECOND(*this)
@@ -785,7 +758,6 @@ QDataStream &QDataStream::operator<<(bool i)
 
     \sa setFloatingPointPrecision()
 */
-
 QDataStream &QDataStream::operator<<(float f)
 {
     if (floatingPointPrecision() == QDataStream::DoublePrecision) {
@@ -813,7 +785,6 @@ QDataStream &QDataStream::operator<<(float f)
     return *this;
 }
 
-
 /*!
     \overload
 
@@ -822,7 +793,6 @@ QDataStream &QDataStream::operator<<(float f)
 
     \sa setFloatingPointPrecision()
 */
-
 QDataStream &QDataStream::operator<<(double f)
 {
     if (floatingPointPrecision() == QDataStream::SinglePrecision) {
@@ -854,7 +824,6 @@ QDataStream &QDataStream::operator<<(double f)
 
     \sa QIODevice::write(), readRawData()
 */
-
 int QDataStream::writeRawData(const char *s, int len)
 {
     CHECK_STREAM_WRITE_PRECOND(-1)
index 36a5800..59c3181 100644 (file)
@@ -85,7 +85,6 @@ public:
     QDataStream &operator>>(quint32 &i);
     QDataStream &operator>>(qint64 &i);
     QDataStream &operator>>(quint64 &i);
-
     QDataStream &operator>>(bool &i);
     QDataStream &operator>>(float &f);
     QDataStream &operator>>(double &f);
index cfc54ef..7ac70cc 100644 (file)
 ****************************************************************************/
 
 #include "qdebug.h"
+#include "qiodevice.h"
+#include "qbuffer.h"
+
+QT_BEGIN_NAMESPACE
+
+class QDebugPrivate
+{
+public:
+    QDebugPrivate(QIODevice *device);
+    QDebugPrivate(QtMsgType t);
+
+    QAtomicInt ref;
+    QIODevice *dev;
+    QByteArray buffer;
+    QtMsgType type;
+    bool space;
+};
+
+QDebugPrivate::QDebugPrivate(QIODevice *device)
+    : ref(1),
+    dev(device),
+    type(QtDebugMsg),
+    space(true)
+{
+}
+
+QDebugPrivate::QDebugPrivate(QtMsgType t)
+    : ref(1),
+    dev(nullptr),
+    type(t),
+    space(true)
+{
+}
 
-// This file is needed to force compilation of QDebug into the kernel library.
 
 /*!
     \class QDebug
 */
 
 /*!
-    \fn QDebug::QDebug(QIODevice *device)
-
     Constructs a debug stream that writes to the given \a device.
 */
+QDebug::QDebug(QIODevice *device)
+    : d_ptr(new QDebugPrivate(device))
+{
+}
 
 /*!
-    \fn QDebug::QDebug(QString *string)
-
-    Constructs a debug stream that writes to the given \a string.
-*/
-
-/*!
-    \fn QDebug::QDebug(QtMsgType type)
-
     Constructs a debug stream that writes to the handler for the message type specified by \a type.
 */
+QDebug::QDebug(QtMsgType type)
+    : d_ptr(new QDebugPrivate(type))
+{
+}
 
 /*!
-    \fn QDebug::QDebug(const QDebug &other)
-
     Constructs a copy of the \a other debug stream.
 */
+QDebug::QDebug(const QDebug &other)
+    : d_ptr(other.d_ptr)
+{
+    d_ptr->ref.ref();
+}
 
 /*!
-    \fn QDebug &QDebug::operator=(const QDebug &other)
-
     Assigns the \a other debug stream to this stream and returns a reference to
     this stream.
 */
+QDebug &QDebug::operator=(const QDebug &other)
+{
+    if (d_ptr != other.d_ptr) {
+        QDebug copy(other);
+        qSwap(d_ptr, copy.d_ptr);
+    }
+    return *this;
+}
 
 /*!
-    \fn QDebug::~QDebug()
-
     Flushes any pending data to be written and destroys the debug stream.
 */
+QDebug::~QDebug()
+{
+    if (!d_ptr->ref.deref()) {
+        if (!d_ptr->dev) {
+            qt_message_output(d_ptr->type, d_ptr->buffer.constData());
+        } else {
+            d_ptr->dev->write(d_ptr->buffer.constData(), d_ptr->buffer.size());
+        }
+        delete d_ptr;
+    }
+}
 
 /*!
-    \fn QDebug &QDebug::space()
-
     Writes a space character to the debug stream and returns a reference to
     the stream.
 
 
     \sa nospace(), maybeSpace()
 */
+QDebug &QDebug::space()
+{
+    d_ptr->space = true;
+    d_ptr->buffer.append(" ", 1);
+    return *this;
+}
 
 /*!
-    \fn QDebug &QDebug::nospace()
-
     Clears the stream's internal flag that records whether the last character
     was a space and returns a reference to the stream.
 
     \sa space(), maybeSpace()
 */
+QDebug &QDebug::nospace()
+{
+    d_ptr->space = false;
+    return *this;
+}
 
 /*!
-    \fn QDebug &QDebug::maybeSpace()
-
     Writes a space character to the debug stream, depending on the last
     character sent to the stream, and returns a reference to the stream.
 
 
     \sa space(), nospace()
 */
+QDebug &QDebug::maybeSpace()
+{
+    if (d_ptr->space) {
+        d_ptr->buffer.append(" ", 1);
+    }
+    return *this;
+}
 
 /*!
-    \fn QDebug &QDebug::operator<<(QChar t)
-
     Writes the character, \a t, to the stream and returns a reference to the
     stream.
 */
+QDebug &QDebug::operator<<(QChar t)
+{
+    const char tc = t.toLatin1();
+    d_ptr->buffer.append("\'", 1);
+    d_ptr->buffer.append(&tc, 1);
+    d_ptr->buffer.append("\'", 1);
+    return maybeSpace();
+}
 
 /*!
-    \fn QDebug &QDebug::operator<<(bool t)
-
     Writes the boolean value, \a t, to the stream and returns a reference to the
     stream.
 */
+QDebug &QDebug::operator<<(bool t)
+{
+    if (t) {
+        d_ptr->buffer.append("true", 4);
+    } else {
+        d_ptr->buffer.append("false", 5);
+    }
+    return maybeSpace();
+}
 
 /*!
-    \fn QDebug &QDebug::operator<<(char t)
-
     Writes the character, \a t, to the stream and returns a reference to the
     stream.
 */
+QDebug &QDebug::operator<<(char t)
+{
+    d_ptr->buffer.append(&t, 1);
+    return maybeSpace();
+}
 
 /*!
-    \fn QDebug &QDebug::operator<<(signed short i)
-
-    Writes the signed short integer, \a i, to the stream and returns a reference
+    Writes the signed short integer, \a t, to the stream and returns a reference
     to the stream.
 */
+QDebug &QDebug::operator<<(qint8 t)
+{
+    return QDebug::operator<<(qint64(t));
+}
 
 /*!
-    \fn QDebug &QDebug::operator<<(unsigned short i)
-
-    Writes then unsigned short integer, \a i, to the stream and returns a
+    Writes then unsigned short integer, \a t, to the stream and returns a
     reference to the stream.
 */
+QDebug &QDebug::operator<<(quint8 t)
+{
+    return QDebug::operator<<(quint64(t));
+}
 
 /*!
-    \fn QDebug &QDebug::operator<<(signed int i)
-
-    Writes the signed integer, \a i, to the stream and returns a reference
+    Writes the signed integer, \a t, to the stream and returns a reference
     to the stream.
 */
+QDebug &QDebug::operator<<(qint16 t)
+{
+    return QDebug::operator<<(qint64(t));
+}
 
 /*!
-    \fn QDebug &QDebug::operator<<(unsigned int i)
-
-    Writes then unsigned integer, \a i, to the stream and returns a reference to
+    Writes then unsigned integer, \a t, to the stream and returns a reference to
     the stream.
 */
+QDebug &QDebug::operator<<(quint16 t)
+{
+    return QDebug::operator<<(quint64(t));
+}
 
 /*!
-    \fn QDebug &QDebug::operator<<(signed long l)
-
-    Writes the signed long integer, \a l, to the stream and returns a reference
+    Writes the signed integer, \a t, to the stream and returns a reference
     to the stream.
 */
+QDebug &QDebug::operator<<(qint32 t)
+{
+    return QDebug::operator<<(qint64(t));
+}
 
 /*!
-    \fn QDebug &QDebug::operator<<(unsigned long l)
+    Writes then unsigned integer, \a t, to the stream and returns a reference to
+    the stream.
+*/
+QDebug &QDebug::operator<<(quint32 t)
+{
+    return QDebug::operator<<(quint64(t));
+}
 
-    Writes then unsigned long integer, \a l, to the stream and returns a reference
+/*!
+    Writes the signed long integer, \a t, to the stream and returns a reference
     to the stream.
 */
+QDebug &QDebug::operator<<(long int t)
+{
+    return QDebug::operator<<(qint64(t));
+}
 
 /*!
-    \fn QDebug &QDebug::operator<<(qint64 i)
-
-    Writes the signed 64-bit integer, \a i, to the stream and returns a reference
+    Writes then unsigned long integer, \a t, to the stream and returns a reference
     to the stream.
 */
+QDebug &QDebug::operator<<(unsigned long int t)
+{
+    return QDebug::operator<<(quint64(t));
+}
 
 /*!
-    \fn QDebug &QDebug::operator<<(quint64 i)
+    Writes the signed 64-bit integer, \a t, to the stream and returns a reference
+    to the stream.
+*/
+QDebug &QDebug::operator<<(qint64 t)
+{
+    d_ptr->buffer.append(QByteArray::number(t));
+    return maybeSpace();
+}
 
-    Writes then unsigned 64-bit integer, \a i, to the stream and returns a
+/*!
+    Writes then unsigned 64-bit integer, \a t, to the stream and returns a
     reference to the stream.
 */
+QDebug &QDebug::operator<<(quint64 t)
+{
+    d_ptr->buffer.append(QByteArray::number(t));
+    return maybeSpace();
+}
 
 /*!
-    \fn QDebug &QDebug::operator<<(float f)
-
-    Writes the 32-bit floating point number, \a f, to the stream and returns a
+    Writes the 32-bit floating point number, \a t, to the stream and returns a
     reference to the stream.
 */
+QDebug &QDebug::operator<<(float t)
+{
+    d_ptr->buffer.append(QByteArray::number(t));
+    return maybeSpace();
+}
 
 /*!
-    \fn QDebug &QDebug::operator<<(double f)
-
-    Writes the 64-bit floating point number, \a f, to the stream and returns a
+    Writes the 64-bit floating point number, \a t, to the stream and returns a
     reference to the stream.
 */
+QDebug &QDebug::operator<<(double t)
+{
+    d_ptr->buffer.append(QByteArray::number(t));
+    return maybeSpace();
+}
 
 /*!
-    \fn QDebug &QDebug::operator<<(const char *s)
-
-    Writes the '\0'-terminated string, \a s, to the stream and returns a
+    Writes the '\0'-terminated string, \a t, to the stream and returns a
     reference to the stream.
 */
+QDebug &QDebug::operator<<(const char* t)
+{
+    d_ptr->buffer.append(t);
+    return maybeSpace();
+}
 
 /*!
-    \fn QDebug &QDebug::operator<<(const QString &s)
-
-    Writes the string, \a s, to the stream and returns a reference to the stream.
+    Writes the string, \a t, to the stream and returns a reference to the stream.
 */
+QDebug &QDebug::operator<<(const QString &t)
+{
+    return QDebug::operator<<(t.toLocal8Bit());
+}
 
 /*!
-    \fn QDebug &QDebug::operator<<(const QStringRef &s)
-
-    Writes the string reference, \a s, to the stream and returns a reference to
+    Writes the string reference, \a t, to the stream and returns a reference to
     the stream.
 */
+QDebug &QDebug::operator<<(const QStringRef &t)
+{
+    return QDebug::operator<<(t.toString());
+}
 
 /*!
-    \fn QDebug &QDebug::operator<<(const QLatin1String &s)
-
     Writes the Latin1-encoded string, \a s, to the stream and returns a reference
     to the stream.
 */
+QDebug &QDebug::operator<<(const QLatin1String &t)
+{
+    return QDebug::operator<<(t.latin1());
+}
 
 /*!
-    \fn QDebug &QDebug::operator<<(const QByteArray &b)
-
-    Writes the byte array, \a b, to the stream and returns a reference to the
+    Writes the byte array, \a t, to the stream and returns a reference to the
     stream.
 */
+QDebug &QDebug::operator<<(const QByteArray &t)
+{
+    d_ptr->buffer.append('\"');
+    d_ptr->buffer.append(t.constData(), t.size());
+    d_ptr->buffer.append('\"');
+    return maybeSpace();
+}
 
 /*!
-    \fn QDebug &QDebug::operator<<(const void *p)
-
-    Writes a pointer, \a p, to the stream and returns a reference to the stream.
-*/
-
-/*!
-    \fn QDebug &QDebug::operator<<(QTextStreamFunction f)
-    \internal
+    Writes a pointer, \a t, to the stream and returns a reference to the stream.
 */
+QDebug &QDebug::operator<<(const void* t)
+{
+    d_ptr->buffer.append(QByteArray::number(qulonglong(quintptr(t))));
+    return maybeSpace();
+}
 
-/*!
-    \fn QDebug &QDebug::operator<<(QTextStreamManipulator m)
-    \internal
-*/
+QT_END_NAMESPACE
index 8e9768f..862b79c 100644 (file)
 #ifndef QDEBUG_H
 #define QDEBUG_H
 
-#include <QtCore/qtextstream.h>
 #include <QtCore/qvector.h>
 #include <QtCore/qset.h>
 
 QT_BEGIN_NAMESPACE
 
+class QDebugPrivate;
+
 class Q_CORE_EXPORT QDebug
 {
-    struct Stream {
-        Stream(QIODevice *device) : ts(device), ref(1), type(QtDebugMsg), space(true), message_output(false) {}
-        Stream(QString *string) : ts(string, QIODevice::WriteOnly), ref(1), type(QtDebugMsg), space(true), message_output(false) {}
-        Stream(QtMsgType t) : ts(&buffer, QIODevice::WriteOnly), ref(1), type(t), space(true), message_output(true) {}
-        QTextStream ts;
-        QString buffer;
-        int ref;
-        QtMsgType type;
-        bool space;
-        bool message_output;
-    } *stream;
 public:
-    inline QDebug(QIODevice *device) : stream(new Stream(device)) {}
-    inline QDebug(QString *string) : stream(new Stream(string)) {}
-    inline QDebug(QtMsgType t) : stream(new Stream(t)) {}
-    inline QDebug(const QDebug &o) : stream(o.stream) { ++stream->ref; }
-    inline QDebug &operator=(const QDebug &other);
-    inline ~QDebug() {
-        if (!--stream->ref) {
-            if(stream->message_output) {
-                QByteArray data = stream->buffer.toLocal8Bit();
-                qt_message_output(stream->type, data.constData());
-            }
-            delete stream;
-        }
-    }
-    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; }
-
-    inline QDebug &operator<<(QChar t) { stream->ts << '\'' << t << '\''; return maybeSpace(); }
-    inline QDebug &operator<<(bool t) { stream->ts << (t ? "true" : "false"); return maybeSpace(); }
-    inline QDebug &operator<<(char t) { stream->ts << t; return maybeSpace(); }
-    inline QDebug &operator<<(signed short t) { stream->ts << t; return maybeSpace(); }
-    inline QDebug &operator<<(unsigned short t) { stream->ts << t; return maybeSpace(); }
-    inline QDebug &operator<<(signed int t) { stream->ts << t; return maybeSpace(); }
-    inline QDebug &operator<<(unsigned int t) { stream->ts << t; return maybeSpace(); }
-    inline QDebug &operator<<(signed long t) { stream->ts << t; return maybeSpace(); }
-    inline QDebug &operator<<(unsigned long t) { stream->ts << t; return maybeSpace(); }
-    inline QDebug &operator<<(qint64 t)
-        { stream->ts << QString::number(t); return maybeSpace(); }
-    inline QDebug &operator<<(quint64 t)
-        { stream->ts << QString::number(t); return maybeSpace(); }
-    inline QDebug &operator<<(float t) { stream->ts << t; return maybeSpace(); }
-    inline QDebug &operator<<(double t) { stream->ts << t; return maybeSpace(); }
-    inline QDebug &operator<<(const char* t) { stream->ts << QString::fromAscii(t); return maybeSpace(); }
-    inline QDebug &operator<<(const QString & t) { stream->ts << '\"' << t << '\"'; return maybeSpace(); }
-    inline QDebug &operator<<(const QStringRef & t) { stream->ts << '\"' << t.toString() << '\"'; return maybeSpace(); }
-    inline QDebug &operator<<(const QLatin1String &t) { stream->ts << '\"' << t.latin1() << '\"'; return maybeSpace(); }
-    inline QDebug &operator<<(const QByteArray & t) { stream->ts  << '\"' << t << '\"'; return maybeSpace(); }
-    inline QDebug &operator<<(const void * t) { stream->ts << t; return maybeSpace(); }
-    inline QDebug &operator<<(QTextStreamFunction f) {
-        stream->ts << f;
-        return *this;
-    }
-
-    inline QDebug &operator<<(QTextStreamManipulator m)
-    { stream->ts << m; return *this; }
+    QDebug(QIODevice *device);
+    QDebug(QtMsgType type);
+    QDebug(const QDebug &o);
+    QDebug &operator=(const QDebug &other);
+    ~QDebug();
+
+    QDebug &space();
+    QDebug &nospace();
+    QDebug &maybeSpace();
+
+    QDebug &operator<<(QChar t);
+    QDebug &operator<<(bool t);
+    QDebug &operator<<(char t);
+    QDebug &operator<<(qint8 t);
+    QDebug &operator<<(quint8 t);
+    QDebug &operator<<(qint16 t);
+    QDebug &operator<<(quint16 t);
+    QDebug &operator<<(qint32 t);
+    QDebug &operator<<(quint32 t);
+    QDebug &operator<<(qint64 t);
+    QDebug &operator<<(quint64 t);
+    QDebug &operator<<(long int t);
+    QDebug &operator<<(unsigned long int t);
+    QDebug &operator<<(float t);
+    QDebug &operator<<(double t);
+    QDebug &operator<<(const char* t);
+    QDebug &operator<<(const QString &t);
+    QDebug &operator<<(const QStringRef &t);
+    QDebug &operator<<(const QLatin1String &t);
+    QDebug &operator<<(const QByteArray &t);
+    QDebug &operator<<(const void* t);
+
+private:
+    QDebugPrivate *d_ptr;
 };
 
-inline QDebug &QDebug::operator=(const QDebug &other)
-{
-    if (this != &other) {
-        QDebug copy(other);
-        qSwap(stream, copy.stream);
-    }
-    return *this;
-}
-
 template <class T>
 inline QDebug operator<<(QDebug debug, const QList<T> &list)
 {
index 69b43ba..ad13991 100644 (file)
@@ -23,7 +23,7 @@
 #define QBITARRAY_H
 
 #include <QtCore/qbytearray.h>
-
+#include <QtCore/qdatastream.h>
 
 QT_BEGIN_NAMESPACE
 
index 3cbfbcc..b5881d1 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <QtCore/qnamespace.h>
 #include <QtCore/qsharedpointer.h>
+#include <QtCore/qdatastream.h>
 
 
 QT_BEGIN_NAMESPACE
index 599df78..a817951 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "qimage.h"
 #include "qimage_p.h"
+#include "qvariant.h"
 #include "qdebug.h"
 #include "qcorecommon_p.h"
 
index 581d05c..96fa2cb 100644 (file)
@@ -2161,7 +2161,7 @@ QDebug operator<<(QDebug dbg, const QEvent *e) {
         if (buttons && button != buttons)
             dbg << ", buttons=" << mouseButtonsToString(buttons).constData();
         if (const int mods = int(me->modifiers()))
-            dbg << ", modifiers=0x" << hex << mods << dec;
+            dbg << ", modifiers=0x" << QByteArray::number(mods, 16);
         dbg << ')';
         break;
     }
@@ -2178,9 +2178,9 @@ QDebug operator<<(QDebug dbg, const QEvent *e) {
     case QEvent::ShortcutOverride: {
         const QKeyEvent *ke = static_cast<const QKeyEvent *>(e);
         dbg << "QKeyEvent("  << eventTypeName(type)
-            << ", key=0x" << hex << ke->key() << dec;
+            << ", key=0x" << QByteArray::number(ke->key(), 16);
         if (const int mods = ke->modifiers())
-            dbg << ", modifiers=0x" << hex << mods << dec;
+            dbg << ", modifiers=0x" << QByteArray::number(mods, 16);
         if (!ke->text().isEmpty())
             dbg << ", text=" << ke->text();
         if (ke->isAutoRepeat())
index b6aaaed..6e86b70 100644 (file)
@@ -26,7 +26,6 @@
 #include <QtCore/qdebug.h>
 #include <QtCore/qdatastream.h>
 
-
 QT_BEGIN_NAMESPACE
 
 
@@ -325,25 +324,24 @@ typedef QGenericMatrix<4, 2> QMatrix4x2;
 typedef QGenericMatrix<4, 3> QMatrix4x3;
 
 #ifndef QT_NO_DEBUG_STREAM
-
 template <int N, int M>
 QDebug operator<<(QDebug dbg, const QGenericMatrix<N, M> &m)
 {
     dbg.nospace() << "QGenericMatrix<" << N << ", " << M
-        << ">(" << endl << qSetFieldWidth(10);
+        << ">(\n";
     for (int row = 0; row < M; ++row) {
+        for (int spc = 0; spc < 10; ++spc)
+            dbg.space();
         for (int col = 0; col < N; ++col)
             dbg << m(row, col);
-        dbg << endl;
+        dbg.nospace() << "\n";
     }
-    dbg << qSetFieldWidth(0) << ')';
+    dbg.nospace() << ')';
     return dbg.space();
 }
-
 #endif
 
 #ifndef QT_NO_DATASTREAM
-
 template <int N, int M>
 QDataStream &operator<<(QDataStream &stream, const QGenericMatrix<N, M> &matrix)
 {
@@ -365,7 +363,6 @@ QDataStream &operator>>(QDataStream &stream, QGenericMatrix<N, M> &matrix)
     }
     return stream;
 }
-
 #endif
 
 QT_END_NAMESPACE
@@ -379,5 +376,4 @@ Q_DECLARE_METATYPE(QMatrix3x4)
 Q_DECLARE_METATYPE(QMatrix4x2)
 Q_DECLARE_METATYPE(QMatrix4x3)
 
-
 #endif
index 370d57f..6e90940 100644 (file)
@@ -25,6 +25,7 @@
 #include "qmatrix.h"
 #include "qtransform.h"
 #include "qguicommon_p.h"
+#include "qcorecommon_p.h"
 
 QT_BEGIN_NAMESPACE
 
@@ -1764,7 +1765,6 @@ QMatrix4x4::operator QVariant() const
 }
 
 #ifndef QT_NO_DEBUG_STREAM
-
 QDebug operator<<(QDebug dbg, const QMatrix4x4 &m)
 {
     // Create a string that represents the matrix type.
@@ -1783,13 +1783,22 @@ QDebug operator<<(QDebug dbg, const QMatrix4x4 &m)
         bits = bits.left(bits.size() - 1);
 
     // Output in row-major order because it is more human-readable.
-    dbg.nospace() << "QMatrix4x4(type:" << bits.constData() << endl
-        << qSetFieldWidth(10)
-        << m(0, 0) << m(0, 1) << m(0, 2) << m(0, 3) << endl
-        << m(1, 0) << m(1, 1) << m(1, 2) << m(1, 3) << endl
-        << m(2, 0) << m(2, 1) << m(2, 2) << m(2, 3) << endl
-        << m(3, 0) << m(3, 1) << m(3, 2) << m(3, 3) << endl
-        << qSetFieldWidth(0) << ')';
+    QSTACKARRAY(char, snprintfbuff, 1024);
+    snprintf(
+        snprintfbuff, sizeof(snprintfbuff),
+        "QMatrix4x4(type: %s\n"
+        "          %f %f %f %f\n"
+        "          %f %f %f %f\n"
+        "          %f %f %f %f\n"
+        "          %f %f %f %f\n"
+        ")",
+        bits.constData(),
+        m(0, 0), m(0, 1), m(0, 2), m(0, 3),
+        m(1, 0), m(1, 1), m(1, 2), m(1, 3),
+        m(2, 0), m(2, 1), m(2, 2), m(2, 3),
+        m(3, 0), m(3, 1), m(3, 2), m(3, 3)
+    );
+    dbg.nospace() << snprintfbuff;
     return dbg.space();
 }
 
index d8eed2a..97b950c 100644 (file)
@@ -80,7 +80,7 @@ QDebug Q_GUI_EXPORT &operator<<(QDebug &s, const QVectorPath &path)
 {
     QRectF rf = path.controlPointRect();
     s << "QVectorPath(size:" << path.elementCount()
-      << " hints:" << hex << path.hints()
+      << " hints:" << QByteArray::number(path.hints(), 16)
       << rf << ')';
     return s;
 }
index 60c0732..83e9f9b 100644 (file)
@@ -3329,7 +3329,7 @@ void QPainterPath::computeControlPointRect() const
 #ifndef QT_NO_DEBUG_STREAM
 QDebug operator<<(QDebug s, const QPainterPath &p)
 {
-    s.nospace() << "QPainterPath: Element count=" << p.elementCount() << endl;
+    s.nospace() << "QPainterPath: Element count=" << p.elementCount() << '\n';
     static const char *types[] = {
         "MoveTo",
         "LineTo",
@@ -3337,7 +3337,7 @@ QDebug operator<<(QDebug s, const QPainterPath &p)
         "CurveToData"
     };
     for (int i=0; i<p.elementCount(); ++i) {
-        s.nospace() << " -> " << types[p.elementAt(i).type] << "(x=" << p.elementAt(i).x << ", y=" << p.elementAt(i).y << ')' << endl;
+        s.nospace() << " -> " << types[p.elementAt(i).type] << "(x=" << p.elementAt(i).x << ", y=" << p.elementAt(i).y << ")\n";
 
     }
     return s;
index ce6daa8..e0489fe 100644 (file)
@@ -28,6 +28,7 @@
 #include "qfontmetrics.h"
 #include "qbrush.h"
 #include "qimagereader.h"
+#include "qtextstream.h"
 
 #ifndef QT_NO_CSSPARSER
 
index f427ed4..6e0b158 100644 (file)
@@ -27,9 +27,9 @@ set(BOOTSTRAP_DEFINITIONS
     -DQT_NO_CAST_FROM_BYTEARRAY
     -DQT_NO_CAST_FROM_ASCII
     -DQT_NO_CAST_TO_ASCII
-    -DQT_NO_DATASTREAM
     -DQT_NO_LIBRARY
     -DQT_NO_QOBJECT
+    -DQT_NO_DATASTREAM
     -DQT_NO_TEXTSTREAM
     -DQT_NO_THREAD
     -DQT_NO_PROCESS
@@ -52,6 +52,7 @@ set(BOOTSTRAP_SOURCES
     ${CMAKE_SOURCE_DIR}/src/core/global/qglobal.cpp
     ${CMAKE_SOURCE_DIR}/src/core/global/qt_error_string.cpp
     ${CMAKE_SOURCE_DIR}/src/core/io/qbuffer.cpp
+    ${CMAKE_SOURCE_DIR}/src/core/io/qdebug.cpp
     ${CMAKE_SOURCE_DIR}/src/core/io/qdir.cpp
     ${CMAKE_SOURCE_DIR}/src/core/io/qdiriterator.cpp
     ${CMAKE_SOURCE_DIR}/src/core/io/qfile.cpp
index e756d2f..abd1aa6 100644 (file)
 
 #include "generator.h"
 #include "utils.h"
-#include <QtCore/qmetatype.h>
-#include <stdio.h>
-
+#include "qvariant.h"
+#include "qmetatype.h"
 #include "qmetaobject_p.h" //for the flags.
 
+#include <stdio.h>
+
 QT_BEGIN_NAMESPACE
 
 static uint qvariant_nameToType(const char* name)
index 0b01451..f5d5f36 100644 (file)
@@ -28,6 +28,7 @@
 #include <QFile>
 #include <QFileInfo>
 #include <QProcess>
+#include <QTextStream>
 
 #include <sys/types.h>
 #include <unistd.h>
index 2f022b1..a725822 100644 (file)
@@ -31,6 +31,7 @@
 #include <qdir.h>
 #include <qfileinfo.h>
 #include <qplatformdefs.h>
+#include <qtextstream.h>
 #include <qdebug.h>
 #include <qfileinfo_p.h>
 #include "../../shared/filesystem.h"
index 555c475..31da789 100644 (file)
@@ -69,7 +69,7 @@ void tst_QNetworkInterface::dump()
         foreach (const QNetworkAddressEntry &e, i.addressEntries()) {
             QDebug s = qDebug();
             s.nospace() <<    "    address "
-                        << qSetFieldWidth(2) << count++ << qSetFieldWidth(0);
+                        << "  " << count++;
             s.nospace() << ": " << qPrintable(e.ip().toString());
             if (!e.netmask().isNull())
                 s.nospace() << '/' << e.prefixLength()
index 76471b7..5435c67 100644 (file)
@@ -28,6 +28,8 @@
 #include <QtCore/QRegExp>
 #include <QtCore/QDebug>
 #include <QtCore/QMetaType>
+#include <QtCore/QTextStream>
+
 #include <stdlib.h>
 
 #ifdef QT_NO_PROCESS