0
|
1 |
/* This file is part of the KDE project.
|
|
2 |
|
|
3 |
Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
|
|
5 |
This library is free software: you can redistribute it and/or modify
|
|
6 |
it under the terms of the GNU Lesser General Public License as published by
|
|
7 |
the Free Software Foundation, either version 2.1 or 3 of the License.
|
|
8 |
|
|
9 |
This library is distributed in the hope that it will be useful,
|
|
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
GNU Lesser General Public License for more details.
|
|
13 |
|
|
14 |
You should have received a copy of the GNU Lesser General Public License
|
|
15 |
along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
16 |
|
|
17 |
*/
|
|
18 |
|
|
19 |
#ifndef OBJECTDUMP_H
|
|
20 |
#define OBJECTDUMP_H
|
|
21 |
|
|
22 |
#include "objectdump_global.h"
|
|
23 |
|
|
24 |
#include <QObject>
|
|
25 |
#include <QList>
|
|
26 |
#include <QByteArray>
|
|
27 |
#include <QScopedPointer>
|
|
28 |
|
|
29 |
QT_BEGIN_NAMESPACE
|
|
30 |
|
|
31 |
namespace ObjectDump
|
|
32 |
{
|
|
33 |
|
|
34 |
/**
|
|
35 |
* Abstract base for annotator classes invoked by QVisitor.
|
|
36 |
*/
|
|
37 |
class OBJECTDUMP_EXPORT QAnnotator : public QObject
|
|
38 |
{
|
|
39 |
Q_OBJECT
|
|
40 |
public:
|
|
41 |
virtual ~QAnnotator();
|
|
42 |
virtual QList<QByteArray> annotation(const QObject& object) = 0;
|
|
43 |
};
|
|
44 |
|
|
45 |
/**
|
|
46 |
* Annotator which replicates QObject::dumpObjectTree functionality.
|
|
47 |
*/
|
|
48 |
class OBJECTDUMP_EXPORT QAnnotatorBasic : public QAnnotator
|
|
49 |
{
|
|
50 |
Q_OBJECT
|
|
51 |
public:
|
|
52 |
QList<QByteArray> annotation(const QObject& object);
|
|
53 |
};
|
|
54 |
|
|
55 |
/**
|
|
56 |
* Annotator which returns widget information.
|
|
57 |
*/
|
|
58 |
class OBJECTDUMP_EXPORT QAnnotatorWidget : public QAnnotator
|
|
59 |
{
|
|
60 |
Q_OBJECT
|
|
61 |
public:
|
|
62 |
QList<QByteArray> annotation(const QObject& object);
|
|
63 |
};
|
|
64 |
|
|
65 |
|
|
66 |
class QDumperPrivate;
|
|
67 |
|
|
68 |
/**
|
|
69 |
* Class used to dump information about individual QObjects.
|
|
70 |
*/
|
|
71 |
class OBJECTDUMP_EXPORT QDumper : public QObject
|
|
72 |
{
|
|
73 |
Q_OBJECT
|
|
74 |
Q_DECLARE_PRIVATE(QDumper)
|
|
75 |
|
|
76 |
public:
|
|
77 |
QDumper();
|
|
78 |
~QDumper();
|
|
79 |
|
|
80 |
/**
|
|
81 |
* Specify a prefix, to be printed on each line of output.
|
|
82 |
*/
|
|
83 |
void setPrefix(const QString& prefix);
|
|
84 |
|
|
85 |
/**
|
|
86 |
* Takes ownership of annotator.
|
|
87 |
*/
|
|
88 |
void addAnnotator(QAnnotator* annotator);
|
|
89 |
|
|
90 |
/**
|
|
91 |
* Invoke each annotator on the object and write to debug output.
|
|
92 |
*/
|
|
93 |
void dumpObject(const QObject& object);
|
|
94 |
|
|
95 |
private:
|
|
96 |
QScopedPointer<QDumperPrivate> d_ptr;
|
|
97 |
|
|
98 |
};
|
|
99 |
|
|
100 |
|
|
101 |
class QVisitorPrivate;
|
|
102 |
|
|
103 |
/**
|
|
104 |
* Visitor class which dumps information about nodes in the object tree.
|
|
105 |
*/
|
|
106 |
class OBJECTDUMP_EXPORT QVisitor : public QObject
|
|
107 |
{
|
|
108 |
Q_OBJECT
|
|
109 |
Q_DECLARE_PRIVATE(QVisitor)
|
|
110 |
|
|
111 |
public:
|
|
112 |
QVisitor();
|
|
113 |
~QVisitor();
|
|
114 |
|
|
115 |
/**
|
|
116 |
* Specify a prefix, to be printed on each line of output.
|
|
117 |
*/
|
|
118 |
void setPrefix(const QString& prefix);
|
|
119 |
|
|
120 |
/**
|
|
121 |
* Set number of spaces by which each level of the tree is indented.
|
|
122 |
*/
|
|
123 |
void setIndent(unsigned indent);
|
|
124 |
|
|
125 |
/**
|
|
126 |
* Called by the visitor algorithm before starting the visit.
|
|
127 |
*/
|
|
128 |
void visitPrepare();
|
|
129 |
|
|
130 |
/**
|
|
131 |
* Called by the visitor algorithm as each node is visited.
|
|
132 |
*/
|
|
133 |
void visitNode(const QObject& object);
|
|
134 |
|
|
135 |
/**
|
|
136 |
* Called by the visitor algorithm when the visit is complete.
|
|
137 |
*/
|
|
138 |
void visitComplete();
|
|
139 |
|
|
140 |
/**
|
|
141 |
* Takes ownership of annotator.
|
|
142 |
*/
|
|
143 |
void addAnnotator(QAnnotator* annotator);
|
|
144 |
|
|
145 |
private:
|
|
146 |
QScopedPointer<QVisitorPrivate> d_ptr;
|
|
147 |
|
|
148 |
};
|
|
149 |
|
|
150 |
|
|
151 |
//-----------------------------------------------------------------------------
|
|
152 |
// Utility functions
|
|
153 |
//-----------------------------------------------------------------------------
|
|
154 |
|
|
155 |
void OBJECTDUMP_EXPORT addDefaultAnnotators(QDumper& dumper);
|
|
156 |
void OBJECTDUMP_EXPORT addDefaultAnnotators(QVisitor& visitor);
|
|
157 |
|
|
158 |
void OBJECTDUMP_EXPORT dumpTreeFromRoot(const QObject& root, QVisitor& visitor);
|
|
159 |
void OBJECTDUMP_EXPORT dumpTreeFromLeaf(const QObject& leaf, QVisitor& visitor);
|
|
160 |
void OBJECTDUMP_EXPORT dumpAncestors(const QObject& leaf, QVisitor& visitor);
|
|
161 |
|
|
162 |
} // namespace ObjectDump
|
|
163 |
|
|
164 |
QT_END_NAMESPACE
|
|
165 |
|
|
166 |
#endif
|