diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2021-09-22 09:32:42 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2021-09-22 20:39:51 +0200 |
commit | 39ca5bc96242f7545d20ccf15abe2a339fd7ba25 (patch) | |
tree | 50bbd86878b262073cb33d5fabeab9a354d9a2a1 /src/qml/qml/qqmllistwrapper.cpp | |
parent | 16646d45b75bb4432f7434a60ffe7120fc78d4de (diff) |
Allow adding null to QQmlListProperty
Setting the length or deleting objects already produces nullptr entries.
It should be possible to add them explicitly.
Also, fix the documentation to mention that you can actually manipulate
list properties, and do not recommend 'var' as replacement.
Change-Id: Ib04356f086b026191e60b6423f6ed44c2870235f
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/qml/qqmllistwrapper.cpp')
-rw-r--r-- | src/qml/qml/qqmllistwrapper.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/qml/qml/qqmllistwrapper.cpp b/src/qml/qml/qqmllistwrapper.cpp index e3ab0082aa..d8bf3c9704 100644 --- a/src/qml/qml/qqmllistwrapper.cpp +++ b/src/qml/qml/qqmllistwrapper.cpp @@ -156,6 +156,11 @@ bool QmlListWrapper::virtualPut(Managed *m, PropertyKey id, const Value &value, if (count < 0 || index >= uint(count)) return false; + if (value.isNull()) { + prop->replace(prop, index, nullptr); + return true; + } + QV4::Scope scope(v4); QV4::ScopedObject so(scope, value.toObject(scope.engine)); if (auto *wrapper = so->as<QV4::QObjectWrapper>()) { @@ -251,15 +256,21 @@ ReturnedValue PropertyListPrototype::method_push(const FunctionObject *b, const QmlListWrapper *w = instance->as<QmlListWrapper>(); if (!w) RETURN_UNDEFINED(); - if (!w->d()->property().append) + + QQmlListProperty<QObject> *property = &w->d()->property(); + if (!property->append) THROW_GENERIC_ERROR("List doesn't define an Append function"); QV4::ScopedObject so(scope); for (int i = 0, ei = argc; i < ei; ++i) { - so = argv[i].toObject(scope.engine); - if (QV4::QObjectWrapper *wrapper = so->as<QV4::QObjectWrapper>()) - w->d()->property().append(&w->d()->property(), wrapper->object() ); + if (argv[i].isNull()) { + property->append(property, nullptr); + } else { + so = argv[i].toObject(scope.engine); + if (QV4::QObjectWrapper *wrapper = so->as<QV4::QObjectWrapper>()) + property->append(property, wrapper->object() ); + } } return Encode::undefined(); } |