Make Binding a value source.
authorMichael Brasser <michael.brasser@nokia.com>
Fri, 11 Mar 2011 05:28:52 +0000 (15:28 +1000)
committerMichael Brasser <michael.brasser@nokia.com>
Thu, 2 Jun 2011 01:59:34 +0000 (11:59 +1000)
Change-Id: I1a9003f1e506c53e172bfae418f536ad0da2bf47
Reviewed-by: Martin Jones

src/declarative/util/qdeclarativebind.cpp
src/declarative/util/qdeclarativebind_p.h

index b7199ac..ff30336 100644 (file)
@@ -65,8 +65,9 @@ public:
     bool when : 1;
     bool componentComplete : 1;
     QObject *obj;
-    QString prop;
+    QString propName;
     QDeclarativeNullableValue<QVariant> value;
+    QDeclarativeProperty prop;
 };
 
 
@@ -146,6 +147,8 @@ void QDeclarativeBind::setObject(QObject *obj)
 {
     Q_D(QDeclarativeBind);
     d->obj = obj;
+    if (d->componentComplete)
+        d->prop = QDeclarativeProperty(d->obj, d->propName);
     eval();
 }
 
@@ -157,13 +160,15 @@ void QDeclarativeBind::setObject(QObject *obj)
 QString QDeclarativeBind::property() const
 {
     Q_D(const QDeclarativeBind);
-    return d->prop;
+    return d->propName;
 }
 
 void QDeclarativeBind::setProperty(const QString &p)
 {
     Q_D(QDeclarativeBind);
-    d->prop = p;
+    d->propName = p;
+    if (d->componentComplete)
+        d->prop = QDeclarativeProperty(d->obj, d->propName);
     eval();
 }
 
@@ -187,6 +192,12 @@ void QDeclarativeBind::setValue(const QVariant &v)
     eval();
 }
 
+void QDeclarativeBind::setTarget(const QDeclarativeProperty &p)
+{
+    Q_D(QDeclarativeBind);
+    d->prop = p;
+}
+
 void QDeclarativeBind::classBegin()
 {
     Q_D(QDeclarativeBind);
@@ -197,17 +208,18 @@ void QDeclarativeBind::componentComplete()
 {
     Q_D(QDeclarativeBind);
     d->componentComplete = true;
+    if (!d->prop.isValid())
+        d->prop = QDeclarativeProperty(d->obj, d->propName);
     eval();
 }
 
 void QDeclarativeBind::eval()
 {
     Q_D(QDeclarativeBind);
-    if (!d->obj || d->value.isNull || !d->when || !d->componentComplete)
+    if (!d->prop.isValid() || d->value.isNull || !d->when || !d->componentComplete)
         return;
 
-    QDeclarativeProperty prop(d->obj, d->prop);
-    prop.write(d->value.value);
+    d->prop.write(d->value.value);
 }
 
 QT_END_NAMESPACE
index b5e14c2..38f15a9 100644 (file)
@@ -53,11 +53,12 @@ QT_BEGIN_NAMESPACE
 QT_MODULE(Declarative)
 
 class QDeclarativeBindPrivate;
-class Q_AUTOTEST_EXPORT QDeclarativeBind : public QObject, public QDeclarativeParserStatus
+class Q_AUTOTEST_EXPORT QDeclarativeBind : public QObject, public QDeclarativePropertyValueSource, public QDeclarativeParserStatus
 {
     Q_OBJECT
     Q_DECLARE_PRIVATE(QDeclarativeBind)
     Q_INTERFACES(QDeclarativeParserStatus)
+    Q_INTERFACES(QDeclarativePropertyValueSource)
     Q_PROPERTY(QObject *target READ object WRITE setObject)
     Q_PROPERTY(QString property READ property WRITE setProperty)
     Q_PROPERTY(QVariant value READ value WRITE setValue)
@@ -80,6 +81,7 @@ public:
     void setValue(const QVariant &);
 
 protected:
+    virtual void setTarget(const QDeclarativeProperty &);
     virtual void classBegin();
     virtual void componentComplete();