aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlproperty.cpp
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2012-05-11 17:37:07 +1000
committerQt by Nokia <qt-info@nokia.com>2012-05-24 05:52:32 +0200
commit4709f30b26042427b225dd164648e3f5907c9d33 (patch)
tree3edac8d14d3fb77406ef93aa2c34c42131109625 /src/qml/qml/qqmlproperty.cpp
parent2542778d4837143a61dfcf143c32683acc8b998a (diff)
Enable binding to properties of type QJSValue.
This allows javascript objects of all types to be bound to properties declared in c++. Compared to a QVariant the primary benefit this offers is a type which functions and objects with functions can be bound to. Change-Id: Idb3313e7ff1d616ab12d44f616083c8296201f3a Reviewed-by: Kent Hansen <kent.hansen@nokia.com>
Diffstat (limited to 'src/qml/qml/qqmlproperty.cpp')
-rw-r--r--src/qml/qml/qqmlproperty.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp
index 761b75acf4..087fbaa9bf 100644
--- a/src/qml/qml/qqmlproperty.cpp
+++ b/src/qml/qml/qqmlproperty.cpp
@@ -62,6 +62,7 @@
#include <math.h>
+Q_DECLARE_METATYPE(QJSValue)
Q_DECLARE_METATYPE(QList<int>)
Q_DECLARE_METATYPE(QList<qreal>)
Q_DECLARE_METATYPE(QList<bool>)
@@ -1489,7 +1490,7 @@ bool QQmlPropertyPrivate::writeBinding(QObject *object,
value = QVariant::fromValue((QObject *)0);
} else if (core.propType == qMetaTypeId<QList<QUrl> >()) {
value = resolvedUrlSequence(v8engine->toVariant(result, qMetaTypeId<QList<QUrl> >()), context);
- } else if (!isVmeProperty) {
+ } else if (!isVmeProperty && type != qMetaTypeId<QJSValue>()) {
value = v8engine->toVariant(result, type);
}
@@ -1511,6 +1512,13 @@ bool QQmlPropertyPrivate::writeBinding(QObject *object,
QMetaObject::metacall(object, QMetaObject::ResetProperty, core.coreIndex, args);
} else if (isUndefined && type == qMetaTypeId<QVariant>()) {
writeValueProperty(object, engine, core, QVariant(), context, flags);
+ } else if (type == qMetaTypeId<QJSValue>()) {
+ if (!result.IsEmpty() && result->IsFunction()
+ && !result->ToObject()->GetHiddenValue(v8engine->bindingFlagKey()).IsEmpty()) {
+ expression->delayedError()->error.setDescription(QLatin1String("Invalid use of Qt.binding() in a binding declaration."));
+ return false;
+ }
+ writeValueProperty(object, engine, core, QVariant::fromValue(v8engine->scriptValueFromInternal(result)), context, flags);
} else if (isUndefined) {
expression->delayedError()->error.setDescription(QLatin1String("Unable to assign [undefined] to ") + QLatin1String(QMetaType::typeName(type)));
return false;