diff options
author | Ionut Alexandrescu <ionut.alexandrescu@qt.io> | 2017-02-20 13:27:22 +0100 |
---|---|---|
committer | Ionut Alexandrescu <ionut.alexandrescu@qt.io> | 2017-02-21 12:30:30 +0000 |
commit | bf1bd3abc9a2d990014fa8be451e0239fe12e198 (patch) | |
tree | 2d635481c7f3d92a686282c55c0d916e19b99dad /src/qml/qml/qqmllistwrapper.cpp | |
parent | 3e537dd3dcf5608241282d8437fb1593d2e6fa17 (diff) |
Add a javascript push method binding to QQmlListProperty
Create a PropertyList prototype, and add the push method to
QQmlListProperty that call the append function if it has been defined.
Added a unit test and updated the documentation.
Change-Id: I2647766e98b60bf0546f6d6ed1422a616e0d3a07
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/qml/qqmllistwrapper.cpp')
-rw-r--r-- | src/qml/qml/qqmllistwrapper.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/qml/qml/qqmllistwrapper.cpp b/src/qml/qml/qqmllistwrapper.cpp index 8aa107dc17..d94f7c56e4 100644 --- a/src/qml/qml/qqmllistwrapper.cpp +++ b/src/qml/qml/qqmllistwrapper.cpp @@ -165,4 +165,29 @@ void QmlListWrapper::advanceIterator(Managed *m, ObjectIterator *it, Value *name return QV4::Object::advanceIterator(m, it, name, index, p, attrs); } +void PropertyListPrototype::init(ExecutionEngine *) +{ + defineDefaultProperty(QStringLiteral("push"), method_push, 1); +} + +void PropertyListPrototype::method_push(const BuiltinFunction *, Scope &scope, CallData *callData) +{ + ScopedObject instance(scope, callData->thisObject.toObject(scope.engine)); + if (!instance) + RETURN_UNDEFINED(); + QmlListWrapper *w = instance->as<QmlListWrapper>(); + if (!w) + RETURN_UNDEFINED(); + if (!w->d()->property().append) + THROW_GENERIC_ERROR("List doesn't define an Append function"); + + QV4::ScopedObject so(scope); + for (int i = 0; i < callData->argc; ++i) + { + so = callData->args[i].toObject(scope.engine); + if (QV4::QObjectWrapper *wrapper = so->as<QV4::QObjectWrapper>()) + w->d()->property().append(&w->d()->property(), wrapper->object() ); + } +} + QT_END_NAMESPACE |