Fix Qt6 related comments in qdebug

Change-Id: I9861d29a6615863094cd007178f214a816865eb7
Reviewed-by: Kai Koehne <kai.koehne@qt.io>
bb10
Lars Knoll 2020-09-03 12:21:46 +02:00
parent defc8414fd
commit 1316a0aef2
2 changed files with 33 additions and 45 deletions

View File

@ -304,7 +304,7 @@ static inline void putEscapedString(QTextStreamPrivate *d, const Char *begin, in
*/
void QDebug::putString(const QChar *begin, size_t length)
{
if (stream->testFlag(Stream::NoQuotes)) {
if (stream->noQuotes) {
// no quotes, write the string directly too (no pretty-printing)
// this respects the QTextStream state, though
stream->ts.d_ptr->putString(begin, int(length));
@ -322,7 +322,7 @@ void QDebug::putString(const QChar *begin, size_t length)
*/
void QDebug::putByteArray(const char *begin, size_t length, Latin1Content content)
{
if (stream->testFlag(Stream::NoQuotes)) {
if (stream->noQuotes) {
// no quotes, write the string directly too (no pretty-printing)
// this respects the QTextStream state, though
QString string = content == ContainsLatin1 ? QString::fromLatin1(begin, int(length)) : QString::fromUtf8(begin, int(length));
@ -354,9 +354,8 @@ QDebug &QDebug::resetFormat()
{
stream->ts.reset();
stream->space = true;
if (stream->context.version > 1)
stream->flags = 0;
stream->setVerbosity(DefaultVerbosity);
stream->noQuotes = false;
stream->verbosity = DefaultVerbosity;
return *this;
}
@ -853,7 +852,8 @@ public:
QDebugStateSaverPrivate(QDebug::Stream *stream)
: m_stream(stream),
m_spaces(stream->space),
m_flags(stream->context.version > 1 ? stream->flags : 0),
m_noQuotes(stream->noQuotes),
m_verbosity(stream->verbosity),
m_streamParams(stream->ts.d_ptr->params)
{
}
@ -865,9 +865,9 @@ public:
m_stream->buffer.chop(1);
m_stream->space = m_spaces;
m_stream->noQuotes = m_noQuotes;
m_stream->ts.d_ptr->params = m_streamParams;
if (m_stream->context.version > 1)
m_stream->flags = m_flags;
m_stream->verbosity = m_verbosity;
if (!currentSpaces && m_spaces)
m_stream->ts << ' ';
@ -877,7 +877,8 @@ public:
// QDebug state
const bool m_spaces;
const int m_flags;
const bool m_noQuotes;
const int m_verbosity;
// QTextStream state
const QTextStreamPrivate::Params m_streamParams;

View File

@ -68,39 +68,26 @@ class Q_CORE_EXPORT QDebug : public QIODeviceBase
struct Stream {
enum { VerbosityShift = 29, VerbosityMask = 0x7 };
Stream(QIODevice *device) : ts(device), ref(1), type(QtDebugMsg),
space(true), message_output(false), flags(DefaultVerbosity << VerbosityShift) {}
Stream(QString *string) : ts(string, WriteOnly), ref(1), type(QtDebugMsg),
space(true), message_output(false), flags(DefaultVerbosity << VerbosityShift) {}
Stream(QtMsgType t) : ts(&buffer, WriteOnly), ref(1), type(t),
space(true), message_output(true), flags(DefaultVerbosity << VerbosityShift) {}
Stream(QIODevice *device)
: ts(device)
{}
Stream(QString *string)
: ts(string, WriteOnly)
{}
Stream(QtMsgType t)
: ts(&buffer, WriteOnly),
type(t),
message_output(true)
{}
QTextStream ts;
QString buffer;
int ref;
QtMsgType type;
bool space;
bool message_output;
int ref = 1;
QtMsgType type = QtDebugMsg;
bool space = true;
bool noQuotes = false;
bool message_output = false;
int verbosity = DefaultVerbosity;
QMessageLogContext context;
enum FormatFlag { // Note: Bits 29..31 are reserved for the verbose level introduced in 5.6.
NoQuotes = 0x1
};
// ### Qt 6: unify with space, introduce own version member
bool testFlag(FormatFlag flag) const { return (context.version > 1) ? (flags & flag) : false; }
void setFlag(FormatFlag flag) { if (context.version > 1) { flags |= flag; } }
void unsetFlag(FormatFlag flag) { if (context.version > 1) { flags &= ~flag; } }
int verbosity() const
{ return context.version > 1 ? (flags >> VerbosityShift) & VerbosityMask : int(DefaultVerbosity); }
void setVerbosity(int v)
{
if (context.version > 1) {
flags &= ~(uint(VerbosityMask) << VerbosityShift);
flags |= (v & VerbosityMask) << VerbosityShift;
}
}
// added in 5.4
int flags;
} *stream;
enum Latin1Content { ContainsBinary = 0, ContainsLatin1 };
@ -125,17 +112,17 @@ public:
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 &verbosity(int verbosityLevel) { setVerbosity(verbosityLevel); return *this; }
int verbosity() const { return stream->verbosity(); }
void setVerbosity(int verbosityLevel) { stream->setVerbosity(verbosityLevel); }
inline QDebug &verbosity(int verbosityLevel) { stream->verbosity = verbosityLevel; return *this; }
int verbosity() const { return stream->verbosity; }
void setVerbosity(int verbosityLevel) { stream->verbosity = verbosityLevel; }
enum VerbosityLevel { MinimumVerbosity = 0, DefaultVerbosity = 2, MaximumVerbosity = 7 };
bool autoInsertSpaces() const { return stream->space; }
void setAutoInsertSpaces(bool b) { stream->space = b; }
inline QDebug &quote() { stream->unsetFlag(Stream::NoQuotes); return *this; }
inline QDebug &noquote() { stream->setFlag(Stream::NoQuotes); return *this; }
inline QDebug &maybeQuote(char c = '"') { if (!(stream->testFlag(Stream::NoQuotes))) stream->ts << c; return *this; }
inline QDebug &quote() { stream->noQuotes = false; return *this; }
inline QDebug &noquote() { stream->noQuotes = true; return *this; }
inline QDebug &maybeQuote(char c = '"') { if (!stream->noQuotes) stream->ts << c; return *this; }
inline QDebug &operator<<(QChar t) { putUcs4(t.unicode()); return maybeSpace(); }
inline QDebug &operator<<(bool t) { stream->ts << (t ? "true" : "false"); return maybeSpace(); }