Commit f3cdbeff authored by Olivier Goffart's avatar Olivier Goffart
Browse files

QmlJsInspector: remove private header dependencies

A copy of the client debugging code is made in src/libs/qmljsdebugclient/
(this comes from the qt code from commit 65642dd343bf61)

So the qmljsinspector plugin does not require anymore Qt private headers.
parent 333334c6
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qdeclarativedebug_p.h"
#include "qdeclarativedebugclient_p.h"
#include <private/qobject_p.h>
namespace QmlJsDebugClient {
class QDeclarativeEngineDebugClient : public QDeclarativeDebugClient
{
public:
QDeclarativeEngineDebugClient(QDeclarativeDebugConnection *client, QDeclarativeEngineDebugPrivate *p);
protected:
virtual void messageReceived(const QByteArray &);
private:
QDeclarativeEngineDebugPrivate *priv;
};
class QDeclarativeEngineDebugPrivate : public QObjectPrivate
{
Q_DECLARE_PUBLIC(QDeclarativeEngineDebug)
public:
QDeclarativeEngineDebugPrivate(QDeclarativeDebugConnection *);
void message(const QByteArray &);
QDeclarativeEngineDebugClient *client;
int nextId;
int getId();
void decode(QDataStream &, QDeclarativeDebugContextReference &);
void decode(QDataStream &, QDeclarativeDebugObjectReference &, bool simple);
static void remove(QDeclarativeEngineDebug *, QDeclarativeDebugEnginesQuery *);
static void remove(QDeclarativeEngineDebug *, QDeclarativeDebugRootContextQuery *);
static void remove(QDeclarativeEngineDebug *, QDeclarativeDebugObjectQuery *);
static void remove(QDeclarativeEngineDebug *, QDeclarativeDebugExpressionQuery *);
QHash<int, QDeclarativeDebugEnginesQuery *> enginesQuery;
QHash<int, QDeclarativeDebugRootContextQuery *> rootContextQuery;
QHash<int, QDeclarativeDebugObjectQuery *> objectQuery;
QHash<int, QDeclarativeDebugExpressionQuery *> expressionQuery;
QHash<int, QDeclarativeDebugWatch *> watched;
};
QDeclarativeEngineDebugClient::QDeclarativeEngineDebugClient(QDeclarativeDebugConnection *client,
QDeclarativeEngineDebugPrivate *p)
: QDeclarativeDebugClient(QLatin1String("QDeclarativeEngine"), client), priv(p)
{
setEnabled(true);
}
void QDeclarativeEngineDebugClient::messageReceived(const QByteArray &data)
{
priv->message(data);
}
QDeclarativeEngineDebugPrivate::QDeclarativeEngineDebugPrivate(QDeclarativeDebugConnection *c)
: client(new QDeclarativeEngineDebugClient(c, this)), nextId(0)
{
}
int QDeclarativeEngineDebugPrivate::getId()
{
return nextId++;
}
void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, QDeclarativeDebugEnginesQuery *q)
{
if (c && q) {
QDeclarativeEngineDebugPrivate *p = (QDeclarativeEngineDebugPrivate *)QObjectPrivate::get(c);
p->enginesQuery.remove(q->m_queryId);
}
}
void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c,
QDeclarativeDebugRootContextQuery *q)
{
if (c && q) {
QDeclarativeEngineDebugPrivate *p = (QDeclarativeEngineDebugPrivate *)QObjectPrivate::get(c);
p->rootContextQuery.remove(q->m_queryId);
}
}
void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, QDeclarativeDebugObjectQuery *q)
{
if (c && q) {
QDeclarativeEngineDebugPrivate *p = (QDeclarativeEngineDebugPrivate *)QObjectPrivate::get(c);
p->objectQuery.remove(q->m_queryId);
}
}
void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, QDeclarativeDebugExpressionQuery *q)
{
if (c && q) {
QDeclarativeEngineDebugPrivate *p = (QDeclarativeEngineDebugPrivate *)QObjectPrivate::get(c);
p->expressionQuery.remove(q->m_queryId);
}
}
//from qdeclarativeenginedebug.cpp
struct QDeclarativeObjectData {
QUrl url;
int lineNumber;
int columnNumber;
QString idString;
QString objectName;
QString objectType;
int objectId;
int contextId;
};
QDataStream &operator>>(QDataStream &ds, QDeclarativeObjectData &data)
{
ds >> data.url >> data.lineNumber >> data.columnNumber >> data.idString
>> data.objectName >> data.objectType >> data.objectId >> data.contextId;
return ds;
}
struct QDeclarativeObjectProperty {
enum Type { Unknown, Basic, Object, List, SignalProperty };
Type type;
QString name;
QVariant value;
QString valueTypeName;
QString binding;
bool hasNotifySignal;
};
QDataStream &operator>>(QDataStream &ds, QDeclarativeObjectProperty &data)
{
int type;
ds >> type >> data.name >> data.value >> data.valueTypeName
>> data.binding >> data.hasNotifySignal;
data.type = (QDeclarativeObjectProperty::Type)type;
return ds;
}
void QDeclarativeEngineDebugPrivate::decode(QDataStream &ds, QDeclarativeDebugObjectReference &o,
bool simple)
{
QDeclarativeObjectData data;
ds >> data;
o.m_debugId = data.objectId;
o.m_class = data.objectType;
o.m_idString = data.idString;
o.m_name = data.objectName;
o.m_source.m_url = data.url;
o.m_source.m_lineNumber = data.lineNumber;
o.m_source.m_columnNumber = data.columnNumber;
o.m_contextDebugId = data.contextId;
if (simple)
return;
int childCount;
bool recur;
ds >> childCount >> recur;
for (int ii = 0; ii < childCount; ++ii) {
o.m_children.append(QDeclarativeDebugObjectReference());
decode(ds, o.m_children.last(), !recur);
}
int propCount;
ds >> propCount;
for (int ii = 0; ii < propCount; ++ii) {
QDeclarativeObjectProperty data;
ds >> data;
QDeclarativeDebugPropertyReference prop;
prop.m_objectDebugId = o.m_debugId;
prop.m_name = data.name;
prop.m_binding = data.binding;
prop.m_hasNotifySignal = data.hasNotifySignal;
prop.m_valueTypeName = data.valueTypeName;
switch (data.type) {
case QDeclarativeObjectProperty::Basic:
case QDeclarativeObjectProperty::List:
case QDeclarativeObjectProperty::SignalProperty:
{
prop.m_value = data.value;
break;
}
case QDeclarativeObjectProperty::Object:
{
QDeclarativeDebugObjectReference obj;
obj.m_debugId = prop.m_value.toInt();
prop.m_value = qVariantFromValue(obj);
break;
}
case QDeclarativeObjectProperty::Unknown:
break;
}
o.m_properties << prop;
}
}
void QDeclarativeEngineDebugPrivate::decode(QDataStream &ds, QDeclarativeDebugContextReference &c)
{
ds >> c.m_name >> c.m_debugId;
int contextCount;
ds >> contextCount;
for (int ii = 0; ii < contextCount; ++ii) {
c.m_contexts.append(QDeclarativeDebugContextReference());
decode(ds, c.m_contexts.last());
}
int objectCount;
ds >> objectCount;
for (int ii = 0; ii < objectCount; ++ii) {
QDeclarativeDebugObjectReference obj;
decode(ds, obj, true);
obj.m_contextDebugId = c.m_debugId;
c.m_objects << obj;
}
}
void QDeclarativeEngineDebugPrivate::message(const QByteArray &data)
{
QDataStream ds(data);
QByteArray type;
ds >> type;
//qDebug() << "QDeclarativeEngineDebugPrivate::message()" << type;
if (type == "LIST_ENGINES_R") {
int queryId;
ds >> queryId;
QDeclarativeDebugEnginesQuery *query = enginesQuery.value(queryId);
if (!query)
return;
enginesQuery.remove(queryId);
int count;
ds >> count;
for (int ii = 0; ii < count; ++ii) {
QDeclarativeDebugEngineReference ref;
ds >> ref.m_name;
ds >> ref.m_debugId;
query->m_engines << ref;
}
query->m_client = 0;
query->setState(QDeclarativeDebugQuery::Completed);
} else if (type == "LIST_OBJECTS_R") {
int queryId;
ds >> queryId;
QDeclarativeDebugRootContextQuery *query = rootContextQuery.value(queryId);
if (!query)
return;
rootContextQuery.remove(queryId);
if (!ds.atEnd())
decode(ds, query->m_context);
query->m_client = 0;
query->setState(QDeclarativeDebugQuery::Completed);
} else if (type == "FETCH_OBJECT_R") {
int queryId;
ds >> queryId;
QDeclarativeDebugObjectQuery *query = objectQuery.value(queryId);
if (!query)
return;
objectQuery.remove(queryId);
if (!ds.atEnd())
decode(ds, query->m_object, false);
query->m_client = 0;
query->setState(QDeclarativeDebugQuery::Completed);
} else if (type == "EVAL_EXPRESSION_R") {
int queryId;
QVariant result;
ds >> queryId >> result;
QDeclarativeDebugExpressionQuery *query = expressionQuery.value(queryId);
if (!query)
return;
expressionQuery.remove(queryId);
query->m_result = result;
query->m_client = 0;
query->setState(QDeclarativeDebugQuery::Completed);
} else if (type == "WATCH_PROPERTY_R") {
int queryId;
bool ok;
ds >> queryId >> ok;
QDeclarativeDebugWatch *watch = watched.value(queryId);
if (!watch)
return;
watch->setState(ok ? QDeclarativeDebugWatch::Active : QDeclarativeDebugWatch::Inactive);
} else if (type == "WATCH_OBJECT_R") {
int queryId;
bool ok;
ds >> queryId >> ok;
QDeclarativeDebugWatch *watch = watched.value(queryId);
if (!watch)
return;
watch->setState(ok ? QDeclarativeDebugWatch::Active : QDeclarativeDebugWatch::Inactive);
} else if (type == "WATCH_EXPR_OBJECT_R") {
int queryId;
bool ok;
ds >> queryId >> ok;
QDeclarativeDebugWatch *watch = watched.value(queryId);
if (!watch)
return;
watch->setState(ok ? QDeclarativeDebugWatch::Active : QDeclarativeDebugWatch::Inactive);
} else if (type == "UPDATE_WATCH") {
int queryId;
int debugId;
QByteArray name;
QVariant value;
ds >> queryId >> debugId >> name >> value;
QDeclarativeDebugWatch *watch = watched.value(queryId, 0);
if (!watch)
return;
emit watch->valueChanged(name, value);
}
}
QDeclarativeEngineDebug::QDeclarativeEngineDebug(QDeclarativeDebugConnection *client, QObject *parent)
: QObject(*(new QDeclarativeEngineDebugPrivate(client)), parent)
{
}
QDeclarativeDebugPropertyWatch *QDeclarativeEngineDebug::addWatch(const QDeclarativeDebugPropertyReference &property, QObject *parent)
{
Q_D(QDeclarativeEngineDebug);
QDeclarativeDebugPropertyWatch *watch = new QDeclarativeDebugPropertyWatch(parent);
if (d->client->isConnected()) {
int queryId = d->getId();
watch->m_queryId = queryId;
watch->m_client = this;
watch->m_objectDebugId = property.objectDebugId();
watch->m_name = property.name();
d->watched.insert(queryId, watch);
QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("WATCH_PROPERTY") << queryId << property.objectDebugId() << property.name().toUtf8();
d->client->sendMessage(message);
} else {
watch->m_state = QDeclarativeDebugWatch::Dead;
}
return watch;
}
QDeclarativeDebugWatch *QDeclarativeEngineDebug::addWatch(const QDeclarativeDebugContextReference &, const QString &, QObject *)
{
qWarning("QDeclarativeEngineDebug::addWatch(): Not implemented");
return 0;
}
QDeclarativeDebugObjectExpressionWatch *QDeclarativeEngineDebug::addWatch(const QDeclarativeDebugObjectReference &object, const QString &expr, QObject *parent)
{
Q_D(QDeclarativeEngineDebug);
QDeclarativeDebugObjectExpressionWatch *watch = new QDeclarativeDebugObjectExpressionWatch(parent);
if (d->client->isConnected()) {
int queryId = d->getId();
watch->m_queryId = queryId;
watch->m_client = this;
watch->m_objectDebugId = object.debugId();
watch->m_expr = expr;
d->watched.insert(queryId, watch);
QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("WATCH_EXPR_OBJECT") << queryId << object.debugId() << expr;
d->client->sendMessage(message);
} else {
watch->m_state = QDeclarativeDebugWatch::Dead;
}
return watch;
}
QDeclarativeDebugWatch *QDeclarativeEngineDebug::addWatch(const QDeclarativeDebugObjectReference &object, QObject *parent)
{
Q_D(QDeclarativeEngineDebug);
QDeclarativeDebugWatch *watch = new QDeclarativeDebugWatch(parent);
if (d->client->isConnected()) {
int queryId = d->getId();
watch->m_queryId = queryId;
watch->m_client = this;
watch->m_objectDebugId = object.debugId();
d->watched.insert(queryId, watch);
QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("WATCH_OBJECT") << queryId << object.debugId();
d->client->sendMessage(message);
} else {
watch->m_state = QDeclarativeDebugWatch::Dead;
}
return watch;
}
QDeclarativeDebugWatch *QDeclarativeEngineDebug::addWatch(const QDeclarativeDebugFileReference &, QObject *)
{
qWarning("QDeclarativeEngineDebug::addWatch(): Not implemented");
return 0;
}
void QDeclarativeEngineDebug::removeWatch(QDeclarativeDebugWatch *watch)
{
Q_D(QDeclarativeEngineDebug);
if (!watch || !watch->m_client)
return;
watch->m_client = 0;
watch->setState(QDeclarativeDebugWatch::Inactive);
d->watched.remove(watch->queryId());
if (d->client && d->client->isConnected()) {
QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("NO_WATCH") << watch->queryId();
d->client->sendMessage(message);
}
}
QDeclarativeDebugEnginesQuery *QDeclarativeEngineDebug::queryAvailableEngines(QObject *parent)
{
Q_D(QDeclarativeEngineDebug);
QDeclarativeDebugEnginesQuery *query = new QDeclarativeDebugEnginesQuery(parent);
if (d->client->isConnected()) {
query->m_client = this;
int queryId = d->getId();
query->m_queryId = queryId;
d->enginesQuery.insert(queryId, query);
QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("LIST_ENGINES") << queryId;
d->client->sendMessage(message);
} else {
query->m_state = QDeclarativeDebugQuery::Error;
}
return query;
}
QDeclarativeDebugRootContextQuery *QDeclarativeEngineDebug::queryRootContexts(const QDeclarativeDebugEngineReference &engine, QObject *parent)
{
Q_D(QDeclarativeEngineDebug);
QDeclarativeDebugRootContextQuery *query = new QDeclarativeDebugRootContextQuery(parent);
if (d->client->isConnected() && engine.debugId() != -1) {
query->m_client = this;
int queryId = d->getId();
query->m_queryId = queryId;
d->rootContextQuery.insert(queryId, query);
QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("LIST_OBJECTS") << queryId << engine.debugId();
d->client->sendMessage(message);
} else {
query->m_state = QDeclarativeDebugQuery::Error;
}
return query;
}
QDeclarativeDebugObjectQuery *QDeclarativeEngineDebug::queryObject(const QDeclarativeDebugObjectReference &object, QObject *parent)
{
Q_D(QDeclarativeEngineDebug);
QDeclarativeDebugObjectQuery *query = new QDeclarativeDebugObjectQuery(parent);
if (d->client->isConnected() && object.debugId() != -1) {
query->m_client = this;
int queryId = d->getId();
query->m_queryId = queryId;
d->objectQuery.insert(queryId, query);
QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("FETCH_OBJECT") << queryId << object.debugId()
<< false;
d->client->sendMessage(message);
} else {
query->m_state = QDeclarativeDebugQuery::Error;
}
return query;
}
QDeclarativeDebugObjectQuery *QDeclarativeEngineDebug::queryObjectRecursive(const QDeclarativeDebugObjectReference &object, QObject *parent)
{
Q_D(QDeclarativeEngineDebug);
QDeclarativeDebugObjectQuery *query = new QDeclarativeDebugObjectQuery(parent);
if (d->client->isConnected() && object.debugId() != -1) {
query->m_client = this;
int queryId = d->getId();
query->m_queryId = queryId;
d->objectQuery.insert(queryId, query);
QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("FETCH_OBJECT") << queryId << object.debugId()
<< true;
d->client->sendMessage(message);
} else {
query->m_state = QDeclarativeDebugQuery::Error;
}
return query;
}
QDeclarativeDebugExpressionQuery *QDeclarativeEngineDebug::queryExpressionResult(int objectDebugId, const QString &expr, QObject *parent)
{
Q_D(QDeclarativeEngineDebug);
QDeclarativeDebugExpressionQuery *query = new QDeclarativeDebugExpressionQuery(parent);
if (d->client->isConnected() && objectDebugId != -1) {
query->m_client = this;
query->m_expr = expr;
int queryId = d->getId();
query->m_queryId = queryId;
d->expressionQuery.insert(queryId, query);
QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("EVAL_EXPRESSION") << queryId << objectDebugId << expr;