diff options
author | Bea Lam <bea.lam@nokia.com> | 2009-10-19 23:54:57 (GMT) |
---|---|---|
committer | Bea Lam <bea.lam@nokia.com> | 2009-10-19 23:54:57 (GMT) |
commit | 515cb0f40654e54384fd75c7042b9fa25d3df193 (patch) | |
tree | b30ca86a22c4f02c59bb4ec574d85f415e2d03a2 /src/declarative/qml/qmlenginedebug.cpp | |
parent | 0ae3e10fecfe9f6241e8752bdd4deab8663988b7 (diff) | |
download | Qt-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.
Diffstat (limited to 'src/declarative/qml/qmlenginedebug.cpp')
-rw-r--r-- | src/declarative/qml/qmlenginedebug.cpp | 78 |
1 files changed, 56 insertions, 22 deletions
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); |