summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2009-10-19 23:54:57 (GMT)
committerBea Lam <bea.lam@nokia.com>2009-10-19 23:54:57 (GMT)
commit515cb0f40654e54384fd75c7042b9fa25d3df193 (patch)
treeb30ca86a22c4f02c59bb4ec574d85f415e2d03a2
parent0ae3e10fecfe9f6241e8752bdd4deab8663988b7 (diff)
downloadQt-515cb0f40654e54384fd75c7042b9fa25d3df193.zip
Qt-515cb0f40654e54384fd75c7042b9fa25d3df193.tar.gz
Qt-515cb0f40654e54384fd75c7042b9fa25d3df193.tar.bz2
Add EVAL_EXPRESSION so clients can evaluate an expression within the
current object's context.
-rw-r--r--src/declarative/debugger/qmldebug.cpp66
-rw-r--r--src/declarative/debugger/qmldebug.h22
-rw-r--r--src/declarative/qml/qmlenginedebug.cpp78
-rw-r--r--src/declarative/qml/qmlenginedebug_p.h1
4 files changed, 144 insertions, 23 deletions
diff --git a/src/declarative/debugger/qmldebug.cpp b/src/declarative/debugger/qmldebug.cpp
index 1ef7503..75418e8 100644
--- a/src/declarative/debugger/qmldebug.cpp
+++ b/src/declarative/debugger/qmldebug.cpp
@@ -32,10 +32,12 @@ public:
static void remove(QmlEngineDebug *, QmlDebugEnginesQuery *);
static void remove(QmlEngineDebug *, QmlDebugRootContextQuery *);
static void remove(QmlEngineDebug *, QmlDebugObjectQuery *);
+ static void remove(QmlEngineDebug *, QmlDebugExpressionQuery *);
QHash<int, QmlDebugEnginesQuery *> enginesQuery;
QHash<int, QmlDebugRootContextQuery *> rootContextQuery;
QHash<int, QmlDebugObjectQuery *> objectQuery;
+ QHash<int, QmlDebugExpressionQuery *> expressionQuery;
QHash<int, QmlDebugWatch *> watched;
};
@@ -81,6 +83,12 @@ void QmlEngineDebugPrivate::remove(QmlEngineDebug *c, QmlDebugObjectQuery *q)
p->objectQuery.remove(q->m_queryId);
}
+void QmlEngineDebugPrivate::remove(QmlEngineDebug *c, QmlDebugExpressionQuery *q)
+{
+ QmlEngineDebugPrivate *p = (QmlEngineDebugPrivate *)QObjectPrivate::get(c);
+ p->expressionQuery.remove(q->m_queryId);
+}
+
Q_DECLARE_METATYPE(QmlDebugObjectReference);
void QmlEngineDebugPrivate::decode(QDataStream &ds, QmlDebugObjectReference &o,
bool simple)
@@ -212,6 +220,19 @@ void QmlEngineDebugPrivate::message(const QByteArray &data)
query->m_client = 0;
query->setState(QmlDebugQuery::Completed);
+ } else if (type == "EVAL_EXPRESSION_R") {
+ int queryId;
+ QVariant result;
+ ds >> queryId >> result;
+
+ QmlDebugExpressionQuery *query = expressionQuery.value(queryId);
+ if (!query)
+ return;
+ expressionQuery.remove(queryId);
+
+ query->m_result = result;
+ query->m_client = 0;
+ query->setState(QmlDebugQuery::Completed);
} else if (type == "WATCH_PROPERTY_R") {
int queryId;
bool ok;
@@ -267,7 +288,6 @@ QmlDebugPropertyWatch *QmlEngineDebug::addWatch(const QmlDebugPropertyReference
QmlDebugPropertyWatch *watch = new QmlDebugPropertyWatch(parent);
if (d->client->isConnected()) {
- //query->m_client = this;
int queryId = d->getId();
watch->m_queryId = queryId;
watch->m_objectDebugId = property.objectDebugId();
@@ -445,6 +465,29 @@ QmlDebugObjectQuery *QmlEngineDebug::queryObjectRecursive(const QmlDebugObjectRe
return query;
}
+QmlDebugExpressionQuery *QmlEngineDebug::queryExpressionResult(int objectDebugId, const QString &expr, QObject *parent)
+{
+ Q_D(QmlEngineDebug);
+
+ QmlDebugExpressionQuery *query = new QmlDebugExpressionQuery(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;
+ d->client->sendMessage(message);
+ } else {
+ query->m_state = QmlDebugQuery::Error;
+ }
+
+ return query;
+}
+
QmlDebugWatch::QmlDebugWatch(QObject *parent)
: QObject(parent), m_state(Waiting), m_queryId(-1), m_objectDebugId(-1)
{
@@ -566,6 +609,27 @@ QmlDebugObjectReference QmlDebugObjectQuery::object() const
return m_object;
}
+QmlDebugExpressionQuery::QmlDebugExpressionQuery(QObject *parent)
+: QmlDebugQuery(parent), m_client(0), m_queryId(-1)
+{
+}
+
+QmlDebugExpressionQuery::~QmlDebugExpressionQuery()
+{
+ if (m_client && m_queryId != -1)
+ QmlEngineDebugPrivate::remove(m_client, this);
+}
+
+QString QmlDebugExpressionQuery::expression() const
+{
+ return m_expr;
+}
+
+QVariant QmlDebugExpressionQuery::result() const
+{
+ return m_result;
+}
+
QmlDebugEngineReference::QmlDebugEngineReference()
: m_debugId(-1)
{
diff --git a/src/declarative/debugger/qmldebug.h b/src/declarative/debugger/qmldebug.h
index 681ee08..153a10f 100644
--- a/src/declarative/debugger/qmldebug.h
+++ b/src/declarative/debugger/qmldebug.h
@@ -12,6 +12,7 @@ class QmlDebugObjectExpressionWatch;
class QmlDebugEnginesQuery;
class QmlDebugRootContextQuery;
class QmlDebugObjectQuery;
+class QmlDebugExpressionQuery;
class QmlDebugPropertyReference;
class QmlDebugContextReference;
class QmlDebugObjectReference;
@@ -44,6 +45,9 @@ public:
QObject *parent = 0);
QmlDebugObjectQuery *queryObjectRecursive(const QmlDebugObjectReference &,
QObject *parent = 0);
+ QmlDebugExpressionQuery *queryExpressionResult(int objectDebugId,
+ const QString &expr,
+ QObject *parent = 0);
private:
Q_DECLARE_PRIVATE(QmlEngineDebug)
@@ -287,4 +291,22 @@ private:
};
+class Q_DECLARATIVE_EXPORT QmlDebugExpressionQuery : public QmlDebugQuery
+{
+Q_OBJECT
+public:
+ virtual ~QmlDebugExpressionQuery();
+ QString expression() const;
+ QVariant result() const;
+private:
+ friend class QmlEngineDebug;
+ friend class QmlEngineDebugPrivate;
+ QmlDebugExpressionQuery(QObject *);
+ QmlEngineDebug *m_client;
+ int m_queryId;
+ QString m_expr;
+ QVariant m_result;
+
+};
+
#endif // QMLDEBUG_H
diff --git a/src/declarative/qml/qmlenginedebug.cpp b/src/declarative/qml/qmlenginedebug.cpp
index 1c7450a..bbe6f77 100644
--- a/src/declarative/qml/qmlenginedebug.cpp
+++ b/src/declarative/qml/qmlenginedebug.cpp
@@ -184,6 +184,33 @@ void QmlEngineDebugServer::buildObjectList(QDataStream &message,
}
}
+QVariant QmlEngineDebugServer::serializableVariant(const QVariant &value)
+{
+ QVariant v;
+ if (value.type() == QVariant::UserType || QmlMetaType::isObject(value.userType())) {
+ QObject *o = QmlMetaType::toQObject(value);
+ if (o) {
+ QString objectName = o->objectName();
+ if (objectName.isEmpty())
+ objectName = QLatin1String("<unnamed>");
+ v = QString::fromUtf8(o->metaObject()->className()) +
+ QLatin1String(": ") + objectName;
+ } else {
+ v = QString::fromUtf8(value.typeName());
+ }
+ if (v.isNull()) {
+ QString s = value.toString();
+ if (s.isEmpty())
+ s = QLatin1String("<unknown>");
+ v = s;
+ }
+ } else {
+ v = value;
+ }
+
+ return v;
+}
+
QmlEngineDebugServer::QmlObjectData
QmlEngineDebugServer::objectData(QObject *object)
{
@@ -310,36 +337,43 @@ void QmlEngineDebugServer::messageReceived(const QByteArray &message)
ds >> queryId;
m_watch->removeWatch(queryId);
+ } else if (type == "EVAL_EXPRESSION") {
+ int queryId;
+ int objectId;
+ QString expr;
+
+ ds >> queryId >> objectId >> expr;
+
+ QObject *object = QmlDebugService::objectForId(objectId);
+ QmlContext *context = qmlContext(object);
+ QVariant result;
+ if (object && context) {
+ QmlExpression *exprObj = new QmlExpression(context, expr, object);
+ bool undefined = false;
+ QVariant value = exprObj->value(&undefined);
+ if (undefined)
+ result = QLatin1String("<undefined>");
+ else
+ result = serializableVariant(value);
+ delete exprObj;
+ } else {
+ result = QLatin1String("<unknown context>");
+ }
+
+ QByteArray reply;
+ QDataStream rs(&reply, QIODevice::WriteOnly);
+ rs << QByteArray("EVAL_EXPRESSION_R") << queryId << result;
+
+ sendMessage(reply);
}
}
void QmlEngineDebugServer::propertyChanged(int id, int objectId, const QByteArray &property, const QVariant &value)
{
QByteArray reply;
- QVariant v;
+ QVariant v = serializableVariant(value);
QDataStream rs(&reply, QIODevice::WriteOnly);
- if (value.type() == QVariant::UserType || QmlMetaType::isObject(value.userType())) {
- QObject *o = QmlMetaType::toQObject(value);
- if (o) {
- QString objectName = o->objectName();
- if (objectName.isEmpty())
- objectName = QLatin1String("<unnamed>");
- v = QString::fromUtf8(o->metaObject()->className()) +
- QLatin1String(": ") + objectName;
- } else {
- v = QString::fromUtf8(value.typeName());
- }
- if (v.isNull()) {
- QString s = value.toString();
- if (s.isEmpty())
- s = QLatin1String("<unknown>");
- v = s;
- }
- } else {
- v = value;
- }
-
rs << QByteArray("UPDATE_WATCH") << id << objectId << property << v;
sendMessage(reply);
diff --git a/src/declarative/qml/qmlenginedebug_p.h b/src/declarative/qml/qmlenginedebug_p.h
index e2f903c..9ad198a 100644
--- a/src/declarative/qml/qmlenginedebug_p.h
+++ b/src/declarative/qml/qmlenginedebug_p.h
@@ -103,6 +103,7 @@ private:
void buildObjectDump(QDataStream &, QObject *, bool);
QmlObjectData objectData(QObject *);
QmlObjectProperty propertyData(QObject *, int);
+ QVariant serializableVariant(const QVariant &value);
static QList<QmlEngine *> m_engines;
QmlWatcher *m_watch;