blob: 86aeabada77e51b9f32279fa9e96ca892a651f30 (
plain)
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
|
/* This file is part of the KDE project.
Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
This library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 or 3 of the License.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OBJECTDUMP_H
#define OBJECTDUMP_H
#include <QObject>
#include <QList>
#include <QByteArray>
#include <QScopedPointer>
QT_BEGIN_NAMESPACE
namespace ObjectDump
{
/**
* Abstract base for annotator classes invoked by QVisitor.
*/
class QAnnotator : public QObject
{
Q_OBJECT
public:
virtual ~QAnnotator();
virtual QList<QByteArray> annotation(const QObject& object) = 0;
};
/**
* Annotator which replicates QObject::dumpObjectTree functionality.
*/
class QAnnotatorBasic : public QAnnotator
{
Q_OBJECT
public:
QList<QByteArray> annotation(const QObject& object);
};
/**
* Annotator which returns widget information.
*/
class QAnnotatorWidget : public QAnnotator
{
Q_OBJECT
public:
QList<QByteArray> annotation(const QObject& object);
};
class QDumperPrivate;
/**
* Class used to dump information about individual QObjects.
*/
class QDumper : public QObject
{
Q_OBJECT
Q_DECLARE_PRIVATE(QDumper)
public:
QDumper();
~QDumper();
/**
* Specify a prefix, to be printed on each line of output.
*/
void setPrefix(const QString& prefix);
/**
* Takes ownership of annotator.
*/
void addAnnotator(QAnnotator* annotator);
/**
* Invoke each annotator on the object and write to debug output.
*/
void dumpObject(const QObject& object);
private:
QScopedPointer<QDumperPrivate> d_ptr;
};
class QVisitorPrivate;
/**
* Visitor class which dumps information about nodes in the object tree.
*/
class QVisitor : public QObject
{
Q_OBJECT
Q_DECLARE_PRIVATE(QVisitor)
public:
QVisitor();
~QVisitor();
/**
* Specify a prefix, to be printed on each line of output.
*/
void setPrefix(const QString& prefix);
/**
* Set number of spaces by which each level of the tree is indented.
*/
void setIndent(unsigned indent);
/**
* Called by the visitor algorithm before starting the visit.
*/
void visitPrepare();
/**
* Called by the visitor algorithm as each node is visited.
*/
void visitNode(const QObject& object);
/**
* Called by the visitor algorithm when the visit is complete.
*/
void visitComplete();
/**
* Takes ownership of annotator.
*/
void addAnnotator(QAnnotator* annotator);
private:
QScopedPointer<QVisitorPrivate> d_ptr;
};
//-----------------------------------------------------------------------------
// Utility functions
//-----------------------------------------------------------------------------
void addDefaultAnnotators(QDumper& dumper);
void addDefaultAnnotators(QVisitor& visitor);
void dumpTreeFromRoot(const QObject& root, QVisitor& visitor);
void dumpTreeFromLeaf(const QObject& leaf, QVisitor& visitor);
void dumpAncestors(const QObject& leaf, QVisitor& visitor);
} // namespace ObjectDump
QT_END_NAMESPACE
#endif
|