summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-06-26 04:52:07 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-06-26 04:52:07 (GMT)
commit3c45c081ce33f05ae200d252ebb5e9e1484bcc6d (patch)
tree5f8a6752e610ed8ca8bbf0ebd58cf16faad9b5e5 /src/declarative/qml
parent0362832c16f95c2909e2a68351e15242b7d1b795 (diff)
downloadQt-3c45c081ce33f05ae200d252ebb5e9e1484bcc6d.zip
Qt-3c45c081ce33f05ae200d252ebb5e9e1484bcc6d.tar.gz
Qt-3c45c081ce33f05ae200d252ebb5e9e1484bcc6d.tar.bz2
Update SetProperties to handle changing bindings
Also removed all uses of SetProperty
Diffstat (limited to 'src/declarative/qml')
-rw-r--r--src/declarative/qml/qmlbindablevalue.cpp35
-rw-r--r--src/declarative/qml/qmlbindablevalue.h10
-rw-r--r--src/declarative/qml/qmlbindablevalue_p.h6
-rw-r--r--src/declarative/qml/qmlmetaproperty.cpp47
-rw-r--r--src/declarative/qml/qmlmetaproperty.h4
-rw-r--r--src/declarative/qml/qmlvme.cpp4
6 files changed, 91 insertions, 15 deletions
diff --git a/src/declarative/qml/qmlbindablevalue.cpp b/src/declarative/qml/qmlbindablevalue.cpp
index d1835cf..222ea87 100644
--- a/src/declarative/qml/qmlbindablevalue.cpp
+++ b/src/declarative/qml/qmlbindablevalue.cpp
@@ -53,18 +53,18 @@ QT_BEGIN_NAMESPACE
DEFINE_BOOL_CONFIG_OPTION(scriptWarnings, QML_SCRIPT_WARNINGS);
QmlBindableValuePrivate::QmlBindableValuePrivate()
-: inited(false), updating(false), mePtr(0)
+: inited(false), updating(false), enabled(true), mePtr(0)
{
}
QML_DEFINE_NOCREATE_TYPE(QmlBindableValue);
-QmlBindableValue::QmlBindableValue(void *data, QmlRefCount *rc, QObject *obj, QObject *parent)
-: QmlPropertyValueSource(*new QmlBindableValuePrivate, parent), QmlExpression(QmlContext::activeContext(), data, rc, obj)
+QmlBindableValue::QmlBindableValue(void *data, QmlRefCount *rc, QObject *obj, QmlContext *ctxt, QObject *parent)
+: QmlPropertyValueSource(*new QmlBindableValuePrivate, parent), QmlExpression(ctxt, data, rc, obj)
{
}
-QmlBindableValue::QmlBindableValue(const QString &str, QObject *obj, QObject *parent)
-: QmlPropertyValueSource(*new QmlBindableValuePrivate, parent), QmlExpression(QmlContext::activeContext(), str, obj)
+QmlBindableValue::QmlBindableValue(const QString &str, QObject *obj, QmlContext *ctxt, QObject *parent)
+: QmlPropertyValueSource(*new QmlBindableValuePrivate, parent), QmlExpression(ctxt, str, obj)
{
}
@@ -105,6 +105,15 @@ void QmlBindableValue::setExpression(const QString &expr)
update();
}
+void QmlBindableValue::forceUpdate()
+{
+ Q_D(QmlBindableValue);
+ if (!d->inited)
+ init();
+ else
+ update();
+}
+
Q_DECLARE_METATYPE(QList<QObject *>);
void QmlBindableValue::update()
{
@@ -113,7 +122,7 @@ void QmlBindableValue::update()
#ifdef Q_ENABLE_PERFORMANCE_LOG
QFxPerfTimer<QFxPerf::BindableValueUpdate> bu;
#endif
- if (!d->inited)
+ if (!d->inited || !d->enabled)
return;
if (!d->updating) {
@@ -159,4 +168,18 @@ void QmlBindableValue::valueChanged()
update();
}
+void QmlBindableValue::setEnabled(bool e)
+{
+ Q_D(QmlBindableValue);
+ d->enabled = e;
+ setTrackChange(e);
+}
+
+bool QmlBindableValue::enabled() const
+{
+ Q_D(const QmlBindableValue);
+
+ return d->enabled;
+}
+
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qmlbindablevalue.h b/src/declarative/qml/qmlbindablevalue.h
index f54481a..50bbf36 100644
--- a/src/declarative/qml/qmlbindablevalue.h
+++ b/src/declarative/qml/qmlbindablevalue.h
@@ -62,8 +62,8 @@ class Q_DECLARATIVE_EXPORT QmlBindableValue : public QmlPropertyValueSource,
{
Q_OBJECT
public:
- QmlBindableValue(const QString &, QObject *, QObject *parent=0);
- QmlBindableValue(void *, QmlRefCount *, QObject *, QObject *parent);
+ QmlBindableValue(const QString &, QObject *, QmlContext *, QObject *parent=0);
+ QmlBindableValue(void *, QmlRefCount *, QObject *, QmlContext *, QObject *parent);
~QmlBindableValue();
virtual void setTarget(const QmlMetaProperty &);
@@ -74,8 +74,12 @@ public:
virtual void setExpression(const QString &);
void init();
+ void forceUpdate();
-private Q_SLOTS:
+ void setEnabled(bool);
+ bool enabled() const;
+
+public Q_SLOTS:
void update();
protected:
diff --git a/src/declarative/qml/qmlbindablevalue_p.h b/src/declarative/qml/qmlbindablevalue_p.h
index 9476b80..b55a314 100644
--- a/src/declarative/qml/qmlbindablevalue_p.h
+++ b/src/declarative/qml/qmlbindablevalue_p.h
@@ -54,8 +54,10 @@ class QmlBindableValuePrivate : public QObjectPrivate
public:
QmlBindableValuePrivate();
- bool inited;
- bool updating;
+ bool inited:1;
+ bool updating:1;
+ bool enabled:1;
+
QmlMetaProperty property;
QmlBindableValue **mePtr;
diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp
index 52036c2..30e818b 100644
--- a/src/declarative/qml/qmlmetaproperty.cpp
+++ b/src/declarative/qml/qmlmetaproperty.cpp
@@ -519,7 +519,7 @@ QMetaProperty QmlMetaProperty::property() const
Returns the binding associated with this property, or 0 if no binding
exists.
*/
-QmlBindableValue *QmlMetaProperty::binding()
+QmlBindableValue *QmlMetaProperty::binding() const
{
if (!isProperty() || type() & Attached)
return 0;
@@ -537,6 +537,51 @@ QmlBindableValue *QmlMetaProperty::binding()
return 0;
}
+/*!
+ Set the binding associated with this property to \a binding. Returns
+ the existing binding (if any), otherwise 0.
+
+ \a binding will be enabled, and the returned binding (if any) will be
+ disabled.
+*/
+QmlBindableValue *QmlMetaProperty::setBinding(QmlBindableValue *binding) const
+{
+ if (!isProperty() || type() & Attached)
+ return 0;
+
+ const QObjectList &children = object()->children();
+ for (QObjectList::ConstIterator iter = children.begin();
+ iter != children.end(); ++iter) {
+ QObject *child = *iter;
+ if (child->metaObject() == &QmlBindableValue::staticMetaObject) {
+ QmlBindableValue *v = static_cast<QmlBindableValue *>(child);
+ if (v->property() == *this && v->enabled()) {
+
+ v->setEnabled(false);
+
+ if (binding) {
+ binding->setParent(object());
+ binding->setTarget(*this);
+ binding->setEnabled(true);
+ binding->forceUpdate();
+ }
+
+ return v;
+
+ }
+ }
+ }
+
+ if (binding) {
+ binding->setParent(object());
+ binding->setTarget(*this);
+ binding->setEnabled(true);
+ binding->forceUpdate();
+ }
+
+ return 0;
+}
+
/*! \internal */
int QmlMetaProperty::findSignal(const QObject *obj, const char *name)
{
diff --git a/src/declarative/qml/qmlmetaproperty.h b/src/declarative/qml/qmlmetaproperty.h
index 9daef59..ce2fbcf 100644
--- a/src/declarative/qml/qmlmetaproperty.h
+++ b/src/declarative/qml/qmlmetaproperty.h
@@ -123,7 +123,9 @@ public:
QMetaProperty property() const;
- QmlBindableValue *binding();
+ QmlBindableValue *binding() const;
+ QmlBindableValue *setBinding(QmlBindableValue *) const;
+
static int findSignal(const QObject *, const char *);
int coreIndex() const;
diff --git a/src/declarative/qml/qmlvme.cpp b/src/declarative/qml/qmlvme.cpp
index a3ee4e5..962d917 100644
--- a/src/declarative/qml/qmlvme.cpp
+++ b/src/declarative/qml/qmlvme.cpp
@@ -564,7 +564,7 @@ QObject *QmlVME::run(QStack<QObject *> &stack, QmlContext *ctxt, QmlCompiledComp
QmlMetaProperty mp(target, instr.assignBinding.property,
(QmlMetaProperty::PropertyCategory)instr.assignBinding.category);
- QmlBindableValue *bind = new QmlBindableValue((void *)datas.at(instr.assignBinding.value).constData(), comp, context, 0);
+ QmlBindableValue *bind = new QmlBindableValue((void *)datas.at(instr.assignBinding.value).constData(), comp, context, QmlContext::activeContext(), 0);
bindValues.append(bind);
QmlBindableValuePrivate *p =
static_cast<QmlBindableValuePrivate *>(QObjectPrivate::get(bind));
@@ -584,7 +584,7 @@ QObject *QmlVME::run(QStack<QObject *> &stack, QmlContext *ctxt, QmlCompiledComp
QmlMetaProperty mp(target, instr.assignBinding.property,
(QmlMetaProperty::PropertyCategory)instr.assignBinding.category);
- QmlBindableValue *bind = new QmlBindableValue(primitives.at(instr.assignBinding.value), context, false);
+ QmlBindableValue *bind = new QmlBindableValue(primitives.at(instr.assignBinding.value), context, QmlContext::activeContext());
bindValues.append(bind);
QmlBindableValuePrivate *p =
static_cast<QmlBindableValuePrivate *>(QObjectPrivate::get(bind));