src/declarative/debugger/qdeclarativedebug.cpp
changeset 30 5dc02b23752f
child 33 3e2da88830cd
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 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 "private/qdeclarativedebug_p.h"
       
    43 
       
    44 #include "private/qdeclarativedebugclient_p.h"
       
    45 
       
    46 #include <qdeclarativeenginedebug_p.h>
       
    47 
       
    48 #include <private/qobject_p.h>
       
    49 
       
    50 QT_BEGIN_NAMESPACE
       
    51 
       
    52 class QDeclarativeEngineDebugClient : public QDeclarativeDebugClient
       
    53 {
       
    54 public:
       
    55     QDeclarativeEngineDebugClient(QDeclarativeDebugConnection *client, QDeclarativeEngineDebugPrivate *p);
       
    56 
       
    57 protected:
       
    58     virtual void messageReceived(const QByteArray &);
       
    59 
       
    60 private:
       
    61     QDeclarativeEngineDebugPrivate *priv;
       
    62 };
       
    63 
       
    64 class QDeclarativeEngineDebugPrivate : public QObjectPrivate
       
    65 {
       
    66     Q_DECLARE_PUBLIC(QDeclarativeEngineDebug)
       
    67 public:
       
    68     QDeclarativeEngineDebugPrivate(QDeclarativeDebugConnection *);
       
    69 
       
    70     void message(const QByteArray &);
       
    71 
       
    72     QDeclarativeEngineDebugClient *client;
       
    73     int nextId;
       
    74     int getId();
       
    75 
       
    76     void decode(QDataStream &, QDeclarativeDebugContextReference &);
       
    77     void decode(QDataStream &, QDeclarativeDebugObjectReference &, bool simple);
       
    78 
       
    79     static void remove(QDeclarativeEngineDebug *, QDeclarativeDebugEnginesQuery *);
       
    80     static void remove(QDeclarativeEngineDebug *, QDeclarativeDebugRootContextQuery *);
       
    81     static void remove(QDeclarativeEngineDebug *, QDeclarativeDebugObjectQuery *);
       
    82     static void remove(QDeclarativeEngineDebug *, QDeclarativeDebugExpressionQuery *);
       
    83 
       
    84     QHash<int, QDeclarativeDebugEnginesQuery *> enginesQuery;
       
    85     QHash<int, QDeclarativeDebugRootContextQuery *> rootContextQuery;
       
    86     QHash<int, QDeclarativeDebugObjectQuery *> objectQuery;
       
    87     QHash<int, QDeclarativeDebugExpressionQuery *> expressionQuery;
       
    88 
       
    89     QHash<int, QDeclarativeDebugWatch *> watched;
       
    90 };
       
    91 
       
    92 QDeclarativeEngineDebugClient::QDeclarativeEngineDebugClient(QDeclarativeDebugConnection *client,
       
    93                                            QDeclarativeEngineDebugPrivate *p)
       
    94 : QDeclarativeDebugClient(QLatin1String("QDeclarativeEngine"), client), priv(p)
       
    95 {
       
    96     setEnabled(true);
       
    97 }
       
    98 
       
    99 void QDeclarativeEngineDebugClient::messageReceived(const QByteArray &data)
       
   100 {
       
   101     priv->message(data);
       
   102 }
       
   103 
       
   104 QDeclarativeEngineDebugPrivate::QDeclarativeEngineDebugPrivate(QDeclarativeDebugConnection *c)
       
   105 : client(new QDeclarativeEngineDebugClient(c, this)), nextId(0)
       
   106 {
       
   107 }
       
   108 
       
   109 int QDeclarativeEngineDebugPrivate::getId()
       
   110 {
       
   111     return nextId++;
       
   112 }
       
   113 
       
   114 void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, QDeclarativeDebugEnginesQuery *q)
       
   115 {
       
   116     if (c && q) {
       
   117         QDeclarativeEngineDebugPrivate *p = (QDeclarativeEngineDebugPrivate *)QObjectPrivate::get(c);
       
   118         p->enginesQuery.remove(q->m_queryId);
       
   119     }
       
   120 }
       
   121 
       
   122 void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, 
       
   123                                    QDeclarativeDebugRootContextQuery *q)
       
   124 {
       
   125     if (c && q) {
       
   126         QDeclarativeEngineDebugPrivate *p = (QDeclarativeEngineDebugPrivate *)QObjectPrivate::get(c);
       
   127         p->rootContextQuery.remove(q->m_queryId);
       
   128     }
       
   129 }
       
   130 
       
   131 void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, QDeclarativeDebugObjectQuery *q)
       
   132 {
       
   133     if (c && q) {
       
   134         QDeclarativeEngineDebugPrivate *p = (QDeclarativeEngineDebugPrivate *)QObjectPrivate::get(c);
       
   135         p->objectQuery.remove(q->m_queryId);
       
   136     }
       
   137 }
       
   138 
       
   139 void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, QDeclarativeDebugExpressionQuery *q)
       
   140 {
       
   141     if (c && q) {
       
   142         QDeclarativeEngineDebugPrivate *p = (QDeclarativeEngineDebugPrivate *)QObjectPrivate::get(c);
       
   143         p->expressionQuery.remove(q->m_queryId);
       
   144     }
       
   145 }
       
   146 
       
   147 void QDeclarativeEngineDebugPrivate::decode(QDataStream &ds, QDeclarativeDebugObjectReference &o,
       
   148                                    bool simple)
       
   149 {
       
   150     QDeclarativeEngineDebugServer::QDeclarativeObjectData data;
       
   151     ds >> data;
       
   152     o.m_debugId = data.objectId;
       
   153     o.m_class = data.objectType;
       
   154     o.m_idString = data.idString;
       
   155     o.m_name = data.objectName;
       
   156     o.m_source.m_url = data.url;
       
   157     o.m_source.m_lineNumber = data.lineNumber;
       
   158     o.m_source.m_columnNumber = data.columnNumber;
       
   159     o.m_contextDebugId = data.contextId;
       
   160 
       
   161     if (simple)
       
   162         return;
       
   163 
       
   164     int childCount;
       
   165     bool recur;
       
   166     ds >> childCount >> recur;
       
   167 
       
   168     for (int ii = 0; ii < childCount; ++ii) {
       
   169         o.m_children.append(QDeclarativeDebugObjectReference());
       
   170         decode(ds, o.m_children.last(), !recur);
       
   171     }
       
   172 
       
   173     int propCount;
       
   174     ds >> propCount;
       
   175 
       
   176     for (int ii = 0; ii < propCount; ++ii) {
       
   177         QDeclarativeEngineDebugServer::QDeclarativeObjectProperty data;
       
   178         ds >> data;
       
   179         QDeclarativeDebugPropertyReference prop;
       
   180         prop.m_objectDebugId = o.m_debugId;
       
   181         prop.m_name = data.name;
       
   182         prop.m_binding = data.binding;
       
   183         prop.m_hasNotifySignal = data.hasNotifySignal;
       
   184         prop.m_valueTypeName = data.valueTypeName;
       
   185         switch (data.type) {
       
   186             case QDeclarativeEngineDebugServer::QDeclarativeObjectProperty::Basic:
       
   187             case QDeclarativeEngineDebugServer::QDeclarativeObjectProperty::List:
       
   188             case QDeclarativeEngineDebugServer::QDeclarativeObjectProperty::SignalProperty:
       
   189             {
       
   190                 prop.m_value = data.value;
       
   191                 break;
       
   192             }
       
   193             case QDeclarativeEngineDebugServer::QDeclarativeObjectProperty::Object:
       
   194             {
       
   195                 QDeclarativeDebugObjectReference obj;
       
   196                 obj.m_debugId = prop.m_value.toInt();
       
   197                 prop.m_value = qVariantFromValue(obj);
       
   198                 break;
       
   199             }
       
   200             case QDeclarativeEngineDebugServer::QDeclarativeObjectProperty::Unknown:
       
   201                 break;
       
   202         }
       
   203         o.m_properties << prop;
       
   204     }
       
   205 }
       
   206 
       
   207 void QDeclarativeEngineDebugPrivate::decode(QDataStream &ds, QDeclarativeDebugContextReference &c)
       
   208 {
       
   209     ds >> c.m_name >> c.m_debugId;
       
   210 
       
   211     int contextCount;
       
   212     ds >> contextCount;
       
   213 
       
   214     for (int ii = 0; ii < contextCount; ++ii) {
       
   215         c.m_contexts.append(QDeclarativeDebugContextReference());
       
   216         decode(ds, c.m_contexts.last());
       
   217     }
       
   218 
       
   219     int objectCount;
       
   220     ds >> objectCount;
       
   221 
       
   222     for (int ii = 0; ii < objectCount; ++ii) {
       
   223         QDeclarativeDebugObjectReference obj;
       
   224         decode(ds, obj, true);
       
   225 
       
   226         obj.m_contextDebugId = c.m_debugId;
       
   227         c.m_objects << obj;
       
   228     }
       
   229 }
       
   230 
       
   231 void QDeclarativeEngineDebugPrivate::message(const QByteArray &data)
       
   232 {
       
   233     QDataStream ds(data);
       
   234 
       
   235     QByteArray type;
       
   236     ds >> type;
       
   237 
       
   238     //qDebug() << "QDeclarativeEngineDebugPrivate::message()" << type;
       
   239 
       
   240     if (type == "LIST_ENGINES_R") {
       
   241         int queryId;
       
   242         ds >> queryId;
       
   243 
       
   244         QDeclarativeDebugEnginesQuery *query = enginesQuery.value(queryId);
       
   245         if (!query)
       
   246             return;
       
   247         enginesQuery.remove(queryId);
       
   248 
       
   249         int count;
       
   250         ds >> count;
       
   251 
       
   252         for (int ii = 0; ii < count; ++ii) {
       
   253             QDeclarativeDebugEngineReference ref;
       
   254             ds >> ref.m_name;
       
   255             ds >> ref.m_debugId;
       
   256             query->m_engines << ref;
       
   257         }
       
   258 
       
   259         query->m_client = 0;
       
   260         query->setState(QDeclarativeDebugQuery::Completed);
       
   261     } else if (type == "LIST_OBJECTS_R") {
       
   262         int queryId;
       
   263         ds >> queryId;
       
   264 
       
   265         QDeclarativeDebugRootContextQuery *query = rootContextQuery.value(queryId);
       
   266         if (!query)
       
   267             return;
       
   268         rootContextQuery.remove(queryId);
       
   269 
       
   270         if (!ds.atEnd()) 
       
   271             decode(ds, query->m_context);
       
   272 
       
   273         query->m_client = 0;
       
   274         query->setState(QDeclarativeDebugQuery::Completed);
       
   275     } else if (type == "FETCH_OBJECT_R") {
       
   276         int queryId;
       
   277         ds >> queryId;
       
   278 
       
   279         QDeclarativeDebugObjectQuery *query = objectQuery.value(queryId);
       
   280         if (!query)
       
   281             return;
       
   282         objectQuery.remove(queryId);
       
   283 
       
   284         if (!ds.atEnd())
       
   285             decode(ds, query->m_object, false);
       
   286 
       
   287         query->m_client = 0;
       
   288         query->setState(QDeclarativeDebugQuery::Completed);
       
   289     } else if (type == "EVAL_EXPRESSION_R") {
       
   290         int queryId;
       
   291         QVariant result;
       
   292         ds >> queryId >> result;
       
   293 
       
   294         QDeclarativeDebugExpressionQuery *query = expressionQuery.value(queryId);
       
   295         if (!query)
       
   296             return;
       
   297         expressionQuery.remove(queryId);
       
   298 
       
   299         query->m_result = result;
       
   300         query->m_client = 0;
       
   301         query->setState(QDeclarativeDebugQuery::Completed);
       
   302     } else if (type == "WATCH_PROPERTY_R") {
       
   303         int queryId;
       
   304         bool ok;
       
   305         ds >> queryId >> ok;
       
   306 
       
   307         QDeclarativeDebugWatch *watch = watched.value(queryId);
       
   308         if (!watch)
       
   309             return;
       
   310 
       
   311         watch->setState(ok ? QDeclarativeDebugWatch::Active : QDeclarativeDebugWatch::Inactive);
       
   312     } else if (type == "WATCH_OBJECT_R") {
       
   313         int queryId;
       
   314         bool ok;
       
   315         ds >> queryId >> ok;
       
   316 
       
   317         QDeclarativeDebugWatch *watch = watched.value(queryId);
       
   318         if (!watch)
       
   319             return;
       
   320 
       
   321         watch->setState(ok ? QDeclarativeDebugWatch::Active : QDeclarativeDebugWatch::Inactive);
       
   322     } else if (type == "WATCH_EXPR_OBJECT_R") {
       
   323         int queryId;
       
   324         bool ok;
       
   325         ds >> queryId >> ok;
       
   326 
       
   327         QDeclarativeDebugWatch *watch = watched.value(queryId);
       
   328         if (!watch)
       
   329             return;
       
   330 
       
   331         watch->setState(ok ? QDeclarativeDebugWatch::Active : QDeclarativeDebugWatch::Inactive);
       
   332     } else if (type == "UPDATE_WATCH") {
       
   333         int queryId;
       
   334         int debugId;
       
   335         QByteArray name;
       
   336         QVariant value;
       
   337         ds >> queryId >> debugId >> name >> value;
       
   338 
       
   339         QDeclarativeDebugWatch *watch = watched.value(queryId, 0);
       
   340         if (!watch)
       
   341             return;
       
   342         emit watch->valueChanged(name, value);
       
   343     }
       
   344 }
       
   345 
       
   346 QDeclarativeEngineDebug::QDeclarativeEngineDebug(QDeclarativeDebugConnection *client, QObject *parent)
       
   347 : QObject(*(new QDeclarativeEngineDebugPrivate(client)), parent)
       
   348 {
       
   349 }
       
   350 
       
   351 QDeclarativeDebugPropertyWatch *QDeclarativeEngineDebug::addWatch(const QDeclarativeDebugPropertyReference &property, QObject *parent)
       
   352 {
       
   353     Q_D(QDeclarativeEngineDebug);
       
   354 
       
   355     QDeclarativeDebugPropertyWatch *watch = new QDeclarativeDebugPropertyWatch(parent);
       
   356     if (d->client->isConnected()) {
       
   357         int queryId = d->getId();
       
   358         watch->m_queryId = queryId;
       
   359         watch->m_client = this;
       
   360         watch->m_objectDebugId = property.objectDebugId();
       
   361         watch->m_name = property.name();
       
   362         d->watched.insert(queryId, watch);
       
   363 
       
   364         QByteArray message;
       
   365         QDataStream ds(&message, QIODevice::WriteOnly);
       
   366         ds << QByteArray("WATCH_PROPERTY") << queryId << property.objectDebugId() << property.name().toUtf8();
       
   367         d->client->sendMessage(message);
       
   368     } else {
       
   369         watch->m_state = QDeclarativeDebugWatch::Dead;
       
   370     }
       
   371 
       
   372     return watch;
       
   373 }
       
   374 
       
   375 QDeclarativeDebugWatch *QDeclarativeEngineDebug::addWatch(const QDeclarativeDebugContextReference &, const QString &, QObject *)
       
   376 {
       
   377     qWarning("QDeclarativeEngineDebug::addWatch(): Not implemented");
       
   378     return 0;
       
   379 }
       
   380 
       
   381 QDeclarativeDebugObjectExpressionWatch *QDeclarativeEngineDebug::addWatch(const QDeclarativeDebugObjectReference &object, const QString &expr, QObject *parent)
       
   382 {
       
   383     Q_D(QDeclarativeEngineDebug);
       
   384     QDeclarativeDebugObjectExpressionWatch *watch = new QDeclarativeDebugObjectExpressionWatch(parent);
       
   385     if (d->client->isConnected()) {
       
   386         int queryId = d->getId();
       
   387         watch->m_queryId = queryId;
       
   388         watch->m_client = this;
       
   389         watch->m_objectDebugId = object.debugId();
       
   390         watch->m_expr = expr;
       
   391         d->watched.insert(queryId, watch);
       
   392 
       
   393         QByteArray message;
       
   394         QDataStream ds(&message, QIODevice::WriteOnly);
       
   395         ds << QByteArray("WATCH_EXPR_OBJECT") << queryId << object.debugId() << expr;
       
   396         d->client->sendMessage(message);
       
   397     } else {
       
   398         watch->m_state = QDeclarativeDebugWatch::Dead;
       
   399     }
       
   400     return watch;
       
   401 }
       
   402 
       
   403 QDeclarativeDebugWatch *QDeclarativeEngineDebug::addWatch(const QDeclarativeDebugObjectReference &object, QObject *parent)
       
   404 {
       
   405     Q_D(QDeclarativeEngineDebug);
       
   406 
       
   407     QDeclarativeDebugWatch *watch = new QDeclarativeDebugWatch(parent);
       
   408     if (d->client->isConnected()) {
       
   409         int queryId = d->getId();
       
   410         watch->m_queryId = queryId;
       
   411         watch->m_client = this;
       
   412         watch->m_objectDebugId = object.debugId();
       
   413         d->watched.insert(queryId, watch);
       
   414 
       
   415         QByteArray message;
       
   416         QDataStream ds(&message, QIODevice::WriteOnly);
       
   417         ds << QByteArray("WATCH_OBJECT") << queryId << object.debugId();
       
   418         d->client->sendMessage(message);
       
   419     } else {
       
   420         watch->m_state = QDeclarativeDebugWatch::Dead;
       
   421     }
       
   422 
       
   423     return watch;
       
   424 }
       
   425 
       
   426 QDeclarativeDebugWatch *QDeclarativeEngineDebug::addWatch(const QDeclarativeDebugFileReference &, QObject *)
       
   427 {
       
   428     qWarning("QDeclarativeEngineDebug::addWatch(): Not implemented");
       
   429     return 0;
       
   430 }
       
   431 
       
   432 void QDeclarativeEngineDebug::removeWatch(QDeclarativeDebugWatch *watch)
       
   433 {
       
   434     Q_D(QDeclarativeEngineDebug);
       
   435 
       
   436     if (!watch || !watch->m_client)
       
   437         return;
       
   438 
       
   439     watch->m_client = 0;
       
   440     watch->setState(QDeclarativeDebugWatch::Inactive);
       
   441     
       
   442     d->watched.remove(watch->queryId());
       
   443 
       
   444     if (d->client && d->client->isConnected()) {
       
   445         QByteArray message;
       
   446         QDataStream ds(&message, QIODevice::WriteOnly);
       
   447         ds << QByteArray("NO_WATCH") << watch->queryId();
       
   448         d->client->sendMessage(message);
       
   449     }
       
   450 }
       
   451 
       
   452 QDeclarativeDebugEnginesQuery *QDeclarativeEngineDebug::queryAvailableEngines(QObject *parent)
       
   453 {
       
   454     Q_D(QDeclarativeEngineDebug);
       
   455 
       
   456     QDeclarativeDebugEnginesQuery *query = new QDeclarativeDebugEnginesQuery(parent);
       
   457     if (d->client->isConnected()) {
       
   458         query->m_client = this;
       
   459         int queryId = d->getId();
       
   460         query->m_queryId = queryId;
       
   461         d->enginesQuery.insert(queryId, query);
       
   462 
       
   463         QByteArray message;
       
   464         QDataStream ds(&message, QIODevice::WriteOnly);
       
   465         ds << QByteArray("LIST_ENGINES") << queryId;
       
   466         d->client->sendMessage(message);
       
   467     } else {
       
   468         query->m_state = QDeclarativeDebugQuery::Error;
       
   469     }
       
   470 
       
   471     return query;
       
   472 }
       
   473 
       
   474 QDeclarativeDebugRootContextQuery *QDeclarativeEngineDebug::queryRootContexts(const QDeclarativeDebugEngineReference &engine, QObject *parent)
       
   475 {
       
   476     Q_D(QDeclarativeEngineDebug);
       
   477 
       
   478     QDeclarativeDebugRootContextQuery *query = new QDeclarativeDebugRootContextQuery(parent);
       
   479     if (d->client->isConnected() && engine.debugId() != -1) {
       
   480         query->m_client = this;
       
   481         int queryId = d->getId();
       
   482         query->m_queryId = queryId;
       
   483         d->rootContextQuery.insert(queryId, query);
       
   484 
       
   485         QByteArray message;
       
   486         QDataStream ds(&message, QIODevice::WriteOnly);
       
   487         ds << QByteArray("LIST_OBJECTS") << queryId << engine.debugId();
       
   488         d->client->sendMessage(message);
       
   489     } else {
       
   490         query->m_state = QDeclarativeDebugQuery::Error;
       
   491     }
       
   492 
       
   493     return query;
       
   494 }
       
   495 
       
   496 QDeclarativeDebugObjectQuery *QDeclarativeEngineDebug::queryObject(const QDeclarativeDebugObjectReference &object, QObject *parent)
       
   497 {
       
   498     Q_D(QDeclarativeEngineDebug);
       
   499 
       
   500     QDeclarativeDebugObjectQuery *query = new QDeclarativeDebugObjectQuery(parent);
       
   501     if (d->client->isConnected() && object.debugId() != -1) {
       
   502         query->m_client = this;
       
   503         int queryId = d->getId();
       
   504         query->m_queryId = queryId;
       
   505         d->objectQuery.insert(queryId, query);
       
   506 
       
   507         QByteArray message;
       
   508         QDataStream ds(&message, QIODevice::WriteOnly);
       
   509         ds << QByteArray("FETCH_OBJECT") << queryId << object.debugId() 
       
   510            << false;
       
   511         d->client->sendMessage(message);
       
   512     } else {
       
   513         query->m_state = QDeclarativeDebugQuery::Error;
       
   514     }
       
   515 
       
   516     return query;
       
   517 }
       
   518 
       
   519 QDeclarativeDebugObjectQuery *QDeclarativeEngineDebug::queryObjectRecursive(const QDeclarativeDebugObjectReference &object, QObject *parent)
       
   520 {
       
   521     Q_D(QDeclarativeEngineDebug);
       
   522 
       
   523     QDeclarativeDebugObjectQuery *query = new QDeclarativeDebugObjectQuery(parent);
       
   524     if (d->client->isConnected() && object.debugId() != -1) {
       
   525         query->m_client = this;
       
   526         int queryId = d->getId();
       
   527         query->m_queryId = queryId;
       
   528         d->objectQuery.insert(queryId, query);
       
   529 
       
   530         QByteArray message;
       
   531         QDataStream ds(&message, QIODevice::WriteOnly);
       
   532         ds << QByteArray("FETCH_OBJECT") << queryId << object.debugId() 
       
   533            << true;
       
   534         d->client->sendMessage(message);
       
   535     } else {
       
   536         query->m_state = QDeclarativeDebugQuery::Error;
       
   537     }
       
   538 
       
   539     return query;
       
   540 }
       
   541 
       
   542 QDeclarativeDebugExpressionQuery *QDeclarativeEngineDebug::queryExpressionResult(int objectDebugId, const QString &expr, QObject *parent)
       
   543 {
       
   544     Q_D(QDeclarativeEngineDebug);
       
   545 
       
   546     QDeclarativeDebugExpressionQuery *query = new QDeclarativeDebugExpressionQuery(parent);
       
   547     if (d->client->isConnected() && objectDebugId != -1) {
       
   548         query->m_client = this;
       
   549         query->m_expr = expr;
       
   550         int queryId = d->getId();
       
   551         query->m_queryId = queryId;
       
   552         d->expressionQuery.insert(queryId, query);
       
   553 
       
   554         QByteArray message;
       
   555         QDataStream ds(&message, QIODevice::WriteOnly);
       
   556         ds << QByteArray("EVAL_EXPRESSION") << queryId << objectDebugId << expr;
       
   557         d->client->sendMessage(message);
       
   558     } else {
       
   559         query->m_state = QDeclarativeDebugQuery::Error;
       
   560     }
       
   561 
       
   562     return query;
       
   563 }
       
   564 
       
   565 QDeclarativeDebugWatch::QDeclarativeDebugWatch(QObject *parent)
       
   566 : QObject(parent), m_state(Waiting), m_queryId(-1), m_client(0), m_objectDebugId(-1)
       
   567 {
       
   568 }
       
   569 
       
   570 QDeclarativeDebugWatch::~QDeclarativeDebugWatch()
       
   571 {
       
   572 }
       
   573 
       
   574 int QDeclarativeDebugWatch::queryId() const
       
   575 {
       
   576     return m_queryId;
       
   577 }
       
   578 
       
   579 int QDeclarativeDebugWatch::objectDebugId() const
       
   580 {
       
   581     return m_objectDebugId;
       
   582 }
       
   583 
       
   584 QDeclarativeDebugWatch::State QDeclarativeDebugWatch::state() const
       
   585 {
       
   586     return m_state;
       
   587 }
       
   588 
       
   589 void QDeclarativeDebugWatch::setState(State s)
       
   590 {
       
   591     if (m_state == s)
       
   592         return;
       
   593     m_state = s;
       
   594     emit stateChanged(m_state);
       
   595 }
       
   596 
       
   597 QDeclarativeDebugPropertyWatch::QDeclarativeDebugPropertyWatch(QObject *parent)
       
   598     : QDeclarativeDebugWatch(parent)
       
   599 {
       
   600 }
       
   601 
       
   602 QString QDeclarativeDebugPropertyWatch::name() const
       
   603 {
       
   604     return m_name;
       
   605 }
       
   606 
       
   607 
       
   608 QDeclarativeDebugObjectExpressionWatch::QDeclarativeDebugObjectExpressionWatch(QObject *parent)
       
   609     : QDeclarativeDebugWatch(parent)
       
   610 {
       
   611 }
       
   612 
       
   613 QString QDeclarativeDebugObjectExpressionWatch::expression() const
       
   614 {
       
   615     return m_expr;
       
   616 }
       
   617 
       
   618 
       
   619 QDeclarativeDebugQuery::QDeclarativeDebugQuery(QObject *parent)
       
   620 : QObject(parent), m_state(Waiting)
       
   621 {
       
   622 }
       
   623 
       
   624 QDeclarativeDebugQuery::State QDeclarativeDebugQuery::state() const
       
   625 {
       
   626     return m_state;
       
   627 }
       
   628 
       
   629 bool QDeclarativeDebugQuery::isWaiting() const
       
   630 {
       
   631     return m_state == Waiting;
       
   632 }
       
   633 
       
   634 void QDeclarativeDebugQuery::setState(State s)
       
   635 {
       
   636     if (m_state == s)
       
   637         return;
       
   638     m_state = s;
       
   639     emit stateChanged(m_state);
       
   640 }
       
   641 
       
   642 QDeclarativeDebugEnginesQuery::QDeclarativeDebugEnginesQuery(QObject *parent)
       
   643 : QDeclarativeDebugQuery(parent), m_client(0), m_queryId(-1)
       
   644 {
       
   645 }
       
   646 
       
   647 QDeclarativeDebugEnginesQuery::~QDeclarativeDebugEnginesQuery()
       
   648 {
       
   649     if (m_client && m_queryId != -1) 
       
   650         QDeclarativeEngineDebugPrivate::remove(m_client, this);
       
   651 }
       
   652 
       
   653 QList<QDeclarativeDebugEngineReference> QDeclarativeDebugEnginesQuery::engines() const
       
   654 {
       
   655     return m_engines;
       
   656 }
       
   657 
       
   658 QDeclarativeDebugRootContextQuery::QDeclarativeDebugRootContextQuery(QObject *parent)
       
   659 : QDeclarativeDebugQuery(parent), m_client(0), m_queryId(-1)
       
   660 {
       
   661 }
       
   662 
       
   663 QDeclarativeDebugRootContextQuery::~QDeclarativeDebugRootContextQuery()
       
   664 {
       
   665     if (m_client && m_queryId != -1) 
       
   666         QDeclarativeEngineDebugPrivate::remove(m_client, this);
       
   667 }
       
   668 
       
   669 QDeclarativeDebugContextReference QDeclarativeDebugRootContextQuery::rootContext() const
       
   670 {
       
   671     return m_context;
       
   672 }
       
   673 
       
   674 QDeclarativeDebugObjectQuery::QDeclarativeDebugObjectQuery(QObject *parent)
       
   675 : QDeclarativeDebugQuery(parent), m_client(0), m_queryId(-1)
       
   676 {
       
   677 }
       
   678 
       
   679 QDeclarativeDebugObjectQuery::~QDeclarativeDebugObjectQuery()
       
   680 {
       
   681     if (m_client && m_queryId != -1) 
       
   682         QDeclarativeEngineDebugPrivate::remove(m_client, this);
       
   683 }
       
   684 
       
   685 QDeclarativeDebugObjectReference QDeclarativeDebugObjectQuery::object() const
       
   686 {
       
   687     return m_object;
       
   688 }
       
   689 
       
   690 QDeclarativeDebugExpressionQuery::QDeclarativeDebugExpressionQuery(QObject *parent)
       
   691 : QDeclarativeDebugQuery(parent), m_client(0), m_queryId(-1)
       
   692 {
       
   693 }
       
   694 
       
   695 QDeclarativeDebugExpressionQuery::~QDeclarativeDebugExpressionQuery()
       
   696 {
       
   697     if (m_client && m_queryId != -1) 
       
   698         QDeclarativeEngineDebugPrivate::remove(m_client, this);
       
   699 }
       
   700 
       
   701 QString QDeclarativeDebugExpressionQuery::expression() const
       
   702 {
       
   703     return m_expr;
       
   704 }
       
   705 
       
   706 QVariant QDeclarativeDebugExpressionQuery::result() const
       
   707 {
       
   708     return m_result;
       
   709 }
       
   710 
       
   711 QDeclarativeDebugEngineReference::QDeclarativeDebugEngineReference()
       
   712 : m_debugId(-1)
       
   713 {
       
   714 }
       
   715 
       
   716 QDeclarativeDebugEngineReference::QDeclarativeDebugEngineReference(int debugId)
       
   717 : m_debugId(debugId)
       
   718 {
       
   719 }
       
   720 
       
   721 QDeclarativeDebugEngineReference::QDeclarativeDebugEngineReference(const QDeclarativeDebugEngineReference &o)
       
   722 : m_debugId(o.m_debugId), m_name(o.m_name)
       
   723 {
       
   724 }
       
   725 
       
   726 QDeclarativeDebugEngineReference &
       
   727 QDeclarativeDebugEngineReference::operator=(const QDeclarativeDebugEngineReference &o)
       
   728 {
       
   729     m_debugId = o.m_debugId; m_name = o.m_name;
       
   730     return *this;
       
   731 }
       
   732 
       
   733 int QDeclarativeDebugEngineReference::debugId() const
       
   734 {
       
   735     return m_debugId;
       
   736 }
       
   737 
       
   738 QString QDeclarativeDebugEngineReference::name() const
       
   739 {
       
   740     return m_name;
       
   741 }
       
   742 
       
   743 QDeclarativeDebugObjectReference::QDeclarativeDebugObjectReference()
       
   744 : m_debugId(-1), m_contextDebugId(-1)
       
   745 {
       
   746 }
       
   747 
       
   748 QDeclarativeDebugObjectReference::QDeclarativeDebugObjectReference(int debugId)
       
   749 : m_debugId(debugId), m_contextDebugId(-1)
       
   750 {
       
   751 }
       
   752 
       
   753 QDeclarativeDebugObjectReference::QDeclarativeDebugObjectReference(const QDeclarativeDebugObjectReference &o)
       
   754 : m_debugId(o.m_debugId), m_class(o.m_class), m_idString(o.m_idString),
       
   755   m_name(o.m_name), m_source(o.m_source), m_contextDebugId(o.m_contextDebugId),
       
   756   m_properties(o.m_properties), m_children(o.m_children)
       
   757 {
       
   758 }
       
   759 
       
   760 QDeclarativeDebugObjectReference &
       
   761 QDeclarativeDebugObjectReference::operator=(const QDeclarativeDebugObjectReference &o)
       
   762 {
       
   763     m_debugId = o.m_debugId; m_class = o.m_class; m_idString = o.m_idString;
       
   764     m_name = o.m_name; m_source = o.m_source; m_contextDebugId = o.m_contextDebugId;
       
   765     m_properties = o.m_properties; m_children = o.m_children;
       
   766     return *this;
       
   767 }
       
   768 
       
   769 int QDeclarativeDebugObjectReference::debugId() const
       
   770 {
       
   771     return m_debugId;
       
   772 }
       
   773 
       
   774 QString QDeclarativeDebugObjectReference::className() const
       
   775 {
       
   776     return m_class;
       
   777 }
       
   778 
       
   779 QString QDeclarativeDebugObjectReference::idString() const
       
   780 {
       
   781     return m_idString;
       
   782 }
       
   783 
       
   784 QString QDeclarativeDebugObjectReference::name() const
       
   785 {
       
   786     return m_name;
       
   787 }
       
   788 
       
   789 QDeclarativeDebugFileReference QDeclarativeDebugObjectReference::source() const
       
   790 {
       
   791     return m_source;
       
   792 }
       
   793 
       
   794 int QDeclarativeDebugObjectReference::contextDebugId() const
       
   795 {
       
   796     return m_contextDebugId;
       
   797 }
       
   798 
       
   799 QList<QDeclarativeDebugPropertyReference> QDeclarativeDebugObjectReference::properties() const
       
   800 {
       
   801     return m_properties;
       
   802 }
       
   803 
       
   804 QList<QDeclarativeDebugObjectReference> QDeclarativeDebugObjectReference::children() const
       
   805 {
       
   806     return m_children;
       
   807 }
       
   808 
       
   809 QDeclarativeDebugContextReference::QDeclarativeDebugContextReference()
       
   810 : m_debugId(-1)
       
   811 {
       
   812 }
       
   813 
       
   814 QDeclarativeDebugContextReference::QDeclarativeDebugContextReference(const QDeclarativeDebugContextReference &o)
       
   815 : m_debugId(o.m_debugId), m_name(o.m_name), m_objects(o.m_objects), m_contexts(o.m_contexts)
       
   816 {
       
   817 }
       
   818 
       
   819 QDeclarativeDebugContextReference &QDeclarativeDebugContextReference::operator=(const QDeclarativeDebugContextReference &o)
       
   820 {
       
   821     m_debugId = o.m_debugId; m_name = o.m_name; m_objects = o.m_objects; 
       
   822     m_contexts = o.m_contexts;
       
   823     return *this;
       
   824 }
       
   825 
       
   826 int QDeclarativeDebugContextReference::debugId() const
       
   827 {
       
   828     return m_debugId;
       
   829 }
       
   830 
       
   831 QString QDeclarativeDebugContextReference::name() const
       
   832 {
       
   833     return m_name;
       
   834 }
       
   835 
       
   836 QList<QDeclarativeDebugObjectReference> QDeclarativeDebugContextReference::objects() const
       
   837 {
       
   838     return m_objects;
       
   839 }
       
   840 
       
   841 QList<QDeclarativeDebugContextReference> QDeclarativeDebugContextReference::contexts() const
       
   842 {
       
   843     return m_contexts;
       
   844 }
       
   845 
       
   846 QDeclarativeDebugFileReference::QDeclarativeDebugFileReference()
       
   847 : m_lineNumber(-1), m_columnNumber(-1)
       
   848 {
       
   849 }
       
   850 
       
   851 QDeclarativeDebugFileReference::QDeclarativeDebugFileReference(const QDeclarativeDebugFileReference &o)
       
   852 : m_url(o.m_url), m_lineNumber(o.m_lineNumber), m_columnNumber(o.m_columnNumber)
       
   853 {
       
   854 }
       
   855 
       
   856 QDeclarativeDebugFileReference &QDeclarativeDebugFileReference::operator=(const QDeclarativeDebugFileReference &o)
       
   857 {
       
   858     m_url = o.m_url; m_lineNumber = o.m_lineNumber; m_columnNumber = o.m_columnNumber;
       
   859     return *this;
       
   860 }
       
   861 
       
   862 QUrl QDeclarativeDebugFileReference::url() const
       
   863 {
       
   864     return m_url;
       
   865 }
       
   866 
       
   867 void QDeclarativeDebugFileReference::setUrl(const QUrl &u)
       
   868 {
       
   869     m_url = u;
       
   870 }
       
   871 
       
   872 int QDeclarativeDebugFileReference::lineNumber() const
       
   873 {
       
   874     return m_lineNumber;
       
   875 }
       
   876 
       
   877 void QDeclarativeDebugFileReference::setLineNumber(int l)
       
   878 {
       
   879     m_lineNumber = l;
       
   880 }
       
   881 
       
   882 int QDeclarativeDebugFileReference::columnNumber() const
       
   883 {
       
   884     return m_columnNumber;
       
   885 }
       
   886 
       
   887 void QDeclarativeDebugFileReference::setColumnNumber(int c)
       
   888 {
       
   889     m_columnNumber = c;
       
   890 }
       
   891 
       
   892 QDeclarativeDebugPropertyReference::QDeclarativeDebugPropertyReference()
       
   893 : m_objectDebugId(-1), m_hasNotifySignal(false)
       
   894 {
       
   895 }
       
   896 
       
   897 QDeclarativeDebugPropertyReference::QDeclarativeDebugPropertyReference(const QDeclarativeDebugPropertyReference &o)
       
   898 : m_objectDebugId(o.m_objectDebugId), m_name(o.m_name), m_value(o.m_value),
       
   899   m_valueTypeName(o.m_valueTypeName), m_binding(o.m_binding),
       
   900   m_hasNotifySignal(o.m_hasNotifySignal)
       
   901 {
       
   902 }
       
   903 
       
   904 QDeclarativeDebugPropertyReference &QDeclarativeDebugPropertyReference::operator=(const QDeclarativeDebugPropertyReference &o)
       
   905 {
       
   906     m_objectDebugId = o.m_objectDebugId; m_name = o.m_name; m_value = o.m_value;
       
   907     m_valueTypeName = o.m_valueTypeName; m_binding = o.m_binding;
       
   908     m_hasNotifySignal = o.m_hasNotifySignal;
       
   909     return *this;
       
   910 }
       
   911 
       
   912 int QDeclarativeDebugPropertyReference::objectDebugId() const
       
   913 {
       
   914     return m_objectDebugId;
       
   915 }
       
   916 
       
   917 QString QDeclarativeDebugPropertyReference::name() const
       
   918 {
       
   919     return m_name;
       
   920 }
       
   921 
       
   922 QString QDeclarativeDebugPropertyReference::valueTypeName() const
       
   923 {
       
   924     return m_valueTypeName;
       
   925 }
       
   926 
       
   927 QVariant QDeclarativeDebugPropertyReference::value() const
       
   928 {
       
   929     return m_value;
       
   930 }
       
   931 
       
   932 QString QDeclarativeDebugPropertyReference::binding() const
       
   933 {
       
   934     return m_binding;
       
   935 }
       
   936 
       
   937 bool QDeclarativeDebugPropertyReference::hasNotifySignal() const
       
   938 {
       
   939     return m_hasNotifySignal;
       
   940 }
       
   941 
       
   942 QT_END_NAMESPACE
       
   943