1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
// Copyright (C) 2020 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include "metaobjectdump.h"
#include <QMetaMethod>
#include <QMetaObject>
#include <QTextStream>
QT_USE_NAMESPACE
using rightAlignNumber = QPair<int, int>; // Use as str << rightAlignNumber(value, width)
QTextStream &operator<<(QTextStream &str, const rightAlignNumber &r)
{
auto oldWidth = str.fieldWidth();
str.setFieldWidth(r.second);
auto oldAlignment = str.fieldAlignment();
str.setFieldAlignment(QTextStream::AlignRight);
str << r.first;
str.setFieldAlignment(oldAlignment);
str.setFieldWidth(oldWidth);
return str;
}
QTextStream &operator<<(QTextStream &str, const QMetaEnum &me)
{
const int keyCount = me.keyCount();
str << me.name() << ' ' << keyCount << " keys";
if (me.isFlag())
str << " [flag]";
if (me.isScoped())
str << " [scoped]";
const int maxLogCount = std::min(6, keyCount);
str << " {";
for (int k = 0; k < maxLogCount; ++k) {
if (k)
str << ", ";
str << me.key(k) << " = " << me.value(k);
}
if (maxLogCount < keyCount)
str << ",...";
str << '}';
return str;
}
QTextStream &operator<<(QTextStream &str, const QMetaClassInfo &mc)
{
str << '"' << mc.name() << "\": \"" << mc.value() << '"';
return str;
}
QTextStream &operator<<(QTextStream &str, const QMetaProperty &mp)
{
str << mp.typeName() << ' ' << mp.name();
if (mp.isWritable())
str << " [writable]";
if (mp.isResettable())
str << " [resettable]";
if (mp.isDesignable())
str << " [designable]";
if (mp.isStored())
str << " [stored]";
if (mp.isUser())
str << " [user]";
if (mp.isConstant())
str << " [constant]";
if (mp.isFinal())
str << " [final]";
if (mp.isRequired())
str << " [required]";
if (mp.isFlagType())
str << " [flag]";
if (mp.isEnumType())
str << " [enum " << mp.enumerator().name() << ']';
if (mp.hasNotifySignal())
str << " [notify " << mp.notifySignal().name() << ']';
return str;
}
QTextStream &operator<<(QTextStream &str, const QMetaMethod &m)
{
switch (m.access()) {
case QMetaMethod::Private:
str << "private ";
break;
case QMetaMethod::Protected:
str << "protected ";
break;
case QMetaMethod::Public:
break;
}
str << m.typeName() << ' ' << m.methodSignature();
switch (m.methodType()) {
case QMetaMethod::Method:
break;
case QMetaMethod::Signal:
str << " [signal]";
break;
case QMetaMethod::Slot:
str << " [slot]";
break;
case QMetaMethod::Constructor:
str << " [ct]";
break;
}
if (auto attributes = m.attributes()) {
str << " attributes: " << Qt::hex << Qt::showbase << attributes
<< Qt::dec << Qt::noshowbase;
}
if (const int count = m.parameterCount()) {
str << " Parameters: ";
const auto parameterNames = m.parameterNames();
const auto parameterTypes = m.parameterTypes();
for (int p = 0; p < count; ++p) {
if (p)
str << ", ";
str << parameterTypes.at(p) << ' ' << parameterNames.at(p);
}
}
return str;
}
static void formatMetaObject(QTextStream &str, const QMetaObject *mo, const QByteArray &indent)
{
str << indent << "--- " << mo->className() << " ---\n";
const int classInfoOffset = mo->classInfoOffset();
const int classInfoCount = mo->classInfoCount();
if (classInfoOffset < classInfoCount) {
str << indent << " Class Info of " << mo->className() << ": "
<< classInfoOffset << ".." << classInfoCount << '\n';
for (int i = classInfoOffset; i < classInfoCount; ++i) {
str << indent << " " << rightAlignNumber(i, 3) << ' '
<< mo->classInfo(i) << '\n';
}
}
const int enumOffset = mo->enumeratorOffset();
const int enumCount = mo->enumeratorCount();
if (enumOffset < enumCount) {
str << indent << " Enums of " << mo->className() << ": " << enumOffset
<< ".." << enumCount << '\n';
for (int e = enumOffset; e < enumCount; ++e)
str << indent << " " << rightAlignNumber(e, 3) << ' ' << mo->enumerator(e) << '\n';
}
const int methodOffset = mo->methodOffset();
const int methodCount = mo->methodCount();
if (methodOffset < methodCount) {
str << indent << " Methods of " << mo->className() << ": " << methodOffset
<< ".." << methodCount << '\n';
for (int m = methodOffset; m < methodCount; ++m)
str << indent << " " << rightAlignNumber(m, 3) << ' ' << mo->method(m) << '\n';
}
const int propertyOffset = mo->propertyOffset();
const int propertyCount = mo-> propertyCount();
if (propertyOffset < propertyCount) {
str << indent << " Properties of " << mo->className() << ": " << propertyOffset
<< ".." << propertyCount << '\n';
for (int p = propertyOffset; p < propertyCount; ++p)
str << indent << " " << rightAlignNumber(p, 3) << ' ' << mo->property(p) << '\n';
}
}
QTextStream &operator<<(QTextStream &str, const QMetaObject &o)
{
QList<const QMetaObject *> klasses;
for (auto s = &o; s; s = s->superClass())
klasses.prepend(s);
QByteArray indent;
for (auto k : klasses) {
formatMetaObject(str, k, indent);
indent += " ";
}
return str;
}
|