Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qdebug_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QDEBUG_P_H
5#define QDEBUG_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of other Qt classes. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/private/qglobal_p.h>
19#include "QtCore/qdebug.h"
20#include "QtCore/qmetaobject.h"
21#include "QtCore/qflags.h"
22#include "QtCore/qbytearray.h"
23
24QT_BEGIN_NAMESPACE
25
26namespace QtDebugUtils {
27
28Q_CORE_EXPORT QByteArray toPrintable(const char *data, qint64 len, qsizetype maxSize);
29
30// inline helpers for formatting basic classes.
31
32template <class Point>
33static inline void formatQPoint(QDebug &debug, const Point &point)
34{
35 debug << point.x() << ',' << point.y();
36}
37
38template <class Size>
39static inline void formatQSize(QDebug &debug, const Size &size)
40{
41 debug << size.width() << ", " << size.height();
42}
43
44template <class Rect>
45static inline void formatQRect(QDebug &debug, const Rect &rect)
46{
47 debug << rect.x() << ',' << rect.y() << ' ' << rect.width() << 'x' << rect.height();
48}
49
50template <class Margins>
51static inline void formatQMargins(QDebug &debug, const Margins &margins)
52{
53 debug << margins.left() << ", " << margins.top() << ", " << margins.right()
54 << ", " << margins.bottom();
55}
56
57#ifndef QT_NO_QOBJECT
58template <class QEnum>
59static inline void formatQEnum(QDebug &debug, QEnum value)
60{
61 const QMetaObject *metaObject = qt_getEnumMetaObject(value);
62 const QMetaEnum me = metaObject->enumerator(metaObject->indexOfEnumerator(qt_getEnumName(value)));
63 if (const char *key = me.valueToKey(int(value)))
64 debug << key;
65 else
66 debug << int(value);
67}
68
69template <class QEnum>
70static inline void formatNonNullQEnum(QDebug &debug, const char *prefix, QEnum value)
71{
72 if (value) {
73 debug << prefix;
74 formatQEnum(debug, value);
75 }
76}
77
78template <class Enum>
79static inline void formatQFlags(QDebug &debug, const QFlags<Enum> &value)
80{
81 const QMetaEnum me = QMetaEnum::fromType<QFlags<Enum>>();
82 const QDebugStateSaver saver(debug);
83 debug.noquote();
84 debug << me.valueToKeys(value.toInt());
85}
86
87template <class Enum>
88static inline void formatNonNullQFlags(QDebug &debug, const char *prefix, const QFlags<Enum> &value)
89{
90 if (value) {
91 debug << prefix;
92 formatQFlags(debug, value);
93 }
94}
95
96#endif // !QT_NO_QOBJECT
97
98} // namespace QtDebugUtils
99
100QT_END_NAMESPACE
101
102#endif // QDEBUG_P_H
static void formatNonNullQEnum(QDebug &debug, const char *prefix, QEnum value)
Definition qdebug_p.h:70
static void formatQEnum(QDebug &debug, QEnum value)
Definition qdebug_p.h:59
static void formatQRect(QDebug &debug, const Rect &rect)
Definition qdebug_p.h:45
static void formatQMargins(QDebug &debug, const Margins &margins)
Definition qdebug_p.h:51
static void formatQFlags(QDebug &debug, const QFlags< Enum > &value)
Definition qdebug_p.h:79
static void formatQSize(QDebug &debug, const Size &size)
Definition qdebug_p.h:39
static void formatQPoint(QDebug &debug, const Point &point)
Definition qdebug_p.h:33
static void formatNonNullQFlags(QDebug &debug, const char *prefix, const QFlags< Enum > &value)
Definition qdebug_p.h:88