OSDN Git Service

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