diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2023-06-23 15:02:25 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2023-06-26 09:59:21 +0200 |
commit | 67f2b2020e8959f0b95ff5522beec787766261b0 (patch) | |
tree | d16353e9ad071afb74833bbc29cbeed484d9918f /src/qml/qml/qqmllistwrapper.cpp | |
parent | e786048a0e42b5490df8f6be1f2b6106d97a05ca (diff) |
QtQml: Add an "owned" mode to QmlListWrapper
We can store the list in the wrapper itself.
Change-Id: I69732bb6d3b4fb2a88f8ebd4b4646cf24bad9dcc
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/qml/qqmllistwrapper.cpp')
-rw-r--r-- | src/qml/qml/qqmllistwrapper.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/qml/qml/qqmllistwrapper.cpp b/src/qml/qml/qqmllistwrapper.cpp index 244b77f76f..eadd95fce8 100644 --- a/src/qml/qml/qqmllistwrapper.cpp +++ b/src/qml/qml/qqmllistwrapper.cpp @@ -27,11 +27,22 @@ static void setCustomArrayData(Heap::QmlListWrapper *d) o->setArrayType(Heap::ArrayData::Custom); } +void Heap::QmlListWrapper::init(QMetaType propertyType) +{ + Object::init(); + m_object.init(); + m_propertyType = propertyType.iface(); + m_ownData = new QObjectList; + *property() = QQmlListProperty<QObject>(nullptr, m_ownData); + setCustomArrayData(this); +} + void Heap::QmlListWrapper::init(QObject *object, int propertyId, QMetaType propertyType) { Object::init(); m_object.init(object); m_propertyType = propertyType.iface(); + m_ownData = nullptr; void *args[] = { property(), nullptr }; QMetaObject::metacall(object, QMetaObject::ReadProperty, propertyId, args); setCustomArrayData(this); @@ -43,6 +54,7 @@ void Heap::QmlListWrapper::init( Object::init(); m_object.init(object); m_propertyType = propertyType.iface(); + m_ownData = nullptr; *property() = list; setCustomArrayData(this); } @@ -50,6 +62,7 @@ void Heap::QmlListWrapper::init( void Heap::QmlListWrapper::destroy() { m_object.destroy(); + delete m_ownData; Object::destroy(); } @@ -69,6 +82,11 @@ ReturnedValue QmlListWrapper::create( ->asReturnedValue(); } +ReturnedValue QmlListWrapper::create(ExecutionEngine *engine, QMetaType propType) +{ + return engine->memoryManager->allocate<QmlListWrapper>(propType)->asReturnedValue(); +} + QVariant QmlListWrapper::toVariant() const { if (!d()->object()) |