1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 #ifndef QDECLARATIVEENGINEDEBUG_H
42 #define QDECLARATIVEENGINEDEBUG_H
43 
44 #include <QtCore/qobject.h>
45 #include <QtCore/qurl.h>
46 #include <QtCore/qvariant.h>
47 
48 #include <private/qdeclarativeglobal_p.h>
49 
50 QT_BEGIN_HEADER
51 
52 QT_BEGIN_NAMESPACE
53 
54 QT_MODULE(Declarative)
55 
56 class QDeclarativeDebugConnection;
57 class QDeclarativeDebugWatch;
58 class QDeclarativeDebugPropertyWatch;
59 class QDeclarativeDebugObjectExpressionWatch;
60 class QDeclarativeDebugEnginesQuery;
61 class QDeclarativeDebugRootContextQuery;
62 class QDeclarativeDebugObjectQuery;
63 class QDeclarativeDebugExpressionQuery;
64 class QDeclarativeDebugPropertyReference;
65 class QDeclarativeDebugContextReference;
66 class QDeclarativeDebugObjectReference;
67 class QDeclarativeDebugFileReference;
68 class QDeclarativeDebugEngineReference;
69 class QDeclarativeEngineDebugPrivate;
70 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeEngineDebug : public QObject
71 {
72 Q_OBJECT
73 public:
74     enum Status { NotConnected, Unavailable, Enabled };
75 
76     explicit QDeclarativeEngineDebug(QDeclarativeDebugConnection *, QObject * = 0);
77 
78     Status status() const;
79 
80     QDeclarativeDebugPropertyWatch *addWatch(const QDeclarativeDebugPropertyReference &,
81                             QObject *parent = 0);
82     QDeclarativeDebugWatch *addWatch(const QDeclarativeDebugContextReference &, const QString &,
83                             QObject *parent = 0);
84     QDeclarativeDebugObjectExpressionWatch *addWatch(const QDeclarativeDebugObjectReference &, const QString &,
85                             QObject *parent = 0);
86     QDeclarativeDebugWatch *addWatch(const QDeclarativeDebugObjectReference &,
87                             QObject *parent = 0);
88     QDeclarativeDebugWatch *addWatch(const QDeclarativeDebugFileReference &,
89                             QObject *parent = 0);
90 
91     void removeWatch(QDeclarativeDebugWatch *watch);
92 
93     QDeclarativeDebugEnginesQuery *queryAvailableEngines(QObject *parent = 0);
94     QDeclarativeDebugRootContextQuery *queryRootContexts(const QDeclarativeDebugEngineReference &,
95                                                 QObject *parent = 0);
96     QDeclarativeDebugObjectQuery *queryObject(const QDeclarativeDebugObjectReference &,
97                                      QObject *parent = 0);
98     QDeclarativeDebugObjectQuery *queryObjectRecursive(const QDeclarativeDebugObjectReference &,
99                                               QObject *parent = 0);
100     QDeclarativeDebugExpressionQuery *queryExpressionResult(int objectDebugId,
101                                                    const QString &expr,
102                                                    QObject *parent = 0);
103     bool setBindingForObject(int objectDebugId, const QString &propertyName,
104                              const QVariant &bindingExpression, bool isLiteralValue,
105                              QString source = QString(), int line = -1);
106     bool resetBindingForObject(int objectDebugId, const QString &propertyName);
107     bool setMethodBody(int objectDebugId, const QString &methodName, const QString &methodBody);
108 
109 Q_SIGNALS:
110     void newObjects();
111     void statusChanged(Status status);
112 
113 private:
114     Q_DECLARE_PRIVATE(QDeclarativeEngineDebug)
115 };
116 
117 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugWatch : public QObject
118 {
119 Q_OBJECT
120 public:
121     enum State { Waiting, Active, Inactive, Dead };
122 
123     QDeclarativeDebugWatch(QObject *);
124     ~QDeclarativeDebugWatch();
125 
126     int queryId() const;
127     int objectDebugId() const;
128     State state() const;
129 
130 Q_SIGNALS:
131     void stateChanged(QDeclarativeDebugWatch::State);
132     //void objectChanged(int, const QDeclarativeDebugObjectReference &);
133     //void valueChanged(int, const QVariant &);
134 
135     // Server sends value as string if it is a user-type variant
136     void valueChanged(const QByteArray &name, const QVariant &value);
137 
138 private:
139     friend class QDeclarativeEngineDebug;
140     friend class QDeclarativeEngineDebugPrivate;
141     void setState(State);
142     State m_state;
143     int m_queryId;
144     QDeclarativeEngineDebug *m_client;
145     int m_objectDebugId;
146 };
147 
148 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugPropertyWatch : public QDeclarativeDebugWatch
149 {
150     Q_OBJECT
151 public:
152     QDeclarativeDebugPropertyWatch(QObject *parent);
153 
154     QString name() const;
155 
156 private:
157     friend class QDeclarativeEngineDebug;
158     QString m_name;
159 };
160 
161 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugObjectExpressionWatch : public QDeclarativeDebugWatch
162 {
163     Q_OBJECT
164 public:
165     QDeclarativeDebugObjectExpressionWatch(QObject *parent);
166 
167     QString expression() const;
168 
169 private:
170     friend class QDeclarativeEngineDebug;
171     QString m_expr;
172     int m_debugId;
173 };
174 
175 
176 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugQuery : public QObject
177 {
178 Q_OBJECT
179 public:
180     enum State { Waiting, Error, Completed };
181 
182     State state() const;
183     bool isWaiting() const;
184 
185 //    bool waitUntilCompleted();
186 
187 Q_SIGNALS:
188     void stateChanged(QDeclarativeDebugQuery::State);
189 
190 protected:
191     QDeclarativeDebugQuery(QObject *);
192 
193 private:
194     friend class QDeclarativeEngineDebug;
195     friend class QDeclarativeEngineDebugPrivate;
196     void setState(State);
197     State m_state;
198 };
199 
200 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugFileReference
201 {
202 public:
203     QDeclarativeDebugFileReference();
204     QDeclarativeDebugFileReference(const QDeclarativeDebugFileReference &);
205     QDeclarativeDebugFileReference &operator=(const QDeclarativeDebugFileReference &);
206 
207     QUrl url() const;
208     void setUrl(const QUrl &);
209     int lineNumber() const;
210     void setLineNumber(int);
211     int columnNumber() const;
212     void setColumnNumber(int);
213 
214 private:
215     friend class QDeclarativeEngineDebugPrivate;
216     QUrl m_url;
217     int m_lineNumber;
218     int m_columnNumber;
219 };
220 
221 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugEngineReference
222 {
223 public:
224     QDeclarativeDebugEngineReference();
225     QDeclarativeDebugEngineReference(int);
226     QDeclarativeDebugEngineReference(const QDeclarativeDebugEngineReference &);
227     QDeclarativeDebugEngineReference &operator=(const QDeclarativeDebugEngineReference &);
228 
229     int debugId() const;
230     QString name() const;
231 
232 private:
233     friend class QDeclarativeEngineDebugPrivate;
234     int m_debugId;
235     QString m_name;
236 };
237 
238 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugObjectReference
239 {
240 public:
241     QDeclarativeDebugObjectReference();
242     QDeclarativeDebugObjectReference(int);
243     QDeclarativeDebugObjectReference(const QDeclarativeDebugObjectReference &);
244     QDeclarativeDebugObjectReference &operator=(const QDeclarativeDebugObjectReference &);
245 
246     int debugId() const;
247     int parentId() const;
248     QString className() const;
249     QString idString() const;
250     QString name() const;
251 
252     QDeclarativeDebugFileReference source() const;
253     int contextDebugId() const;
254     bool needsMoreData() const;
255 
256     QList<QDeclarativeDebugPropertyReference> properties() const;
257     QList<QDeclarativeDebugObjectReference> children() const;
258 
259 private:
260     friend class QDeclarativeEngineDebugPrivate;
261     int m_debugId;
262     int m_parentId;
263     QString m_class;
264     QString m_idString;
265     QString m_name;
266     QDeclarativeDebugFileReference m_source;
267     int m_contextDebugId;
268     bool m_needsMoreData;
269     QList<QDeclarativeDebugPropertyReference> m_properties;
270     QList<QDeclarativeDebugObjectReference> m_children;
271 };
272 
273 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugContextReference
274 {
275 public:
276     QDeclarativeDebugContextReference();
277     QDeclarativeDebugContextReference(const QDeclarativeDebugContextReference &);
278     QDeclarativeDebugContextReference &operator=(const QDeclarativeDebugContextReference &);
279 
280     int debugId() const;
281     QString name() const;
282 
283     QList<QDeclarativeDebugObjectReference> objects() const;
284     QList<QDeclarativeDebugContextReference> contexts() const;
285 
286 private:
287     friend class QDeclarativeEngineDebugPrivate;
288     int m_debugId;
289     QString m_name;
290     QList<QDeclarativeDebugObjectReference> m_objects;
291     QList<QDeclarativeDebugContextReference> m_contexts;
292 };
293 
294 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugPropertyReference
295 {
296 public:
297     QDeclarativeDebugPropertyReference();
298     QDeclarativeDebugPropertyReference(const QDeclarativeDebugPropertyReference &);
299     QDeclarativeDebugPropertyReference &operator=(const QDeclarativeDebugPropertyReference &);
300 
301     int objectDebugId() const;
302     QString name() const;
303     QVariant value() const;
304     QString valueTypeName() const;
305     QString binding() const;
306     bool hasNotifySignal() const;
307 
308 private:
309     friend class QDeclarativeEngineDebugPrivate;
310     int m_objectDebugId;
311     QString m_name;
312     QVariant m_value;
313     QString m_valueTypeName;
314     QString m_binding;
315     bool m_hasNotifySignal;
316 };
317 
318 
319 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugEnginesQuery : public QDeclarativeDebugQuery
320 {
321 Q_OBJECT
322 public:
323     virtual ~QDeclarativeDebugEnginesQuery();
324     QList<QDeclarativeDebugEngineReference> engines() const;
325 private:
326     friend class QDeclarativeEngineDebug;
327     friend class QDeclarativeEngineDebugPrivate;
328     QDeclarativeDebugEnginesQuery(QObject *);
329     QDeclarativeEngineDebug *m_client;
330     int m_queryId;
331     QList<QDeclarativeDebugEngineReference> m_engines;
332 };
333 
334 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugRootContextQuery : public QDeclarativeDebugQuery
335 {
336 Q_OBJECT
337 public:
338     virtual ~QDeclarativeDebugRootContextQuery();
339     QDeclarativeDebugContextReference rootContext() const;
340 private:
341     friend class QDeclarativeEngineDebug;
342     friend class QDeclarativeEngineDebugPrivate;
343     QDeclarativeDebugRootContextQuery(QObject *);
344     QDeclarativeEngineDebug *m_client;
345     int m_queryId;
346     QDeclarativeDebugContextReference m_context;
347 };
348 
349 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugObjectQuery : public QDeclarativeDebugQuery
350 {
351 Q_OBJECT
352 public:
353     virtual ~QDeclarativeDebugObjectQuery();
354     QDeclarativeDebugObjectReference object() const;
355 private:
356     friend class QDeclarativeEngineDebug;
357     friend class QDeclarativeEngineDebugPrivate;
358     QDeclarativeDebugObjectQuery(QObject *);
359     QDeclarativeEngineDebug *m_client;
360     int m_queryId;
361     QDeclarativeDebugObjectReference m_object;
362 
363 };
364 
365 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugExpressionQuery : public QDeclarativeDebugQuery
366 {
367 Q_OBJECT
368 public:
369     virtual ~QDeclarativeDebugExpressionQuery();
370     QVariant expression() const;
371     QVariant result() const;
372 private:
373     friend class QDeclarativeEngineDebug;
374     friend class QDeclarativeEngineDebugPrivate;
375     QDeclarativeDebugExpressionQuery(QObject *);
376     QDeclarativeEngineDebug *m_client;
377     int m_queryId;
378     QVariant m_expr;
379     QVariant m_result;
380 };
381 
382 QT_END_NAMESPACE
383 
384 Q_DECLARE_METATYPE(QDeclarativeDebugEngineReference)
385 Q_DECLARE_METATYPE(QDeclarativeDebugObjectReference)
386 Q_DECLARE_METATYPE(QDeclarativeDebugContextReference)
387 Q_DECLARE_METATYPE(QDeclarativeDebugPropertyReference)
388 
389 QT_END_HEADER
390 
391 #endif // QDECLARATIVEENGINEDEBUG_H
392