diff options
author | Mike Krus <mike.krus@kdab.com> | 2020-11-23 09:06:01 +0000 |
---|---|---|
committer | Mike Krus <mike.krus@kdab.com> | 2021-01-08 11:32:08 +0000 |
commit | d2fe37b3480cc55cf301426d7fa40475080cc6f9 (patch) | |
tree | 8c0ef31cdc3d2f75f4eed7d851a6d22e793d4c00 | |
parent | eee0fca4abc800883dde40559290403e7e550d14 (diff) |
Update QQMLPropertyList API
Use lambdas with local typedefs for index type
Change-Id: I2876c71d619815e7e777f936e8bb0835b8269336
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
63 files changed, 1226 insertions, 1622 deletions
diff --git a/src/quick3d/quick3d/items/quick3dentity.cpp b/src/quick3d/quick3d/items/quick3dentity.cpp index da87cbf1c..0ef1f8863 100644 --- a/src/quick3d/quick3d/items/quick3dentity.cpp +++ b/src/quick3d/quick3d/items/quick3dentity.cpp @@ -81,41 +81,38 @@ Quick3DEntity::Quick3DEntity(QObject *parent) QQmlListProperty<QComponent> Quick3DEntity::componentList() { - return QQmlListProperty<Qt3DCore::QComponent>(this, 0, - Quick3DEntity::qmlAppendComponent, - Quick3DEntity::qmlComponentsCount, - Quick3DEntity::qmlComponentAt, - Quick3DEntity::qmlClearComponents); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = Qt3DCore::QComponent; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *comp) { + if (comp == nullptr) + return; + Quick3DEntity *self = static_cast<Quick3DEntity *>(list->object); + self->m_managedComponents.push_back(comp); + self->parentEntity()->addComponent(comp); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DEntity *self = static_cast<Quick3DEntity *>(list->object); + return self->parentEntity()->components().count(); + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DEntity *self = static_cast<Quick3DEntity *>(list->object); + return self->parentEntity()->components().at(index); + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DEntity *self = static_cast<Quick3DEntity *>(list->object); + for (QComponent *comp : qAsConst(self->m_managedComponents)) + self->parentEntity()->removeComponent(comp); + self->m_managedComponents.clear(); + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } -void Quick3DEntity::qmlAppendComponent(QQmlListProperty<QComponent> *list, QComponent *comp) -{ - if (comp == nullptr) - return; - Quick3DEntity *self = static_cast<Quick3DEntity *>(list->object); - self->m_managedComponents.push_back(comp); - self->parentEntity()->addComponent(comp); -} - -QComponent *Quick3DEntity::qmlComponentAt(QQmlListProperty<QComponent> *list, qsizetype index) -{ - Quick3DEntity *self = static_cast<Quick3DEntity *>(list->object); - return self->parentEntity()->components().at(index); -} - -qsizetype Quick3DEntity::qmlComponentsCount(QQmlListProperty<QComponent> *list) -{ - Quick3DEntity *self = static_cast<Quick3DEntity *>(list->object); - return self->parentEntity()->components().count(); -} - -void Quick3DEntity::qmlClearComponents(QQmlListProperty<QComponent> *list) -{ - Quick3DEntity *self = static_cast<Quick3DEntity *>(list->object); - for (QComponent *comp : qAsConst(self->m_managedComponents)) - self->parentEntity()->removeComponent(comp); - self->m_managedComponents.clear(); -} } // namespace Quick } // namespace Qt3DCore diff --git a/src/quick3d/quick3d/items/quick3dentity_p.h b/src/quick3d/quick3d/items/quick3dentity_p.h index ee62ecf59..6c34236e9 100644 --- a/src/quick3d/quick3d/items/quick3dentity_p.h +++ b/src/quick3d/quick3d/items/quick3dentity_p.h @@ -72,18 +72,12 @@ class Q_3DQUICKSHARED_PRIVATE_EXPORT Quick3DEntity : public QObject Q_PROPERTY(QQmlListProperty<Qt3DCore::QComponent> components READ componentList) public: - explicit Quick3DEntity(QObject *parent = 0); + explicit Quick3DEntity(QObject *parent = nullptr); QQmlListProperty<Qt3DCore::QComponent> componentList(); inline QEntity *parentEntity() const { return qobject_cast<QEntity*>(parent()); } private: - - static void qmlAppendComponent(QQmlListProperty<Qt3DCore::QComponent> *list, Qt3DCore::QComponent *comp); - static QComponent *qmlComponentAt(QQmlListProperty<Qt3DCore::QComponent> *list, qsizetype index); - static qsizetype qmlComponentsCount(QQmlListProperty<Qt3DCore::QComponent> *list); - static void qmlClearComponents(QQmlListProperty<Qt3DCore::QComponent> *list); - QList<Qt3DCore::QComponent *> m_managedComponents; }; diff --git a/src/quick3d/quick3d/items/quick3dgeometry.cpp b/src/quick3d/quick3d/items/quick3dgeometry.cpp index 192b17b7e..bcd25731d 100644 --- a/src/quick3d/quick3d/items/quick3dgeometry.cpp +++ b/src/quick3d/quick3d/items/quick3dgeometry.cpp @@ -51,38 +51,34 @@ Quick3DGeometry::Quick3DGeometry(QObject *parent) QQmlListProperty<Qt3DCore::QAttribute> Quick3DGeometry::attributeList() { - return QQmlListProperty<Qt3DCore::QAttribute>(this, nullptr, - &Quick3DGeometry::appendAttribute, - &Quick3DGeometry::attributesCount, - &Quick3DGeometry::attributeAt, - &Quick3DGeometry::clearAttributes); -} - -void Quick3DGeometry::appendAttribute(QQmlListProperty<Qt3DCore::QAttribute> *list, Qt3DCore::QAttribute *attribute) -{ - Quick3DGeometry *geometry = static_cast<Quick3DGeometry *>(list->object); - geometry->m_managedAttributes.append(attribute); - geometry->parentGeometry()->addAttribute(attribute); -} - -Qt3DCore::QAttribute *Quick3DGeometry::attributeAt(QQmlListProperty<Qt3DCore::QAttribute> *list, qsizetype index) -{ - Quick3DGeometry *geometry = static_cast<Quick3DGeometry *>(list->object); - return geometry->parentGeometry()->attributes().at(index); -} +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif -qsizetype Quick3DGeometry::attributesCount(QQmlListProperty<Qt3DCore::QAttribute> *list) -{ - Quick3DGeometry *geometry = static_cast<Quick3DGeometry *>(list->object); - return geometry->parentGeometry()->attributes().count(); -} + using ListContentType = Qt3DCore::QAttribute; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *attribute) { + Quick3DGeometry *geometry = static_cast<Quick3DGeometry *>(list->object); + geometry->m_managedAttributes.append(attribute); + geometry->parentGeometry()->addAttribute(attribute); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DGeometry *geometry = static_cast<Quick3DGeometry *>(list->object); + return geometry->parentGeometry()->attributes().count(); + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DGeometry *geometry = static_cast<Quick3DGeometry *>(list->object); + return geometry->parentGeometry()->attributes().at(index); + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DGeometry *geometry = static_cast<Quick3DGeometry *>(list->object); + for (Qt3DCore::QAttribute *attribute : qAsConst(geometry->m_managedAttributes)) + geometry->parentGeometry()->removeAttribute(attribute); + geometry->m_managedAttributes.clear(); + }; -void Quick3DGeometry::clearAttributes(QQmlListProperty<Qt3DCore::QAttribute> *list) -{ - Quick3DGeometry *geometry = static_cast<Quick3DGeometry *>(list->object); - for (Qt3DCore::QAttribute *attribute : qAsConst(geometry->m_managedAttributes)) - geometry->parentGeometry()->removeAttribute(attribute); - geometry->m_managedAttributes.clear(); + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } } // namespace Quick diff --git a/src/quick3d/quick3d/items/quick3dgeometry_p.h b/src/quick3d/quick3d/items/quick3dgeometry_p.h index 8a4e5e16a..348f7ade1 100644 --- a/src/quick3d/quick3d/items/quick3dgeometry_p.h +++ b/src/quick3d/quick3d/items/quick3dgeometry_p.h @@ -74,11 +74,6 @@ public: QQmlListProperty<Qt3DCore::QAttribute> attributeList(); private: - static void appendAttribute(QQmlListProperty<Qt3DCore::QAttribute> *list, Qt3DCore::QAttribute *provider); - static Qt3DCore::QAttribute *attributeAt(QQmlListProperty<Qt3DCore::QAttribute> *list, qsizetype index); - static qsizetype attributesCount(QQmlListProperty<Qt3DCore::QAttribute> *list); - static void clearAttributes(QQmlListProperty<Qt3DCore::QAttribute> *list); - QList<Qt3DCore::QAttribute *> m_managedAttributes; }; diff --git a/src/quick3d/quick3d/items/quick3djoint.cpp b/src/quick3d/quick3d/items/quick3djoint.cpp index f59f3451e..91f84c5e1 100644 --- a/src/quick3d/quick3d/items/quick3djoint.cpp +++ b/src/quick3d/quick3d/items/quick3djoint.cpp @@ -56,37 +56,33 @@ Quick3DJoint::Quick3DJoint(QObject *parent) */ QQmlListProperty<QJoint> Quick3DJoint::childJoints() { - return QQmlListProperty<QJoint>(this, 0, - Quick3DJoint::appendJoint, - Quick3DJoint::jointCount, - Quick3DJoint::jointAt, - Quick3DJoint::clearJoints); -} - -void Quick3DJoint::appendJoint(QQmlListProperty<QJoint> *list, QJoint *joint) -{ - Quick3DJoint *jointExtension = qobject_cast<Quick3DJoint *>(list->object); - jointExtension->parentJoint()->addChildJoint(joint); -} - -QJoint *Quick3DJoint::jointAt(QQmlListProperty<QJoint> *list, qsizetype index) -{ - Quick3DJoint *jointExtension = qobject_cast<Quick3DJoint *>(list->object); - return jointExtension->parentJoint()->childJoints().at(index); -} +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif -qsizetype Quick3DJoint::jointCount(QQmlListProperty<QJoint> *list) -{ - Quick3DJoint *jointExtension = qobject_cast<Quick3DJoint *>(list->object); - return jointExtension->parentJoint()->childJoints().count(); -} + using ListContentType = QJoint; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *joint) { + Quick3DJoint *jointExtension = qobject_cast<Quick3DJoint *>(list->object); + jointExtension->parentJoint()->addChildJoint(joint); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DJoint *jointExtension = qobject_cast<Quick3DJoint *>(list->object); + return jointExtension->parentJoint()->childJoints().count(); + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DJoint *jointExtension = qobject_cast<Quick3DJoint *>(list->object); + return jointExtension->parentJoint()->childJoints().at(index); + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DJoint *jointExtension = qobject_cast<Quick3DJoint *>(list->object); + const auto joints = jointExtension->parentJoint()->childJoints(); + for (QJoint *joint : joints) + jointExtension->parentJoint()->removeChildJoint(joint); + }; -void Quick3DJoint::clearJoints(QQmlListProperty<QJoint> *list) -{ - Quick3DJoint *jointExtension = qobject_cast<Quick3DJoint *>(list->object); - const auto joints = jointExtension->parentJoint()->childJoints(); - for (QJoint *joint : joints) - jointExtension->parentJoint()->removeChildJoint(joint); + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } } // namespace Quick diff --git a/src/quick3d/quick3d/items/quick3djoint_p.h b/src/quick3d/quick3d/items/quick3djoint_p.h index 73dccc39d..6b755a420 100644 --- a/src/quick3d/quick3d/items/quick3djoint_p.h +++ b/src/quick3d/quick3d/items/quick3djoint_p.h @@ -72,12 +72,6 @@ public: QQmlListProperty<Qt3DCore::QJoint> childJoints(); inline QJoint *parentJoint() const { return qobject_cast<QJoint*>(parent()); } - -private: - static void appendJoint(QQmlListProperty<Qt3DCore::QJoint> *list, Qt3DCore::QJoint *obj); - static QJoint *jointAt(QQmlListProperty<Qt3DCore::QJoint> *list, qsizetype index); - static qsizetype jointCount(QQmlListProperty<Qt3DCore::QJoint> *list); - static void clearJoints(QQmlListProperty<Qt3DCore::QJoint> *list); }; } // namespace Quick diff --git a/src/quick3d/quick3d/items/quick3dnode.cpp b/src/quick3d/quick3d/items/quick3dnode.cpp index 67fe26b63..25016a817 100644 --- a/src/quick3d/quick3d/items/quick3dnode.cpp +++ b/src/quick3d/quick3d/items/quick3dnode.cpp @@ -67,11 +67,35 @@ Quick3DNode::Quick3DNode(QObject *parent) QQmlListProperty<QObject> Quick3DNode::data() { - return QQmlListProperty<QObject>(this, 0, - Quick3DNode::appendData, - Quick3DNode::dataCount, - Quick3DNode::dataAt, - Quick3DNode::clearData); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = QObject; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *obj) { + if (!obj) + return; + + Quick3DNode *self = static_cast<Quick3DNode *>(list->object); + self->childAppended(0, obj); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DNode *self = static_cast<Quick3DNode *>(list->object); + return self->parentNode()->children().count(); + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DNode *self = static_cast<Quick3DNode *>(list->object); + return self->parentNode()->children().at(index); + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DNode *self = static_cast<Quick3DNode *>(list->object); + for (QObject *const child : self->parentNode()->children()) + self->childRemoved(0, child); + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } /*! @@ -81,76 +105,44 @@ QQmlListProperty<QObject> Quick3DNode::data() QQmlListProperty<QNode> Quick3DNode::childNodes() { - return QQmlListProperty<QNode>(this, 0, - Quick3DNode::appendChild, - Quick3DNode::childCount, - Quick3DNode::childAt, - Quick3DNode::clearChildren); -} - -void Quick3DNode::appendData(QQmlListProperty<QObject> *list, QObject *obj) -{ - if (!obj) - return; - - Quick3DNode *self = static_cast<Quick3DNode *>(list->object); - self->childAppended(0, obj); -} - -QObject *Quick3DNode::dataAt(QQmlListProperty<QObject> *list, qsizetype index) -{ - Quick3DNode *self = static_cast<Quick3DNode *>(list->object); - return self->parentNode()->children().at(index); -} - -qsizetype Quick3DNode::dataCount(QQmlListProperty<QObject> *list) -{ - Quick3DNode *self = static_cast<Quick3DNode *>(list->object); - return self->parentNode()->children().count(); -} - -void Quick3DNode::clearData(QQmlListProperty<QObject> *list) -{ - Quick3DNode *self = static_cast<Quick3DNode *>(list->object); - for (QObject *const child : self->parentNode()->children()) - self->childRemoved(0, child); -} - -void Quick3DNode::appendChild(QQmlListProperty<Qt3DCore::QNode> *list, Qt3DCore::QNode *obj) -{ - if (!obj) - return; - - Quick3DNode *self = static_cast<Quick3DNode *>(list->object); - Q_ASSERT(!self->parentNode()->children().contains(obj)); - - self->childAppended(0, obj); -} - -Qt3DCore::QNode *Quick3DNode::childAt(QQmlListProperty<Qt3DCore::QNode> *list, qsizetype index) -{ - Quick3DNode *self = static_cast<Quick3DNode *>(list->object); - return qobject_cast<QNode *>(self->parentNode()->children().at(index)); -} - -qsizetype Quick3DNode::childCount(QQmlListProperty<Qt3DCore::QNode> *list) -{ - Quick3DNode *self = static_cast<Quick3DNode *>(list->object); - return self->parentNode()->children().count(); -} - -void Quick3DNode::clearChildren(QQmlListProperty<Qt3DCore::QNode> *list) -{ - Quick3DNode *self = static_cast<Quick3DNode *>(list->object); - for (QObject *const child : self->parentNode()->children()) - self->childRemoved(0, child); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = QNode; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *obj) { + if (!obj) + return; + + Quick3DNode *self = static_cast<Quick3DNode *>(list->object); + Q_ASSERT(!self->parentNode()->children().contains(obj)); + + self->childAppended(0, obj); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DNode *self = static_cast<Quick3DNode *>(list->object); + return self->parentNode()->children().count(); + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DNode *self = static_cast<Quick3DNode *>(list->object); + return qobject_cast<QNode *>(self->parentNode()->children().at(index)); + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DNode *self = static_cast<Quick3DNode *>(list->object); + for (QObject *const child : self->parentNode()->children()) + self->childRemoved(0, child); + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } void Quick3DNode::childAppended(int, QObject *obj) { QNode *parentNode = this->parentNode(); if (obj->parent() == parentNode) - obj->setParent(0); + obj->setParent(nullptr); // Set after otherwise addChild might not work if (QNode *n = qobject_cast<QNode *>(obj)) n->setParent(parentNode); diff --git a/src/quick3d/quick3d/items/quick3dnode_p.h b/src/quick3d/quick3d/items/quick3dnode_p.h index aa6cb788e..688f1c578 100644 --- a/src/quick3d/quick3d/items/quick3dnode_p.h +++ b/src/quick3d/quick3d/items/quick3dnode_p.h @@ -75,17 +75,6 @@ public: inline QNode *parentNode() const { return qobject_cast<QNode*>(parent()); } -private: - static void appendData(QQmlListProperty<QObject> *list, QObject *obj); - static QObject *dataAt(QQmlListProperty<QObject> *list, qsizetype index); - static qsizetype dataCount(QQmlListProperty<QObject> *list); - static void clearData(QQmlListProperty<QObject> *list); - - static void appendChild(QQmlListProperty<Qt3DCore::QNode> *list, Qt3DCore::QNode *obj); - static QNode *childAt(QQmlListProperty<Qt3DCore::QNode> *list, qsizetype index); - static qsizetype childCount(QQmlListProperty<Qt3DCore::QNode> *list); - static void clearChildren(QQmlListProperty<Qt3DCore::QNode> *list); - private Q_SLOTS: void childAppended(int idx, QObject *child); void childRemoved(int idx, QObject *child); diff --git a/src/quick3d/quick3danimation/items/quick3danimationcontroller.cpp b/src/quick3d/quick3danimation/items/quick3danimationcontroller.cpp index 3d2fef555..07bfb4a72 100644 --- a/src/quick3d/quick3danimation/items/quick3danimationcontroller.cpp +++ b/src/quick3d/quick3danimation/items/quick3danimationcontroller.cpp @@ -48,44 +48,37 @@ QQuick3DAnimationController::QQuick3DAnimationController(QObject *parent) QQmlListProperty<QAnimationGroup> QQuick3DAnimationController::animationGroups() { - return QQmlListProperty<QAnimationGroup>(this, 0, - &QQuick3DAnimationController::appendAnimationGroup, - &QQuick3DAnimationController::animationGroupCount, - &QQuick3DAnimationController::animationGroupAt, - &QQuick3DAnimationController::clearAnimationGroups); -} - +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif -void QQuick3DAnimationController::appendAnimationGroup(QQmlListProperty<QAnimationGroup> *list, QAnimationGroup *bar) -{ - QQuick3DAnimationController *controller = qobject_cast<QQuick3DAnimationController *>(list->object); - if (controller) - controller->parentAnimationController()->addAnimationGroup(bar); -} + using ListContentType = QAnimationGroup; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *bar) { + QQuick3DAnimationController *controller = qobject_cast<QQuick3DAnimationController *>(list->object); + if (controller) + controller->parentAnimationController()->addAnimationGroup(bar); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + QQuick3DAnimationController *controller = qobject_cast<QQuick3DAnimationController *>(list->object); + if (controller) + return controller->parentAnimationController()->animationGroupList().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + QQuick3DAnimationController *controller = qobject_cast<QQuick3DAnimationController *>(list->object); + if (controller) + return qobject_cast<QAnimationGroup *>(controller->parentAnimationController()->getGroup(index)); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + QQuick3DAnimationController *controller = qobject_cast<QQuick3DAnimationController *>(list->object); + if (controller) + controller->parentAnimationController()->setAnimationGroups({}); + }; -qsizetype QQuick3DAnimationController::animationGroupCount(QQmlListProperty<QAnimationGroup> *list) -{ - QQuick3DAnimationController *controller = qobject_cast<QQuick3DAnimationController *>(list->object); - if (controller) - return controller->parentAnimationController()->animationGroupList().count(); - return 0; -} - -QAnimationGroup *QQuick3DAnimationController::animationGroupAt(QQmlListProperty<QAnimationGroup> *list, qsizetype index) -{ - QQuick3DAnimationController *controller = qobject_cast<QQuick3DAnimationController *>(list->object); - if (controller) - return qobject_cast<QAnimationGroup *>(controller->parentAnimationController()->getGroup(index)); - return nullptr; -} - -void QQuick3DAnimationController::clearAnimationGroups(QQmlListProperty<QAnimationGroup> *list) -{ - QQuick3DAnimationController *controller = qobject_cast<QQuick3DAnimationController *>(list->object); - if (controller) { - QList<QAnimationGroup *> emptyList; - controller->parentAnimationController()->setAnimationGroups(emptyList); - } + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } diff --git a/src/quick3d/quick3danimation/items/quick3danimationcontroller_p.h b/src/quick3d/quick3danimation/items/quick3danimationcontroller_p.h index ee5d643c6..516b13885 100644 --- a/src/quick3d/quick3danimation/items/quick3danimationcontroller_p.h +++ b/src/quick3d/quick3danimation/items/quick3danimationcontroller_p.h @@ -72,13 +72,6 @@ public: } QQmlListProperty<Qt3DAnimation::QAnimationGroup> animationGroups(); - -private: - - static void appendAnimationGroup(QQmlListProperty<Qt3DAnimation::QAnimationGroup> *list, Qt3DAnimation::QAnimationGroup *bar); - static QAnimationGroup *animationGroupAt(QQmlListProperty<Qt3DAnimation::QAnimationGroup> *list, qsizetype index); - static qsizetype animationGroupCount(QQmlListProperty<Qt3DAnimation::QAnimationGroup> *list); - static void clearAnimationGroups(QQmlListProperty<Qt3DAnimation::QAnimationGroup> *list); }; } // namespace Quick diff --git a/src/quick3d/quick3danimation/items/quick3danimationgroup.cpp b/src/quick3d/quick3danimation/items/quick3danimationgroup.cpp index 090b7a959..b6b070169 100644 --- a/src/quick3d/quick3danimation/items/quick3danimationgroup.cpp +++ b/src/quick3d/quick3danimation/items/quick3danimationgroup.cpp @@ -50,48 +50,43 @@ QQuick3DAnimationGroup::QQuick3DAnimationGroup(QObject *parent) QQmlListProperty<Qt3DAnimation::QAbstractAnimation> QQuick3DAnimationGroup::animations() { - return QQmlListProperty<Qt3DAnimation::QAbstractAnimation>(this, 0, - &QQuick3DAnimationGroup::appendAnimation, - &QQuick3DAnimationGroup::animationCount, - &QQuick3DAnimationGroup::animationAt, - &QQuick3DAnimationGroup::clearAnimation); -} - - -void QQuick3DAnimationGroup::appendAnimation(QQmlListProperty<Qt3DAnimation::QAbstractAnimation> *list, - Qt3DAnimation::QAbstractAnimation *animation) -{ - QQuick3DAnimationGroup *animationGroup = qobject_cast<QQuick3DAnimationGroup *>(list->object); - if (animationGroup) - animationGroup->parentAnimationGroup()->addAnimation(animation); -} +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif -qsizetype QQuick3DAnimationGroup::animationCount(QQmlListProperty<Qt3DAnimation::QAbstractAnimation> *list) -{ - QQuick3DAnimationGroup *animationGroup = qobject_cast<QQuick3DAnimationGroup *>(list->object); - if (animationGroup) - return animationGroup->parentAnimationGroup()->animationList().count(); - return 0; -} + using ListContentType = Qt3DAnimation::QAbstractAnimation; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *animation) { + QQuick3DAnimationGroup *animationGroup = qobject_cast<QQuick3DAnimationGroup *>(list->object); + if (animationGroup) + animationGroup->parentAnimationGroup()->addAnimation(animation); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + QQuick3DAnimationGroup *animationGroup = qobject_cast<QQuick3DAnimationGroup *>(list->object); + if (animationGroup) + return animationGroup->parentAnimationGroup()->animationList().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + QQuick3DAnimationGroup *animationGroup = qobject_cast<QQuick3DAnimationGroup *>(list->object); + if (animationGroup) { + return qobject_cast<Qt3DAnimation::QAbstractAnimation *>( + animationGroup->parentAnimationGroup()->animationList().at(index)); + } + return nullptr; + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + QQuick3DAnimationGroup *animationGroup = qobject_cast<QQuick3DAnimationGroup *>(list->object); + if (animationGroup) { + QList<Qt3DAnimation::QAbstractAnimation *> emptyList; + animationGroup->parentAnimationGroup()->setAnimations(emptyList); + } + }; -Qt3DAnimation::QAbstractAnimation *QQuick3DAnimationGroup::animationAt(QQmlListProperty<Qt3DAnimation::QAbstractAnimation> *list, qsizetype index) -{ - QQuick3DAnimationGroup *animationGroup = qobject_cast<QQuick3DAnimationGroup *>(list->object); - if (animationGroup) { - return qobject_cast<Qt3DAnimation::QAbstractAnimation *>( - animationGroup->parentAnimationGroup()->animationList().at(index)); - } - return nullptr; + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } -void QQuick3DAnimationGroup::clearAnimation(QQmlListProperty<Qt3DAnimation::QAbstractAnimation> *list) -{ - QQuick3DAnimationGroup *animationGroup = qobject_cast<QQuick3DAnimationGroup *>(list->object); - if (animationGroup) { - QList<Qt3DAnimation::QAbstractAnimation *> emptyList; - animationGroup->parentAnimationGroup()->setAnimations(emptyList); - } -} } // namespace Quick } // namespace Qt3DAnimation diff --git a/src/quick3d/quick3danimation/items/quick3danimationgroup_p.h b/src/quick3d/quick3danimation/items/quick3danimationgroup_p.h index 6c7f634a3..1f966ee65 100644 --- a/src/quick3d/quick3danimation/items/quick3danimationgroup_p.h +++ b/src/quick3d/quick3danimation/items/quick3danimationgroup_p.h @@ -74,13 +74,6 @@ public: } QQmlListProperty<Qt3DAnimation::QAbstractAnimation> animations(); - -private: - - static void appendAnimation(QQmlListProperty<Qt3DAnimation::QAbstractAnimation> *list, Qt3DAnimation::QAbstractAnimation *animation); - static Qt3DAnimation::QAbstractAnimation *animationAt(QQmlListProperty<Qt3DAnimation::QAbstractAnimation> *list, qsizetype index); - static qsizetype animationCount(QQmlListProperty<Qt3DAnimation::QAbstractAnimation> *list); - static void clearAnimation(QQmlListProperty<Qt3DAnimation::QAbstractAnimation> *list); }; } // namespace Quick diff --git a/src/quick3d/quick3danimation/items/quick3dchannelmapper.cpp b/src/quick3d/quick3danimation/items/quick3dchannelmapper.cpp index a2bc51d45..3c62ae03b 100644 --- a/src/quick3d/quick3danimation/items/quick3dchannelmapper.cpp +++ b/src/quick3d/quick3danimation/items/quick3dchannelmapper.cpp @@ -52,37 +52,33 @@ Quick3DChannelMapper::Quick3DChannelMapper(QObject *parent) QQmlListProperty<QAbstractChannelMapping> Quick3DChannelMapper::qmlMappings() { - return QQmlListProperty<QAbstractChannelMapping>(this, 0, - &Quick3DChannelMapper::appendMapping, - &Quick3DChannelMapper::mappingCount, - &Quick3DChannelMapper::mappingAt, - &Quick3DChannelMapper::clearMappings); -} - -void Quick3DChannelMapper::appendMapping(QQmlListProperty<QAbstractChannelMapping> *list, QAbstractChannelMapping *mapping) -{ - Quick3DChannelMapper *extension = qobject_cast<Quick3DChannelMapper *>(list->object); - extension->parentMapper()->addMapping(mapping); -} - -QAbstractChannelMapping *Quick3DChannelMapper::mappingAt(QQmlListProperty<QAbstractChannelMapping> *list, qsizetype index) -{ - Quick3DChannelMapper *extension = qobject_cast<Quick3DChannelMapper *>(list->object); - return extension->parentMapper()->mappings().at(index); -} +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif -qsizetype Quick3DChannelMapper::mappingCount(QQmlListProperty<QAbstractChannelMapping> *list) -{ - Quick3DChannelMapper *extension = qobject_cast<Quick3DChannelMapper *>(list->object); - return extension->parentMapper()->mappings().count(); -} + using ListContentType = QAbstractChannelMapping; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *mapping) { + Quick3DChannelMapper *extension = qobject_cast<Quick3DChannelMapper *>(list->object); + extension->parentMapper()->addMapping(mapping); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DChannelMapper *extension = qobject_cast<Quick3DChannelMapper *>(list->object); + return extension->parentMapper()->mappings().size(); + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DChannelMapper *extension = qobject_cast<Quick3DChannelMapper *>(list->object); + return extension->parentMapper()->mappings().at(index); + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DChannelMapper *extension = qobject_cast<Quick3DChannelMapper *>(list->object); + const auto mappings = extension->parentMapper()->mappings(); + for (QAbstractChannelMapping *mapping : mappings) + extension->parentMapper()->removeMapping(mapping); + }; -void Quick3DChannelMapper::clearMappings(QQmlListProperty<QAbstractChannelMapping> *list) -{ - Quick3DChannelMapper *extension = qobject_cast<Quick3DChannelMapper *>(list->object); - const auto mappings = extension->parentMapper()->mappings(); - for (QAbstractChannelMapping *mapping : mappings) - extension->parentMapper()->removeMapping(mapping); + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } } // namespace Quick diff --git a/src/quick3d/quick3danimation/items/quick3dchannelmapper_p.h b/src/quick3d/quick3danimation/items/quick3dchannelmapper_p.h index ab7b6fdbe..378ea5e3b 100644 --- a/src/quick3d/quick3danimation/items/quick3dchannelmapper_p.h +++ b/src/quick3d/quick3danimation/items/quick3dchannelmapper_p.h @@ -73,12 +73,6 @@ public: inline QChannelMapper *parentMapper() const { return qobject_cast<QChannelMapper *>(parent()); } QQmlListProperty<QAbstractChannelMapping> qmlMappings(); - -private: - static void appendMapping(QQmlListProperty<QAbstractChannelMapping> *list, QAbstractChannelMapping *mapping); - static QAbstractChannelMapping *mappingAt(QQmlListProperty<QAbstractChannelMapping> *list, qsizetype index); - static qsizetype mappingCount(QQmlListProperty<QAbstractChannelMapping> *list); - static void clearMappings(QQmlListProperty<QAbstractChannelMapping> *list); }; } // namespace Quick diff --git a/src/quick3d/quick3danimation/items/quick3dkeyframeanimation.cpp b/src/quick3d/quick3danimation/items/quick3dkeyframeanimation.cpp index 61bc14a4f..28627a10f 100644 --- a/src/quick3d/quick3danimation/items/quick3dkeyframeanimation.cpp +++ b/src/quick3d/quick3danimation/items/quick3dkeyframeanimation.cpp @@ -48,51 +48,43 @@ QQuick3DKeyframeAnimation::QQuick3DKeyframeAnimation(QObject *parent) QQmlListProperty<Qt3DCore::QTransform> QQuick3DKeyframeAnimation::keyframes() { - return QQmlListProperty<Qt3DCore::QTransform>(this, 0, - &QQuick3DKeyframeAnimation::appendKeyframe, - &QQuick3DKeyframeAnimation::keyframeCount, - &QQuick3DKeyframeAnimation::keyframeAt, - &QQuick3DKeyframeAnimation::clearKeyframes); -} +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif -void QQuick3DKeyframeAnimation::appendKeyframe(QQmlListProperty<Qt3DCore::QTransform> *list, - Qt3DCore::QTransform *transform) -{ - QQuick3DKeyframeAnimation *keyframeAnimation + using ListContentType = Qt3DCore::QTransform; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *transform) { + QQuick3DKeyframeAnimation *keyframeAnimation = qobject_cast<QQuick3DKeyframeAnimation *>(list->object); - if (keyframeAnimation) - keyframeAnimation->parentKeyframeAnimation()->addKeyframe(transform); -} - -qsizetype QQuick3DKeyframeAnimation::keyframeCount(QQmlListProperty<Qt3DCore::QTransform> *list) -{ - QQuick3DKeyframeAnimation *keyframeAnimation + if (keyframeAnimation) + keyframeAnimation->parentKeyframeAnimation()->addKeyframe(transform); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + QQuick3DKeyframeAnimation *keyframeAnimation = qobject_cast<QQuick3DKeyframeAnimation *>(list->object); - if (keyframeAnimation) - return keyframeAnimation->parentKeyframeAnimation()->keyframeList().count(); - return 0; -} - -Qt3DCore::QTransform *QQuick3DKeyframeAnimation::keyframeAt(QQmlListProperty<Qt3DCore::QTransform> *list, - qsizetype index) -{ - QQuick3DKeyframeAnimation *keyframeAnimation + if (keyframeAnimation) + return keyframeAnimation->parentKeyframeAnimation()->keyframeList().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + QQuick3DKeyframeAnimation *keyframeAnimation = qobject_cast<QQuick3DKeyframeAnimation *>(list->object); - if (keyframeAnimation) { - return qobject_cast<Qt3DCore::QTransform *>( - keyframeAnimation->parentKeyframeAnimation()->keyframeList().at(index)); - } - return nullptr; -} - -void QQuick3DKeyframeAnimation::clearKeyframes(QQmlListProperty<Qt3DCore::QTransform> *list) -{ - QQuick3DKeyframeAnimation *keyframeAnimation + if (keyframeAnimation) + return qobject_cast<Qt3DCore::QTransform *>(keyframeAnimation->parentKeyframeAnimation()->keyframeList().at(index)); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + QQuick3DKeyframeAnimation *keyframeAnimation = qobject_cast<QQuick3DKeyframeAnimation *>(list->object); - if (keyframeAnimation) { - QList<Qt3DCore::QTransform *> emptyList; - keyframeAnimation->parentKeyframeAnimation()->setKeyframes(emptyList); - } + if (keyframeAnimation) { + QList<Qt3DCore::QTransform *> emptyList; + keyframeAnimation->parentKeyframeAnimation()->setKeyframes(emptyList); + } + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } } // namespace Quick diff --git a/src/quick3d/quick3danimation/items/quick3dkeyframeanimation_p.h b/src/quick3d/quick3danimation/items/quick3dkeyframeanimation_p.h index 488d91c39..96a37491e 100644 --- a/src/quick3d/quick3danimation/items/quick3dkeyframeanimation_p.h +++ b/src/quick3d/quick3danimation/items/quick3dkeyframeanimation_p.h @@ -73,15 +73,6 @@ public: } QQmlListProperty<Qt3DCore::QTransform> keyframes(); - -private: - - static void appendKeyframe(QQmlListProperty<Qt3DCore::QTransform> *list, - Qt3DCore::QTransform *transform); - static Qt3DCore::QTransform *keyframeAt(QQmlListProperty<Qt3DCore::QTransform> *list, - qsizetype index); - static qsizetype keyframeCount(QQmlListProperty<Qt3DCore::QTransform> *list); - static void clearKeyframes(QQmlListProperty<Qt3DCore::QTransform> *list); }; } // namespace Quick diff --git a/src/quick3d/quick3danimation/items/quick3dmorphinganimation.cpp b/src/quick3d/quick3danimation/items/quick3dmorphinganimation.cpp index 5e25c00c5..acb2f096f 100644 --- a/src/quick3d/quick3danimation/items/quick3dmorphinganimation.cpp +++ b/src/quick3d/quick3danimation/items/quick3dmorphinganimation.cpp @@ -48,47 +48,39 @@ QQuick3DMorphingAnimation::QQuick3DMorphingAnimation(QObject *parent) QQmlListProperty<Qt3DAnimation::QMorphTarget> QQuick3DMorphingAnimation::morphTargets() { - return QQmlListProperty<Qt3DAnimation::QMorphTarget>(this, 0, - &QQuick3DMorphingAnimation::appendMorphTarget, - &QQuick3DMorphingAnimation::morphTargetCount, - &QQuick3DMorphingAnimation::morphTargetAt, - &QQuick3DMorphingAnimation::clearMorphTargets); -} - -void QQuick3DMorphingAnimation::appendMorphTarget(QQmlListProperty<Qt3DAnimation::QMorphTarget> *list, - Qt3DAnimation::QMorphTarget *morphTarget) -{ - QQuick3DMorphingAnimation *animation = qobject_cast<QQuick3DMorphingAnimation *>(list->object); - if (animation) - animation->parentMorphingAnimation()->addMorphTarget(morphTarget); -} - -qsizetype QQuick3DMorphingAnimation::morphTargetCount(QQmlListProperty<Qt3DAnimation::QMorphTarget> *list) -{ - QQuick3DMorphingAnimation *animation = qobject_cast<QQuick3DMorphingAnimation *>(list->object); - if (animation) - return animation->parentMorphingAnimation()->morphTargetList().count(); - return 0; -} +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif -Qt3DAnimation::QMorphTarget *QQuick3DMorphingAnimation::morphTargetAt(QQmlListProperty<Qt3DAnimation::QMorphTarget> *list, - qsizetype index) -{ - QQuick3DMorphingAnimation *animation = qobject_cast<QQuick3DMorphingAnimation *>(list->object); - if (animation) { - return qobject_cast<Qt3DAnimation::QMorphTarget *>( - animation->parentMorphingAnimation()->morphTargetList().at(index)); - } - return nullptr; -} + using ListContentType = Qt3DAnimation::QMorphTarget; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *morphTarget) { + QQuick3DMorphingAnimation *animation = qobject_cast<QQuick3DMorphingAnimation *>(list->object); + if (animation) + animation->parentMorphingAnimation()->addMorphTarget(morphTarget); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + QQuick3DMorphingAnimation *animation = qobject_cast<QQuick3DMorphingAnimation *>(list->object); + if (animation) + return animation->parentMorphingAnimation()->morphTargetList().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + QQuick3DMorphingAnimation *animation = qobject_cast<QQuick3DMorphingAnimation *>(list->object); + if (animation) { + return qobject_cast<Qt3DAnimation::QMorphTarget *>( + animation->parentMorphingAnimation()->morphTargetList().at(index)); + } + return nullptr; + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + QQuick3DMorphingAnimation *animation = qobject_cast<QQuick3DMorphingAnimation *>(list->object); + if (animation) + animation->parentMorphingAnimation()->setMorphTargets({}); + }; -void QQuick3DMorphingAnimation::clearMorphTargets(QQmlListProperty<Qt3DAnimation::QMorphTarget> *list) -{ - QQuick3DMorphingAnimation *animation = qobject_cast<QQuick3DMorphingAnimation *>(list->object); - if (animation) { - QList<Qt3DAnimation::QMorphTarget *> emptyList; - animation->parentMorphingAnimation()->setMorphTargets(emptyList); - } + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } } // namespace Quick diff --git a/src/quick3d/quick3danimation/items/quick3dmorphinganimation_p.h b/src/quick3d/quick3danimation/items/quick3dmorphinganimation_p.h index 465addead..04a2a9aff 100644 --- a/src/quick3d/quick3danimation/items/quick3dmorphinganimation_p.h +++ b/src/quick3d/quick3danimation/items/quick3dmorphinganimation_p.h @@ -73,15 +73,6 @@ public: } QQmlListProperty<Qt3DAnimation::QMorphTarget> morphTargets(); - -private: - - static void appendMorphTarget(QQmlListProperty<Qt3DAnimation::QMorphTarget> *list, - Qt3DAnimation::QMorphTarget *morphTarget); - static Qt3DAnimation::QMorphTarget *morphTargetAt(QQmlListProperty<Qt3DAnimation::QMorphTarget> *list, - qsizetype index); - static qsizetype morphTargetCount(QQmlListProperty<Qt3DAnimation::QMorphTarget> *list); - static void clearMorphTargets(QQmlListProperty<Qt3DAnimation::QMorphTarget> *list); }; } // namespace Quick diff --git a/src/quick3d/quick3danimation/items/quick3dmorphtarget.cpp b/src/quick3d/quick3danimation/items/quick3dmorphtarget.cpp index 06933331f..7069fa182 100644 --- a/src/quick3d/quick3danimation/items/quick3dmorphtarget.cpp +++ b/src/quick3d/quick3danimation/items/quick3dmorphtarget.cpp @@ -48,43 +48,39 @@ QQuick3DMorphTarget::QQuick3DMorphTarget(QObject *parent) QQmlListProperty<Qt3DCore::QAttribute> QQuick3DMorphTarget::attributes() { - return QQmlListProperty<Qt3DCore::QAttribute>(this, 0, - &QQuick3DMorphTarget::appendAttribute, - &QQuick3DMorphTarget::attributeCount, - &QQuick3DMorphTarget::attributeAt, - &QQuick3DMorphTarget::clearAttributes); -} - -void QQuick3DMorphTarget::appendAttribute(QQmlListProperty<Qt3DCore::QAttribute> *list, Qt3DCore::QAttribute *bar) -{ - QQuick3DMorphTarget *target = qobject_cast<QQuick3DMorphTarget *>(list->object); - if (target) - target->parentMorphTarget()->addAttribute(bar); -} - -qsizetype QQuick3DMorphTarget::attributeCount(QQmlListProperty<Qt3DCore::QAttribute> *list) -{ - QQuick3DMorphTarget *target = qobject_cast<QQuick3DMorphTarget *>(list->object); - if (target) - return target->parentMorphTarget()->attributeList().count(); - return 0; -} +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif -Qt3DCore::QAttribute *QQuick3DMorphTarget::attributeAt(QQmlListProperty<Qt3DCore::QAttribute> *list, qsizetype index) -{ - QQuick3DMorphTarget *target = qobject_cast<QQuick3DMorphTarget *>(list->object); - if (target) - return qobject_cast<Qt3DCore::QAttribute *>(target->parentMorphTarget()->attributeList().at(index)); - return nullptr; -} + using ListContentType = Qt3DCore::QAttribute; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *bar) { + QQuick3DMorphTarget *target = qobject_cast<QQuick3DMorphTarget *>(list->object); + if (target) + target->parentMorphTarget()->addAttribute(bar); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + QQuick3DMorphTarget *target = qobject_cast<QQuick3DMorphTarget *>(list->object); + if (target) + return target->parentMorphTarget()->attributeList().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + QQuick3DMorphTarget *target = qobject_cast<QQuick3DMorphTarget *>(list->object); + if (target) + return qobject_cast<Qt3DCore::QAttribute *>(target->parentMorphTarget()->attributeList().at(index)); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + QQuick3DMorphTarget *target = qobject_cast<QQuick3DMorphTarget *>(list->object); + if (target) { + QList<Qt3DCore::QAttribute *> emptyList; + target->parentMorphTarget()->setAttributes(emptyList); + } + }; -void QQuick3DMorphTarget::clearAttributes(QQmlListProperty<Qt3DCore::QAttribute> *list) -{ - QQuick3DMorphTarget *target = qobject_cast<QQuick3DMorphTarget *>(list->object); - if (target) { - QList<Qt3DCore::QAttribute *> emptyList; - target->parentMorphTarget()->setAttributes(emptyList); - } + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } } // namespace Quick diff --git a/src/quick3d/quick3danimation/items/quick3dmorphtarget_p.h b/src/quick3d/quick3danimation/items/quick3dmorphtarget_p.h index 172202e5c..c255d4348 100644 --- a/src/quick3d/quick3danimation/items/quick3dmorphtarget_p.h +++ b/src/quick3d/quick3danimation/items/quick3dmorphtarget_p.h @@ -68,13 +68,6 @@ public: inline QMorphTarget *parentMorphTarget() const { return qobject_cast<QMorphTarget *>(parent()); } QQmlListProperty<Qt3DCore::QAttribute> attributes(); - -private: - - static void appendAttribute(QQmlListProperty<Qt3DCore::QAttribute> *list, Qt3DCore::QAttribute *bar); - static Qt3DCore::QAttribute *attributeAt(QQmlListProperty<Qt3DCore::QAttribute> *list, qsizetype index); - static qsizetype attributeCount(QQmlListProperty<Qt3DCore::QAttribute> *list); - static void clearAttributes(QQmlListProperty<Qt3DCore::QAttribute> *list); }; } // namespace Quick diff --git a/src/quick3d/quick3danimation/items/quick3dvertexblendanimation.cpp b/src/quick3d/quick3danimation/items/quick3dvertexblendanimation.cpp index bd62e35e4..e1895b20c 100644 --- a/src/quick3d/quick3danimation/items/quick3dvertexblendanimation.cpp +++ b/src/quick3d/quick3danimation/items/quick3dvertexblendanimation.cpp @@ -48,54 +48,43 @@ QQuick3DVertexBlendAnimation::QQuick3DVertexBlendAnimation(QObject *parent) QQmlListProperty<Qt3DAnimation::QMorphTarget> QQuick3DVertexBlendAnimation::morphTargets() { - return QQmlListProperty<Qt3DAnimation::QMorphTarget>(this, 0, - &QQuick3DVertexBlendAnimation::appendMorphTarget, - &QQuick3DVertexBlendAnimation::morphTargetCount, - &QQuick3DVertexBlendAnimation::morphTargetAt, - &QQuick3DVertexBlendAnimation::clearMorphTargets); -} +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif -void QQuick3DVertexBlendAnimation::appendMorphTarget( - QQmlListProperty<Qt3DAnimation::QMorphTarget> *list, - Qt3DAnimation::QMorphTarget *morphTarget) -{ - QQuick3DVertexBlendAnimation *animation + using ListContentType = Qt3DAnimation::QMorphTarget; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *morphTarget) { + QQuick3DVertexBlendAnimation *animation = qobject_cast<QQuick3DVertexBlendAnimation *>(list->object); - if (animation) - animation->parentVertexBlendAnimation()->addMorphTarget(morphTarget); -} - -qsizetype QQuick3DVertexBlendAnimation::morphTargetCount( - QQmlListProperty<Qt3DAnimation::QMorphTarget> *list) -{ - QQuick3DVertexBlendAnimation *animation + if (animation) + animation->parentVertexBlendAnimation()->addMorphTarget(morphTarget); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + QQuick3DVertexBlendAnimation *animation = qobject_cast<QQuick3DVertexBlendAnimation *>(list->object); - if (animation) - return animation->parentVertexBlendAnimation()->morphTargetList().count(); - return 0; -} - -Qt3DAnimation::QMorphTarget *QQuick3DVertexBlendAnimation::morphTargetAt( - QQmlListProperty<Qt3DAnimation::QMorphTarget> *list, - qsizetype index) -{ - QQuick3DVertexBlendAnimation *animation + if (animation) + return animation->parentVertexBlendAnimation()->morphTargetList().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + QQuick3DVertexBlendAnimation *animation = qobject_cast<QQuick3DVertexBlendAnimation *>(list->object); - if (animation) { - return qobject_cast<Qt3DAnimation::QMorphTarget *>( - animation->parentVertexBlendAnimation()->morphTargetList().at(index)); - } - return nullptr; -} - -void QQuick3DVertexBlendAnimation::clearMorphTargets(QQmlListProperty<Qt3DAnimation::QMorphTarget> *list) -{ - QQuick3DVertexBlendAnimation *animation + if (animation) { + return qobject_cast<Qt3DAnimation::QMorphTarget *>( + animation->parentVertexBlendAnimation()->morphTargetList().at(index)); + } + return nullptr; + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + QQuick3DVertexBlendAnimation *animation = qobject_cast<QQuick3DVertexBlendAnimation *>(list->object); - if (animation) { - QList<Qt3DAnimation::QMorphTarget *> emptyList; - animation->parentVertexBlendAnimation()->setMorphTargets(emptyList); - } + if (animation) + animation->parentVertexBlendAnimation()->setMorphTargets({}); + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } } // namespace Quick diff --git a/src/quick3d/quick3danimation/items/quick3dvertexblendanimation_p.h b/src/quick3d/quick3danimation/items/quick3dvertexblendanimation_p.h index bea39deb7..300608850 100644 --- a/src/quick3d/quick3danimation/items/quick3dvertexblendanimation_p.h +++ b/src/quick3d/quick3danimation/items/quick3dvertexblendanimation_p.h @@ -73,15 +73,6 @@ public: } QQmlListProperty<Qt3DAnimation::QMorphTarget> morphTargets(); - -private: - - static void appendMorphTarget(QQmlListProperty<Qt3DAnimation::QMorphTarget> *list, - Qt3DAnimation::QMorphTarget *morphTarget); - static Qt3DAnimation::QMorphTarget *morphTargetAt(QQmlListProperty<Qt3DAnimation::QMorphTarget> *list, - qsizetype index); - static qsizetype morphTargetCount(QQmlListProperty<Qt3DAnimation::QMorphTarget> *list); - static void clearMorphTargets(QQmlListProperty<Qt3DAnimation::QMorphTarget> *list); }; } // namespace Quick diff --git a/src/quick3d/quick3dextras/items/quick3dspritesheet.cpp b/src/quick3d/quick3dextras/items/quick3dspritesheet.cpp index e0b5d77b6..361295382 100644 --- a/src/quick3d/quick3dextras/items/quick3dspritesheet.cpp +++ b/src/quick3d/quick3dextras/items/quick3dspritesheet.cpp @@ -57,39 +57,33 @@ Quick3DSpriteSheet::~Quick3DSpriteSheet() QQmlListProperty<Qt3DExtras::QSpriteSheetItem> Quick3DSpriteSheet::sprites() { - return QQmlListProperty<Qt3DExtras::QSpriteSheetItem>(this, 0, - &Quick3DSpriteSheet::appendSprite, - &Quick3DSpriteSheet::spriteCount, - &Quick3DSpriteSheet::spriteAt, - &Quick3DSpriteSheet::clearSprites); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif -} - -void Quick3DSpriteSheet::appendSprite(QQmlListProperty<Qt3DExtras::QSpriteSheetItem> *list, - Qt3DExtras::QSpriteSheetItem *sprite) -{ - Quick3DSpriteSheet *spritesheet = qobject_cast<Quick3DSpriteSheet *>(list->object); - spritesheet->parentSpriteSheet()->addSprite(sprite); -} + using ListContentType = Qt3DExtras::QSpriteSheetItem; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *sprite) { + Quick3DSpriteSheet *spritesheet = qobject_cast<Quick3DSpriteSheet *>(list->object); + spritesheet->parentSpriteSheet()->addSprite(sprite); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DSpriteSheet *spritesheet = qobject_cast<Quick3DSpriteSheet *>(list->object); + return spritesheet->parentSpriteSheet()->sprites().count(); + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DSpriteSheet *spritesheet = qobject_cast<Quick3DSpriteSheet *>(list->object); + return spritesheet->parentSpriteSheet()->sprites().at(index); + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DSpriteSheet *spritesheet = qobject_cast<Quick3DSpriteSheet *>(list->object); + const auto sprites = spritesheet->parentSpriteSheet()->sprites(); + for (QSpriteSheetItem *sprite : sprites) + spritesheet->parentSpriteSheet()->removeSprite(sprite); + }; -Qt3DExtras::QSpriteSheetItem *Quick3DSpriteSheet::spriteAt(QQmlListProperty<Qt3DExtras::QSpriteSheetItem> *list, qsizetype index) -{ - Quick3DSpriteSheet *spritesheet = qobject_cast<Quick3DSpriteSheet *>(list->object); - return spritesheet->parentSpriteSheet()->sprites().at(index); -} - -qsizetype Quick3DSpriteSheet::spriteCount(QQmlListProperty<Qt3DExtras::QSpriteSheetItem> *list) -{ - Quick3DSpriteSheet *spritesheet = qobject_cast<Quick3DSpriteSheet *>(list->object); - return spritesheet->parentSpriteSheet()->sprites().count(); -} - -void Quick3DSpriteSheet::clearSprites(QQmlListProperty<Qt3DExtras::QSpriteSheetItem> *list) -{ - Quick3DSpriteSheet *spritesheet = qobject_cast<Quick3DSpriteSheet *>(list->object); - const auto sprites = spritesheet->parentSpriteSheet()->sprites(); - for (QSpriteSheetItem *sprite : sprites) - spritesheet->parentSpriteSheet()->removeSprite(sprite); + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } } // namespace Quick diff --git a/src/quick3d/quick3dextras/items/quick3dspritesheet_p.h b/src/quick3d/quick3dextras/items/quick3dspritesheet_p.h index e04231417..1c38524fe 100644 --- a/src/quick3d/quick3dextras/items/quick3dspritesheet_p.h +++ b/src/quick3d/quick3dextras/items/quick3dspritesheet_p.h @@ -72,12 +72,6 @@ public: QQmlListProperty<Qt3DExtras::QSpriteSheetItem> sprites(); inline QSpriteSheet *parentSpriteSheet() const { return qobject_cast<QSpriteSheet *>(parent()); } - -private: - static void appendSprite(QQmlListProperty<Qt3DExtras::QSpriteSheetItem> *list, Qt3DExtras::QSpriteSheetItem *state); - static Qt3DExtras::QSpriteSheetItem *spriteAt(QQmlListProperty<Qt3DExtras::QSpriteSheetItem> *list, qsizetype index); - static qsizetype spriteCount(QQmlListProperty<Qt3DExtras::QSpriteSheetItem> *list); - static void clearSprites(QQmlListProperty<Qt3DExtras::QSpriteSheetItem> *list); }; } // namespace Quick diff --git a/src/quick3d/quick3dinput/items/quick3daction.cpp b/src/quick3d/quick3dinput/items/quick3daction.cpp index e46153551..10c1b5a56 100644 --- a/src/quick3d/quick3dinput/items/quick3daction.cpp +++ b/src/quick3d/quick3dinput/items/quick3daction.cpp @@ -52,37 +52,32 @@ Quick3DAction::Quick3DAction(QObject *parent) QQmlListProperty<QAbstractActionInput> Quick3DAction::qmlActionInputs() { - return QQmlListProperty<QAbstractActionInput>(this, 0, - &Quick3DAction::appendActionInput, - &Quick3DAction::actionInputCount, - &Quick3DAction::actionInputAt, - &Quick3DAction::clearActionInputs); -} - -void Quick3DAction::appendActionInput(QQmlListProperty<QAbstractActionInput> *list, QAbstractActionInput *input) -{ - Quick3DAction *action = qobject_cast<Quick3DAction *>(list->object); - action->parentAction()->addInput(input); -} - -QAbstractActionInput *Quick3DAction::actionInputAt(QQmlListProperty<QAbstractActionInput> *list, qsizetype index) -{ - Quick3DAction *action = qobject_cast<Quick3DAction *>(list->object); - return action->parentAction()->inputs().at(index); -} +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif -qsizetype Quick3DAction::actionInputCount(QQmlListProperty<QAbstractActionInput> *list) -{ - Quick3DAction *action = qobject_cast<Quick3DAction *>(list->object); - return action->parentAction()->inputs().count(); -} + auto appendFunction = [](QQmlListProperty<QAbstractActionInput> *list, QAbstractActionInput *input) { + Quick3DAction *action = qobject_cast<Quick3DAction *>(list->object); + action->parentAction()->addInput(input); + }; + auto countFunction = [](QQmlListProperty<QAbstractActionInput> *list) -> qt_size_type { + Quick3DAction *action = qobject_cast<Quick3DAction *>(list->object); + return action->parentAction()->inputs().count(); + }; + auto atFunction = [](QQmlListProperty<QAbstractActionInput> *list, qt_size_type index) -> QAbstractActionInput * { + Quick3DAction *action = qobject_cast<Quick3DAction *>(list->object); + return action->parentAction()->inputs().at(index); + }; + auto clearFunction = [](QQmlListProperty<QAbstractActionInput> *list) { + Quick3DAction *action = qobject_cast<Quick3DAction *>(list->object); + const auto inputs = action->parentAction()->inputs(); + for (QAbstractActionInput *input : inputs) + action->parentAction()->removeInput(input); + }; -void Quick3DAction::clearActionInputs(QQmlListProperty<QAbstractActionInput> *list) -{ - Quick3DAction *action = qobject_cast<Quick3DAction *>(list->object); - const auto inputs = action->parentAction()->inputs(); - for (QAbstractActionInput *input : inputs) - action->parentAction()->removeInput(input); + return QQmlListProperty<QAbstractActionInput>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } diff --git a/src/quick3d/quick3dinput/items/quick3daction_p.h b/src/quick3d/quick3dinput/items/quick3daction_p.h index 8d3b233ca..c219a0924 100644 --- a/src/quick3d/quick3dinput/items/quick3daction_p.h +++ b/src/quick3d/quick3dinput/items/quick3daction_p.h @@ -73,12 +73,6 @@ public: inline QAction *parentAction() const { return qobject_cast<QAction *>(parent()); } QQmlListProperty<QAbstractActionInput> qmlActionInputs(); - -private: - static void appendActionInput(QQmlListProperty<QAbstractActionInput> *list, QAbstractActionInput *input); - static QAbstractActionInput *actionInputAt(QQmlListProperty<QAbstractActionInput> *list, qsizetype index); - static qsizetype actionInputCount(QQmlListProperty<QAbstractActionInput> *list); - static void clearActionInputs(QQmlListProperty<QAbstractActionInput> *list); }; } // namespace Quick diff --git a/src/quick3d/quick3dinput/items/quick3daxis.cpp b/src/quick3d/quick3dinput/items/quick3daxis.cpp index 86ad22f25..115fa4b78 100644 --- a/src/quick3d/quick3dinput/items/quick3daxis.cpp +++ b/src/quick3d/quick3dinput/items/quick3daxis.cpp @@ -52,37 +52,33 @@ Quick3DAxis::Quick3DAxis(QObject *parent) QQmlListProperty<QAbstractAxisInput> Quick3DAxis::qmlAxisInputs() { - return QQmlListProperty<QAbstractAxisInput>(this, 0, - &Quick3DAxis::appendAxisInput, - &Quick3DAxis::axesInputCount, - &Quick3DAxis::axisInputAt, - &Quick3DAxis::clearAxisInputs); -} - -void Quick3DAxis::appendAxisInput(QQmlListProperty<QAbstractAxisInput> *list, QAbstractAxisInput *input) -{ - Quick3DAxis *axis = qobject_cast<Quick3DAxis *>(list->object); - axis->parentAxis()->addInput(input); -} - -QAbstractAxisInput *Quick3DAxis::axisInputAt(QQmlListProperty<QAbstractAxisInput> *list, qsizetype index) -{ - Quick3DAxis *axis = qobject_cast<Quick3DAxis *>(list->object); - return axis->parentAxis()->inputs().at(index); -} +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif -qsizetype Quick3DAxis::axesInputCount(QQmlListProperty<QAbstractAxisInput> *list) -{ - Quick3DAxis *axis = qobject_cast<Quick3DAxis *>(list->object); - return axis->parentAxis()->inputs().count(); -} + using ListContentType = QAbstractAxisInput; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *input) { + Quick3DAxis *axis = qobject_cast<Quick3DAxis *>(list->object); + axis->parentAxis()->addInput(input); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DAxis *axis = qobject_cast<Quick3DAxis *>(list->object); + return axis->parentAxis()->inputs().count(); + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DAxis *axis = qobject_cast<Quick3DAxis *>(list->object); + return axis->parentAxis()->inputs().at(index); + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DAxis *axis = qobject_cast<Quick3DAxis *>(list->object); + const auto inputs = axis->parentAxis()->inputs(); + for (QAbstractAxisInput *input : inputs) + axis->parentAxis()->removeInput(input); + }; -void Quick3DAxis::clearAxisInputs(QQmlListProperty<QAbstractAxisInput> *list) -{ - Quick3DAxis *axis = qobject_cast<Quick3DAxis *>(list->object); - const auto inputs = axis->parentAxis()->inputs(); - for (QAbstractAxisInput *input : inputs) - axis->parentAxis()->removeInput(input); + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } diff --git a/src/quick3d/quick3dinput/items/quick3daxis_p.h b/src/quick3d/quick3dinput/items/quick3daxis_p.h index 5f7785a3b..e6d726d8e 100644 --- a/src/quick3d/quick3dinput/items/quick3daxis_p.h +++ b/src/quick3d/quick3dinput/items/quick3daxis_p.h @@ -73,12 +73,6 @@ public: inline QAxis *parentAxis() const { return qobject_cast<QAxis *>(parent()); } QQmlListProperty<QAbstractAxisInput> qmlAxisInputs(); - -private: - static void appendAxisInput(QQmlListProperty<QAbstractAxisInput> *list, QAbstractAxisInput *input); - static QAbstractAxisInput *axisInputAt(QQmlListProperty<QAbstractAxisInput> *list, qsizetype index); - static qsizetype axesInputCount(QQmlListProperty<QAbstractAxisInput> *list); - static void clearAxisInputs(QQmlListProperty<QAbstractAxisInput> *list); }; } // namespace Quick diff --git a/src/quick3d/quick3dinput/items/quick3dinputchord.cpp b/src/quick3d/quick3dinput/items/quick3dinputchord.cpp index 684e2f283..669c251d2 100644 --- a/src/quick3d/quick3dinput/items/quick3dinputchord.cpp +++ b/src/quick3d/quick3dinput/items/quick3dinputchord.cpp @@ -52,37 +52,33 @@ Quick3DInputChord::Quick3DInputChord(QObject *parent) QQmlListProperty<QAbstractActionInput> Quick3DInputChord::qmlActionInputs() { - return QQmlListProperty<QAbstractActionInput>(this, 0, - &Quick3DInputChord::appendActionInput, - &Quick3DInputChord::actionInputCount, - &Quick3DInputChord::actionInputAt, - &Quick3DInputChord::clearActionInputs); -} - -void Quick3DInputChord::appendActionInput(QQmlListProperty<QAbstractActionInput> *list, QAbstractActionInput *input) -{ - Quick3DInputChord *action = qobject_cast<Quick3DInputChord *>(list->object); - action->parentChord()->addChord(input); -} - -QAbstractActionInput *Quick3DInputChord::actionInputAt(QQmlListProperty<QAbstractActionInput> *list, qsizetype index) -{ - Quick3DInputChord *action = qobject_cast<Quick3DInputChord *>(list->object); - return action->parentChord()->chords().at(index); -} +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif -qsizetype Quick3DInputChord::actionInputCount(QQmlListProperty<QAbstractActionInput> *list) -{ - Quick3DInputChord *action = qobject_cast<Quick3DInputChord *>(list->object); - return action->parentChord()->chords().count(); -} + using ListContentType = QAbstractActionInput; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *input) { + Quick3DInputChord *action = qobject_cast<Quick3DInputChord *>(list->object); + action->parentChord()->addChord(input); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DInputChord *action = qobject_cast<Quick3DInputChord *>(list->object); + return action->parentChord()->chords().count(); + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DInputChord *action = qobject_cast<Quick3DInputChord *>(list->object); + return action->parentChord()->chords().at(index); + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DInputChord *action = qobject_cast<Quick3DInputChord *>(list->object); + const auto chords = action->parentChord()->chords(); + for (QAbstractActionInput *input : chords) + action->parentChord()->removeChord(input); + }; -void Quick3DInputChord::clearActionInputs(QQmlListProperty<QAbstractActionInput> *list) -{ - Quick3DInputChord *action = qobject_cast<Quick3DInputChord *>(list->object); - const auto chords = action->parentChord()->chords(); - for (QAbstractActionInput *input : chords) - action->parentChord()->removeChord(input); + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } } // namespace Quick diff --git a/src/quick3d/quick3dinput/items/quick3dinputchord_p.h b/src/quick3d/quick3dinput/items/quick3dinputchord_p.h index 1ce165cf1..7c0acc488 100644 --- a/src/quick3d/quick3dinput/items/quick3dinputchord_p.h +++ b/src/quick3d/quick3dinput/items/quick3dinputchord_p.h @@ -71,12 +71,6 @@ public: inline QInputChord *parentChord() const { return qobject_cast<QInputChord *>(parent()); } QQmlListProperty<QAbstractActionInput> qmlActionInputs(); - -private: - static void appendActionInput(QQmlListProperty<QAbstractActionInput> *list, QAbstractActionInput *input); - static QAbstractActionInput *actionInputAt(QQmlListProperty<QAbstractActionInput> *list, qsizetype index); - static qsizetype actionInputCount(QQmlListProperty<QAbstractActionInput> *list); - static void clearActionInputs(QQmlListProperty<QAbstractActionInput> *list); }; } // namespace Quick diff --git a/src/quick3d/quick3dinput/items/quick3dinputsequence.cpp b/src/quick3d/quick3dinput/items/quick3dinputsequence.cpp index eaf3582b6..4d637c18b 100644 --- a/src/quick3d/quick3dinput/items/quick3dinputsequence.cpp +++ b/src/quick3d/quick3dinput/items/quick3dinputsequence.cpp @@ -52,37 +52,33 @@ Quick3DInputSequence::Quick3DInputSequence(QObject *parent) QQmlListProperty<QAbstractActionInput> Quick3DInputSequence::qmlActionInputs() { - return QQmlListProperty<QAbstractActionInput>(this, 0, - &Quick3DInputSequence::appendActionInput, - &Quick3DInputSequence::actionInputCount, - &Quick3DInputSequence::actionInputAt, - &Quick3DInputSequence::clearActionInputs); -} - -void Quick3DInputSequence::appendActionInput(QQmlListProperty<QAbstractActionInput> *list, QAbstractActionInput *input) -{ - Quick3DInputSequence *action = qobject_cast<Quick3DInputSequence *>(list->object); - action->parentSequence()->addSequence(input); -} - -QAbstractActionInput *Quick3DInputSequence::actionInputAt(QQmlListProperty<QAbstractActionInput> *list, qsizetype index) -{ - Quick3DInputSequence *action = qobject_cast<Quick3DInputSequence *>(list->object); - return action->parentSequence()->sequences().at(index); -} +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif -qsizetype Quick3DInputSequence::actionInputCount(QQmlListProperty<QAbstractActionInput> *list) -{ - Quick3DInputSequence *action = qobject_cast<Quick3DInputSequence *>(list->object); - return action->parentSequence()->sequences().count(); -} + using ListContentType = QAbstractActionInput; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *input) { + Quick3DInputSequence *action = qobject_cast<Quick3DInputSequence *>(list->object); + action->parentSequence()->addSequence(input); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DInputSequence *action = qobject_cast<Quick3DInputSequence *>(list->object); + return action->parentSequence()->sequences().count(); + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DInputSequence *action = qobject_cast<Quick3DInputSequence *>(list->object); + return action->parentSequence()->sequences().at(index); + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DInputSequence *action = qobject_cast<Quick3DInputSequence *>(list->object); + const auto sequences = action->parentSequence()->sequences(); + for (QAbstractActionInput *input : sequences) + action->parentSequence()->removeSequence(input); + }; -void Quick3DInputSequence::clearActionInputs(QQmlListProperty<QAbstractActionInput> *list) -{ - Quick3DInputSequence *action = qobject_cast<Quick3DInputSequence *>(list->object); - const auto sequences = action->parentSequence()->sequences(); - for (QAbstractActionInput *input : sequences) - action->parentSequence()->removeSequence(input); + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } diff --git a/src/quick3d/quick3dinput/items/quick3dinputsequence_p.h b/src/quick3d/quick3dinput/items/quick3dinputsequence_p.h index 9aedce8a0..fe379d31b 100644 --- a/src/quick3d/quick3dinput/items/quick3dinputsequence_p.h +++ b/src/quick3d/quick3dinput/items/quick3dinputsequence_p.h @@ -71,12 +71,6 @@ public: inline QInputSequence *parentSequence() const { return qobject_cast<QInputSequence *>(parent()); } QQmlListProperty<QAbstractActionInput> qmlActionInputs(); - -private: - static void appendActionInput(QQmlListProperty<QAbstractActionInput> *list, QAbstractActionInput *input); - static QAbstractActionInput *actionInputAt(QQmlListProperty<QAbstractActionInput> *list, qsizetype index); - static qsizetype actionInputCount(QQmlListProperty<QAbstractActionInput> *list); - static void clearActionInputs(QQmlListProperty<QAbstractActionInput> *list); }; } // namespace Quick diff --git a/src/quick3d/quick3dinput/items/quick3dlogicaldevice.cpp b/src/quick3d/quick3dinput/items/quick3dlogicaldevice.cpp index df52cf8c8..061fe1433 100644 --- a/src/quick3d/quick3dinput/items/quick3dlogicaldevice.cpp +++ b/src/quick3d/quick3dinput/items/quick3dlogicaldevice.cpp @@ -52,72 +52,64 @@ Quick3DLogicalDevice::Quick3DLogicalDevice(QObject *parent) QQmlListProperty<QAxis> Quick3DLogicalDevice::qmlAxes() { - return QQmlListProperty<QAxis>(this, 0, - &Quick3DLogicalDevice::appendAxis, - &Quick3DLogicalDevice::axesCount, - &Quick3DLogicalDevice::axisAt, - &Quick3DLogicalDevice::clearAxes); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = QAxis; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *axes) { + Quick3DLogicalDevice *device = qobject_cast<Quick3DLogicalDevice *>(list->object); + device->parentLogicalDevice()->addAxis(axes); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DLogicalDevice *device = qobject_cast<Quick3DLogicalDevice *>(list->object); + return device->parentLogicalDevice()->axes().count(); + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DLogicalDevice *device = qobject_cast<Quick3DLogicalDevice *>(list->object); + return device->parentLogicalDevice()->axes().at(index); + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DLogicalDevice *device = qobject_cast<Quick3DLogicalDevice *>(list->object); + const auto axes = device->parentLogicalDevice()->axes(); + for (QAxis *axis : axes) + device->parentLogicalDevice()->removeAxis(axis); + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } QQmlListProperty<QAction> Quick3DLogicalDevice::qmlActions() { - return QQmlListProperty<QAction>(this, 0, - &Quick3DLogicalDevice::appendAction, - &Quick3DLogicalDevice::actionCount, - &Quick3DLogicalDevice::actionAt, - &Quick3DLogicalDevice::clearActions); -} - -void Quick3DLogicalDevice::appendAxis(QQmlListProperty<QAxis> *list, QAxis *axes) -{ - Quick3DLogicalDevice *device = qobject_cast<Quick3DLogicalDevice *>(list->object); - device->parentLogicalDevice()->addAxis(axes); -} - -QAxis *Quick3DLogicalDevice::axisAt(QQmlListProperty<QAxis> *list, qsizetype index) -{ - Quick3DLogicalDevice *device = qobject_cast<Quick3DLogicalDevice *>(list->object); - return device->parentLogicalDevice()->axes().at(index); -} - -qsizetype Quick3DLogicalDevice::axesCount(QQmlListProperty<QAxis> *list) -{ - Quick3DLogicalDevice *device = qobject_cast<Quick3DLogicalDevice *>(list->object); - return device->parentLogicalDevice()->axes().count(); -} - -void Quick3DLogicalDevice::clearAxes(QQmlListProperty<QAxis> *list) -{ - Quick3DLogicalDevice *device = qobject_cast<Quick3DLogicalDevice *>(list->object); - const auto axes = device->parentLogicalDevice()->axes(); - for (QAxis *axis : axes) - device->parentLogicalDevice()->removeAxis(axis); -} - -void Quick3DLogicalDevice::appendAction(QQmlListProperty<QAction> *list, QAction *action) -{ - Quick3DLogicalDevice *device = qobject_cast<Quick3DLogicalDevice *>(list->object); - device->parentLogicalDevice()->addAction(action); -} - -QAction *Quick3DLogicalDevice::actionAt(QQmlListProperty<QAction> *list, qsizetype index) -{ - Quick3DLogicalDevice *device = qobject_cast<Quick3DLogicalDevice *>(list->object); - return device->parentLogicalDevice()->actions().at(index); -} - -qsizetype Quick3DLogicalDevice::actionCount(QQmlListProperty<QAction> *list) -{ - Quick3DLogicalDevice *device = qobject_cast<Quick3DLogicalDevice *>(list->object); - return device->parentLogicalDevice()->actions().count(); -} - -void Quick3DLogicalDevice::clearActions(QQmlListProperty<QAction> *list) -{ - Quick3DLogicalDevice *device = qobject_cast<Quick3DLogicalDevice *>(list->object); - const auto actions = device->parentLogicalDevice()->actions(); - for (QAction *action : actions) - device->parentLogicalDevice()->removeAction(action); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = QAction; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *action) { + Quick3DLogicalDevice *device = qobject_cast<Quick3DLogicalDevice *>(list->object); + device->parentLogicalDevice()->addAction(action); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DLogicalDevice *device = qobject_cast<Quick3DLogicalDevice *>(list->object); + return device->parentLogicalDevice()->actions().count(); + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DLogicalDevice *device = qobject_cast<Quick3DLogicalDevice *>(list->object); + return device->parentLogicalDevice()->actions().at(index); + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DLogicalDevice *device = qobject_cast<Quick3DLogicalDevice *>(list->object); + const auto actions = device->parentLogicalDevice()->actions(); + for (QAction *action : actions) + device->parentLogicalDevice()->removeAction(action); + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } diff --git a/src/quick3d/quick3dinput/items/quick3dlogicaldevice_p.h b/src/quick3d/quick3dinput/items/quick3dlogicaldevice_p.h index 6e28ce349..5e6de8bcf 100644 --- a/src/quick3d/quick3dinput/items/quick3dlogicaldevice_p.h +++ b/src/quick3d/quick3dinput/items/quick3dlogicaldevice_p.h @@ -75,17 +75,6 @@ public: inline QLogicalDevice *parentLogicalDevice() const { return qobject_cast<QLogicalDevice *>(parent()); } QQmlListProperty<QAxis> qmlAxes(); QQmlListProperty<QAction> qmlActions(); - -private: - static void appendAxis(QQmlListProperty<QAxis> *list, QAxis *axes); - static QAxis *axisAt(QQmlListProperty<QAxis> *list, qsizetype index); - static qsizetype axesCount(QQmlListProperty<QAxis> *list); - static void clearAxes(QQmlListProperty<QAxis> *list); - - static void appendAction(QQmlListProperty<QAction> *list, QAction *action); - static QAction *actionAt(QQmlListProperty<QAction> *list, qsizetype index); - static qsizetype actionCount(QQmlListProperty<QAction> *list); - static void clearActions(QQmlListProperty<QAction> *list); }; } // namespace Quick diff --git a/src/quick3d/quick3dinput/items/quick3dphysicaldevice.cpp b/src/quick3d/quick3dinput/items/quick3dphysicaldevice.cpp index dc1fdcf6d..07b017735 100644 --- a/src/quick3d/quick3dinput/items/quick3dphysicaldevice.cpp +++ b/src/quick3d/quick3dinput/items/quick3dphysicaldevice.cpp @@ -52,37 +52,33 @@ Quick3DPhysicalDevice::Quick3DPhysicalDevice(QObject *parent) : QObject(parent) QQmlListProperty<QAxisSetting> Quick3DPhysicalDevice::axisSettings() { - return QQmlListProperty<QAxisSetting>(this, 0, - &Quick3DPhysicalDevice::appendAxisSetting, - &Quick3DPhysicalDevice::axisSettingsCount, - &Quick3DPhysicalDevice::axisSettingAt, - &Quick3DPhysicalDevice::clearAxisSettings); -} - -void Quick3DPhysicalDevice::appendAxisSetting(QQmlListProperty<QAxisSetting> *list, QAxisSetting *axisSetting) -{ - Quick3DPhysicalDevice *device = qobject_cast<Quick3DPhysicalDevice *>(list->object); - device->parentPhysicalDevice()->addAxisSetting(axisSetting); -} - -QAxisSetting *Quick3DPhysicalDevice::axisSettingAt(QQmlListProperty<QAxisSetting> *list, qsizetype index) -{ - Quick3DPhysicalDevice *device = qobject_cast<Quick3DPhysicalDevice *>(list->object); - return device->parentPhysicalDevice()->axisSettings().at(index); -} +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif -qsizetype Quick3DPhysicalDevice::axisSettingsCount(QQmlListProperty<QAxisSetting> *list) -{ - Quick3DPhysicalDevice *device = qobject_cast<Quick3DPhysicalDevice *>(list->object); - return device->parentPhysicalDevice()->axisSettings().count(); -} + using ListContentType = QAxisSetting; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *axisSetting) { + Quick3DPhysicalDevice *device = qobject_cast<Quick3DPhysicalDevice *>(list->object); + device->parentPhysicalDevice()->addAxisSetting(axisSetting); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DPhysicalDevice *device = qobject_cast<Quick3DPhysicalDevice *>(list->object); + return device->parentPhysicalDevice()->axisSettings().count(); + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DPhysicalDevice *device = qobject_cast<Quick3DPhysicalDevice *>(list->object); + return device->parentPhysicalDevice()->axisSettings().at(index); + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DPhysicalDevice *device = qobject_cast<Quick3DPhysicalDevice *>(list->object); + const auto axisSettings = device->parentPhysicalDevice()->axisSettings(); + for (QAxisSetting *axisSetting : axisSettings) + device->parentPhysicalDevice()->removeAxisSetting(axisSetting); + }; -void Quick3DPhysicalDevice::clearAxisSettings(QQmlListProperty<QAxisSetting> *list) -{ - Quick3DPhysicalDevice *device = qobject_cast<Quick3DPhysicalDevice *>(list->object); - const auto axisSettings = device->parentPhysicalDevice()->axisSettings(); - for (QAxisSetting *axisSetting : axisSettings) - device->parentPhysicalDevice()->removeAxisSetting(axisSetting); + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } } // namespace Quick diff --git a/src/quick3d/quick3dinput/items/quick3dphysicaldevice_p.h b/src/quick3d/quick3dinput/items/quick3dphysicaldevice_p.h index fff0deca7..e8a0c4794 100644 --- a/src/quick3d/quick3dinput/items/quick3dphysicaldevice_p.h +++ b/src/quick3d/quick3dinput/items/quick3dphysicaldevice_p.h @@ -73,12 +73,6 @@ public: inline QAbstractPhysicalDevice *parentPhysicalDevice() const { return qobject_cast<QAbstractPhysicalDevice *>(parent()); } QQmlListProperty<Qt3DInput::QAxisSetting> axisSettings(); - -private: - static void appendAxisSetting(QQmlListProperty<QAxisSetting> *list, QAxisSetting *axes); - static QAxisSetting *axisSettingAt(QQmlListProperty<QAxisSetting> *list, qsizetype index); - static qsizetype axisSettingsCount(QQmlListProperty<QAxisSetting> *list); - static void clearAxisSettings(QQmlListProperty<QAxisSetting> *list); }; } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3deffect.cpp b/src/quick3d/quick3drender/items/quick3deffect.cpp index 617b52e85..09045011b 100644 --- a/src/quick3d/quick3drender/items/quick3deffect.cpp +++ b/src/quick3d/quick3drender/items/quick3deffect.cpp @@ -54,82 +54,74 @@ Quick3DEffect::Quick3DEffect(QObject *parent) QQmlListProperty<QTechnique> Quick3DEffect::techniqueList() { - return QQmlListProperty<QTechnique>(this, 0, - &Quick3DEffect::appendTechnique, - &Quick3DEffect::techniqueCount, - &Quick3DEffect::techniqueAt, - &Quick3DEffect::clearTechniqueList); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = QTechnique; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *bar) { + Quick3DEffect *eff = qobject_cast<Quick3DEffect*>(list->object); + if (eff) + eff->parentEffect()->addTechnique(bar); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DEffect *eff = qobject_cast<Quick3DEffect*>(list->object); + if (eff) + return eff->parentEffect()->techniques().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + // TO DO : Return a QAbstractTechnique once properly defined + Quick3DEffect *eff = qobject_cast<Quick3DEffect*>(list->object); + if (eff) + return qobject_cast<QTechnique*>(eff->parentEffect()->techniques().at(index)); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DEffect *eff = qobject_cast<Quick3DEffect*>(list->object); + if (eff) { + // Ownership of techniques is handled by the QmlEngine so we shouldn't class clearTechniques + // which deletes techniques + const auto techniques = eff->parentEffect()->techniques(); + for (QTechnique *tech : techniques) + eff->parentEffect()->removeTechnique(tech); + } + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } QQmlListProperty<QParameter> Quick3DEffect::parameterList() { - return QQmlListProperty<QParameter>(this, 0, - &Quick3DEffect::appendParameter, - &Quick3DEffect::parametersCount, - &Quick3DEffect::parameterAt, - &Quick3DEffect::clearParameterList); -} - -void Quick3DEffect::appendTechnique(QQmlListProperty<QTechnique> *list, QTechnique *bar) -{ - Quick3DEffect *eff = qobject_cast<Quick3DEffect*>(list->object); - if (eff) - eff->parentEffect()->addTechnique(bar); -} - -// TO DO : Return a QAbstractTechnique once properly defined -QTechnique *Quick3DEffect::techniqueAt(QQmlListProperty<QTechnique> *list, qsizetype index) -{ - Quick3DEffect *eff = qobject_cast<Quick3DEffect*>(list->object); - if (eff) - return qobject_cast<QTechnique*>(eff->parentEffect()->techniques().at(index)); - return nullptr; -} - -qsizetype Quick3DEffect::techniqueCount(QQmlListProperty<QTechnique> *list) -{ - Quick3DEffect *eff = qobject_cast<Quick3DEffect*>(list->object); - if (eff) - return eff->parentEffect()->techniques().count(); - return 0; -} - -void Quick3DEffect::clearTechniqueList(QQmlListProperty<QTechnique> *list) -{ - Quick3DEffect *eff = qobject_cast<Quick3DEffect*>(list->object); - if (eff) { - // Ownership of techniques is handled by the QmlEngine so we shouldn't class clearTechniques - // which deletes techniques - const auto techniques = eff->parentEffect()->techniques(); - for (QTechnique *tech : techniques) - eff->parentEffect()->removeTechnique(tech); - } -} - -void Quick3DEffect::appendParameter(QQmlListProperty<QParameter> *list, QParameter *param) -{ - Quick3DEffect *effect = qobject_cast<Quick3DEffect *>(list->object); - qobject_cast<QEffect *>(effect->parentEffect())->addParameter(param); -} - -QParameter *Quick3DEffect::parameterAt(QQmlListProperty<QParameter> *list, qsizetype index) -{ - Quick3DEffect *effect = qobject_cast<Quick3DEffect *>(list->object); - return qobject_cast<QEffect *>(effect->parentEffect())->parameters().at(index); -} - -qsizetype Quick3DEffect::parametersCount(QQmlListProperty<QParameter> *list) -{ - Quick3DEffect *effect = qobject_cast<Quick3DEffect *>(list->object); - return qobject_cast<QEffect *>(effect->parentEffect())->parameters().count(); -} - -void Quick3DEffect::clearParameterList(QQmlListProperty<QParameter> *list) -{ - Quick3DEffect *effect = qobject_cast<Quick3DEffect *>(list->object); - const auto parameters = qobject_cast<QEffect *>(effect->parentEffect())->parameters(); - for (QParameter *p : parameters) - qobject_cast<QEffect *>(effect->parentEffect())->removeParameter(p); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = QParameter; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *param) { + Quick3DEffect *effect = qobject_cast<Quick3DEffect *>(list->object); + qobject_cast<QEffect *>(effect->parentEffect())->addParameter(param); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DEffect *effect = qobject_cast<Quick3DEffect *>(list->object); + return qobject_cast<QEffect *>(effect->parentEffect())->parameters().count(); + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DEffect *effect = qobject_cast<Quick3DEffect *>(list->object); + return qobject_cast<QEffect *>(effect->parentEffect())->parameters().at(index); + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DEffect *effect = qobject_cast<Quick3DEffect *>(list->object); + const auto parameters = qobject_cast<QEffect *>(effect->parentEffect())->parameters(); + for (QParameter *p : parameters) + qobject_cast<QEffect *>(effect->parentEffect())->removeParameter(p); + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3deffect_p.h b/src/quick3d/quick3drender/items/quick3deffect_p.h index fb6fa2bdd..93215cc2c 100644 --- a/src/quick3d/quick3drender/items/quick3deffect_p.h +++ b/src/quick3d/quick3drender/items/quick3deffect_p.h @@ -76,17 +76,6 @@ public: QQmlListProperty<QTechnique> techniqueList(); QQmlListProperty<QParameter> parameterList(); - -private: - static void appendTechnique(QQmlListProperty<QTechnique> *list, QTechnique *bar); - static QTechnique *techniqueAt(QQmlListProperty<QTechnique> *list, qsizetype index); - static qsizetype techniqueCount(QQmlListProperty<QTechnique> *list); - static void clearTechniqueList(QQmlListProperty<QTechnique> *list); - - static void appendParameter(QQmlListProperty<QParameter> *list, QParameter *param); - static QParameter *parameterAt(QQmlListProperty<QParameter> *list, qsizetype index); - static qsizetype parametersCount(QQmlListProperty<QParameter> *list); - static void clearParameterList(QQmlListProperty<QParameter> *list); }; } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3dlayerfilter.cpp b/src/quick3d/quick3drender/items/quick3dlayerfilter.cpp index 505495eb3..431391af6 100644 --- a/src/quick3d/quick3drender/items/quick3dlayerfilter.cpp +++ b/src/quick3d/quick3drender/items/quick3dlayerfilter.cpp @@ -56,47 +56,41 @@ Quick3DLayerFilter::Quick3DLayerFilter(QObject *parent) QQmlListProperty<QLayer> Quick3DLayerFilter::qmlLayers() { - return QQmlListProperty<QLayer>(this, 0, - &Quick3DLayerFilter::appendLayer, - &Quick3DLayerFilter::layerCount, - &Quick3DLayerFilter::layerAt, - &Quick3DLayerFilter::clearLayers); -} - -void Quick3DLayerFilter::appendLayer(QQmlListProperty<QLayer> *list, QLayer *layer) -{ - Quick3DLayerFilter *filter = qobject_cast<Quick3DLayerFilter *>(list->object); - if (filter) { - filter->parentFilter()->addLayer(layer); - } -} - -QLayer *Quick3DLayerFilter::layerAt(QQmlListProperty<QLayer> *list, qsizetype index) -{ - Quick3DLayerFilter *filter = qobject_cast<Quick3DLayerFilter *>(list->object); - if (filter) { - return filter->parentFilter()->layers().at(index); - } - return 0; -} - -qsizetype Quick3DLayerFilter::layerCount(QQmlListProperty<QLayer> *list) -{ - Quick3DLayerFilter *filter = qobject_cast<Quick3DLayerFilter *>(list->object); - if (filter) { - return filter->parentFilter()->layers().count(); - } - return 0; -} - -void Quick3DLayerFilter::clearLayers(QQmlListProperty<QLayer> *list) -{ - Quick3DLayerFilter *filter = qobject_cast<Quick3DLayerFilter *>(list->object); - if (filter) { - const auto layers = filter->parentFilter()->layers(); - for (QLayer *layer : layers) - filter->parentFilter()->removeLayer(layer); - } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = QLayer; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *layer) { + Quick3DLayerFilter *filter = qobject_cast<Quick3DLayerFilter *>(list->object); + if (filter) { + filter->parentFilter()->addLayer(layer); + } + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DLayerFilter *filter = qobject_cast<Quick3DLayerFilter *>(list->object); + if (filter) + return filter->parentFilter()->layers().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DLayerFilter *filter = qobject_cast<Quick3DLayerFilter *>(list->object); + if (filter) + return filter->parentFilter()->layers().at(index); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DLayerFilter *filter = qobject_cast<Quick3DLayerFilter *>(list->object); + if (filter) { + const auto layers = filter->parentFilter()->layers(); + for (QLayer *layer : layers) + filter->parentFilter()->removeLayer(layer); + } + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } } // Quick diff --git a/src/quick3d/quick3drender/items/quick3dlayerfilter_p.h b/src/quick3d/quick3drender/items/quick3dlayerfilter_p.h index 3bcb6aaa2..ab5bf5c55 100644 --- a/src/quick3d/quick3drender/items/quick3dlayerfilter_p.h +++ b/src/quick3d/quick3drender/items/quick3dlayerfilter_p.h @@ -69,17 +69,11 @@ class Q_3DQUICKRENDERSHARED_PRIVATE_EXPORT Quick3DLayerFilter : public QObject Q_PROPERTY(QQmlListProperty<Qt3DRender::QLayer> layers READ qmlLayers) public: - explicit Quick3DLayerFilter(QObject *parent = 0); + explicit Quick3DLayerFilter(QObject *parent = nullptr); inline QLayerFilter *parentFilter() const { return qobject_cast<QLayerFilter*>(parent()); } QQmlListProperty<QLayer> qmlLayers(); - -private: - static void appendLayer(QQmlListProperty<QLayer> *list, QLayer *bar); - static QLayer *layerAt(QQmlListProperty<QLayer> *list, qsizetype index); - static qsizetype layerCount(QQmlListProperty<QLayer> *list); - static void clearLayers(QQmlListProperty<QLayer> *list); }; } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3dmaterial.cpp b/src/quick3d/quick3drender/items/quick3dmaterial.cpp index 4e5cc1947..0e1528fe2 100644 --- a/src/quick3d/quick3drender/items/quick3dmaterial.cpp +++ b/src/quick3d/quick3drender/items/quick3dmaterial.cpp @@ -56,46 +56,42 @@ Quick3DMaterial::Quick3DMaterial(QObject *parent) QQmlListProperty<QParameter> Quick3DMaterial::qmlParameters() { - return QQmlListProperty<QParameter>(this, 0, - &Quick3DMaterial::appendParameter, - &Quick3DMaterial::parameterCount, - &Quick3DMaterial::parameterAt, - &Quick3DMaterial::clearParameters); -} - -void Quick3DMaterial::appendParameter(QQmlListProperty<QParameter> *list, QParameter *param) -{ - Quick3DMaterial *mat = qobject_cast<Quick3DMaterial *>(list->object); - if (mat) { - param->setParent(mat->parentMaterial()); - mat->parentMaterial()->addParameter(param); - } -} - -QParameter *Quick3DMaterial::parameterAt(QQmlListProperty<QParameter> *list, qsizetype index) -{ - Quick3DMaterial *mat = qobject_cast<Quick3DMaterial *>(list->object); - if (mat) - return mat->parentMaterial()->parameters().at(index); - return 0; -} - -qsizetype Quick3DMaterial::parameterCount(QQmlListProperty<QParameter> *list) -{ - Quick3DMaterial *mat = qobject_cast<Quick3DMaterial *>(list->object); - if (mat) - return mat->parentMaterial()->parameters().count(); - return 0; -} - -void Quick3DMaterial::clearParameters(QQmlListProperty<QParameter> *list) -{ - Quick3DMaterial *mat = qobject_cast<Quick3DMaterial *>(list->object); - if (mat) { - const auto parameters = mat->parentMaterial()->parameters(); - for (QParameter *p : parameters) - mat->parentMaterial()->removeParameter(p); - } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = QParameter; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *param) { + Quick3DMaterial *mat = qobject_cast<Quick3DMaterial *>(list->object); + if (mat) { + param->setParent(mat->parentMaterial()); + mat->parentMaterial()->addParameter(param); + } + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DMaterial *mat = qobject_cast<Quick3DMaterial *>(list->object); + if (mat) + return mat->parentMaterial()->parameters().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DMaterial *mat = qobject_cast<Quick3DMaterial *>(list->object); + if (mat) + return mat->parentMaterial()->parameters().at(index); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DMaterial *mat = qobject_cast<Quick3DMaterial *>(list->object); + if (mat) { + const auto parameters = mat->parentMaterial()->parameters(); + for (QParameter *p : parameters) + mat->parentMaterial()->removeParameter(p); + } + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } } // Quick diff --git a/src/quick3d/quick3drender/items/quick3dmaterial_p.h b/src/quick3d/quick3drender/items/quick3dmaterial_p.h index adb0d066b..a8d07ac32 100644 --- a/src/quick3d/quick3drender/items/quick3dmaterial_p.h +++ b/src/quick3d/quick3drender/items/quick3dmaterial_p.h @@ -72,20 +72,12 @@ class Q_3DQUICKRENDERSHARED_PRIVATE_EXPORT Quick3DMaterial : public QObject Q_PROPERTY(QQmlListProperty<Qt3DRender::QParameter> parameters READ qmlParameters) public: - explicit Quick3DMaterial(QObject *parent = 0); + explicit Quick3DMaterial(QObject *parent = nullptr); // TO DO : replace by QAbstractMaterial later on inline QMaterial *parentMaterial() const { return qobject_cast<QMaterial*>(parent()); } QQmlListProperty<QParameter> qmlParameters(); - - -private: - // FIXME - remove when we have a custom QML parser - static void appendParameter(QQmlListProperty<QParameter> *list, QParameter *bar); - static QParameter *parameterAt(QQmlListProperty<QParameter> *list, qsizetype index); - static qsizetype parameterCount(QQmlListProperty<QParameter> *list); - static void clearParameters(QQmlListProperty<QParameter> *list); }; } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3draycaster.cpp b/src/quick3d/quick3drender/items/quick3draycaster.cpp index dad28bbbe..4e901c82b 100644 --- a/src/quick3d/quick3drender/items/quick3draycaster.cpp +++ b/src/quick3d/quick3drender/items/quick3draycaster.cpp @@ -49,39 +49,6 @@ namespace Qt3DRender { namespace Render { namespace Quick { -void Quick3DRayCasterPrivate::appendLayer(QQmlListProperty<QLayer> *list, QLayer *layer) -{ - QAbstractRayCaster *filter = qobject_cast<QAbstractRayCaster *>(list->object); - if (filter) - filter->addLayer(layer); -} - -QLayer *Quick3DRayCasterPrivate::layerAt(QQmlListProperty<QLayer> *list, qsizetype index) -{ - QAbstractRayCaster *filter = qobject_cast<QAbstractRayCaster *>(list->object); - if (filter) - return filter->layers().at(index); - return nullptr; -} - -qsizetype Quick3DRayCasterPrivate::layerCount(QQmlListProperty<QLayer> *list) -{ - QAbstractRayCaster *filter = qobject_cast<QAbstractRayCaster *>(list->object); - if (filter) - return int(filter->layers().size()); - return 0; -} - -void Quick3DRayCasterPrivate::clearLayers(QQmlListProperty<QLayer> *list) -{ - QAbstractRayCaster *filter = qobject_cast<QAbstractRayCaster *>(list->object); - if (filter) { - const auto layers = filter->layers(); - for (QLayer *layer : layers) - filter->removeLayer(layer); - } -} - Quick3DRayCaster::Quick3DRayCaster(QObject *parent) : QRayCaster(*new Quick3DRayCasterPrivate(), qobject_cast<Qt3DCore::QNode *>(parent)) { @@ -89,11 +56,40 @@ Quick3DRayCaster::Quick3DRayCaster(QObject *parent) QQmlListProperty<Qt3DRender::QLayer> Qt3DRender::Render::Quick::Quick3DRayCaster::qmlLayers() { - return QQmlListProperty<QLayer>(this, nullptr, - &Quick3DRayCasterPrivate::appendLayer, - &Quick3DRayCasterPrivate::layerCount, - &Quick3DRayCasterPrivate::layerAt, - &Quick3DRayCasterPrivate::clearLayers); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = Qt3DRender::QLayer; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *layer) { + QAbstractRayCaster *filter = qobject_cast<QAbstractRayCaster *>(list->object); + if (filter) + filter->addLayer(layer); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + QAbstractRayCaster *filter = qobject_cast<QAbstractRayCaster *>(list->object); + if (filter) + return int(filter->layers().size()); + return 0; + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + QAbstractRayCaster *filter = qobject_cast<QAbstractRayCaster *>(list->object); + if (filter) + return filter->layers().at(index); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + QAbstractRayCaster *filter = qobject_cast<QAbstractRayCaster *>(list->object); + if (filter) { + const auto layers = filter->layers(); + for (QLayer *layer : layers) + filter->removeLayer(layer); + } + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3draycaster_p_p.h b/src/quick3d/quick3drender/items/quick3draycaster_p_p.h index 096cae351..dd4c10e62 100644 --- a/src/quick3d/quick3drender/items/quick3draycaster_p_p.h +++ b/src/quick3d/quick3drender/items/quick3draycaster_p_p.h @@ -68,11 +68,6 @@ class Q_3DQUICKRENDERSHARED_PRIVATE_EXPORT Quick3DRayCasterPrivate : public QAbs public: explicit Quick3DRayCasterPrivate() : QAbstractRayCasterPrivate() { } - static void appendLayer(QQmlListProperty<QLayer> *list, QLayer *bar); - static QLayer *layerAt(QQmlListProperty<QLayer> *list, qsizetype index); - static qsizetype layerCount(QQmlListProperty<QLayer> *list); - static void clearLayers(QQmlListProperty<QLayer> *list); - Q_DECLARE_PUBLIC(Quick3DRayCaster) }; diff --git a/src/quick3d/quick3drender/items/quick3drenderpass.cpp b/src/quick3d/quick3drender/items/quick3drenderpass.cpp index e05bd9c74..0006191a5 100644 --- a/src/quick3d/quick3drender/items/quick3drenderpass.cpp +++ b/src/quick3d/quick3drender/items/quick3drenderpass.cpp @@ -53,110 +53,97 @@ Quick3DRenderPass::Quick3DRenderPass(QObject *parent) QQmlListProperty<QFilterKey> Quick3DRenderPass::filterKeyList() { - return QQmlListProperty<QFilterKey>(this, 0, - &Quick3DRenderPass::appendFilterKey, - &Quick3DRenderPass::filterKeysCount, - &Quick3DRenderPass::filterKeyAt, - &Quick3DRenderPass::clearFilterKey); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = QFilterKey; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *filterKey) { + Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); + rPass->parentRenderPass()->addFilterKey(filterKey); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); + return rPass->parentRenderPass()->filterKeys().count(); + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); + return rPass->parentRenderPass()->filterKeys().at(index); + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); + const auto keys = rPass->parentRenderPass()->filterKeys(); + for (QFilterKey *c : keys) + rPass->parentRenderPass()->removeFilterKey(c); + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } QQmlListProperty<QRenderState> Quick3DRenderPass::renderStateList() { - return QQmlListProperty<QRenderState>(this, 0, - &Quick3DRenderPass::appendRenderState, - &Quick3DRenderPass::renderStateCount, - &Quick3DRenderPass::renderStateAt, - &Quick3DRenderPass::clearRenderStates); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = QRenderState; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *state) { + Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); + rPass->parentRenderPass()->addRenderState(state); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); + return rPass->parentRenderPass()->renderStates().count(); + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); + return rPass->parentRenderPass()->renderStates().at(index); + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); + const auto states = rPass->parentRenderPass()->renderStates(); + for (QRenderState *s : states) + rPass->parentRenderPass()->removeRenderState(s); + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } QQmlListProperty<QParameter> Quick3DRenderPass::parameterList() { - return QQmlListProperty<QParameter>(this, 0, - &Quick3DRenderPass::appendParameter, - &Quick3DRenderPass::parametersCount, - &Quick3DRenderPass::parameterAt, - &Quick3DRenderPass::clearParameterList); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = QParameter; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *param) { + Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); + rPass->parentRenderPass()->addParameter(param); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); + return rPass->parentRenderPass()->parameters().count(); + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); + return rPass->parentRenderPass()->parameters().at(index); + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); + const auto parameters = rPass->parentRenderPass()->parameters(); + for (QParameter *p : parameters) + rPass->parentRenderPass()->removeParameter(p); + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } -void Quick3DRenderPass::appendFilterKey(QQmlListProperty<QFilterKey> *list, QFilterKey *filterKey) -{ - Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); - rPass->parentRenderPass()->addFilterKey(filterKey); -} - -QFilterKey *Quick3DRenderPass::filterKeyAt(QQmlListProperty<QFilterKey> *list, qsizetype index) -{ - Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); - return rPass->parentRenderPass()->filterKeys().at(index); -} - -qsizetype Quick3DRenderPass::filterKeysCount(QQmlListProperty<QFilterKey> *list) -{ - Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); - return rPass->parentRenderPass()->filterKeys().count(); -} - -void Quick3DRenderPass::clearFilterKey(QQmlListProperty<QFilterKey> *list) -{ - Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); - const auto keys = rPass->parentRenderPass()->filterKeys(); - for (QFilterKey *c : keys) - rPass->parentRenderPass()->removeFilterKey(c); -} - -void Quick3DRenderPass::appendRenderState(QQmlListProperty<QRenderState> *list, QRenderState *state) -{ - Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); - rPass->parentRenderPass()->addRenderState(state); -} - -QRenderState *Quick3DRenderPass::renderStateAt(QQmlListProperty<QRenderState> *list, qsizetype index) -{ - Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); - return rPass->parentRenderPass()->renderStates().at(index); -} - -qsizetype Quick3DRenderPass::renderStateCount(QQmlListProperty<QRenderState> *list) -{ - Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); - return rPass->parentRenderPass()->renderStates().count(); -} - -void Quick3DRenderPass::clearRenderStates(QQmlListProperty<QRenderState> *list) -{ - Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); - const auto states = rPass->parentRenderPass()->renderStates(); - for (QRenderState *s : states) - rPass->parentRenderPass()->removeRenderState(s); -} - -void Quick3DRenderPass::appendParameter(QQmlListProperty<QParameter> *list, QParameter *param) -{ - Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); - rPass->parentRenderPass()->addParameter(param); -} - -QParameter *Quick3DRenderPass::parameterAt(QQmlListProperty<QParameter> *list, qsizetype index) -{ - Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); - return rPass->parentRenderPass()->parameters().at(index); -} - -qsizetype Quick3DRenderPass::parametersCount(QQmlListProperty<QParameter> *list) -{ - Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); - return rPass->parentRenderPass()->parameters().count(); -} - -void Quick3DRenderPass::clearParameterList(QQmlListProperty<QParameter> *list) -{ - Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); - const auto parameters = rPass->parentRenderPass()->parameters(); - for (QParameter *p : parameters) - rPass->parentRenderPass()->removeParameter(p); -} - - } // namespace Quick } // namespace Render } // namespace Qt3DRender diff --git a/src/quick3d/quick3drender/items/quick3drenderpass_p.h b/src/quick3d/quick3drender/items/quick3drenderpass_p.h index 58ef251ff..a67605239 100644 --- a/src/quick3d/quick3drender/items/quick3drenderpass_p.h +++ b/src/quick3d/quick3drender/items/quick3drenderpass_p.h @@ -77,22 +77,6 @@ public: QQmlListProperty<QParameter> parameterList(); inline QRenderPass *parentRenderPass() const { return qobject_cast<QRenderPass *>(parent()); } - -private: - static void appendFilterKey(QQmlListProperty<QFilterKey> *list, QFilterKey *filterKey); - static QFilterKey *filterKeyAt(QQmlListProperty<QFilterKey> *list, qsizetype index); - static qsizetype filterKeysCount(QQmlListProperty<QFilterKey> *list); - static void clearFilterKey(QQmlListProperty<QFilterKey> *list); - - static void appendRenderState(QQmlListProperty<QRenderState> *list, QRenderState *state); - static QRenderState *renderStateAt(QQmlListProperty<QRenderState> *list, qsizetype index); - static qsizetype renderStateCount(QQmlListProperty<QRenderState> *list); - static void clearRenderStates(QQmlListProperty<QRenderState> *list); - - static void appendParameter(QQmlListProperty<QParameter> *list, QParameter *param); - static QParameter *parameterAt(QQmlListProperty<QParameter> *list, qsizetype index); - static qsizetype parametersCount(QQmlListProperty<QParameter> *list); - static void clearParameterList(QQmlListProperty<QParameter> *list); }; } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3drenderpassfilter.cpp b/src/quick3d/quick3drender/items/quick3drenderpassfilter.cpp index 5cf45b4a8..6323911b4 100644 --- a/src/quick3d/quick3drender/items/quick3drenderpassfilter.cpp +++ b/src/quick3d/quick3drender/items/quick3drenderpassfilter.cpp @@ -52,82 +52,79 @@ Quick3DRenderPassFilter::Quick3DRenderPassFilter(QObject *parent) QQmlListProperty<QFilterKey> Quick3DRenderPassFilter::includeList() { - return QQmlListProperty<QFilterKey>(this, 0, - &Quick3DRenderPassFilter::appendInclude, - &Quick3DRenderPassFilter::includesCount, - &Quick3DRenderPassFilter::includeAt, - &Quick3DRenderPassFilter::clearIncludes); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + auto appendFunction = [](QQmlListProperty<QFilterKey> *list, QFilterKey *v) { + auto self = qobject_cast<Quick3DRenderPassFilter *>(list->object); + if (self) { + v->setParent(self->parentRenderPassFilter()); + self->parentRenderPassFilter()->addMatch(v); + } + }; + auto countFunction = [](QQmlListProperty<QFilterKey> *list) -> qt_size_type { + auto self = qobject_cast<Quick3DRenderPassFilter *>(list->object); + if (self) + return self->parentRenderPassFilter()->matchAny().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty<QFilterKey> *list, qt_size_type index) -> QFilterKey * { + auto self = qobject_cast<Quick3DRenderPassFilter *>(list->object); + if (self) + return self->parentRenderPassFilter()->matchAny().at(index); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty<QFilterKey> *list) { + auto self = qobject_cast<Quick3DRenderPassFilter *>(list->object); + if (self) { + const auto l = self->parentRenderPassFilter()->matchAny(); + for (auto *v : l) + self->parentRenderPassFilter()->removeMatch(v); + } + }; + + return QQmlListProperty<QFilterKey>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } QQmlListProperty<QParameter> Quick3DRenderPassFilter::parameterList() { - return QQmlListProperty<QParameter>(this, 0, - &Quick3DRenderPassFilter::appendParameter, - &Quick3DRenderPassFilter::parametersCount, - &Quick3DRenderPassFilter::parameterAt, - &Quick3DRenderPassFilter::clearParameterList); - -} - -void Quick3DRenderPassFilter::appendInclude(QQmlListProperty<QFilterKey> *list, QFilterKey *annotation) -{ - Quick3DRenderPassFilter *filter = qobject_cast<Quick3DRenderPassFilter *>(list->object); - if (filter) { - annotation->setParent(filter->parentRenderPassFilter()); - filter->parentRenderPassFilter()->addMatch(annotation); - } -} - -QFilterKey *Quick3DRenderPassFilter::includeAt(QQmlListProperty<QFilterKey> *list, qsizetype index) -{ - Quick3DRenderPassFilter *filter = qobject_cast<Quick3DRenderPassFilter *>(list->object); - if (filter) - return filter->parentRenderPassFilter()->matchAny().at(index); - return 0; -} - -qsizetype Quick3DRenderPassFilter::includesCount(QQmlListProperty<QFilterKey> *list) -{ - Quick3DRenderPassFilter *filter = qobject_cast<Quick3DRenderPassFilter *>(list->object); - if (filter) - return filter->parentRenderPassFilter()->matchAny().count(); - return 0; -} - -void Quick3DRenderPassFilter::clearIncludes(QQmlListProperty<QFilterKey> *list) -{ - Quick3DRenderPassFilter *filter = qobject_cast<Quick3DRenderPassFilter *>(list->object); - if (filter) { - const auto criteria = filter->parentRenderPassFilter()->matchAny(); - for (QFilterKey *criterion : criteria) - filter->parentRenderPassFilter()->removeMatch(criterion); - } -} - -void Quick3DRenderPassFilter::appendParameter(QQmlListProperty<QParameter> *list, QParameter *param) -{ - Quick3DRenderPassFilter *rPassFilter = qobject_cast<Quick3DRenderPassFilter *>(list->object); - rPassFilter->parentRenderPassFilter()->addParameter(param); -} - -QParameter *Quick3DRenderPassFilter::parameterAt(QQmlListProperty<QParameter> *list, qsizetype index) -{ - Quick3DRenderPassFilter *rPassFilter = qobject_cast<Quick3DRenderPassFilter *>(list->object); - return rPassFilter->parentRenderPassFilter()->parameters().at(index); -} - -qsizetype Quick3DRenderPassFilter::parametersCount(QQmlListProperty<QParameter> *list) -{ - Quick3DRenderPassFilter *rPassFilter = qobject_cast<Quick3DRenderPassFilter *>(list->object); - return rPassFilter->parentRenderPassFilter()->parameters().count(); -} - -void Quick3DRenderPassFilter::clearParameterList(QQmlListProperty<QParameter> *list) -{ - Quick3DRenderPassFilter *rPassFilter = qobject_cast<Quick3DRenderPassFilter *>(list->object); - const auto parameters = rPassFilter->parentRenderPassFilter()->parameters(); - for (QParameter *p : parameters) - rPassFilter->parentRenderPassFilter()->removeParameter(p); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + auto appendFunction = [](QQmlListProperty<QParameter> *list, QParameter *v) { + auto self = qobject_cast<Quick3DRenderPassFilter *>(list->object); + if (self) { + self->parentRenderPassFilter()->addParameter(v); + } + }; + auto countFunction = [](QQmlListProperty<QParameter> *list) -> qt_size_type { + auto self = qobject_cast<Quick3DRenderPassFilter *>(list->object); + if (self) + return self->parentRenderPassFilter()->parameters().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty<QParameter> *list, qt_size_type index) -> QParameter * { + auto self = qobject_cast<Quick3DRenderPassFilter *>(list->object); + if (self) + return self->parentRenderPassFilter()->parameters().at(index); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty<QParameter> *list) { + auto self = qobject_cast<Quick3DRenderPassFilter *>(list->object); + if (self) { + const auto l = self->parentRenderPassFilter()->parameters(); + for (auto *v : l) + self->parentRenderPassFilter()->removeParameter(v); + } + }; + + return QQmlListProperty<QParameter>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3drenderpassfilter_p.h b/src/quick3d/quick3drender/items/quick3drenderpassfilter_p.h index 1f13f1d2f..03e435edb 100644 --- a/src/quick3d/quick3drender/items/quick3drenderpassfilter_p.h +++ b/src/quick3d/quick3drender/items/quick3drenderpassfilter_p.h @@ -77,17 +77,6 @@ public: QQmlListProperty<QParameter> parameterList(); inline QRenderPassFilter *parentRenderPassFilter() const { return qobject_cast<Qt3DRender::QRenderPassFilter*>(parent()); } - -private: - static void appendInclude(QQmlListProperty<QFilterKey> *list, QFilterKey *criterion); - static QFilterKey *includeAt(QQmlListProperty<QFilterKey> *list, qsizetype index); - static qsizetype includesCount(QQmlListProperty<QFilterKey> *list); - static void clearIncludes(QQmlListProperty<QFilterKey> *list); - - static void appendParameter(QQmlListProperty<QParameter> *list, QParameter *param); - static QParameter *parameterAt(QQmlListProperty<QParameter> *list, qsizetype index); - static qsizetype parametersCount(QQmlListProperty<QParameter> *list); - static void clearParameterList(QQmlListProperty<QParameter> *list); }; } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3drendertargetoutput.cpp b/src/quick3d/quick3drender/items/quick3drendertargetoutput.cpp index 5d35e7e00..810ded8b0 100644 --- a/src/quick3d/quick3drender/items/quick3drendertargetoutput.cpp +++ b/src/quick3d/quick3drender/items/quick3drendertargetoutput.cpp @@ -52,44 +52,40 @@ Quick3DRenderTargetOutput::Quick3DRenderTargetOutput(QObject * parent) QQmlListProperty<QRenderTargetOutput> Quick3DRenderTargetOutput::qmlAttachments() { - return QQmlListProperty<QRenderTargetOutput>(this, 0, - &Quick3DRenderTargetOutput::appendRenderAttachment, - &Quick3DRenderTargetOutput::renderAttachmentCount, - &Quick3DRenderTargetOutput::renderAttachmentAt, - &Quick3DRenderTargetOutput::clearRenderAttachments); -} - -void Quick3DRenderTargetOutput::appendRenderAttachment(QQmlListProperty<QRenderTargetOutput> *list, QRenderTargetOutput *output) -{ - Quick3DRenderTargetOutput *rT = qobject_cast<Quick3DRenderTargetOutput *>(list->object); - if (rT) - rT->parentRenderTarget()->addOutput(output); -} - -QRenderTargetOutput *Quick3DRenderTargetOutput::renderAttachmentAt(QQmlListProperty<QRenderTargetOutput> *list, qsizetype index) -{ - Quick3DRenderTargetOutput *rT = qobject_cast<Quick3DRenderTargetOutput *>(list->object); - if (rT) - return rT->parentRenderTarget()->outputs().at(index); - return nullptr; -} +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif -qsizetype Quick3DRenderTargetOutput::renderAttachmentCount(QQmlListProperty<QRenderTargetOutput> *list) -{ - Quick3DRenderTargetOutput *rT = qobject_cast<Quick3DRenderTargetOutput *>(list->object); - if (rT) - return rT->parentRenderTarget()->outputs().count(); - return -1; -} + using ListContentType = QRenderTargetOutput; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *output) { + Quick3DRenderTargetOutput *rT = qobject_cast<Quick3DRenderTargetOutput *>(list->object); + if (rT) + rT->parentRenderTarget()->addOutput(output); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DRenderTargetOutput *rT = qobject_cast<Quick3DRenderTargetOutput *>(list->object); + if (rT) + return rT->parentRenderTarget()->outputs().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DRenderTargetOutput *rT = qobject_cast<Quick3DRenderTargetOutput *>(list->object); + if (rT) + return rT->parentRenderTarget()->outputs().at(index); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DRenderTargetOutput *rT = qobject_cast<Quick3DRenderTargetOutput *>(list->object); + if (rT) { + const auto outputs = rT->parentRenderTarget()->outputs(); + for (QRenderTargetOutput *output : outputs) + rT->parentRenderTarget()->removeOutput(output); + } + }; -void Quick3DRenderTargetOutput::clearRenderAttachments(QQmlListProperty<QRenderTargetOutput> *list) -{ - Quick3DRenderTargetOutput *rT = qobject_cast<Quick3DRenderTargetOutput *>(list->object); - if (rT) { - const auto outputs = rT->parentRenderTarget()->outputs(); - for (QRenderTargetOutput *output : outputs) - rT->parentRenderTarget()->removeOutput(output); - } + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3drendertargetoutput_p.h b/src/quick3d/quick3drender/items/quick3drendertargetoutput_p.h index 076d034ed..df250929e 100644 --- a/src/quick3d/quick3drender/items/quick3drendertargetoutput_p.h +++ b/src/quick3d/quick3drender/items/quick3drendertargetoutput_p.h @@ -68,16 +68,10 @@ class Q_3DQUICKRENDERSHARED_PRIVATE_EXPORT Quick3DRenderTargetOutput : public QO Q_OBJECT Q_PROPERTY(QQmlListProperty<Qt3DRender::QRenderTargetOutput> attachments READ qmlAttachments) public: - explicit Quick3DRenderTargetOutput(QObject *parent = 0); + explicit Quick3DRenderTargetOutput(QObject *parent = nullptr); inline QRenderTarget *parentRenderTarget() const { return qobject_cast<QRenderTarget *>(parent()); } QQmlListProperty<QRenderTargetOutput> qmlAttachments(); - -private: - static void appendRenderAttachment(QQmlListProperty<QRenderTargetOutput> *list, QRenderTargetOutput *attachment); - static QRenderTargetOutput *renderAttachmentAt(QQmlListProperty<QRenderTargetOutput> *list, qsizetype index); - static qsizetype renderAttachmentCount(QQmlListProperty<QRenderTargetOutput> *list); - static void clearRenderAttachments(QQmlListProperty<QRenderTargetOutput> *list); }; } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3dscreenraycaster.cpp b/src/quick3d/quick3drender/items/quick3dscreenraycaster.cpp index 03d6268c3..206073426 100644 --- a/src/quick3d/quick3drender/items/quick3dscreenraycaster.cpp +++ b/src/quick3d/quick3drender/items/quick3dscreenraycaster.cpp @@ -60,11 +60,40 @@ Quick3DScreenRayCaster::Quick3DScreenRayCaster(QObject *parent) QQmlListProperty<Qt3DRender::QLayer> Qt3DRender::Render::Quick::Quick3DScreenRayCaster::qmlLayers() { - return QQmlListProperty<QLayer>(this, nullptr, - &Quick3DRayCasterPrivate::appendLayer, - &Quick3DRayCasterPrivate::layerCount, - &Quick3DRayCasterPrivate::layerAt, - &Quick3DRayCasterPrivate::clearLayers); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = Qt3DRender::QLayer; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *layer) { + QAbstractRayCaster *filter = qobject_cast<QAbstractRayCaster *>(list->object); + if (filter) + filter->addLayer(layer); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + QAbstractRayCaster *filter = qobject_cast<QAbstractRayCaster *>(list->object); + if (filter) + return int(filter->layers().size()); + return 0; + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + QAbstractRayCaster *filter = qobject_cast<QAbstractRayCaster *>(list->object); + if (filter) + return filter->layers().at(index); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + QAbstractRayCaster *filter = qobject_cast<QAbstractRayCaster *>(list->object); + if (filter) { + const auto layers = filter->layers(); + for (QLayer *layer : layers) + filter->removeLayer(layer); + } + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3dshaderdataarray.cpp b/src/quick3d/quick3drender/items/quick3dshaderdataarray.cpp index 51e8911a6..146a17477 100644 --- a/src/quick3d/quick3drender/items/quick3dshaderdataarray.cpp +++ b/src/quick3d/quick3drender/items/quick3dshaderdataarray.cpp @@ -63,11 +63,31 @@ Quick3DShaderDataArray::Quick3DShaderDataArray(QNode *parent) QQmlListProperty<QShaderData> Quick3DShaderDataArray::valuesList() { - return QQmlListProperty<QShaderData>(this, 0, - &Quick3DShaderDataArray::appendValue, - &Quick3DShaderDataArray::valueCount, - &Quick3DShaderDataArray::valueAt, - &Quick3DShaderDataArray::clearValues); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = QShaderData; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *bar) { + Quick3DShaderDataArray *self = static_cast<Quick3DShaderDataArray *>(list->object); + static_cast<Quick3DShaderDataArrayPrivate *>(Quick3DShaderDataArrayPrivate::get(self))->m_values.append(bar); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DShaderDataArray *self = static_cast<Quick3DShaderDataArray *>(list->object); + return static_cast<Quick3DShaderDataArrayPrivate *>(Quick3DShaderDataArrayPrivate::get(self))->m_values.count(); + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DShaderDataArray *self = static_cast<Quick3DShaderDataArray *>(list->object); + return static_cast<Quick3DShaderDataArrayPrivate *>(Quick3DShaderDataArrayPrivate::get(self))->m_values.at(index); + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DShaderDataArray *self = static_cast<Quick3DShaderDataArray *>(list->object); + static_cast<Quick3DShaderDataArrayPrivate *>(Quick3DShaderDataArrayPrivate::get(self))->m_values.clear(); + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } QList<QShaderData *> Quick3DShaderDataArray::values() const @@ -85,30 +105,6 @@ QList<QShaderData *> Quick3DShaderDataArray::values() const // d_func()->m_values.append(static_cast<QShaderData *>(QNode::clone(v))); //} -void Quick3DShaderDataArray::appendValue(QQmlListProperty<QShaderData> *list, QShaderData *bar) -{ - Quick3DShaderDataArray *self = static_cast<Quick3DShaderDataArray *>(list->object); - static_cast<Quick3DShaderDataArrayPrivate *>(Quick3DShaderDataArrayPrivate::get(self))->m_values.append(bar); -} - -QShaderData *Quick3DShaderDataArray::valueAt(QQmlListProperty<QShaderData> *list, qsizetype index) -{ - Quick3DShaderDataArray *self = static_cast<Quick3DShaderDataArray *>(list->object); - return static_cast<Quick3DShaderDataArrayPrivate *>(Quick3DShaderDataArrayPrivate::get(self))->m_values.at(index); -} - -qsizetype Quick3DShaderDataArray::valueCount(QQmlListProperty<QShaderData> *list) -{ - Quick3DShaderDataArray *self = static_cast<Quick3DShaderDataArray *>(list->object); - return static_cast<Quick3DShaderDataArrayPrivate *>(Quick3DShaderDataArrayPrivate::get(self))->m_values.count(); -} - -void Quick3DShaderDataArray::clearValues(QQmlListProperty<QShaderData> *list) -{ - Quick3DShaderDataArray *self = static_cast<Quick3DShaderDataArray *>(list->object); - static_cast<Quick3DShaderDataArrayPrivate *>(Quick3DShaderDataArrayPrivate::get(self))->m_values.clear(); -} - } // namespace Quick } // namespace Render } // namespace Qt3DRender diff --git a/src/quick3d/quick3drender/items/quick3dshaderdataarray_p.h b/src/quick3d/quick3drender/items/quick3dshaderdataarray_p.h index 4a1347cf8..6e800328a 100644 --- a/src/quick3d/quick3drender/items/quick3dshaderdataarray_p.h +++ b/src/quick3d/quick3drender/items/quick3dshaderdataarray_p.h @@ -76,15 +76,11 @@ class Q_3DQUICKRENDERSHARED_PRIVATE_EXPORT Quick3DShaderDataArray : public Qt3DC Q_CLASSINFO("DefaultProperty", "values") public: - explicit Quick3DShaderDataArray(Qt3DCore::QNode *parent = 0); + explicit Quick3DShaderDataArray(Qt3DCore::QNode *parent = nullptr); QQmlListProperty<QShaderData> valuesList(); QList<QShaderData *> values() const; private: - static void appendValue(QQmlListProperty<QShaderData> *list, QShaderData *bar); - static QShaderData *valueAt(QQmlListProperty<QShaderData> *list, qsizetype index); - static qsizetype valueCount(QQmlListProperty<QShaderData> *list); - static void clearValues(QQmlListProperty<QShaderData> *list); Q_DECLARE_PRIVATE(Quick3DShaderDataArray) }; diff --git a/src/quick3d/quick3drender/items/quick3dstateset.cpp b/src/quick3d/quick3drender/items/quick3dstateset.cpp index 49fa0b96a..396fab309 100644 --- a/src/quick3d/quick3drender/items/quick3dstateset.cpp +++ b/src/quick3d/quick3drender/items/quick3dstateset.cpp @@ -56,38 +56,33 @@ Quick3DStateSet::~Quick3DStateSet() QQmlListProperty<QRenderState> Quick3DStateSet::renderStateList() { - return QQmlListProperty<QRenderState>(this, 0, - &Quick3DStateSet::appendRenderState, - &Quick3DStateSet::renderStateCount, - &Quick3DStateSet::renderStateAt, - &Quick3DStateSet::clearRenderStates); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif -} - -void Quick3DStateSet::appendRenderState(QQmlListProperty<QRenderState> *list, QRenderState *state) -{ - Quick3DStateSet *stateSet = qobject_cast<Quick3DStateSet *>(list->object); - stateSet->parentStateSet()->addRenderState(state); -} + using ListContentType = QRenderState; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *state) { + Quick3DStateSet *stateSet = qobject_cast<Quick3DStateSet *>(list->object); + stateSet->parentStateSet()->addRenderState(state); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DStateSet *stateSet = qobject_cast<Quick3DStateSet *>(list->object); + return stateSet->parentStateSet()->renderStates().count(); + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DStateSet *stateSet = qobject_cast<Quick3DStateSet *>(list->object); + return stateSet->parentStateSet()->renderStates().at(index); + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DStateSet *stateSet = qobject_cast<Quick3DStateSet *>(list->object); + const auto states = stateSet->parentStateSet()->renderStates(); + for (QRenderState *s : states) + stateSet->parentStateSet()->removeRenderState(s); + }; -QRenderState *Quick3DStateSet::renderStateAt(QQmlListProperty<QRenderState> *list, qsizetype index) -{ - Quick3DStateSet *stateSet = qobject_cast<Quick3DStateSet *>(list->object); - return stateSet->parentStateSet()->renderStates().at(index); -} - -qsizetype Quick3DStateSet::renderStateCount(QQmlListProperty<QRenderState> *list) -{ - Quick3DStateSet *stateSet = qobject_cast<Quick3DStateSet *>(list->object); - return stateSet->parentStateSet()->renderStates().count(); -} - -void Quick3DStateSet::clearRenderStates(QQmlListProperty<QRenderState> *list) -{ - Quick3DStateSet *stateSet = qobject_cast<Quick3DStateSet *>(list->object); - const auto states = stateSet->parentStateSet()->renderStates(); - for (QRenderState *s : states) - stateSet->parentStateSet()->removeRenderState(s); + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3dstateset_p.h b/src/quick3d/quick3drender/items/quick3dstateset_p.h index 4d060e149..f4bd13cd2 100644 --- a/src/quick3d/quick3drender/items/quick3dstateset_p.h +++ b/src/quick3d/quick3drender/items/quick3dstateset_p.h @@ -67,17 +67,11 @@ class Q_3DQUICKRENDERSHARED_PRIVATE_EXPORT Quick3DStateSet : public QObject Q_OBJECT Q_PROPERTY(QQmlListProperty<Qt3DRender::QRenderState> renderStates READ renderStateList CONSTANT) public: - explicit Quick3DStateSet(QObject *parent = 0); + explicit Quick3DStateSet(QObject *parent = nullptr); ~Quick3DStateSet(); QQmlListProperty<QRenderState> renderStateList(); inline QRenderStateSet *parentStateSet() const { return qobject_cast<QRenderStateSet *>(parent()); } - -private: - static void appendRenderState(QQmlListProperty<QRenderState> *list, QRenderState *state); - static QRenderState *renderStateAt(QQmlListProperty<QRenderState> *list, qsizetype index); - static qsizetype renderStateCount(QQmlListProperty<QRenderState> *list); - static void clearRenderStates(QQmlListProperty<QRenderState> *list); }; } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3dtechnique.cpp b/src/quick3d/quick3drender/items/quick3dtechnique.cpp index 805748a1c..edc6f3da2 100644 --- a/src/quick3d/quick3drender/items/quick3dtechnique.cpp +++ b/src/quick3d/quick3drender/items/quick3dtechnique.cpp @@ -52,125 +52,112 @@ Quick3DTechnique::Quick3DTechnique(QObject *parent) QQmlListProperty<QRenderPass> Quick3DTechnique::renderPassList() { - return QQmlListProperty<QRenderPass>(this, 0, - &Quick3DTechnique::appendRenderPass, - &Quick3DTechnique::renderPassCount, - &Quick3DTechnique::renderPassAt, - &Quick3DTechnique::clearRenderPasses); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = QRenderPass; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *renderPass) { + Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); + if (technique) + technique->parentTechnique()->addRenderPass(renderPass); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); + if (technique) + return technique->parentTechnique()->renderPasses().size(); + return 0; + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); + if (technique) + return qobject_cast<QRenderPass *>(technique->parentTechnique()->renderPasses().at(index)); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); + if (technique) { + const auto passes = technique->parentTechnique()->renderPasses(); + for (QRenderPass *pass : passes) + technique->parentTechnique()->removeRenderPass(pass); + } + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } QQmlListProperty<QParameter> Quick3DTechnique::parameterList() { - return QQmlListProperty<QParameter>(this, 0, - &Quick3DTechnique::appendParameter, - &Quick3DTechnique::parametersCount, - &Quick3DTechnique::parameterAt, - &Quick3DTechnique::clearParameterList); -} - -void Quick3DTechnique::appendParameter(QQmlListProperty<QParameter> *list, QParameter *param) -{ - Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); - technique->parentTechnique()->addParameter(param); -} - -QParameter *Quick3DTechnique::parameterAt(QQmlListProperty<QParameter> *list, qsizetype index) -{ - Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); - return technique->parentTechnique()->parameters().at(index); -} - -qsizetype Quick3DTechnique::parametersCount(QQmlListProperty<QParameter> *list) -{ - Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); - return technique->parentTechnique()->parameters().count(); -} - -void Quick3DTechnique::clearParameterList(QQmlListProperty<QParameter> *list) -{ - Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); - const auto parameters = technique->parentTechnique()->parameters(); - for (QParameter *p : parameters) - technique->parentTechnique()->removeParameter(p); -} - -void Quick3DTechnique::appendRenderPass(QQmlListProperty<QRenderPass> *list, QRenderPass *renderPass) -{ - Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); - if (technique) { - technique->parentTechnique()->addRenderPass(renderPass); - } -} - -QRenderPass *Quick3DTechnique::renderPassAt(QQmlListProperty<QRenderPass> *list, qsizetype index) -{ - Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); - if (technique) - return qobject_cast<QRenderPass *>(technique->parentTechnique()->renderPasses().at(index)); - return 0; -} - -qsizetype Quick3DTechnique::renderPassCount(QQmlListProperty<QRenderPass> *list) -{ - Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); - if (technique) - return technique->parentTechnique()->renderPasses().size(); - return 0; -} - -void Quick3DTechnique::clearRenderPasses(QQmlListProperty<QRenderPass> *list) -{ - Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); - if (technique) { - const auto passes = technique->parentTechnique()->renderPasses(); - for (QRenderPass *pass : passes) - technique->parentTechnique()->removeRenderPass(pass); - } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = QParameter; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *param) { + Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); + technique->parentTechnique()->addParameter(param); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); + return technique->parentTechnique()->parameters().count(); + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); + return technique->parentTechnique()->parameters().at(index); + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); + const auto parameters = technique->parentTechnique()->parameters(); + for (QParameter *p : parameters) + technique->parentTechnique()->removeParameter(p); + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } QQmlListProperty<QFilterKey> Quick3DTechnique::filterKeyList() { - return QQmlListProperty<QFilterKey>(this, 0, - &Quick3DTechnique::appendFilterKey, - &Quick3DTechnique::filterKeyCount, - &Quick3DTechnique::filterKeyAt, - &Quick3DTechnique::clearFilterKeyList); -} - -void Quick3DTechnique::appendFilterKey(QQmlListProperty<QFilterKey> *list, QFilterKey *filterKey) -{ - Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); - if (technique) { - if (!filterKey->parent()) - filterKey->setParent(technique->parentTechnique()); - technique->parentTechnique()->addFilterKey(filterKey); - } -} - -QFilterKey *Quick3DTechnique::filterKeyAt(QQmlListProperty<QFilterKey> *list, qsizetype index) -{ - Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); - if (technique) - return technique->parentTechnique()->filterKeys().at(index); - return 0; -} - -qsizetype Quick3DTechnique::filterKeyCount(QQmlListProperty<QFilterKey> *list) -{ - Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); - if (technique) - return technique->parentTechnique()->filterKeys().size(); - return 0; -} - -void Quick3DTechnique::clearFilterKeyList(QQmlListProperty<QFilterKey> *list) -{ - Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); - if (technique) { - const auto keys = technique->parentTechnique()->filterKeys(); - for (QFilterKey *a : keys) - technique->parentTechnique()->removeFilterKey(a); - } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = QFilterKey; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *filterKey) { + Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); + if (technique) { + if (!filterKey->parent()) + filterKey->setParent(technique->parentTechnique()); + technique->parentTechnique()->addFilterKey(filterKey); + } + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); + if (technique) + return technique->parentTechnique()->filterKeys().size(); + return 0; + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); + if (technique) + return technique->parentTechnique()->filterKeys().at(index); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); + if (technique) { + const auto keys = technique->parentTechnique()->filterKeys(); + for (QFilterKey *a : keys) + technique->parentTechnique()->removeFilterKey(a); + } + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3dtechnique_p.h b/src/quick3d/quick3drender/items/quick3dtechnique_p.h index 425eb0b25..e8b2fbc0b 100644 --- a/src/quick3d/quick3drender/items/quick3dtechnique_p.h +++ b/src/quick3d/quick3drender/items/quick3dtechnique_p.h @@ -77,23 +77,6 @@ public: // Use QAbstractTechnique when it has been properly defined inline QTechnique *parentTechnique() const { return qobject_cast<QTechnique*>(parent()); } - -private: - - static void appendParameter(QQmlListProperty<QParameter> *list, QParameter *param); - static QParameter *parameterAt(QQmlListProperty<QParameter> *list, qsizetype index); - static qsizetype parametersCount(QQmlListProperty<QParameter> *list); - static void clearParameterList(QQmlListProperty<QParameter> *list); - - static void appendFilterKey(QQmlListProperty<QFilterKey> *list, QFilterKey *filterKey); - static QFilterKey *filterKeyAt(QQmlListProperty<QFilterKey> *list, qsizetype index); - static qsizetype filterKeyCount(QQmlListProperty<QFilterKey> *list); - static void clearFilterKeyList(QQmlListProperty<QFilterKey> *list); - - static void appendRenderPass(QQmlListProperty<QRenderPass> *list, QRenderPass* renderPass); - static QRenderPass *renderPassAt(QQmlListProperty<QRenderPass> *list, qsizetype index); - static qsizetype renderPassCount(QQmlListProperty<QRenderPass> *list); - static void clearRenderPasses( QQmlListProperty<QRenderPass> *list); }; } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3dtechniquefilter.cpp b/src/quick3d/quick3drender/items/quick3dtechniquefilter.cpp index 01e114fab..0de7fe5ba 100644 --- a/src/quick3d/quick3drender/items/quick3dtechniquefilter.cpp +++ b/src/quick3d/quick3drender/items/quick3dtechniquefilter.cpp @@ -52,81 +52,73 @@ Quick3DTechniqueFilter::Quick3DTechniqueFilter(QObject *parent) QQmlListProperty<QFilterKey> Quick3DTechniqueFilter::matchList() { - return QQmlListProperty<QFilterKey>(this, 0, - &Quick3DTechniqueFilter::appendRequire, - &Quick3DTechniqueFilter::requiresCount, - &Quick3DTechniqueFilter::requireAt, - &Quick3DTechniqueFilter::clearRequires); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = QFilterKey; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *criterion) { + Quick3DTechniqueFilter *filter = qobject_cast<Quick3DTechniqueFilter *>(list->object); + if (filter) { + criterion->setParent(filter->parentTechniqueFilter()); + filter->parentTechniqueFilter()->addMatch(criterion); + } + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DTechniqueFilter *filter = qobject_cast<Quick3DTechniqueFilter *>(list->object); + if (filter) + return filter->parentTechniqueFilter()->matchAll().size(); + return 0; + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DTechniqueFilter *filter = qobject_cast<Quick3DTechniqueFilter *>(list->object); + if (filter) + return filter->parentTechniqueFilter()->matchAll().at(index); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DTechniqueFilter *filter = qobject_cast<Quick3DTechniqueFilter *>(list->object); + if (filter) { + const auto criteria = filter->parentTechniqueFilter()->matchAll(); + for (QFilterKey *criterion : criteria) + filter->parentTechniqueFilter()->removeMatch(criterion); + } + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } QQmlListProperty<QParameter> Quick3DTechniqueFilter::parameterList() { - return QQmlListProperty<QParameter>(this, 0, - &Quick3DTechniqueFilter::appendParameter, - &Quick3DTechniqueFilter::parametersCount, - &Quick3DTechniqueFilter::parameterAt, - &Quick3DTechniqueFilter::clearParameterList); -} - -void Quick3DTechniqueFilter::appendRequire(QQmlListProperty<QFilterKey> *list, QFilterKey *criterion) -{ - Quick3DTechniqueFilter *filter = qobject_cast<Quick3DTechniqueFilter *>(list->object); - if (filter) { - criterion->setParent(filter->parentTechniqueFilter()); - filter->parentTechniqueFilter()->addMatch(criterion); - } -} - -QFilterKey *Quick3DTechniqueFilter::requireAt(QQmlListProperty<QFilterKey> *list, qsizetype index) -{ - Quick3DTechniqueFilter *filter = qobject_cast<Quick3DTechniqueFilter *>(list->object); - if (filter) - return filter->parentTechniqueFilter()->matchAll().at(index); - return 0; -} - -qsizetype Quick3DTechniqueFilter::requiresCount(QQmlListProperty<QFilterKey> *list) -{ - Quick3DTechniqueFilter *filter = qobject_cast<Quick3DTechniqueFilter *>(list->object); - if (filter) - return filter->parentTechniqueFilter()->matchAll().size(); - return 0; -} - -void Quick3DTechniqueFilter::clearRequires(QQmlListProperty<QFilterKey> *list) -{ - Quick3DTechniqueFilter *filter = qobject_cast<Quick3DTechniqueFilter *>(list->object); - if (filter) { - const auto criteria = filter->parentTechniqueFilter()->matchAll(); - for (QFilterKey *criterion : criteria) - filter->parentTechniqueFilter()->removeMatch(criterion); - } -} - -void Quick3DTechniqueFilter::appendParameter(QQmlListProperty<QParameter> *list, QParameter *param) -{ - Quick3DTechniqueFilter *techniqueFilter = qobject_cast<Quick3DTechniqueFilter *>(list->object); - techniqueFilter->parentTechniqueFilter()->addParameter(param); -} - -QParameter *Quick3DTechniqueFilter::parameterAt(QQmlListProperty<QParameter> *list, qsizetype index) -{ - Quick3DTechniqueFilter *techniqueFilter = qobject_cast<Quick3DTechniqueFilter *>(list->object); - return techniqueFilter->parentTechniqueFilter()->parameters().at(index); -} - -qsizetype Quick3DTechniqueFilter::parametersCount(QQmlListProperty<QParameter> *list) -{ - Quick3DTechniqueFilter *techniqueFilter = qobject_cast<Quick3DTechniqueFilter *>(list->object); - return techniqueFilter->parentTechniqueFilter()->parameters().count(); -} - -void Quick3DTechniqueFilter::clearParameterList(QQmlListProperty<QParameter> *list) -{ - Quick3DTechniqueFilter *techniqueFilter = qobject_cast<Quick3DTechniqueFilter *>(list->object); - const auto parameters = techniqueFilter->parentTechniqueFilter()->parameters(); - for (QParameter *p : parameters) - techniqueFilter->parentTechniqueFilter()->removeParameter(p); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = QParameter; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *param) { + Quick3DTechniqueFilter *techniqueFilter = qobject_cast<Quick3DTechniqueFilter *>(list->object); + techniqueFilter->parentTechniqueFilter()->addParameter(param); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DTechniqueFilter *techniqueFilter = qobject_cast<Quick3DTechniqueFilter *>(list->object); + return techniqueFilter->parentTechniqueFilter()->parameters().count(); + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DTechniqueFilter *techniqueFilter = qobject_cast<Quick3DTechniqueFilter *>(list->object); + return techniqueFilter->parentTechniqueFilter()->parameters().at(index); + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DTechniqueFilter *techniqueFilter = qobject_cast<Quick3DTechniqueFilter *>(list->object); + const auto parameters = techniqueFilter->parentTechniqueFilter()->parameters(); + for (QParameter *p : parameters) + techniqueFilter->parentTechniqueFilter()->removeParameter(p); + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3dtechniquefilter_p.h b/src/quick3d/quick3drender/items/quick3dtechniquefilter_p.h index 9a2b396ac..22900d175 100644 --- a/src/quick3d/quick3drender/items/quick3dtechniquefilter_p.h +++ b/src/quick3d/quick3drender/items/quick3dtechniquefilter_p.h @@ -77,17 +77,6 @@ public: QQmlListProperty<QParameter> parameterList(); inline QTechniqueFilter *parentTechniqueFilter() const { return qobject_cast<QTechniqueFilter*>(parent()); } - -private: - static void appendRequire(QQmlListProperty<QFilterKey> *list, QFilterKey *criterion); - static QFilterKey *requireAt(QQmlListProperty<QFilterKey> *list, qsizetype index); - static qsizetype requiresCount(QQmlListProperty<QFilterKey> *list); - static void clearRequires(QQmlListProperty<QFilterKey> *list); - - static void appendParameter(QQmlListProperty<QParameter> *list, QParameter *param); - static QParameter *parameterAt(QQmlListProperty<QParameter> *list, qsizetype index); - static qsizetype parametersCount(QQmlListProperty<QParameter> *list); - static void clearParameterList(QQmlListProperty<QParameter> *list); }; } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3dtexture.cpp b/src/quick3d/quick3drender/items/quick3dtexture.cpp index 01f36542d..8e1deed1c 100644 --- a/src/quick3d/quick3drender/items/quick3dtexture.cpp +++ b/src/quick3d/quick3drender/items/quick3dtexture.cpp @@ -54,43 +54,39 @@ Quick3DTextureExtension::Quick3DTextureExtension(QObject *parent) QQmlListProperty<QAbstractTextureImage> Quick3DTextureExtension::textureImages() { - return QQmlListProperty<QAbstractTextureImage>(this, 0, - &Quick3DTextureExtension::appendTextureImage, - &Quick3DTextureExtension::textureImageCount, - &Quick3DTextureExtension::textureImageAt, - &Quick3DTextureExtension::clearTextureImageList); -} - -void Quick3DTextureExtension::appendTextureImage(QQmlListProperty<QAbstractTextureImage> *list, QAbstractTextureImage *textureImage) -{ - Quick3DTextureExtension *self = qobject_cast<Quick3DTextureExtension *>(list->object); - if (self) - self->parentTexture()->addTextureImage(textureImage); -} - -QAbstractTextureImage *Quick3DTextureExtension::textureImageAt(QQmlListProperty<QAbstractTextureImage> *list, qsizetype index) -{ - Quick3DTextureExtension *self = qobject_cast<Quick3DTextureExtension *>(list->object); - if (self) - return self->parentTexture()->textureImages().at(index); - return nullptr; -} +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif -qsizetype Quick3DTextureExtension::textureImageCount(QQmlListProperty<QAbstractTextureImage> *list) -{ - Quick3DTextureExtension *self = qobject_cast<Quick3DTextureExtension *>(list->object); - if (self) - return self->parentTexture()->textureImages().count(); - return 0; -} + using ListContentType = QAbstractTextureImage; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *textureImage) { + Quick3DTextureExtension *self = qobject_cast<Quick3DTextureExtension *>(list->object); + if (self) + self->parentTexture()->addTextureImage(textureImage); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DTextureExtension *self = qobject_cast<Quick3DTextureExtension *>(list->object); + if (self) + return self->parentTexture()->textureImages().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DTextureExtension *self = qobject_cast<Quick3DTextureExtension *>(list->object); + if (self) + return self->parentTexture()->textureImages().at(index); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + if (Quick3DTextureExtension *self = qobject_cast<Quick3DTextureExtension *>(list->object)) { + const auto images = self->parentTexture()->textureImages(); + for (QAbstractTextureImage *img : images) + self->parentTexture()->removeTextureImage(img); + } + }; -void Quick3DTextureExtension::clearTextureImageList(QQmlListProperty<QAbstractTextureImage> *list) -{ - if (Quick3DTextureExtension *self = qobject_cast<Quick3DTextureExtension *>(list->object)) { - const auto images = self->parentTexture()->textureImages(); - for (QAbstractTextureImage *img : images) - self->parentTexture()->removeTextureImage(img); - } + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3dtexture_p.h b/src/quick3d/quick3drender/items/quick3dtexture_p.h index 2f22d404e..a401a6932 100644 --- a/src/quick3d/quick3drender/items/quick3dtexture_p.h +++ b/src/quick3d/quick3drender/items/quick3dtexture_p.h @@ -70,16 +70,10 @@ class Q_3DQUICKRENDERSHARED_PRIVATE_EXPORT Quick3DTextureExtension : public QObj Q_CLASSINFO("DefaultProperty", "textureImages") public: - explicit Quick3DTextureExtension(QObject *parent = 0); + explicit Quick3DTextureExtension(QObject *parent = nullptr); QQmlListProperty<QAbstractTextureImage> textureImages(); inline QAbstractTexture *parentTexture() const { return qobject_cast<QAbstractTexture *>(parent()); } - -private: - static void appendTextureImage(QQmlListProperty<QAbstractTextureImage> *list, QAbstractTextureImage *textureImage); - static QAbstractTextureImage *textureImageAt(QQmlListProperty<QAbstractTextureImage> *list, qsizetype index); - static qsizetype textureImageCount(QQmlListProperty<QAbstractTextureImage> *list); - static void clearTextureImageList(QQmlListProperty<QAbstractTextureImage> *list); }; } // namespace Quick diff --git a/src/quick3d/quick3dscene2d/items/qt3dquick3dscene2d.cpp b/src/quick3d/quick3dscene2d/items/qt3dquick3dscene2d.cpp index a1b8c96de..c80a9ea2e 100644 --- a/src/quick3d/quick3dscene2d/items/qt3dquick3dscene2d.cpp +++ b/src/quick3d/quick3dscene2d/items/qt3dquick3dscene2d.cpp @@ -50,47 +50,42 @@ QQuick3DScene2D::QQuick3DScene2D(QObject *parent) QQmlListProperty<Qt3DCore::QEntity> QQuick3DScene2D::entities() { - return QQmlListProperty<Qt3DCore::QEntity>(this, 0, - &QQuick3DScene2D::appendEntity, - &QQuick3DScene2D::entityCount, - &QQuick3DScene2D::entityAt, - &QQuick3DScene2D::clearEntities); -} - -void QQuick3DScene2D::appendEntity(QQmlListProperty<Qt3DCore::QEntity> *list, - Qt3DCore::QEntity *entity) -{ - QQuick3DScene2D *scene2d = qobject_cast<QQuick3DScene2D *>(list->object); - if (scene2d) - scene2d->parentScene2D()->addEntity(entity); -} - -qsizetype QQuick3DScene2D::entityCount(QQmlListProperty<Qt3DCore::QEntity> *list) -{ - QQuick3DScene2D *scene2d = qobject_cast<QQuick3DScene2D *>(list->object); - if (scene2d) - return scene2d->parentScene2D()->entities().count(); - return 0; -} +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif -Qt3DCore::QEntity *QQuick3DScene2D::entityAt(QQmlListProperty<Qt3DCore::QEntity> *list, qsizetype index) -{ - QQuick3DScene2D *scene2d = qobject_cast<QQuick3DScene2D *>(list->object); - if (scene2d) { - return qobject_cast<Qt3DCore::QEntity *>( - scene2d->parentScene2D()->entities().at(index)); - } - return nullptr; -} + using ListContentType = Qt3DCore::QEntity; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *entity) { + QQuick3DScene2D *scene2d = qobject_cast<QQuick3DScene2D *>(list->object); + if (scene2d) + scene2d->parentScene2D()->addEntity(entity); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + QQuick3DScene2D *scene2d = qobject_cast<QQuick3DScene2D *>(list->object); + if (scene2d) + return scene2d->parentScene2D()->entities().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + QQuick3DScene2D *scene2d = qobject_cast<QQuick3DScene2D *>(list->object); + if (scene2d) { + return qobject_cast<Qt3DCore::QEntity *>( + scene2d->parentScene2D()->entities().at(index)); + } + return nullptr; + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + QQuick3DScene2D *scene2d = qobject_cast<QQuick3DScene2D *>(list->object); + if (scene2d) { + QList<Qt3DCore::QEntity*> entities = scene2d->parentScene2D()->entities(); + for (Qt3DCore::QEntity *e : entities) + scene2d->parentScene2D()->removeEntity(e); + } + }; -void QQuick3DScene2D::clearEntities(QQmlListProperty<Qt3DCore::QEntity> *list) -{ - QQuick3DScene2D *scene2d = qobject_cast<QQuick3DScene2D *>(list->object); - if (scene2d) { - QList<Qt3DCore::QEntity*> entities = scene2d->parentScene2D()->entities(); - for (Qt3DCore::QEntity *e : entities) - scene2d->parentScene2D()->removeEntity(e); - } + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } } // namespace Quick diff --git a/src/quick3d/quick3dscene2d/items/qt3dquick3dscene2d_p.h b/src/quick3d/quick3dscene2d/items/qt3dquick3dscene2d_p.h index 26887cd3a..e5f627eaf 100644 --- a/src/quick3d/quick3dscene2d/items/qt3dquick3dscene2d_p.h +++ b/src/quick3d/quick3dscene2d/items/qt3dquick3dscene2d_p.h @@ -74,13 +74,6 @@ public: } QQmlListProperty<Qt3DCore::QEntity> entities(); - -private: - - static void appendEntity(QQmlListProperty<Qt3DCore::QEntity> *list, Qt3DCore::QEntity *entity); - static Qt3DCore::QEntity *entityAt(QQmlListProperty<Qt3DCore::QEntity> *list, qsizetype index); - static qsizetype entityCount(QQmlListProperty<Qt3DCore::QEntity> *list); - static void clearEntities(QQmlListProperty<Qt3DCore::QEntity> *list); }; } // namespace Quick |