From 29a872456828a5a01d61520db399f2537ee9bbf4 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sun, 13 Nov 2022 15:39:19 +0200 Subject: [PATCH] QDebug rewrite to use QByteArray as internal buffer Signed-off-by: Ivailo Monev --- src/core/io/qdatastream.cpp | 31 --- src/core/io/qdatastream.h | 1 - src/core/io/qdebug.cpp | 293 +++++++++++++++------ src/core/io/qdebug.h | 103 +++----- src/core/tools/qbitarray.h | 2 +- src/core/tools/qdatetime.h | 1 + src/gui/image/qkathandler.cpp | 1 + src/gui/kernel/qevent.cpp | 6 +- src/gui/math3d/qgenericmatrix.h | 14 +- src/gui/math3d/qmatrix4x4.cpp | 25 +- src/gui/painting/qpaintengineex.cpp | 2 +- src/gui/painting/qpainterpath.cpp | 4 +- src/gui/text/qcssparser.cpp | 1 + src/tools/moc/CMakeLists.txt | 3 +- src/tools/moc/generator.cpp | 7 +- tests/auto/qfile/tst_qfile.cpp | 1 + tests/auto/qfileinfo/tst_qfileinfo.cpp | 1 + .../qnetworkinterface/tst_qnetworkinterface.cpp | 2 +- tests/auto/qprocess/tst_qprocess.cpp | 2 + 19 files changed, 289 insertions(+), 211 deletions(-) diff --git a/src/core/io/qdatastream.cpp b/src/core/io/qdatastream.cpp index 4c97c8daa..7d0ef2ba7 100644 --- a/src/core/io/qdatastream.cpp +++ b/src/core/io/qdatastream.cpp @@ -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) diff --git a/src/core/io/qdatastream.h b/src/core/io/qdatastream.h index 36a5800d1..59c318150 100644 --- a/src/core/io/qdatastream.h +++ b/src/core/io/qdatastream.h @@ -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); diff --git a/src/core/io/qdebug.cpp b/src/core/io/qdebug.cpp index cfc54efb8..7ac70ccde 100644 --- a/src/core/io/qdebug.cpp +++ b/src/core/io/qdebug.cpp @@ -20,8 +20,40 @@ ****************************************************************************/ #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 @@ -61,45 +93,59 @@ */ /*! - \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. @@ -108,19 +154,26 @@ \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. @@ -129,144 +182,218 @@ \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 diff --git a/src/core/io/qdebug.h b/src/core/io/qdebug.h index 8e9768f14..862b79c89 100644 --- a/src/core/io/qdebug.h +++ b/src/core/io/qdebug.h @@ -22,83 +22,52 @@ #ifndef QDEBUG_H #define QDEBUG_H -#include #include #include 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 inline QDebug operator<<(QDebug debug, const QList &list) { diff --git a/src/core/tools/qbitarray.h b/src/core/tools/qbitarray.h index 69b43ba9e..ad139919e 100644 --- a/src/core/tools/qbitarray.h +++ b/src/core/tools/qbitarray.h @@ -23,7 +23,7 @@ #define QBITARRAY_H #include - +#include QT_BEGIN_NAMESPACE diff --git a/src/core/tools/qdatetime.h b/src/core/tools/qdatetime.h index 3cbfbccbd..b5881d1ce 100644 --- a/src/core/tools/qdatetime.h +++ b/src/core/tools/qdatetime.h @@ -24,6 +24,7 @@ #include #include +#include QT_BEGIN_NAMESPACE diff --git a/src/gui/image/qkathandler.cpp b/src/gui/image/qkathandler.cpp index 599df781c..a81795197 100644 --- a/src/gui/image/qkathandler.cpp +++ b/src/gui/image/qkathandler.cpp @@ -24,6 +24,7 @@ #include "qimage.h" #include "qimage_p.h" +#include "qvariant.h" #include "qdebug.h" #include "qcorecommon_p.h" diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 581d05c20..96fa2cbb5 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -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(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()) diff --git a/src/gui/math3d/qgenericmatrix.h b/src/gui/math3d/qgenericmatrix.h index b6aaaeda4..6e86b708a 100644 --- a/src/gui/math3d/qgenericmatrix.h +++ b/src/gui/math3d/qgenericmatrix.h @@ -26,7 +26,6 @@ #include #include - QT_BEGIN_NAMESPACE @@ -325,25 +324,24 @@ typedef QGenericMatrix<4, 2> QMatrix4x2; typedef QGenericMatrix<4, 3> QMatrix4x3; #ifndef QT_NO_DEBUG_STREAM - template QDebug operator<<(QDebug dbg, const QGenericMatrix &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 QDataStream &operator<<(QDataStream &stream, const QGenericMatrix &matrix) { @@ -365,7 +363,6 @@ QDataStream &operator>>(QDataStream &stream, QGenericMatrix &matrix) } return stream; } - #endif QT_END_NAMESPACE @@ -379,5 +376,4 @@ Q_DECLARE_METATYPE(QMatrix3x4) Q_DECLARE_METATYPE(QMatrix4x2) Q_DECLARE_METATYPE(QMatrix4x3) - #endif diff --git a/src/gui/math3d/qmatrix4x4.cpp b/src/gui/math3d/qmatrix4x4.cpp index 370d57fa9..6e9094028 100644 --- a/src/gui/math3d/qmatrix4x4.cpp +++ b/src/gui/math3d/qmatrix4x4.cpp @@ -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(); } diff --git a/src/gui/painting/qpaintengineex.cpp b/src/gui/painting/qpaintengineex.cpp index d8eed2a96..97b950c8b 100644 --- a/src/gui/painting/qpaintengineex.cpp +++ b/src/gui/painting/qpaintengineex.cpp @@ -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; } diff --git a/src/gui/painting/qpainterpath.cpp b/src/gui/painting/qpainterpath.cpp index 60c07328d..83e9f9b0b 100644 --- a/src/gui/painting/qpainterpath.cpp +++ b/src/gui/painting/qpainterpath.cpp @@ -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 " << 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; diff --git a/src/gui/text/qcssparser.cpp b/src/gui/text/qcssparser.cpp index ce6daa82b..e0489fe15 100644 --- a/src/gui/text/qcssparser.cpp +++ b/src/gui/text/qcssparser.cpp @@ -28,6 +28,7 @@ #include "qfontmetrics.h" #include "qbrush.h" #include "qimagereader.h" +#include "qtextstream.h" #ifndef QT_NO_CSSPARSER diff --git a/src/tools/moc/CMakeLists.txt b/src/tools/moc/CMakeLists.txt index f427ed40b..6e0b1589e 100644 --- a/src/tools/moc/CMakeLists.txt +++ b/src/tools/moc/CMakeLists.txt @@ -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 diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp index e756d2fdb..abd1aa659 100644 --- a/src/tools/moc/generator.cpp +++ b/src/tools/moc/generator.cpp @@ -21,11 +21,12 @@ #include "generator.h" #include "utils.h" -#include -#include - +#include "qvariant.h" +#include "qmetatype.h" #include "qmetaobject_p.h" //for the flags. +#include + QT_BEGIN_NAMESPACE static uint qvariant_nameToType(const char* name) diff --git a/tests/auto/qfile/tst_qfile.cpp b/tests/auto/qfile/tst_qfile.cpp index 0b0145102..f5d5f3653 100644 --- a/tests/auto/qfile/tst_qfile.cpp +++ b/tests/auto/qfile/tst_qfile.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include diff --git a/tests/auto/qfileinfo/tst_qfileinfo.cpp b/tests/auto/qfileinfo/tst_qfileinfo.cpp index 2f022b10a..a7258227e 100644 --- a/tests/auto/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/qfileinfo/tst_qfileinfo.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include "../../shared/filesystem.h" diff --git a/tests/auto/qnetworkinterface/tst_qnetworkinterface.cpp b/tests/auto/qnetworkinterface/tst_qnetworkinterface.cpp index 555c475af..31da78958 100644 --- a/tests/auto/qnetworkinterface/tst_qnetworkinterface.cpp +++ b/tests/auto/qnetworkinterface/tst_qnetworkinterface.cpp @@ -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() diff --git a/tests/auto/qprocess/tst_qprocess.cpp b/tests/auto/qprocess/tst_qprocess.cpp index 76471b749..5435c67a8 100644 --- a/tests/auto/qprocess/tst_qprocess.cpp +++ b/tests/auto/qprocess/tst_qprocess.cpp @@ -28,6 +28,8 @@ #include #include #include +#include + #include #ifdef QT_NO_PROCESS -- 2.11.0