summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml/qdeclarativeenginedebug.cpp
diff options
context:
space:
mode:
authorLasse Holmstedt <lasse.holmstedt@nokia.com>2010-06-30 08:10:23 (GMT)
committerLasse Holmstedt <lasse.holmstedt@nokia.com>2010-06-30 08:16:45 (GMT)
commited82b3d0f93b9876201aa8145eafbaf4b50f2f36 (patch)
tree4af208b97ae052604a38addf8c39dfce40888b60 /src/declarative/qml/qdeclarativeenginedebug.cpp
parent730511f15bd619319e99fba484cf415b87a38052 (diff)
downloadQt-ed82b3d0f93b9876201aa8145eafbaf4b50f2f36.zip
Qt-ed82b3d0f93b9876201aa8145eafbaf4b50f2f36.tar.gz
Qt-ed82b3d0f93b9876201aa8145eafbaf4b50f2f36.tar.bz2
Added SET_BINDING message to QDeclarative debugger protocol
The new message currently enables resetting bindings, literal values and signal handlers (onX: {...}) through the debugger. Reviewed-by: Roberto Raggi
Diffstat (limited to 'src/declarative/qml/qdeclarativeenginedebug.cpp')
-rw-r--r--src/declarative/qml/qdeclarativeenginedebug.cpp67
1 files changed, 65 insertions, 2 deletions
diff --git a/src/declarative/qml/qdeclarativeenginedebug.cpp b/src/declarative/qml/qdeclarativeenginedebug.cpp
index 7ae0050..d765649 100644
--- a/src/declarative/qml/qdeclarativeenginedebug.cpp
+++ b/src/declarative/qml/qdeclarativeenginedebug.cpp
@@ -59,7 +59,7 @@ QT_BEGIN_NAMESPACE
QList<QDeclarativeEngine *> QDeclarativeEngineDebugServer::m_engines;
QDeclarativeEngineDebugServer::QDeclarativeEngineDebugServer(QObject *parent)
: QDeclarativeDebugService(QLatin1String("QDeclarativeEngine"), parent),
- m_watch(new QDeclarativeWatcher(this))
+ m_watch(new QDeclarativeWatcher(this))
{
QObject::connect(m_watch, SIGNAL(propertyChanged(int,int,QMetaProperty,QVariant)),
this, SLOT(propertyChanged(int,int,QMetaProperty,QVariant)));
@@ -99,6 +99,29 @@ QDataStream &operator>>(QDataStream &ds,
return ds;
}
+static inline bool isSignalPropertyName(const QString &signalName)
+{
+ // see QmlCompiler::isSignalPropertyName
+ return signalName.length() >= 3 && signalName.startsWith(QLatin1String("on")) &&
+ signalName.at(2).isLetter() && signalName.at(2).isUpper();
+}
+
+static bool hasValidSignal(QObject *object, const QString &propertyName)
+{
+ if (!isSignalPropertyName(propertyName))
+ return false;
+
+ QString signalName = propertyName.mid(2);
+ signalName[0] = signalName.at(0).toLower();
+
+ int sigIdx = QDeclarativePropertyPrivate::findSignalByName(object->metaObject(), signalName.toLatin1()).methodIndex();
+
+ if (sigIdx == -1)
+ return false;
+
+ return true;
+}
+
QDeclarativeEngineDebugServer::QDeclarativeObjectProperty
QDeclarativeEngineDebugServer::propertyData(QObject *obj, int propIdx)
{
@@ -396,7 +419,6 @@ void QDeclarativeEngineDebugServer::messageReceived(const QByteArray &message)
QByteArray reply;
QDataStream rs(&reply, QIODevice::WriteOnly);
rs << QByteArray("WATCH_EXPR_OBJECT_R") << queryId << ok;
-
sendMessage(reply);
} else if (type == "NO_WATCH") {
int queryId;
@@ -430,7 +452,48 @@ void QDeclarativeEngineDebugServer::messageReceived(const QByteArray &message)
rs << QByteArray("EVAL_EXPRESSION_R") << queryId << result;
sendMessage(reply);
+ } else if (type == "SET_BINDING") {
+ int queryId;
+ int objectId;
+ QString propertyName;
+ QVariant expr;
+ bool isLiteralValue;
+ ds >> queryId >> objectId >> propertyName >> expr >> isLiteralValue;
+ setBinding(objectId, propertyName, expr, isLiteralValue);
+ }
+}
+
+void QDeclarativeEngineDebugServer::setBinding(int objectId,
+ const QString &propertyName,
+ const QVariant &expression,
+ bool isLiteralValue)
+{
+ QObject *object = objectForId(objectId);
+ QDeclarativeContext *context = qmlContext(object);
+
+ if (object && context) {
+
+ if (isLiteralValue) {
+ QDeclarativeProperty literalProperty(object, propertyName, context);
+ literalProperty.write(expression);
+ } else {
+ if (hasValidSignal(object, propertyName)) {
+ QDeclarativeProperty property(object, propertyName);
+ QDeclarativeExpression *declarativeExpression = new QDeclarativeExpression(context, object, expression.toString());
+ QDeclarativePropertyPrivate::setSignalExpression(property, declarativeExpression);
+ } else {
+ QDeclarativeBinding *binding = new QDeclarativeBinding(expression.toString(), object, context);
+ QDeclarativeProperty property(object, propertyName);
+ binding->setTarget(property);
+ binding->setNotifyOnValueChanged(true);
+ QDeclarativeAbstractBinding *oldBinding = QDeclarativePropertyPrivate::setBinding(property, binding);
+ if (oldBinding)
+ oldBinding->destroy();
+ binding->update();
+ }
+ }
}
+
}
void QDeclarativeEngineDebugServer::propertyChanged(int id, int objectId, const QMetaProperty &property, const QVariant &value)