2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-15 07:08:27 +00:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
2016-01-21 02:33:50 +00:00
|
|
|
** Copyright (C) 2016 Intel Corporation.
|
2016-01-15 07:08:27 +00:00
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the QtCore module of the Qt Toolkit.
|
|
|
|
**
|
2016-01-15 07:08:27 +00:00
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
2012-09-19 12:28:29 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-28 08:44:43 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-15 07:08:27 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-09-19 12:28:29 +00:00
|
|
|
**
|
2011-04-27 10:05:43 +00:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-09-19 12:28:29 +00:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2016-01-15 07:08:27 +00:00
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL3 included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU Lesser General Public License version 3 requirements
|
|
|
|
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
|
2012-09-19 12:28:29 +00:00
|
|
|
**
|
2016-01-15 07:08:27 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 2.0 or (at your option) the GNU General
|
|
|
|
** Public license version 3 or any later version approved by the KDE Free
|
|
|
|
** Qt Foundation. The licenses are as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
|
|
|
|
** https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef QDEBUG_H
|
|
|
|
#define QDEBUG_H
|
|
|
|
|
|
|
|
#include <QtCore/qalgorithms.h>
|
|
|
|
#include <QtCore/qhash.h>
|
|
|
|
#include <QtCore/qlist.h>
|
|
|
|
#include <QtCore/qmap.h>
|
|
|
|
#include <QtCore/qtextstream.h>
|
|
|
|
#include <QtCore/qstring.h>
|
|
|
|
#include <QtCore/qset.h>
|
|
|
|
#include <QtCore/qcontiguouscache.h>
|
2016-05-12 10:33:04 +00:00
|
|
|
#include <QtCore/qsharedpointer.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2015-06-24 12:54:54 +00:00
|
|
|
// all these have already been included by various headers above, but don't rely on indirect includes:
|
|
|
|
#include <vector>
|
|
|
|
#include <list>
|
|
|
|
#include <map>
|
|
|
|
#include <utility>
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
|
|
|
|
2020-08-07 09:46:07 +00:00
|
|
|
class Q_CORE_EXPORT QDebug : public QIODeviceBase
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
QtDebug: Include file, line, function information
Record the file, line, and function where a qDebug, qWarning, qCritical
or qFatal call happens, and make this information available in a custom
message handler.
The patch uses the C preprocessor to replace qDebug, qWarning, ... with
a line that also records the current file, line, and function. Custom
message handlers can access this information via a new QMessageLogContext
argument.
Change-Id: I0a9b89c1d137e41775932d3b1a35da4ebf12d18d
Reviewed-by: David Faure <faure@kde.org>
2012-01-17 15:20:45 +00:00
|
|
|
friend class QMessageLogger;
|
2019-06-04 10:43:16 +00:00
|
|
|
friend class QDebugStateSaver;
|
2012-07-27 12:17:38 +00:00
|
|
|
friend class QDebugStateSaverPrivate;
|
2011-04-27 10:05:43 +00:00
|
|
|
struct Stream {
|
2018-12-20 13:22:11 +00:00
|
|
|
enum { VerbosityShift = 29, VerbosityMask = 0x7 };
|
2015-02-23 09:06:48 +00:00
|
|
|
|
2020-09-03 10:21:46 +00:00
|
|
|
Stream(QIODevice *device)
|
|
|
|
: ts(device)
|
|
|
|
{}
|
|
|
|
Stream(QString *string)
|
|
|
|
: ts(string, WriteOnly)
|
|
|
|
{}
|
|
|
|
Stream(QtMsgType t)
|
|
|
|
: ts(&buffer, WriteOnly),
|
|
|
|
type(t),
|
|
|
|
message_output(true)
|
|
|
|
{}
|
2011-04-27 10:05:43 +00:00
|
|
|
QTextStream ts;
|
|
|
|
QString buffer;
|
2020-09-03 10:21:46 +00:00
|
|
|
int ref = 1;
|
|
|
|
QtMsgType type = QtDebugMsg;
|
|
|
|
bool space = true;
|
|
|
|
bool noQuotes = false;
|
|
|
|
bool message_output = false;
|
|
|
|
int verbosity = DefaultVerbosity;
|
QtDebug: Include file, line, function information
Record the file, line, and function where a qDebug, qWarning, qCritical
or qFatal call happens, and make this information available in a custom
message handler.
The patch uses the C preprocessor to replace qDebug, qWarning, ... with
a line that also records the current file, line, and function. Custom
message handlers can access this information via a new QMessageLogContext
argument.
Change-Id: I0a9b89c1d137e41775932d3b1a35da4ebf12d18d
Reviewed-by: David Faure <faure@kde.org>
2012-01-17 15:20:45 +00:00
|
|
|
QMessageLogContext context;
|
2011-04-27 10:05:43 +00:00
|
|
|
} *stream;
|
2014-11-18 05:11:23 +00:00
|
|
|
|
2014-11-18 23:20:21 +00:00
|
|
|
enum Latin1Content { ContainsBinary = 0, ContainsLatin1 };
|
|
|
|
|
2014-11-18 05:11:23 +00:00
|
|
|
void putUcs4(uint ucs4);
|
2014-11-18 22:32:38 +00:00
|
|
|
void putString(const QChar *begin, size_t length);
|
2014-11-18 23:20:21 +00:00
|
|
|
void putByteArray(const char *begin, size_t length, Latin1Content content);
|
2011-04-27 10:05:43 +00:00
|
|
|
public:
|
2019-12-11 21:31:02 +00:00
|
|
|
explicit QDebug(QIODevice *device) : stream(new Stream(device)) {}
|
|
|
|
explicit QDebug(QString *string) : stream(new Stream(string)) {}
|
|
|
|
explicit QDebug(QtMsgType t) : stream(new Stream(t)) {}
|
|
|
|
QDebug(const QDebug &o) : stream(o.stream) { ++stream->ref; }
|
2019-06-04 10:43:16 +00:00
|
|
|
QDebug(QDebug &&other) noexcept : stream{qExchange(other.stream, nullptr)} {}
|
2011-04-27 10:05:43 +00:00
|
|
|
inline QDebug &operator=(const QDebug &other);
|
Centralize the implementation of move assignment operators
At the moment we have two main strategies for dealing with move
assignment in Qt:
1) move-and-swap, used by "containers" (in the broad sense): containers,
but also smart pointers and similar classes that can hold user-defined
types;
2) pure swap, used by containers that hold only memory (e.g. QString,
QByteArray, ...) as well as most implicitly shared datatypes.
Given the fact that a move assignment operator's code is just
boilerplate (whether it's move-and-swap or pure swap), provide two
_strictly internal_ macros to help write them, and apply the macros
across corelib and gui, porting away from the hand-rolled
implementations.
The rule of thumb when porting to the new macros is:
* Try to stick to the existing code behavior, unless broken
* if changing, then follow this checklist:
* if the class does not have a move constructor => pure swap
(but consider ADDING a move constructor, if possible!)
* if the class does have a move constructor, try to follow the
criteria above, namely:
* if the class holds only memory, pure swap;
* if the class may hold anything else but memory (file handles,
etc.), then move and swap.
Noteworthy details:
* some operators planned to be removed in Qt 6 were not ported;
* as drive-by, some move constructors were simplified to be using
qExchange(); others were outright broken and got fixed;
* some contained some more interesting code and were not touched.
Change-Id: Idaab3489247dcbabb6df3fa1e5286b69e1d372e9
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
2020-01-03 16:18:02 +00:00
|
|
|
QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QDebug)
|
2014-04-29 10:39:31 +00:00
|
|
|
~QDebug();
|
2019-04-02 08:54:54 +00:00
|
|
|
inline void swap(QDebug &other) noexcept { qSwap(stream, other.stream); }
|
2012-04-05 12:49:02 +00:00
|
|
|
|
2014-06-20 12:44:48 +00:00
|
|
|
QDebug &resetFormat();
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
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; }
|
2020-09-03 10:21:46 +00:00
|
|
|
inline QDebug &verbosity(int verbosityLevel) { stream->verbosity = verbosityLevel; return *this; }
|
|
|
|
int verbosity() const { return stream->verbosity; }
|
|
|
|
void setVerbosity(int verbosityLevel) { stream->verbosity = verbosityLevel; }
|
2018-12-20 13:22:11 +00:00
|
|
|
enum VerbosityLevel { MinimumVerbosity = 0, DefaultVerbosity = 2, MaximumVerbosity = 7 };
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-07-27 11:53:16 +00:00
|
|
|
bool autoInsertSpaces() const { return stream->space; }
|
|
|
|
void setAutoInsertSpaces(bool b) { stream->space = b; }
|
|
|
|
|
2020-09-03 10:21:46 +00:00
|
|
|
inline QDebug "e() { 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; }
|
2014-06-19 09:09:47 +00:00
|
|
|
|
2014-11-18 05:11:23 +00:00
|
|
|
inline QDebug &operator<<(QChar t) { putUcs4(t.unicode()); return maybeSpace(); }
|
2011-04-27 10:05:43 +00:00
|
|
|
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(); }
|
Split Q_COMPILER_UNICODE_STRINGS: add Q_STDLIB_UNICODE_STRINGS
Since commit bf2160e72cd8840a8e604438cbdc807483ac980a, we can rely on
charNN_t support in all compilers except MSVC 2013, and since that
commit, we use (in 5.10, not 5.9, yet)
!defined(Q_OS_WIN) || defined(Q_COMPILER_UNICODE_STRINGS)
when we only need charNN_t, the type, as opposed to its library
support (u16string, char_traits<char16_t>, ...).
This patch splits the Q_C_UNICODE_STRINGS macro into two, adding
Q_STDLIB_UNICODE_STRINGS for when we need std::uNNstring, leaving
Q_C_UNICODE_STRINGS for when we need just charNN_t support.
In QDebug, when constructing a QChar out of a char16_t, cast to ushort
first, since QChar(char16_t) was only officially introduced in Qt 5.10.
[ChangeLog][Potentially Source-Incompatible Changes] The internal
Q_COMPILER_UNICODE_STRINGS macro is now defined if the compiler
supports charNN_t, even if the standard library does not. To check for
availability of std::uNNstring, use the new Q_STDLIB_UNICODE_STRINGS
macro.
Change-Id: I8f210fd7f1799fe21faf54506475a759b1f76a59
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2017-03-30 17:49:32 +00:00
|
|
|
inline QDebug &operator<<(char16_t t) { return *this << QChar(ushort(t)); }
|
2014-11-18 05:11:23 +00:00
|
|
|
inline QDebug &operator<<(char32_t t) { putUcs4(t); return maybeSpace(); }
|
2011-04-27 10:05:43 +00:00
|
|
|
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(); }
|
2014-02-13 13:44:38 +00:00
|
|
|
inline QDebug &operator<<(qint64 t) { stream->ts << t; return maybeSpace(); }
|
|
|
|
inline QDebug &operator<<(quint64 t) { stream->ts << t; return maybeSpace(); }
|
2011-04-27 10:05:43 +00:00
|
|
|
inline QDebug &operator<<(float t) { stream->ts << t; return maybeSpace(); }
|
|
|
|
inline QDebug &operator<<(double t) { stream->ts << t; return maybeSpace(); }
|
2012-05-02 11:29:54 +00:00
|
|
|
inline QDebug &operator<<(const char* t) { stream->ts << QString::fromUtf8(t); return maybeSpace(); }
|
2020-07-31 00:21:37 +00:00
|
|
|
inline QDebug &operator<<(const char16_t *t) { stream->ts << QStringView(t); return maybeSpace(); }
|
2017-01-30 09:31:10 +00:00
|
|
|
#if QT_STRINGVIEW_LEVEL < 2
|
2014-11-18 22:32:38 +00:00
|
|
|
inline QDebug &operator<<(const QString & t) { putString(t.constData(), uint(t.length())); return maybeSpace(); }
|
2017-01-30 09:31:10 +00:00
|
|
|
#endif
|
|
|
|
inline QDebug &operator<<(QStringView s) { putString(s.data(), size_t(s.size())); return maybeSpace(); }
|
2020-11-03 14:03:57 +00:00
|
|
|
inline QDebug &operator<<(QUtf8StringView s) { putByteArray(s.data(), s.size(), ContainsBinary); return maybeSpace(); }
|
2014-11-18 23:20:21 +00:00
|
|
|
inline QDebug &operator<<(QLatin1String t) { putByteArray(t.latin1(), t.size(), ContainsLatin1); return maybeSpace(); }
|
|
|
|
inline QDebug &operator<<(const QByteArray & t) { putByteArray(t.constData(), t.size(), ContainsBinary); return maybeSpace(); }
|
2020-11-02 22:29:08 +00:00
|
|
|
inline QDebug &operator<<(QByteArrayView t) { putByteArray(t.constData(), t.size(), ContainsBinary); return maybeSpace(); }
|
2011-04-27 10:05:43 +00:00
|
|
|
inline QDebug &operator<<(const void * t) { stream->ts << t; return maybeSpace(); }
|
2014-11-18 05:11:23 +00:00
|
|
|
inline QDebug &operator<<(std::nullptr_t) { stream->ts << "(nullptr)"; return maybeSpace(); }
|
2011-04-27 10:05:43 +00:00
|
|
|
inline QDebug &operator<<(QTextStreamFunction f) {
|
|
|
|
stream->ts << f;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline QDebug &operator<<(QTextStreamManipulator m)
|
|
|
|
{ stream->ts << m; return *this; }
|
2020-02-19 10:29:37 +00:00
|
|
|
|
|
|
|
template <typename T>
|
2020-10-15 07:10:08 +00:00
|
|
|
static QString toString(T &&object)
|
2020-02-19 10:29:37 +00:00
|
|
|
{
|
|
|
|
QString buffer;
|
|
|
|
QDebug stream(&buffer);
|
2020-10-15 07:10:08 +00:00
|
|
|
stream.nospace() << std::forward<T>(object);
|
2020-02-19 10:29:37 +00:00
|
|
|
return buffer;
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
};
|
|
|
|
|
2012-05-04 13:27:56 +00:00
|
|
|
Q_DECLARE_SHARED(QDebug)
|
|
|
|
|
2012-07-27 12:17:38 +00:00
|
|
|
class QDebugStateSaverPrivate;
|
|
|
|
class Q_CORE_EXPORT QDebugStateSaver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
QDebugStateSaver(QDebug &dbg);
|
|
|
|
~QDebugStateSaver();
|
|
|
|
private:
|
|
|
|
Q_DISABLE_COPY(QDebugStateSaver)
|
|
|
|
QScopedPointer<QDebugStateSaverPrivate> d;
|
|
|
|
};
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
class QNoDebug
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
inline QNoDebug &operator<<(QTextStreamFunction) { return *this; }
|
|
|
|
inline QNoDebug &operator<<(QTextStreamManipulator) { return *this; }
|
|
|
|
inline QNoDebug &space() { return *this; }
|
|
|
|
inline QNoDebug &nospace() { return *this; }
|
|
|
|
inline QNoDebug &maybeSpace() { return *this; }
|
2014-06-19 09:09:47 +00:00
|
|
|
inline QNoDebug "e() { return *this; }
|
|
|
|
inline QNoDebug &noquote() { return *this; }
|
|
|
|
inline QNoDebug &maybeQuote(const char = '"') { return *this; }
|
2018-12-19 15:46:20 +00:00
|
|
|
inline QNoDebug &verbosity(int) { return *this; }
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
inline QNoDebug &operator<<(const T &) { return *this; }
|
|
|
|
};
|
|
|
|
|
|
|
|
inline QDebug &QDebug::operator=(const QDebug &other)
|
|
|
|
{
|
2019-06-04 10:43:16 +00:00
|
|
|
QDebug{other}.swap(*this);
|
2011-04-27 10:05:43 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-06-24 12:54:54 +00:00
|
|
|
namespace QtPrivate {
|
|
|
|
|
|
|
|
template <typename SequentialContainer>
|
|
|
|
inline QDebug printSequentialContainer(QDebug debug, const char *which, const SequentialContainer &c)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2020-05-11 01:09:46 +00:00
|
|
|
const QDebugStateSaver saver(debug);
|
2015-06-24 12:54:54 +00:00
|
|
|
debug.nospace() << which << '(';
|
|
|
|
typename SequentialContainer::const_iterator it = c.begin(), end = c.end();
|
|
|
|
if (it != end) {
|
|
|
|
debug << *it;
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
while (it != end) {
|
|
|
|
debug << ", " << *it;
|
|
|
|
++it;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
debug << ')';
|
2020-05-11 01:09:46 +00:00
|
|
|
return debug;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 01:03:32 +00:00
|
|
|
template <typename AssociativeContainer>
|
|
|
|
inline QDebug printAssociativeContainer(QDebug debug, const char *which, const AssociativeContainer &c)
|
|
|
|
{
|
2020-05-11 01:09:46 +00:00
|
|
|
const QDebugStateSaver saver(debug);
|
2020-05-11 01:03:32 +00:00
|
|
|
debug.nospace() << which << "(";
|
|
|
|
for (typename AssociativeContainer::const_iterator it = c.constBegin();
|
|
|
|
it != c.constEnd(); ++it) {
|
|
|
|
debug << '(' << it.key() << ", " << it.value() << ')';
|
|
|
|
}
|
|
|
|
debug << ')';
|
2020-05-11 01:09:46 +00:00
|
|
|
return debug;
|
2020-05-11 01:03:32 +00:00
|
|
|
}
|
|
|
|
|
2015-06-24 12:54:54 +00:00
|
|
|
} // namespace QtPrivate
|
|
|
|
|
2020-07-06 11:08:40 +00:00
|
|
|
template<typename ...T>
|
|
|
|
using QDebugIfHasDebugStream =
|
|
|
|
std::enable_if_t<std::conjunction_v<QTypeTraits::has_ostream_operator<QDebug, T>...>, QDebug>;
|
|
|
|
|
2020-06-22 09:06:12 +00:00
|
|
|
template<typename T>
|
2020-07-06 11:08:40 +00:00
|
|
|
inline QDebugIfHasDebugStream<T> operator<<(QDebug debug, const QList<T> &vec)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2020-06-22 09:06:12 +00:00
|
|
|
return QtPrivate::printSequentialContainer(debug, "QList", vec);
|
2015-06-24 12:54:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, typename Alloc>
|
2020-07-06 11:08:40 +00:00
|
|
|
inline QDebugIfHasDebugStream<T> operator<<(QDebug debug, const std::vector<T, Alloc> &vec)
|
2015-06-24 12:54:54 +00:00
|
|
|
{
|
|
|
|
return QtPrivate::printSequentialContainer(debug, "std::vector", vec);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, typename Alloc>
|
2020-07-06 11:08:40 +00:00
|
|
|
inline QDebugIfHasDebugStream<T> operator<<(QDebug debug, const std::list<T, Alloc> &vec)
|
2015-06-24 12:54:54 +00:00
|
|
|
{
|
|
|
|
return QtPrivate::printSequentialContainer(debug, "std::list", vec);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Key, typename T, typename Compare, typename Alloc>
|
2020-07-06 11:08:40 +00:00
|
|
|
inline QDebugIfHasDebugStream<Key, T> operator<<(QDebug debug, const std::map<Key, T, Compare, Alloc> &map)
|
2015-06-24 12:54:54 +00:00
|
|
|
{
|
|
|
|
return QtPrivate::printSequentialContainer(debug, "std::map", map); // yes, sequential: *it is std::pair
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Key, typename T, typename Compare, typename Alloc>
|
2020-07-06 11:08:40 +00:00
|
|
|
inline QDebugIfHasDebugStream<Key, T> operator<<(QDebug debug, const std::multimap<Key, T, Compare, Alloc> &map)
|
2015-06-24 12:54:54 +00:00
|
|
|
{
|
|
|
|
return QtPrivate::printSequentialContainer(debug, "std::multimap", map); // yes, sequential: *it is std::pair
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2015-06-24 13:25:11 +00:00
|
|
|
template <class Key, class T>
|
2020-07-06 11:08:40 +00:00
|
|
|
inline QDebugIfHasDebugStream<Key, T> operator<<(QDebug debug, const QMap<Key, T> &map)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2020-05-11 01:03:32 +00:00
|
|
|
return QtPrivate::printAssociativeContainer(debug, "QMap", map);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Key, class T>
|
2020-07-06 11:08:40 +00:00
|
|
|
inline QDebugIfHasDebugStream<Key, T> operator<<(QDebug debug, const QMultiMap<Key, T> &map)
|
2020-05-11 01:03:32 +00:00
|
|
|
{
|
|
|
|
return QtPrivate::printAssociativeContainer(debug, "QMultiMap", map);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2015-06-24 13:25:11 +00:00
|
|
|
template <class Key, class T>
|
2020-07-06 11:08:40 +00:00
|
|
|
inline QDebugIfHasDebugStream<Key, T> operator<<(QDebug debug, const QHash<Key, T> &hash)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2020-05-11 01:03:32 +00:00
|
|
|
return QtPrivate::printAssociativeContainer(debug, "QHash", hash);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Key, class T>
|
2020-07-06 11:08:40 +00:00
|
|
|
inline QDebugIfHasDebugStream<Key, T> operator<<(QDebug debug, const QMultiHash<Key, T> &hash)
|
2020-05-11 01:03:32 +00:00
|
|
|
{
|
|
|
|
return QtPrivate::printAssociativeContainer(debug, "QMultiHash", hash);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2015-06-24 12:54:54 +00:00
|
|
|
template <class T1, class T2>
|
2020-07-06 11:08:40 +00:00
|
|
|
inline QDebugIfHasDebugStream<T1, T2> operator<<(QDebug debug, const std::pair<T1, T2> &pair)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2020-05-11 01:09:46 +00:00
|
|
|
const QDebugStateSaver saver(debug);
|
2015-06-24 12:54:54 +00:00
|
|
|
debug.nospace() << "std::pair(" << pair.first << ',' << pair.second << ')';
|
2020-05-11 01:09:46 +00:00
|
|
|
return debug;
|
2015-06-24 12:54:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2020-07-06 11:08:40 +00:00
|
|
|
inline QDebugIfHasDebugStream<T> operator<<(QDebug debug, const QSet<T> &set)
|
2015-06-24 12:54:54 +00:00
|
|
|
{
|
|
|
|
return QtPrivate::printSequentialContainer(debug, "QSet", set);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
2020-07-06 11:08:40 +00:00
|
|
|
inline QDebugIfHasDebugStream<T> operator<<(QDebug debug, const QContiguousCache<T> &cache)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2020-05-11 01:09:46 +00:00
|
|
|
const QDebugStateSaver saver(debug);
|
2011-04-27 10:05:43 +00:00
|
|
|
debug.nospace() << "QContiguousCache(";
|
|
|
|
for (int i = cache.firstIndex(); i <= cache.lastIndex(); ++i) {
|
|
|
|
debug << cache[i];
|
|
|
|
if (i != cache.lastIndex())
|
|
|
|
debug << ", ";
|
|
|
|
}
|
|
|
|
debug << ')';
|
2020-05-11 01:09:46 +00:00
|
|
|
return debug;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2016-05-12 10:33:04 +00:00
|
|
|
template <class T>
|
|
|
|
inline QDebug operator<<(QDebug debug, const QSharedPointer<T> &ptr)
|
|
|
|
{
|
|
|
|
QDebugStateSaver saver(debug);
|
|
|
|
debug.nospace() << "QSharedPointer(" << ptr.data() << ")";
|
|
|
|
return debug;
|
|
|
|
}
|
|
|
|
|
2017-05-02 17:23:13 +00:00
|
|
|
template <typename T, typename Tag> class QTaggedPointer;
|
|
|
|
|
|
|
|
template <typename T, typename Tag>
|
|
|
|
inline QDebug operator<<(QDebug debug, const QTaggedPointer<T, Tag> &ptr)
|
|
|
|
{
|
|
|
|
QDebugStateSaver saver(debug);
|
|
|
|
debug.nospace() << "QTaggedPointer(" << ptr.pointer() << ", " << ptr.tag() << ")";
|
|
|
|
return debug;
|
|
|
|
}
|
|
|
|
|
2015-11-28 09:57:51 +00:00
|
|
|
Q_CORE_EXPORT void qt_QMetaEnum_flagDebugOperator(QDebug &debug, size_t sizeofT, int value);
|
|
|
|
|
|
|
|
template <typename Int>
|
|
|
|
void qt_QMetaEnum_flagDebugOperator(QDebug &debug, size_t sizeofT, Int value)
|
|
|
|
{
|
|
|
|
const QDebugStateSaver saver(debug);
|
|
|
|
debug.resetFormat();
|
2019-04-30 10:51:36 +00:00
|
|
|
debug.nospace() << "QFlags(" << Qt::hex << Qt::showbase;
|
2015-11-28 09:57:51 +00:00
|
|
|
bool needSeparator = false;
|
|
|
|
for (uint i = 0; i < sizeofT * 8; ++i) {
|
|
|
|
if (value & (Int(1) << i)) {
|
|
|
|
if (needSeparator)
|
|
|
|
debug << '|';
|
|
|
|
else
|
|
|
|
needSeparator = true;
|
|
|
|
debug << (Int(1) << i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
debug << ')';
|
|
|
|
}
|
|
|
|
|
2015-06-24 13:25:11 +00:00
|
|
|
#if !defined(QT_NO_QOBJECT) && !defined(Q_QDOC)
|
2020-07-06 17:59:51 +00:00
|
|
|
Q_CORE_EXPORT QDebug qt_QMetaEnum_debugOperator(QDebug&, qint64 value, const QMetaObject *meta, const char *name);
|
2015-02-17 10:25:36 +00:00
|
|
|
Q_CORE_EXPORT QDebug qt_QMetaEnum_flagDebugOperator(QDebug &dbg, quint64 value, const QMetaObject *meta, const char *name);
|
2015-02-16 14:25:46 +00:00
|
|
|
|
|
|
|
template<typename T>
|
2017-01-20 12:58:10 +00:00
|
|
|
typename std::enable_if<QtPrivate::IsQEnumHelper<T>::Value, QDebug>::type
|
2015-02-16 14:25:46 +00:00
|
|
|
operator<<(QDebug dbg, T value)
|
|
|
|
{
|
|
|
|
const QMetaObject *obj = qt_getEnumMetaObject(value);
|
|
|
|
const char *name = qt_getEnumName(value);
|
2020-07-06 17:59:51 +00:00
|
|
|
return qt_QMetaEnum_debugOperator(dbg, static_cast<typename std::underlying_type<T>::type>(value), obj, name);
|
2015-02-16 14:25:46 +00:00
|
|
|
}
|
|
|
|
|
2018-07-26 15:14:07 +00:00
|
|
|
template<typename T,
|
|
|
|
typename A = typename std::enable_if<std::is_enum<T>::value, void>::type,
|
|
|
|
typename B = typename std::enable_if<sizeof(T) <= sizeof(int), void>::type,
|
|
|
|
typename C = typename std::enable_if<!QtPrivate::IsQEnumHelper<T>::Value, void>::type,
|
|
|
|
typename D = typename std::enable_if<QtPrivate::IsQEnumHelper<QFlags<T>>::Value, void>::type>
|
|
|
|
inline QDebug operator<<(QDebug dbg, T value)
|
|
|
|
{
|
|
|
|
typedef QFlags<T> FlagsT;
|
|
|
|
const QMetaObject *obj = qt_getEnumMetaObject(FlagsT());
|
|
|
|
const char *name = qt_getEnumName(FlagsT());
|
|
|
|
return qt_QMetaEnum_debugOperator(dbg, typename FlagsT::Int(value), obj, name);
|
|
|
|
}
|
|
|
|
|
2015-02-17 10:25:36 +00:00
|
|
|
template <class T>
|
2017-01-20 12:58:10 +00:00
|
|
|
inline typename std::enable_if<
|
2015-03-14 11:41:10 +00:00
|
|
|
QtPrivate::IsQEnumHelper<T>::Value || QtPrivate::IsQEnumHelper<QFlags<T> >::Value,
|
2017-01-20 12:58:10 +00:00
|
|
|
QDebug>::type
|
2015-07-26 12:14:31 +00:00
|
|
|
qt_QMetaEnum_flagDebugOperator_helper(QDebug debug, const QFlags<T> &flags)
|
2015-02-17 10:25:36 +00:00
|
|
|
{
|
|
|
|
const QMetaObject *obj = qt_getEnumMetaObject(T());
|
|
|
|
const char *name = qt_getEnumName(T());
|
|
|
|
return qt_QMetaEnum_flagDebugOperator(debug, quint64(flags), obj, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
2017-01-20 12:58:10 +00:00
|
|
|
inline typename std::enable_if<
|
2015-03-14 11:41:10 +00:00
|
|
|
!QtPrivate::IsQEnumHelper<T>::Value && !QtPrivate::IsQEnumHelper<QFlags<T> >::Value,
|
2017-01-20 12:58:10 +00:00
|
|
|
QDebug>::type
|
2015-07-26 12:14:31 +00:00
|
|
|
qt_QMetaEnum_flagDebugOperator_helper(QDebug debug, const QFlags<T> &flags)
|
2015-06-24 13:25:11 +00:00
|
|
|
#else // !QT_NO_QOBJECT && !Q_QDOC
|
2011-04-27 10:05:43 +00:00
|
|
|
template <class T>
|
2015-07-26 12:14:31 +00:00
|
|
|
inline QDebug qt_QMetaEnum_flagDebugOperator_helper(QDebug debug, const QFlags<T> &flags)
|
2015-02-17 10:25:36 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2015-11-28 09:57:51 +00:00
|
|
|
qt_QMetaEnum_flagDebugOperator(debug, sizeof(T), typename QFlags<T>::Int(flags));
|
2014-06-20 13:35:34 +00:00
|
|
|
return debug;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2015-07-26 12:14:31 +00:00
|
|
|
template<typename T>
|
|
|
|
inline QDebug operator<<(QDebug debug, const QFlags<T> &flags)
|
|
|
|
{
|
|
|
|
// We have to use an indirection otherwise specialisation of some other overload of the
|
2017-01-20 12:58:10 +00:00
|
|
|
// operator<< the compiler would try to instantiate QFlags<T> for the std::enable_if
|
2015-07-26 12:14:31 +00:00
|
|
|
return qt_QMetaEnum_flagDebugOperator_helper(debug, flags);
|
|
|
|
}
|
|
|
|
|
Long live QKeyCombination!
C++20 via P1120 is deprecating arithmetic operations between
unrelated enumeration types, and GCC 10 is already complaining.
Hence, these operations might become illegal in C++23 or C++26 at
the latest.
A case of this that affects Qt is in key combinations: a
QKeySequence can be constructed by summing / ORing modifiers and a
key, for instance:
Qt::CTRL + Qt::Key_A
Qt::SHIFT | Qt::CTRL | Qt::Key_G (recommended, see below)
The problem is that the modifiers and the key belong to different
enumerations (and there's 2 enumerations for the modifier, and one
for the key).
To solve this: add a dedicated class to represent a combination of
keys, and operators between those enumerations to build instances
of this class.
I would've simply defined operator|, but again docs and pre-existing
code use operator+ as well, so added both to at least tackle simple
cases (modifier + key).
Multiple modifiers create a problem: operator+ between them yields
int, not the corresponding flags type (because operator+ is not
overloaded for this use case):
Qt::CTRL + Qt::SHIFT + Qt::Key_A
\__________________/ /
int /
\______________/
int
Not only this loses track of the datatypes involved, but it would
also then "add" the key (with NO warnings, now its int + enum, so
it's not mixing enums!) and yielding int again.
I don't want to special-case this; the point of the class is
that int is the wrong datatype. Everything works just fine when
using operator| instead:
Qt::CTRL | Qt::SHIFT | Qt::Key_A
\__________________/ /
Qt::Modifiers /
\______________/
QKeyCombination
So I'm defining operator+ so that the simple cases still work,
but also deprecating it.
Port some code around Qt to the new class. In certain cases,
it's a huge win for clarity. In some others, I've just added
the necessary casts to make it still compile without warnings,
without attempting refactorings.
[ChangeLog][QtCore][QKeyCombination] New class to represent
a combination of a key and zero or more modifiers, to be used
when defining shortcuts or similar.
[ChangeLog][Potentially Source-Incompatible Changes] A keyboard
modifier (such as Qt::CTRL, Qt::AltModifier, etc.) should be
combined with a key (such as Qt::Key_A, Qt::Key_F1, etc.) by using
operator|, not operator+. The result is now an object of type
QKeyCombination, that stores the key and the modifiers.
Change-Id: I657a3a328232f059023fff69c5031ee31cc91dd6
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2020-04-19 17:56:18 +00:00
|
|
|
inline QDebug operator<<(QDebug debug, QKeyCombination combination)
|
|
|
|
{
|
|
|
|
QDebugStateSaver saver(debug);
|
|
|
|
debug.nospace() << "QKeyCombination("
|
|
|
|
<< combination.keyboardModifiers()
|
|
|
|
<< ", "
|
|
|
|
<< combination.key()
|
|
|
|
<< ")";
|
|
|
|
return debug;
|
|
|
|
}
|
|
|
|
|
2014-11-10 10:17:28 +00:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
|
|
|
|
// We provide QDebug stream operators for commonly used Core Foundation
|
|
|
|
// and Core Graphics types, as well as NSObject. Additional CF/CG types
|
|
|
|
// may be added by the user, using Q_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE.
|
|
|
|
|
|
|
|
#define QT_FOR_EACH_CORE_FOUNDATION_TYPE(F) \
|
|
|
|
F(CFArray) \
|
|
|
|
F(CFURL) \
|
|
|
|
F(CFData) \
|
|
|
|
F(CFNumber) \
|
|
|
|
F(CFDictionary) \
|
|
|
|
F(CFLocale) \
|
|
|
|
F(CFDate) \
|
|
|
|
F(CFBoolean) \
|
|
|
|
F(CFTimeZone) \
|
|
|
|
|
|
|
|
#define QT_FOR_EACH_MUTABLE_CORE_FOUNDATION_TYPE(F) \
|
|
|
|
F(CFError) \
|
|
|
|
F(CFBundle) \
|
|
|
|
|
|
|
|
#define QT_FOR_EACH_CORE_GRAPHICS_TYPE(F) \
|
|
|
|
F(CGPath) \
|
|
|
|
|
|
|
|
#define QT_FOR_EACH_MUTABLE_CORE_GRAPHICS_TYPE(F) \
|
|
|
|
F(CGColorSpace) \
|
|
|
|
F(CGImage) \
|
|
|
|
F(CGFont) \
|
|
|
|
F(CGColor) \
|
|
|
|
|
|
|
|
#define QT_FORWARD_DECLARE_CF_TYPE(type) Q_FORWARD_DECLARE_CF_TYPE(type);
|
|
|
|
#define QT_FORWARD_DECLARE_MUTABLE_CF_TYPE(type) Q_FORWARD_DECLARE_MUTABLE_CF_TYPE(type);
|
2015-11-02 09:49:17 +00:00
|
|
|
#define QT_FORWARD_DECLARE_CG_TYPE(type) Q_FORWARD_DECLARE_CG_TYPE(type);
|
|
|
|
#define QT_FORWARD_DECLARE_MUTABLE_CG_TYPE(type) Q_FORWARD_DECLARE_MUTABLE_CG_TYPE(type);
|
2014-11-10 10:17:28 +00:00
|
|
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
Q_FORWARD_DECLARE_CF_TYPE(CFString);
|
|
|
|
Q_FORWARD_DECLARE_OBJC_CLASS(NSObject);
|
2015-03-14 19:56:42 +00:00
|
|
|
QT_FOR_EACH_CORE_FOUNDATION_TYPE(QT_FORWARD_DECLARE_CF_TYPE)
|
|
|
|
QT_FOR_EACH_MUTABLE_CORE_FOUNDATION_TYPE(QT_FORWARD_DECLARE_MUTABLE_CF_TYPE)
|
|
|
|
QT_FOR_EACH_CORE_GRAPHICS_TYPE(QT_FORWARD_DECLARE_CG_TYPE)
|
|
|
|
QT_FOR_EACH_MUTABLE_CORE_GRAPHICS_TYPE(QT_FORWARD_DECLARE_MUTABLE_CG_TYPE)
|
2014-11-10 10:17:28 +00:00
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
|
|
|
#define QT_FORWARD_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE(CFType) \
|
|
|
|
Q_CORE_EXPORT QDebug operator<<(QDebug, CFType##Ref);
|
|
|
|
|
|
|
|
#define Q_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE(CFType) \
|
|
|
|
QDebug operator<<(QDebug debug, CFType##Ref ref) \
|
|
|
|
{ \
|
|
|
|
if (!ref) \
|
|
|
|
return debug << QT_STRINGIFY(CFType) "Ref(0x0)"; \
|
|
|
|
if (CFStringRef description = CFCopyDescription(ref)) { \
|
|
|
|
QDebugStateSaver saver(debug); \
|
|
|
|
debug.noquote() << description; \
|
|
|
|
CFRelease(description); \
|
|
|
|
} \
|
|
|
|
return debug; \
|
|
|
|
}
|
|
|
|
|
|
|
|
// Defined in qcore_mac_objc.mm
|
|
|
|
Q_CORE_EXPORT QDebug operator<<(QDebug, const NSObject *);
|
|
|
|
Q_CORE_EXPORT QDebug operator<<(QDebug, CFStringRef);
|
|
|
|
|
2015-03-14 19:56:42 +00:00
|
|
|
QT_FOR_EACH_CORE_FOUNDATION_TYPE(QT_FORWARD_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE)
|
|
|
|
QT_FOR_EACH_MUTABLE_CORE_FOUNDATION_TYPE(QT_FORWARD_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE)
|
|
|
|
QT_FOR_EACH_CORE_GRAPHICS_TYPE(QT_FORWARD_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE)
|
|
|
|
QT_FOR_EACH_MUTABLE_CORE_GRAPHICS_TYPE(QT_FORWARD_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE)
|
2014-11-10 10:17:28 +00:00
|
|
|
|
|
|
|
#undef QT_FORWARD_DECLARE_CF_TYPE
|
|
|
|
#undef QT_FORWARD_DECLARE_MUTABLE_CF_TYPE
|
|
|
|
#undef QT_FORWARD_DECLARE_CG_TYPE
|
|
|
|
#undef QT_FORWARD_DECLARE_MUTABLE_CG_TYPE
|
|
|
|
|
|
|
|
#endif // Q_OS_MAC
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
#endif // QDEBUG_H
|