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 | |
24 | QT_BEGIN_NAMESPACE |
25 | |
26 | namespace QtDebugUtils { |
27 | |
28 | Q_CORE_EXPORT QByteArray toPrintable(const char *data, qint64 len, qsizetype maxSize); |
29 | |
30 | // inline helpers for formatting basic classes. |
31 | |
32 | template <class Point> |
33 | static inline void formatQPoint(QDebug &debug, const Point &point) |
34 | { |
35 | debug << point.x() << ',' << point.y(); |
36 | } |
37 | |
38 | template <class Size> |
39 | static inline void formatQSize(QDebug &debug, const Size &size) |
40 | { |
41 | debug << size.width() << ", " << size.height(); |
42 | } |
43 | |
44 | template <class Rect> |
45 | static inline void formatQRect(QDebug &debug, const Rect &rect) |
46 | { |
47 | debug << rect.x() << ',' << rect.y() << ' ' << rect.width() << 'x' << rect.height(); |
48 | } |
49 | |
50 | template <class Margins> |
51 | static 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 |
58 | template <class QEnum> |
59 | static inline void formatQEnum(QDebug &debug, QEnum value) |
60 | { |
61 | const QMetaObject *metaObject = qt_getEnumMetaObject(value); |
62 | const QMetaEnum me = metaObject->enumerator(index: metaObject->indexOfEnumerator(name: qt_getEnumName(value))); |
63 | if (const char *key = me.valueToKey(value: int(value))) |
64 | debug << key; |
65 | else |
66 | debug << int(value); |
67 | } |
68 | |
69 | template <class QEnum> |
70 | static inline void formatNonNullQEnum(QDebug &debug, const char *prefix, QEnum value) |
71 | { |
72 | if (value) { |
73 | debug << prefix; |
74 | formatQEnum(debug, value); |
75 | } |
76 | } |
77 | |
78 | template <class Enum> |
79 | static 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: value.toInt()); |
85 | } |
86 | |
87 | template <class Enum> |
88 | static 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 | |
100 | QT_END_NAMESPACE |
101 | |
102 | #endif // QDEBUG_P_H |
103 | |