Qml : Resetting binding corrected
authorSimjees Abraham <simjees.abraham@nokia.com>
Wed, 16 May 2012 13:20:59 +0000 (15:20 +0200)
committerQt by Nokia <qt-info@nokia.com>
Mon, 21 May 2012 10:40:55 +0000 (12:40 +0200)
Resetting the binding for property corrected in case the property is
nested (eg: font.bold)

Task-number: QTCREATORBUG-6294
Change-Id: I39cca54c17860c4e6df1cf864cc2f70214d50c8f
Reviewed-by: Christiaan Janssen <christiaan.janssen@nokia.com>
src/qml/debugger/qqmlenginedebugservice.cpp
tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp

index 068bc36..764ba6b 100644 (file)
@@ -651,7 +651,11 @@ bool QQmlEngineDebugService::resetBinding(int objectId, const QString &propertyN
     QQmlContext *context = qmlContext(object);
 
     if (object && context) {
-        if (object->property(propertyName.toLatin1()).isValid()) {
+        QString parentProperty = propertyName;
+        if (propertyName.indexOf(QLatin1Char('.')) != -1)
+            parentProperty = propertyName.left(propertyName.indexOf(QLatin1Char('.')));
+
+        if (object->property(parentProperty.toLatin1()).isValid()) {
             QQmlProperty property(object, propertyName);
             QQmlAbstractBinding *oldBinding = QQmlPropertyPrivate::binding(property);
             if (oldBinding) {
@@ -669,7 +673,7 @@ bool QQmlEngineDebugService::resetBinding(int objectId, const QString &propertyN
                 // overwrite with default value
                 if (QQmlType *objType = QQmlMetaType::qmlType(object->metaObject())) {
                     if (QObject *emptyObject = objType->create()) {
-                        if (emptyObject->property(propertyName.toLatin1()).isValid()) {
+                        if (emptyObject->property(parentProperty.toLatin1()).isValid()) {
                             QVariant defaultValue = QQmlProperty(emptyObject, propertyName).read();
                             if (defaultValue.isValid()) {
                                 setBinding(objectId, propertyName, defaultValue, true);
@@ -679,15 +683,24 @@ bool QQmlEngineDebugService::resetBinding(int objectId, const QString &propertyN
                     }
                 }
             }
-        } else if (hasValidSignal(object, propertyName)) {
+            return true;
+        }
+
+        if (hasValidSignal(object, propertyName)) {
             QQmlProperty property(object, propertyName, context);
             QQmlPropertyPrivate::setSignalExpression(property, 0);
-        } else {
-            if (m_statesDelegate)
-                m_statesDelegate->resetBindingForInvalidProperty(object, propertyName);
+            return true;
         }
+
+        if (m_statesDelegate) {
+            m_statesDelegate->resetBindingForInvalidProperty(object, propertyName);
+            return true;
+        }
+
+        return false;
     }
-    return true;
+    // object or context null.
+    return false;
 }
 
 bool QQmlEngineDebugService::setMethodBody(int objectId, const QString &method, const QString &body)
index 3c57c36..b0070b7 100644 (file)
@@ -127,6 +127,7 @@ private slots:
     void queryExpressionResultBC_data();
 
     void setBindingForObject();
+    void resetBindingForObject();
     void setMethodBody();
     void queryObjectTree();
     void setBindingInStates();
@@ -258,7 +259,7 @@ void tst_QQmlEngineDebugService::initTestCase()
                 "id: root\n"
                 "width: 10; height: 20; scale: blueRect.scale;"
                 "Rectangle { id: blueRect; width: 500; height: 600; color: \"blue\"; }"
-                "Text { color: blueRect.color; }"
+                "Text { font.bold: true; color: blueRect.color; }"
                 "MouseArea {"
                     "onEntered: { console.log('hello') }"
                 "}"
@@ -886,20 +887,6 @@ void tst_QQmlEngineDebugService::setBindingForObject()
     QCOMPARE(widthPropertyRef.binding, QString("height"));
 
     //
-    // reset
-    //
-    m_dbg->resetBindingForObject(rootObject.debugId, "width", &success);
-    QVERIFY(success);
-    QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result())));
-    QCOMPARE(m_dbg->valid(), true);
-
-    rootObject = findRootObject();
-    widthPropertyRef =  findProperty(rootObject.properties, "width");
-
-   // QCOMPARE(widthPropertyRef.value(), QVariant(0)); // TODO: Shouldn't this work?
-    QCOMPARE(widthPropertyRef.binding, QString());
-
-    //
     // set handler
     //
     rootObject = findRootObject();
@@ -935,6 +922,50 @@ void tst_QQmlEngineDebugService::setBindingForObject()
     QCOMPARE(onEnteredRef.value,  QVariant("{console.log('hello, world') }"));
 }
 
+void tst_QQmlEngineDebugService::resetBindingForObject()
+{
+    QmlDebugObjectReference rootObject = findRootObject();
+    QVERIFY(rootObject.debugId != -1);
+    QmlDebugPropertyReference widthPropertyRef = findProperty(rootObject.properties, "width");
+
+    bool success = false;
+
+    m_dbg->setBindingForObject(rootObject.debugId, "width", "15", true,
+                               QString(), -1, &success);
+    QVERIFY(success);
+    QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result())));
+    QCOMPARE(m_dbg->valid(), true);
+
+    //
+    // reset
+    //
+    m_dbg->resetBindingForObject(rootObject.debugId, "width", &success);
+    QVERIFY(success);
+    QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result())));
+    QCOMPARE(m_dbg->valid(), true);
+
+    rootObject = findRootObject();
+    widthPropertyRef =  findProperty(rootObject.properties, "width");
+
+    QCOMPARE(widthPropertyRef.value, QVariant(0));
+    QCOMPARE(widthPropertyRef.binding, QString());
+
+    //
+    // reset nested property
+    //
+    success = false;
+    m_dbg->resetBindingForObject(rootObject.debugId, "font.bold", &success);
+    QVERIFY(success);
+    QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result())));
+    QCOMPARE(m_dbg->valid(), true);
+
+    rootObject = findRootObject();
+    QmlDebugPropertyReference boldPropertyRef =  findProperty(rootObject.properties, "font.bold");
+
+    QCOMPARE(boldPropertyRef.value.toBool(), false);
+    QCOMPARE(boldPropertyRef.binding, QString());
+}
+
 void tst_QQmlEngineDebugService::setBindingInStates()
 {
     // Check if changing bindings of propertychanges works