QmlDebugging: Remove QQmlDebugClient
[profile/ivi/qtdeclarative.git] / tests / auto / qml / debugger / shared / qqmlenginedebug.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtQml module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "qqmlenginedebug_p.h"
43
44 #include "qqmldebugclient.h"
45
46 #include <private/qqmlenginedebugservice_p.h>
47
48 #include <QtCore/private/qobject_p.h>
49
50 class QQmlEngineDebugClient : public QQmlDebugClient
51 {
52 public:
53     QQmlEngineDebugClient(QQmlDebugConnection *client, QQmlEngineDebugPrivate *p);
54
55 protected:
56     virtual void stateChanged(State state);
57     virtual void messageReceived(const QByteArray &);
58
59 private:
60     QQmlEngineDebugPrivate *priv;
61     friend class QQmlEngineDebugPrivate;
62 };
63
64 class QQmlEngineDebugPrivate : public QObjectPrivate
65 {
66     Q_DECLARE_PUBLIC(QQmlEngineDebug)
67 public:
68     QQmlEngineDebugPrivate(QQmlDebugConnection *);
69     ~QQmlEngineDebugPrivate();
70
71     void stateChanged(QQmlEngineDebug::State status);
72     void message(const QByteArray &);
73
74     QQmlEngineDebugClient *client;
75     int nextId;
76     int getId();
77
78     void decode(QDataStream &, QQmlDebugContextReference &);
79     void decode(QDataStream &, QQmlDebugObjectReference &, bool simple);
80
81     static void remove(QQmlEngineDebug *, QQmlDebugEnginesQuery *);
82     static void remove(QQmlEngineDebug *, QQmlDebugRootContextQuery *);
83     static void remove(QQmlEngineDebug *, QQmlDebugObjectQuery *);
84     static void remove(QQmlEngineDebug *, QQmlDebugExpressionQuery *);
85     static void remove(QQmlEngineDebug *, QQmlDebugWatch *);
86
87     QHash<int, QQmlDebugEnginesQuery *> enginesQuery;
88     QHash<int, QQmlDebugRootContextQuery *> rootContextQuery;
89     QHash<int, QQmlDebugObjectQuery *> objectQuery;
90     QHash<int, QQmlDebugExpressionQuery *> expressionQuery;
91
92     QHash<int, QQmlDebugWatch *> watched;
93 };
94
95 QQmlEngineDebugClient::QQmlEngineDebugClient(QQmlDebugConnection *client,
96                                                              QQmlEngineDebugPrivate *p)
97     : QQmlDebugClient(QLatin1String("QDeclarativeEngine"), client), priv(p)
98 {
99 }
100
101 void QQmlEngineDebugClient::stateChanged(State status)
102 {
103     if (priv)
104         priv->stateChanged(static_cast<QQmlEngineDebug::State>(status));
105 }
106
107 void QQmlEngineDebugClient::messageReceived(const QByteArray &data)
108 {
109     if (priv)
110         priv->message(data);
111 }
112
113 QQmlEngineDebugPrivate::QQmlEngineDebugPrivate(QQmlDebugConnection *c)
114     : client(new QQmlEngineDebugClient(c, this)), nextId(0)
115 {
116 }
117
118 QQmlEngineDebugPrivate::~QQmlEngineDebugPrivate()
119 {
120     if (client)
121         client->priv = 0;
122     delete client;
123
124     QHash<int, QQmlDebugEnginesQuery*>::iterator enginesIter = enginesQuery.begin();
125     for (; enginesIter != enginesQuery.end(); ++enginesIter) {
126         enginesIter.value()->m_client = 0;
127         if (enginesIter.value()->state() == QQmlDebugQuery::Waiting)
128             enginesIter.value()->setState(QQmlDebugQuery::Error);
129     }
130
131     QHash<int, QQmlDebugRootContextQuery*>::iterator rootContextIter = rootContextQuery.begin();
132     for (; rootContextIter != rootContextQuery.end(); ++rootContextIter) {
133         rootContextIter.value()->m_client = 0;
134         if (rootContextIter.value()->state() == QQmlDebugQuery::Waiting)
135             rootContextIter.value()->setState(QQmlDebugQuery::Error);
136     }
137
138     QHash<int, QQmlDebugObjectQuery*>::iterator objectIter = objectQuery.begin();
139     for (; objectIter != objectQuery.end(); ++objectIter) {
140         objectIter.value()->m_client = 0;
141         if (objectIter.value()->state() == QQmlDebugQuery::Waiting)
142             objectIter.value()->setState(QQmlDebugQuery::Error);
143     }
144
145     QHash<int, QQmlDebugExpressionQuery*>::iterator exprIter = expressionQuery.begin();
146     for (; exprIter != expressionQuery.end(); ++exprIter) {
147         exprIter.value()->m_client = 0;
148         if (exprIter.value()->state() == QQmlDebugQuery::Waiting)
149             exprIter.value()->setState(QQmlDebugQuery::Error);
150     }
151
152     QHash<int, QQmlDebugWatch*>::iterator watchIter = watched.begin();
153     for (; watchIter != watched.end(); ++watchIter) {
154         watchIter.value()->m_client = 0;
155         watchIter.value()->setState(QQmlDebugWatch::Dead);
156     }
157 }
158
159 int QQmlEngineDebugPrivate::getId()
160 {
161     return nextId++;
162 }
163
164 void QQmlEngineDebugPrivate::remove(QQmlEngineDebug *c, QQmlDebugEnginesQuery *q)
165 {
166     if (c && q) {
167         QQmlEngineDebugPrivate *p = (QQmlEngineDebugPrivate *)QObjectPrivate::get(c);
168         p->enginesQuery.remove(q->m_queryId);
169     }
170 }
171
172 void QQmlEngineDebugPrivate::remove(QQmlEngineDebug *c, 
173                                             QQmlDebugRootContextQuery *q)
174 {
175     if (c && q) {
176         QQmlEngineDebugPrivate *p = (QQmlEngineDebugPrivate *)QObjectPrivate::get(c);
177         p->rootContextQuery.remove(q->m_queryId);
178     }
179 }
180
181 void QQmlEngineDebugPrivate::remove(QQmlEngineDebug *c, QQmlDebugObjectQuery *q)
182 {
183     if (c && q) {
184         QQmlEngineDebugPrivate *p = (QQmlEngineDebugPrivate *)QObjectPrivate::get(c);
185         p->objectQuery.remove(q->m_queryId);
186     }
187 }
188
189 void QQmlEngineDebugPrivate::remove(QQmlEngineDebug *c, QQmlDebugExpressionQuery *q)
190 {
191     if (c && q) {
192         QQmlEngineDebugPrivate *p = (QQmlEngineDebugPrivate *)QObjectPrivate::get(c);
193         p->expressionQuery.remove(q->m_queryId);
194     }
195 }
196
197 void QQmlEngineDebugPrivate::remove(QQmlEngineDebug *c, QQmlDebugWatch *w)
198 {
199     if (c && w) {
200         QQmlEngineDebugPrivate *p = (QQmlEngineDebugPrivate *)QObjectPrivate::get(c);
201         p->watched.remove(w->m_queryId);
202     }
203 }
204
205 void QQmlEngineDebugPrivate::decode(QDataStream &ds, QQmlDebugObjectReference &o,
206                                             bool simple)
207 {
208     QQmlEngineDebugService::QQmlObjectData data;
209     ds >> data;
210     o.m_debugId = data.objectId;
211     o.m_class = data.objectType;
212     o.m_idString = data.idString;
213     o.m_name = data.objectName;
214     o.m_source.m_url = data.url;
215     o.m_source.m_lineNumber = data.lineNumber;
216     o.m_source.m_columnNumber = data.columnNumber;
217     o.m_contextDebugId = data.contextId;
218
219     if (simple)
220         return;
221
222     int childCount;
223     bool recur;
224     ds >> childCount >> recur;
225
226     for (int ii = 0; ii < childCount; ++ii) {
227         o.m_children.append(QQmlDebugObjectReference());
228         decode(ds, o.m_children.last(), !recur);
229     }
230
231     int propCount;
232     ds >> propCount;
233
234     for (int ii = 0; ii < propCount; ++ii) {
235         QQmlEngineDebugService::QQmlObjectProperty data;
236         ds >> data;
237         QQmlDebugPropertyReference prop;
238         prop.m_objectDebugId = o.m_debugId;
239         prop.m_name = data.name;
240         prop.m_binding = data.binding;
241         prop.m_hasNotifySignal = data.hasNotifySignal;
242         prop.m_valueTypeName = data.valueTypeName;
243         switch (data.type) {
244         case QQmlEngineDebugService::QQmlObjectProperty::Basic:
245         case QQmlEngineDebugService::QQmlObjectProperty::List:
246         case QQmlEngineDebugService::QQmlObjectProperty::SignalProperty:
247         {
248             prop.m_value = data.value;
249             break;
250         }
251         case QQmlEngineDebugService::QQmlObjectProperty::Object:
252         {
253             QQmlDebugObjectReference obj;
254             obj.m_debugId = prop.m_value.toInt();
255             prop.m_value = QVariant::fromValue(obj);
256             break;
257         }
258         case QQmlEngineDebugService::QQmlObjectProperty::Unknown:
259             break;
260         }
261         o.m_properties << prop;
262     }
263 }
264
265 void QQmlEngineDebugPrivate::decode(QDataStream &ds, QQmlDebugContextReference &c)
266 {
267     ds >> c.m_name >> c.m_debugId;
268
269     int contextCount;
270     ds >> contextCount;
271
272     for (int ii = 0; ii < contextCount; ++ii) {
273         c.m_contexts.append(QQmlDebugContextReference());
274         decode(ds, c.m_contexts.last());
275     }
276
277     int objectCount;
278     ds >> objectCount;
279
280     for (int ii = 0; ii < objectCount; ++ii) {
281         QQmlDebugObjectReference obj;
282         decode(ds, obj, true);
283
284         obj.m_contextDebugId = c.m_debugId;
285         c.m_objects << obj;
286     }
287 }
288
289 void QQmlEngineDebugPrivate::stateChanged(QQmlEngineDebug::State status)
290 {
291     emit q_func()->stateChanged(status);
292 }
293
294 void QQmlEngineDebugPrivate::message(const QByteArray &data)
295 {
296     QDataStream ds(data);
297
298     QByteArray type;
299     ds >> type;
300
301     //qDebug() << "QQmlEngineDebugPrivate::message()" << type;
302
303     if (type == "LIST_ENGINES_R") {
304         int queryId;
305         ds >> queryId;
306
307         QQmlDebugEnginesQuery *query = enginesQuery.value(queryId);
308         if (!query)
309             return;
310         enginesQuery.remove(queryId);
311
312         int count;
313         ds >> count;
314
315         for (int ii = 0; ii < count; ++ii) {
316             QQmlDebugEngineReference ref;
317             ds >> ref.m_name;
318             ds >> ref.m_debugId;
319             query->m_engines << ref;
320         }
321
322         query->m_client = 0;
323         query->setState(QQmlDebugQuery::Completed);
324     } else if (type == "LIST_OBJECTS_R") {
325         int queryId;
326         ds >> queryId;
327
328         QQmlDebugRootContextQuery *query = rootContextQuery.value(queryId);
329         if (!query)
330             return;
331         rootContextQuery.remove(queryId);
332
333         if (!ds.atEnd())
334             decode(ds, query->m_context);
335
336         query->m_client = 0;
337         query->setState(QQmlDebugQuery::Completed);
338     } else if (type == "FETCH_OBJECT_R") {
339         int queryId;
340         ds >> queryId;
341
342         QQmlDebugObjectQuery *query = objectQuery.value(queryId);
343         if (!query)
344             return;
345         objectQuery.remove(queryId);
346
347         if (!ds.atEnd())
348             decode(ds, query->m_object, false);
349
350         query->m_client = 0;
351         query->setState(QQmlDebugQuery::Completed);
352     } else if (type == "EVAL_EXPRESSION_R") {
353         int queryId;
354         QVariant result;
355         ds >> queryId >> result;
356
357         QQmlDebugExpressionQuery *query = expressionQuery.value(queryId);
358         if (!query)
359             return;
360         expressionQuery.remove(queryId);
361
362         query->m_result = result;
363         query->m_client = 0;
364         query->setState(QQmlDebugQuery::Completed);
365     } else if (type == "WATCH_PROPERTY_R") {
366         int queryId;
367         bool ok;
368         ds >> queryId >> ok;
369
370         QQmlDebugWatch *watch = watched.value(queryId);
371         if (!watch)
372             return;
373
374         watch->setState(ok ? QQmlDebugWatch::Active : QQmlDebugWatch::Inactive);
375     } else if (type == "WATCH_OBJECT_R") {
376         int queryId;
377         bool ok;
378         ds >> queryId >> ok;
379
380         QQmlDebugWatch *watch = watched.value(queryId);
381         if (!watch)
382             return;
383
384         watch->setState(ok ? QQmlDebugWatch::Active : QQmlDebugWatch::Inactive);
385     } else if (type == "WATCH_EXPR_OBJECT_R") {
386         int queryId;
387         bool ok;
388         ds >> queryId >> ok;
389
390         QQmlDebugWatch *watch = watched.value(queryId);
391         if (!watch)
392             return;
393
394         watch->setState(ok ? QQmlDebugWatch::Active : QQmlDebugWatch::Inactive);
395     } else if (type == "UPDATE_WATCH") {
396         int queryId;
397         int debugId;
398         QByteArray name;
399         QVariant value;
400         ds >> queryId >> debugId >> name >> value;
401
402         QQmlDebugWatch *watch = watched.value(queryId, 0);
403         if (!watch)
404             return;
405         emit watch->valueChanged(name, value);
406     } else if (type == "OBJECT_CREATED") {
407         emit q_func()->newObjects();
408     }
409 }
410
411 QQmlEngineDebug::QQmlEngineDebug(QQmlDebugConnection *client, QObject *parent)
412     : QObject(*(new QQmlEngineDebugPrivate(client)), parent)
413 {
414 }
415
416 QQmlEngineDebug::~QQmlEngineDebug()
417 {
418 }
419
420 QQmlEngineDebug::State QQmlEngineDebug::state() const
421 {
422     Q_D(const QQmlEngineDebug);
423
424     return static_cast<QQmlEngineDebug::State>(d->client->state());
425 }
426
427 QQmlDebugPropertyWatch *QQmlEngineDebug::addWatch(const QQmlDebugPropertyReference &property, QObject *parent)
428 {
429     Q_D(QQmlEngineDebug);
430
431     QQmlDebugPropertyWatch *watch = new QQmlDebugPropertyWatch(parent);
432     if (d->client->state() == QQmlDebugClient::Enabled) {
433         int queryId = d->getId();
434         watch->m_queryId = queryId;
435         watch->m_client = this;
436         watch->m_objectDebugId = property.objectDebugId();
437         watch->m_name = property.name();
438         d->watched.insert(queryId, watch);
439
440         QByteArray message;
441         QDataStream ds(&message, QIODevice::WriteOnly);
442         ds << QByteArray("WATCH_PROPERTY") << queryId << property.objectDebugId() << property.name().toUtf8();
443         d->client->sendMessage(message);
444     } else {
445         watch->m_state = QQmlDebugWatch::Dead;
446     }
447
448     return watch;
449 }
450
451 QQmlDebugWatch *QQmlEngineDebug::addWatch(const QQmlDebugContextReference &, const QString &, QObject *)
452 {
453     qWarning("QQmlEngineDebug::addWatch(): Not implemented");
454     return 0;
455 }
456
457 QQmlDebugObjectExpressionWatch *QQmlEngineDebug::addWatch(const QQmlDebugObjectReference &object, const QString &expr, QObject *parent)
458 {
459     Q_D(QQmlEngineDebug);
460     QQmlDebugObjectExpressionWatch *watch = new QQmlDebugObjectExpressionWatch(parent);
461     if (d->client->state() == QQmlDebugClient::Enabled) {
462         int queryId = d->getId();
463         watch->m_queryId = queryId;
464         watch->m_client = this;
465         watch->m_objectDebugId = object.debugId();
466         watch->m_expr = expr;
467         d->watched.insert(queryId, watch);
468
469         QByteArray message;
470         QDataStream ds(&message, QIODevice::WriteOnly);
471         ds << QByteArray("WATCH_EXPR_OBJECT") << queryId << object.debugId() << expr;
472         d->client->sendMessage(message);
473     } else {
474         watch->m_state = QQmlDebugWatch::Dead;
475     }
476     return watch;
477 }
478
479 QQmlDebugWatch *QQmlEngineDebug::addWatch(const QQmlDebugObjectReference &object, QObject *parent)
480 {
481     Q_D(QQmlEngineDebug);
482
483     QQmlDebugWatch *watch = new QQmlDebugWatch(parent);
484     if (d->client->state() == QQmlDebugClient::Enabled) {
485         int queryId = d->getId();
486         watch->m_queryId = queryId;
487         watch->m_client = this;
488         watch->m_objectDebugId = object.debugId();
489         d->watched.insert(queryId, watch);
490
491         QByteArray message;
492         QDataStream ds(&message, QIODevice::WriteOnly);
493         ds << QByteArray("WATCH_OBJECT") << queryId << object.debugId();
494         d->client->sendMessage(message);
495     } else {
496         watch->m_state = QQmlDebugWatch::Dead;
497     }
498
499     return watch;
500 }
501
502 QQmlDebugWatch *QQmlEngineDebug::addWatch(const QQmlDebugFileReference &, QObject *)
503 {
504     qWarning("QQmlEngineDebug::addWatch(): Not implemented");
505     return 0;
506 }
507
508 void QQmlEngineDebug::removeWatch(QQmlDebugWatch *watch)
509 {
510     Q_D(QQmlEngineDebug);
511
512     if (!watch || !watch->m_client)
513         return;
514
515     watch->m_client = 0;
516     watch->setState(QQmlDebugWatch::Inactive);
517     
518     d->watched.remove(watch->queryId());
519
520     if (d->client && d->client->state() == QQmlDebugClient::Enabled) {
521         QByteArray message;
522         QDataStream ds(&message, QIODevice::WriteOnly);
523         ds << QByteArray("NO_WATCH") << watch->queryId();
524         d->client->sendMessage(message);
525     }
526 }
527
528 QQmlDebugEnginesQuery *QQmlEngineDebug::queryAvailableEngines(QObject *parent)
529 {
530     Q_D(QQmlEngineDebug);
531
532     QQmlDebugEnginesQuery *query = new QQmlDebugEnginesQuery(parent);
533     if (d->client->state() == QQmlDebugClient::Enabled) {
534         query->m_client = this;
535         int queryId = d->getId();
536         query->m_queryId = queryId;
537         d->enginesQuery.insert(queryId, query);
538
539         QByteArray message;
540         QDataStream ds(&message, QIODevice::WriteOnly);
541         ds << QByteArray("LIST_ENGINES") << queryId;
542         d->client->sendMessage(message);
543     } else {
544         query->m_state = QQmlDebugQuery::Error;
545     }
546
547     return query;
548 }
549
550 QQmlDebugRootContextQuery *QQmlEngineDebug::queryRootContexts(const QQmlDebugEngineReference &engine, QObject *parent)
551 {
552     Q_D(QQmlEngineDebug);
553
554     QQmlDebugRootContextQuery *query = new QQmlDebugRootContextQuery(parent);
555     if (d->client->state() == QQmlDebugClient::Enabled && engine.debugId() != -1) {
556         query->m_client = this;
557         int queryId = d->getId();
558         query->m_queryId = queryId;
559         d->rootContextQuery.insert(queryId, query);
560
561         QByteArray message;
562         QDataStream ds(&message, QIODevice::WriteOnly);
563         ds << QByteArray("LIST_OBJECTS") << queryId << engine.debugId();
564         d->client->sendMessage(message);
565     } else {
566         query->m_state = QQmlDebugQuery::Error;
567     }
568
569     return query;
570 }
571
572 QQmlDebugObjectQuery *QQmlEngineDebug::queryObject(const QQmlDebugObjectReference &object, QObject *parent)
573 {
574     Q_D(QQmlEngineDebug);
575
576     QQmlDebugObjectQuery *query = new QQmlDebugObjectQuery(parent);
577     if (d->client->state() == QQmlDebugClient::Enabled && object.debugId() != -1) {
578         query->m_client = this;
579         int queryId = d->getId();
580         query->m_queryId = queryId;
581         d->objectQuery.insert(queryId, query);
582
583         QByteArray message;
584         QDataStream ds(&message, QIODevice::WriteOnly);
585         ds << QByteArray("FETCH_OBJECT") << queryId << object.debugId()
586            << false << true;
587         d->client->sendMessage(message);
588     } else {
589         query->m_state = QQmlDebugQuery::Error;
590     }
591
592     return query;
593 }
594
595 QQmlDebugObjectQuery *QQmlEngineDebug::queryObjectRecursive(const QQmlDebugObjectReference &object, QObject *parent)
596 {
597     Q_D(QQmlEngineDebug);
598
599     QQmlDebugObjectQuery *query = new QQmlDebugObjectQuery(parent);
600     if (d->client->state() == QQmlDebugClient::Enabled && object.debugId() != -1) {
601         query->m_client = this;
602         int queryId = d->getId();
603         query->m_queryId = queryId;
604         d->objectQuery.insert(queryId, query);
605
606         QByteArray message;
607         QDataStream ds(&message, QIODevice::WriteOnly);
608         ds << QByteArray("FETCH_OBJECT") << queryId << object.debugId()
609            << true << true;
610         d->client->sendMessage(message);
611     } else {
612         query->m_state = QQmlDebugQuery::Error;
613     }
614
615     return query;
616 }
617
618 QQmlDebugExpressionQuery *QQmlEngineDebug::queryExpressionResult(int objectDebugId, const QString &expr, QObject *parent)
619 {
620     Q_D(QQmlEngineDebug);
621
622     QQmlDebugExpressionQuery *query = new QQmlDebugExpressionQuery(parent);
623     if (d->client->state() == QQmlDebugClient::Enabled && objectDebugId != -1) {
624         query->m_client = this;
625         query->m_expr = expr;
626         int queryId = d->getId();
627         query->m_queryId = queryId;
628         d->expressionQuery.insert(queryId, query);
629
630         QByteArray message;
631         QDataStream ds(&message, QIODevice::WriteOnly);
632         ds << QByteArray("EVAL_EXPRESSION") << queryId << objectDebugId << expr;
633         d->client->sendMessage(message);
634     } else {
635         query->m_state = QQmlDebugQuery::Error;
636     }
637
638     return query;
639 }
640
641 bool QQmlEngineDebug::setBindingForObject(int objectDebugId, const QString &propertyName,
642                                                   const QVariant &bindingExpression,
643                                                   bool isLiteralValue,
644                                                   QString source, int line)
645 {
646     Q_D(QQmlEngineDebug);
647
648     if (d->client->state() == QQmlDebugClient::Enabled && objectDebugId != -1) {
649         QByteArray message;
650         QDataStream ds(&message, QIODevice::WriteOnly);
651         ds << QByteArray("SET_BINDING") << objectDebugId << propertyName << bindingExpression << isLiteralValue << source << line;
652         d->client->sendMessage(message);
653         return true;
654     } else {
655         return false;
656     }
657 }
658
659 bool QQmlEngineDebug::resetBindingForObject(int objectDebugId, const QString &propertyName)
660 {
661     Q_D(QQmlEngineDebug);
662
663     if (d->client->state() == QQmlDebugClient::Enabled && objectDebugId != -1) {
664         QByteArray message;
665         QDataStream ds(&message, QIODevice::WriteOnly);
666         ds << QByteArray("RESET_BINDING") << objectDebugId << propertyName;
667         d->client->sendMessage(message);
668         return true;
669     } else {
670         return false;
671     }
672 }
673
674 bool QQmlEngineDebug::setMethodBody(int objectDebugId, const QString &methodName,
675                                             const QString &methodBody)
676 {
677     Q_D(QQmlEngineDebug);
678
679     if (d->client->state() == QQmlDebugClient::Enabled && objectDebugId != -1) {
680         QByteArray message;
681         QDataStream ds(&message, QIODevice::WriteOnly);
682         ds << QByteArray("SET_METHOD_BODY") << objectDebugId << methodName << methodBody;
683         d->client->sendMessage(message);
684         return true;
685     } else {
686         return false;
687     }
688 }
689
690 QQmlDebugWatch::QQmlDebugWatch(QObject *parent)
691     : QObject(parent), m_state(Waiting), m_queryId(-1), m_client(0), m_objectDebugId(-1)
692 {
693 }
694
695 QQmlDebugWatch::~QQmlDebugWatch()
696 {
697     if (m_client && m_queryId != -1)
698         QQmlEngineDebugPrivate::remove(m_client, this);
699 }
700
701 int QQmlDebugWatch::queryId() const
702 {
703     return m_queryId;
704 }
705
706 int QQmlDebugWatch::objectDebugId() const
707 {
708     return m_objectDebugId;
709 }
710
711 QQmlDebugWatch::State QQmlDebugWatch::state() const
712 {
713     return m_state;
714 }
715
716 void QQmlDebugWatch::setState(State s)
717 {
718     if (m_state == s)
719         return;
720     m_state = s;
721     emit stateChanged(m_state);
722 }
723
724 QQmlDebugPropertyWatch::QQmlDebugPropertyWatch(QObject *parent)
725     : QQmlDebugWatch(parent)
726 {
727 }
728
729 QString QQmlDebugPropertyWatch::name() const
730 {
731     return m_name;
732 }
733
734
735 QQmlDebugObjectExpressionWatch::QQmlDebugObjectExpressionWatch(QObject *parent)
736     : QQmlDebugWatch(parent)
737 {
738 }
739
740 QString QQmlDebugObjectExpressionWatch::expression() const
741 {
742     return m_expr;
743 }
744
745
746 QQmlDebugQuery::QQmlDebugQuery(QObject *parent)
747     : QObject(parent), m_state(Waiting)
748 {
749 }
750
751 QQmlDebugQuery::State QQmlDebugQuery::state() const
752 {
753     return m_state;
754 }
755
756 bool QQmlDebugQuery::isWaiting() const
757 {
758     return m_state == Waiting;
759 }
760
761 void QQmlDebugQuery::setState(State s)
762 {
763     if (m_state == s)
764         return;
765     m_state = s;
766     emit stateChanged(m_state);
767 }
768
769 QQmlDebugEnginesQuery::QQmlDebugEnginesQuery(QObject *parent)
770     : QQmlDebugQuery(parent), m_client(0), m_queryId(-1)
771 {
772 }
773
774 QQmlDebugEnginesQuery::~QQmlDebugEnginesQuery()
775 {
776     if (m_client && m_queryId != -1)
777         QQmlEngineDebugPrivate::remove(m_client, this);
778 }
779
780 QList<QQmlDebugEngineReference> QQmlDebugEnginesQuery::engines() const
781 {
782     return m_engines;
783 }
784
785 QQmlDebugRootContextQuery::QQmlDebugRootContextQuery(QObject *parent)
786     : QQmlDebugQuery(parent), m_client(0), m_queryId(-1)
787 {
788 }
789
790 QQmlDebugRootContextQuery::~QQmlDebugRootContextQuery()
791 {
792     if (m_client && m_queryId != -1)
793         QQmlEngineDebugPrivate::remove(m_client, this);
794 }
795
796 QQmlDebugContextReference QQmlDebugRootContextQuery::rootContext() const
797 {
798     return m_context;
799 }
800
801 QQmlDebugObjectQuery::QQmlDebugObjectQuery(QObject *parent)
802     : QQmlDebugQuery(parent), m_client(0), m_queryId(-1)
803 {
804 }
805
806 QQmlDebugObjectQuery::~QQmlDebugObjectQuery()
807 {
808     if (m_client && m_queryId != -1)
809         QQmlEngineDebugPrivate::remove(m_client, this);
810 }
811
812 QQmlDebugObjectReference QQmlDebugObjectQuery::object() const
813 {
814     return m_object;
815 }
816
817 QQmlDebugExpressionQuery::QQmlDebugExpressionQuery(QObject *parent)
818     : QQmlDebugQuery(parent), m_client(0), m_queryId(-1)
819 {
820 }
821
822 QQmlDebugExpressionQuery::~QQmlDebugExpressionQuery()
823 {
824     if (m_client && m_queryId != -1)
825         QQmlEngineDebugPrivate::remove(m_client, this);
826 }
827
828 QVariant QQmlDebugExpressionQuery::expression() const
829 {
830     return m_expr;
831 }
832
833 QVariant QQmlDebugExpressionQuery::result() const
834 {
835     return m_result;
836 }
837
838 QQmlDebugEngineReference::QQmlDebugEngineReference()
839     : m_debugId(-1)
840 {
841 }
842
843 QQmlDebugEngineReference::QQmlDebugEngineReference(int debugId)
844     : m_debugId(debugId)
845 {
846 }
847
848 QQmlDebugEngineReference::QQmlDebugEngineReference(const QQmlDebugEngineReference &o)
849     : m_debugId(o.m_debugId), m_name(o.m_name)
850 {
851 }
852
853 QQmlDebugEngineReference &
854 QQmlDebugEngineReference::operator=(const QQmlDebugEngineReference &o)
855 {
856     m_debugId = o.m_debugId; m_name = o.m_name;
857     return *this;
858 }
859
860 int QQmlDebugEngineReference::debugId() const
861 {
862     return m_debugId;
863 }
864
865 QString QQmlDebugEngineReference::name() const
866 {
867     return m_name;
868 }
869
870 QQmlDebugObjectReference::QQmlDebugObjectReference()
871     : m_debugId(-1), m_contextDebugId(-1)
872 {
873 }
874
875 QQmlDebugObjectReference::QQmlDebugObjectReference(int debugId)
876     : m_debugId(debugId), m_contextDebugId(-1)
877 {
878 }
879
880 QQmlDebugObjectReference::QQmlDebugObjectReference(const QQmlDebugObjectReference &o)
881     : m_debugId(o.m_debugId), m_class(o.m_class), m_idString(o.m_idString),
882       m_name(o.m_name), m_source(o.m_source), m_contextDebugId(o.m_contextDebugId),
883       m_properties(o.m_properties), m_children(o.m_children)
884 {
885 }
886
887 QQmlDebugObjectReference &
888 QQmlDebugObjectReference::operator=(const QQmlDebugObjectReference &o)
889 {
890     m_debugId = o.m_debugId; m_class = o.m_class; m_idString = o.m_idString;
891     m_name = o.m_name; m_source = o.m_source; m_contextDebugId = o.m_contextDebugId;
892     m_properties = o.m_properties; m_children = o.m_children;
893     return *this;
894 }
895
896 int QQmlDebugObjectReference::debugId() const
897 {
898     return m_debugId;
899 }
900
901 QString QQmlDebugObjectReference::className() const
902 {
903     return m_class;
904 }
905
906 QString QQmlDebugObjectReference::idString() const
907 {
908     return m_idString;
909 }
910
911 QString QQmlDebugObjectReference::name() const
912 {
913     return m_name;
914 }
915
916 QQmlDebugFileReference QQmlDebugObjectReference::source() const
917 {
918     return m_source;
919 }
920
921 int QQmlDebugObjectReference::contextDebugId() const
922 {
923     return m_contextDebugId;
924 }
925
926 QList<QQmlDebugPropertyReference> QQmlDebugObjectReference::properties() const
927 {
928     return m_properties;
929 }
930
931 QList<QQmlDebugObjectReference> QQmlDebugObjectReference::children() const
932 {
933     return m_children;
934 }
935
936 QQmlDebugContextReference::QQmlDebugContextReference()
937     : m_debugId(-1)
938 {
939 }
940
941 QQmlDebugContextReference::QQmlDebugContextReference(const QQmlDebugContextReference &o)
942     : m_debugId(o.m_debugId), m_name(o.m_name), m_objects(o.m_objects), m_contexts(o.m_contexts)
943 {
944 }
945
946 QQmlDebugContextReference &QQmlDebugContextReference::operator=(const QQmlDebugContextReference &o)
947 {
948     m_debugId = o.m_debugId; m_name = o.m_name; m_objects = o.m_objects;
949     m_contexts = o.m_contexts;
950     return *this;
951 }
952
953 int QQmlDebugContextReference::debugId() const
954 {
955     return m_debugId;
956 }
957
958 QString QQmlDebugContextReference::name() const
959 {
960     return m_name;
961 }
962
963 QList<QQmlDebugObjectReference> QQmlDebugContextReference::objects() const
964 {
965     return m_objects;
966 }
967
968 QList<QQmlDebugContextReference> QQmlDebugContextReference::contexts() const
969 {
970     return m_contexts;
971 }
972
973 QQmlDebugFileReference::QQmlDebugFileReference()
974     : m_lineNumber(-1), m_columnNumber(-1)
975 {
976 }
977
978 QQmlDebugFileReference::QQmlDebugFileReference(const QQmlDebugFileReference &o)
979     : m_url(o.m_url), m_lineNumber(o.m_lineNumber), m_columnNumber(o.m_columnNumber)
980 {
981 }
982
983 QQmlDebugFileReference &QQmlDebugFileReference::operator=(const QQmlDebugFileReference &o)
984 {
985     m_url = o.m_url; m_lineNumber = o.m_lineNumber; m_columnNumber = o.m_columnNumber;
986     return *this;
987 }
988
989 QUrl QQmlDebugFileReference::url() const
990 {
991     return m_url;
992 }
993
994 void QQmlDebugFileReference::setUrl(const QUrl &u)
995 {
996     m_url = u;
997 }
998
999 int QQmlDebugFileReference::lineNumber() const
1000 {
1001     return m_lineNumber;
1002 }
1003
1004 void QQmlDebugFileReference::setLineNumber(int l)
1005 {
1006     m_lineNumber = l;
1007 }
1008
1009 int QQmlDebugFileReference::columnNumber() const
1010 {
1011     return m_columnNumber;
1012 }
1013
1014 void QQmlDebugFileReference::setColumnNumber(int c)
1015 {
1016     m_columnNumber = c;
1017 }
1018
1019 QQmlDebugPropertyReference::QQmlDebugPropertyReference()
1020     : m_objectDebugId(-1), m_hasNotifySignal(false)
1021 {
1022 }
1023
1024 QQmlDebugPropertyReference::QQmlDebugPropertyReference(const QQmlDebugPropertyReference &o)
1025     : m_objectDebugId(o.m_objectDebugId), m_name(o.m_name), m_value(o.m_value),
1026       m_valueTypeName(o.m_valueTypeName), m_binding(o.m_binding),
1027       m_hasNotifySignal(o.m_hasNotifySignal)
1028 {
1029 }
1030
1031 QQmlDebugPropertyReference &QQmlDebugPropertyReference::operator=(const QQmlDebugPropertyReference &o)
1032 {
1033     m_objectDebugId = o.m_objectDebugId; m_name = o.m_name; m_value = o.m_value;
1034     m_valueTypeName = o.m_valueTypeName; m_binding = o.m_binding;
1035     m_hasNotifySignal = o.m_hasNotifySignal;
1036     return *this;
1037 }
1038
1039 int QQmlDebugPropertyReference::objectDebugId() const
1040 {
1041     return m_objectDebugId;
1042 }
1043
1044 QString QQmlDebugPropertyReference::name() const
1045 {
1046     return m_name;
1047 }
1048
1049 QString QQmlDebugPropertyReference::valueTypeName() const
1050 {
1051     return m_valueTypeName;
1052 }
1053
1054 QVariant QQmlDebugPropertyReference::value() const
1055 {
1056     return m_value;
1057 }
1058
1059 QString QQmlDebugPropertyReference::binding() const
1060 {
1061     return m_binding;
1062 }
1063
1064 bool QQmlDebugPropertyReference::hasNotifySignal() const
1065 {
1066     return m_hasNotifySignal;
1067 }
1068