diff options
author | Chris Adams <christopher.adams@nokia.com> | 2012-02-06 14:24:42 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-05 09:01:47 +0100 |
commit | b6e78b38367a23f0b053bbd2abe4ef161e4053b9 (patch) | |
tree | 022bb82553af5b96a31f6e1ba56944d0e7060437 /src/qml/qml/qqmlproperty.cpp | |
parent | 0284817d6cd7e17afa8da26ee6e9199100754446 (diff) |
Improve support for var properties
This commit changes the semantics of function assignment in QML.
Previously, function assignment was interpreted as binding assignment.
Now, function assignment is interpreted as function assignment, and
therefore fails for all property types other than "var" properties.
To support imperative binding assignment, a new function was added to
the Qt object: Qt.binding(function) which takes a single function
parameter and returns a function object which will be interpreted as
an assignable binding expression by the QML engine.
Finally, this commit also slightly changes the semantics of var
properties in that the "special" JavaScript values of null and
undefined may be assigned to var properties, rather than being
interpreted as reset requests.
Task-number: QTBUG-21842
Change-Id: Iee99a878b9badf0fb76e983da7ebfa493f55ceb5
Reviewed-by: Matthew Vogt <matthew.vogt@nokia.com>
Diffstat (limited to 'src/qml/qml/qqmlproperty.cpp')
-rw-r--r-- | src/qml/qml/qqmlproperty.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp index 6321592e9a..00cb65d106 100644 --- a/src/qml/qml/qqmlproperty.cpp +++ b/src/qml/qml/qqmlproperty.cpp @@ -1486,6 +1486,17 @@ bool QQmlPropertyPrivate::writeBinding(QObject *object, if (expression->hasError()) { return false; + } else if (isVmeProperty) { + typedef QQmlVMEMetaObject VMEMO; + if (!result.IsEmpty() && result->IsFunction() + && !result->ToObject()->GetHiddenValue(v8engine->bindingFlagKey()).IsEmpty()) { + // we explicitly disallow this case to avoid confusion. Users can still store one + // in an array in a var property if they need to, but the common case is user error. + expression->delayedError()->error.setDescription(QLatin1String("Invalid use of Qt.binding() in a binding declaration.")); + return false; + } + VMEMO *vmemo = static_cast<VMEMO *>(const_cast<QMetaObject *>(object->metaObject())); + vmemo->setVMEProperty(core.coreIndex, result); } else if (isUndefined && core.isResettable()) { void *args[] = { 0 }; QMetaObject::metacall(object, QMetaObject::ResetProperty, core.coreIndex, args); @@ -1495,12 +1506,11 @@ bool QQmlPropertyPrivate::writeBinding(QObject *object, expression->delayedError()->error.setDescription(QLatin1String("Unable to assign [undefined] to ") + QLatin1String(QMetaType::typeName(type))); return false; } else if (result->IsFunction()) { - expression->delayedError()->error.setDescription(QLatin1String("Unable to assign a function to a property.")); + if (!result->ToObject()->GetHiddenValue(v8engine->bindingFlagKey()).IsEmpty()) + expression->delayedError()->error.setDescription(QLatin1String("Invalid use of Qt.binding() in a binding declaration.")); + else + expression->delayedError()->error.setDescription(QLatin1String("Unable to assign a function to a property of any type other than var.")); return false; - } else if (isVmeProperty) { - typedef QQmlVMEMetaObject VMEMO; - VMEMO *vmemo = static_cast<VMEMO *>(const_cast<QMetaObject *>(object->metaObject())); - vmemo->setVMEProperty(core.coreIndex, result); } else if (!writeValueProperty(object, engine, core, value, context, flags)) { if (watcher.wasDeleted()) |