diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2015-08-29 20:07:23 +0100 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2015-08-31 07:56:52 +0000 |
commit | 1304b3d5de7e1205417c9b0d093f6b09bdc86bd9 (patch) | |
tree | 3d723272e85f28205eeb6cb399faa36ee89a3238 | |
parent | 1a96c73068a090448a742b058e2a634e6781312d (diff) |
Manage additional attributes separately from base ones
This is needed because hen the QML engine first creates a
QCylinderGeometry and applies a binding such as
CylinderGeometry {
attributes: [ myAttribute ]
}
it first calls the clear function on the QQmlListProperty which removes
all of the attributes for the base cylinder geometry before it calls
the append function to add the myAttribute. This is not what we want so
we explicitly manage the extra attributes added via the list property.
This differs from the case we are more used to in QML where setting a
list property of a contained object from an outer object does not call
the clear function first but rather just does the append.
Change-Id: I4e858f02c0114d667a325735788cb711ad8b8b37
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
-rw-r--r-- | src/quick3d/quick3drenderer/items/quick3dgeometry.cpp | 5 | ||||
-rw-r--r-- | src/quick3d/quick3drenderer/items/quick3dgeometry.h | 2 |
2 files changed, 6 insertions, 1 deletions
diff --git a/src/quick3d/quick3drenderer/items/quick3dgeometry.cpp b/src/quick3d/quick3drenderer/items/quick3dgeometry.cpp index 125b8d7a9..67f39e851 100644 --- a/src/quick3d/quick3drenderer/items/quick3dgeometry.cpp +++ b/src/quick3d/quick3drenderer/items/quick3dgeometry.cpp @@ -61,6 +61,7 @@ QQmlListProperty<QAbstractAttribute> Quick3DGeometry::attributeList() void Quick3DGeometry::appendAttribute(QQmlListProperty<QAbstractAttribute> *list, QAbstractAttribute *attribute) { Quick3DGeometry *geometry = static_cast<Quick3DGeometry *>(list->object); + geometry->m_managedAttributes.append(attribute); geometry->parentGeometry()->addAttribute(attribute); } @@ -79,8 +80,10 @@ int Quick3DGeometry::attributesCount(QQmlListProperty<QAbstractAttribute> *list) void Quick3DGeometry::clearAttributes(QQmlListProperty<QAbstractAttribute> *list) { Quick3DGeometry *geometry = static_cast<Quick3DGeometry *>(list->object); - Q_FOREACH (QAbstractAttribute *attribute, geometry->parentGeometry()->attributes()) + QVector<QAbstractAttribute *> &managedAttributes = geometry->m_managedAttributes; + Q_FOREACH (QAbstractAttribute *attribute, managedAttributes) geometry->parentGeometry()->removeAttribute(attribute); + managedAttributes.clear(); } } // Quick diff --git a/src/quick3d/quick3drenderer/items/quick3dgeometry.h b/src/quick3d/quick3drenderer/items/quick3dgeometry.h index 940e89dad..a5e275f6a 100644 --- a/src/quick3d/quick3drenderer/items/quick3dgeometry.h +++ b/src/quick3d/quick3drenderer/items/quick3dgeometry.h @@ -66,6 +66,8 @@ private: static QAbstractAttribute *attributeAt(QQmlListProperty<QAbstractAttribute> *list, int index); static int attributesCount(QQmlListProperty<QAbstractAttribute> *list); static void clearAttributes(QQmlListProperty<QAbstractAttribute> *list); + + QVector<QAbstractAttribute *> m_managedAttributes; }; } // Quick |