From d2fe37b3480cc55cf301426d7fa40475080cc6f9 Mon Sep 17 00:00:00 2001 From: Mike Krus Date: Mon, 23 Nov 2020 09:06:01 +0000 Subject: Update QQMLPropertyList API Use lambdas with local typedefs for index type Change-Id: I2876c71d619815e7e777f936e8bb0835b8269336 Reviewed-by: Paul Lemire --- src/quick3d/quick3d/items/quick3dentity.cpp | 63 +++---- src/quick3d/quick3d/items/quick3dentity_p.h | 8 +- src/quick3d/quick3d/items/quick3dgeometry.cpp | 56 +++--- src/quick3d/quick3d/items/quick3dgeometry_p.h | 5 - src/quick3d/quick3d/items/quick3djoint.cpp | 54 +++--- src/quick3d/quick3d/items/quick3djoint_p.h | 6 - src/quick3d/quick3d/items/quick3dnode.cpp | 130 ++++++------- src/quick3d/quick3d/items/quick3dnode_p.h | 11 -- .../items/quick3danimationcontroller.cpp | 65 +++---- .../items/quick3danimationcontroller_p.h | 7 - .../items/quick3danimationgroup.cpp | 71 ++++--- .../items/quick3danimationgroup_p.h | 7 - .../items/quick3dchannelmapper.cpp | 54 +++--- .../items/quick3dchannelmapper_p.h | 6 - .../items/quick3dkeyframeanimation.cpp | 72 ++++--- .../items/quick3dkeyframeanimation_p.h | 9 - .../items/quick3dmorphinganimation.cpp | 70 +++---- .../items/quick3dmorphinganimation_p.h | 9 - .../quick3danimation/items/quick3dmorphtarget.cpp | 66 +++---- .../quick3danimation/items/quick3dmorphtarget_p.h | 7 - .../items/quick3dvertexblendanimation.cpp | 75 ++++---- .../items/quick3dvertexblendanimation_p.h | 9 - .../quick3dextras/items/quick3dspritesheet.cpp | 56 +++--- .../quick3dextras/items/quick3dspritesheet_p.h | 6 - src/quick3d/quick3dinput/items/quick3daction.cpp | 53 +++--- src/quick3d/quick3dinput/items/quick3daction_p.h | 6 - src/quick3d/quick3dinput/items/quick3daxis.cpp | 54 +++--- src/quick3d/quick3dinput/items/quick3daxis_p.h | 6 - .../quick3dinput/items/quick3dinputchord.cpp | 54 +++--- .../quick3dinput/items/quick3dinputchord_p.h | 6 - .../quick3dinput/items/quick3dinputsequence.cpp | 54 +++--- .../quick3dinput/items/quick3dinputsequence_p.h | 6 - .../quick3dinput/items/quick3dlogicaldevice.cpp | 116 ++++++------ .../quick3dinput/items/quick3dlogicaldevice_p.h | 11 -- .../quick3dinput/items/quick3dphysicaldevice.cpp | 54 +++--- .../quick3dinput/items/quick3dphysicaldevice_p.h | 6 - src/quick3d/quick3drender/items/quick3deffect.cpp | 136 +++++++------- src/quick3d/quick3drender/items/quick3deffect_p.h | 11 -- .../quick3drender/items/quick3dlayerfilter.cpp | 76 ++++---- .../quick3drender/items/quick3dlayerfilter_p.h | 8 +- .../quick3drender/items/quick3dmaterial.cpp | 76 ++++---- .../quick3drender/items/quick3dmaterial_p.h | 10 +- .../quick3drender/items/quick3draycaster.cpp | 72 ++++--- .../quick3drender/items/quick3draycaster_p_p.h | 5 - .../quick3drender/items/quick3drenderpass.cpp | 175 ++++++++--------- .../quick3drender/items/quick3drenderpass_p.h | 16 -- .../items/quick3drenderpassfilter.cpp | 141 +++++++------- .../items/quick3drenderpassfilter_p.h | 11 -- .../items/quick3drendertargetoutput.cpp | 68 ++++--- .../items/quick3drendertargetoutput_p.h | 8 +- .../quick3drender/items/quick3dscreenraycaster.cpp | 39 +++- .../quick3drender/items/quick3dshaderdataarray.cpp | 54 +++--- .../quick3drender/items/quick3dshaderdataarray_p.h | 6 +- .../quick3drender/items/quick3dstateset.cpp | 55 +++--- .../quick3drender/items/quick3dstateset_p.h | 8 +- .../quick3drender/items/quick3dtechnique.cpp | 209 ++++++++++----------- .../quick3drender/items/quick3dtechnique_p.h | 17 -- .../quick3drender/items/quick3dtechniquefilter.cpp | 134 +++++++------ .../quick3drender/items/quick3dtechniquefilter_p.h | 11 -- src/quick3d/quick3drender/items/quick3dtexture.cpp | 66 +++---- src/quick3d/quick3drender/items/quick3dtexture_p.h | 8 +- .../quick3dscene2d/items/qt3dquick3dscene2d.cpp | 73 ++++--- .../quick3dscene2d/items/qt3dquick3dscene2d_p.h | 7 - 63 files changed, 1226 insertions(+), 1622 deletions(-) (limited to 'src') 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 Quick3DEntity::componentList() { - return QQmlListProperty(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 *list, ListContentType *comp) { + if (comp == nullptr) + return; + Quick3DEntity *self = static_cast(list->object); + self->m_managedComponents.push_back(comp); + self->parentEntity()->addComponent(comp); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + Quick3DEntity *self = static_cast(list->object); + return self->parentEntity()->components().count(); + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + Quick3DEntity *self = static_cast(list->object); + return self->parentEntity()->components().at(index); + }; + auto clearFunction = [](QQmlListProperty *list) { + Quick3DEntity *self = static_cast(list->object); + for (QComponent *comp : qAsConst(self->m_managedComponents)) + self->parentEntity()->removeComponent(comp); + self->m_managedComponents.clear(); + }; + + return QQmlListProperty(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } -void Quick3DEntity::qmlAppendComponent(QQmlListProperty *list, QComponent *comp) -{ - if (comp == nullptr) - return; - Quick3DEntity *self = static_cast(list->object); - self->m_managedComponents.push_back(comp); - self->parentEntity()->addComponent(comp); -} - -QComponent *Quick3DEntity::qmlComponentAt(QQmlListProperty *list, qsizetype index) -{ - Quick3DEntity *self = static_cast(list->object); - return self->parentEntity()->components().at(index); -} - -qsizetype Quick3DEntity::qmlComponentsCount(QQmlListProperty *list) -{ - Quick3DEntity *self = static_cast(list->object); - return self->parentEntity()->components().count(); -} - -void Quick3DEntity::qmlClearComponents(QQmlListProperty *list) -{ - Quick3DEntity *self = static_cast(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 components READ componentList) public: - explicit Quick3DEntity(QObject *parent = 0); + explicit Quick3DEntity(QObject *parent = nullptr); QQmlListProperty componentList(); inline QEntity *parentEntity() const { return qobject_cast(parent()); } private: - - static void qmlAppendComponent(QQmlListProperty *list, Qt3DCore::QComponent *comp); - static QComponent *qmlComponentAt(QQmlListProperty *list, qsizetype index); - static qsizetype qmlComponentsCount(QQmlListProperty *list); - static void qmlClearComponents(QQmlListProperty *list); - QList 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 Quick3DGeometry::attributeList() { - return QQmlListProperty(this, nullptr, - &Quick3DGeometry::appendAttribute, - &Quick3DGeometry::attributesCount, - &Quick3DGeometry::attributeAt, - &Quick3DGeometry::clearAttributes); -} - -void Quick3DGeometry::appendAttribute(QQmlListProperty *list, Qt3DCore::QAttribute *attribute) -{ - Quick3DGeometry *geometry = static_cast(list->object); - geometry->m_managedAttributes.append(attribute); - geometry->parentGeometry()->addAttribute(attribute); -} - -Qt3DCore::QAttribute *Quick3DGeometry::attributeAt(QQmlListProperty *list, qsizetype index) -{ - Quick3DGeometry *geometry = static_cast(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 *list) -{ - Quick3DGeometry *geometry = static_cast(list->object); - return geometry->parentGeometry()->attributes().count(); -} + using ListContentType = Qt3DCore::QAttribute; + auto appendFunction = [](QQmlListProperty *list, ListContentType *attribute) { + Quick3DGeometry *geometry = static_cast(list->object); + geometry->m_managedAttributes.append(attribute); + geometry->parentGeometry()->addAttribute(attribute); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + Quick3DGeometry *geometry = static_cast(list->object); + return geometry->parentGeometry()->attributes().count(); + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + Quick3DGeometry *geometry = static_cast(list->object); + return geometry->parentGeometry()->attributes().at(index); + }; + auto clearFunction = [](QQmlListProperty *list) { + Quick3DGeometry *geometry = static_cast(list->object); + for (Qt3DCore::QAttribute *attribute : qAsConst(geometry->m_managedAttributes)) + geometry->parentGeometry()->removeAttribute(attribute); + geometry->m_managedAttributes.clear(); + }; -void Quick3DGeometry::clearAttributes(QQmlListProperty *list) -{ - Quick3DGeometry *geometry = static_cast(list->object); - for (Qt3DCore::QAttribute *attribute : qAsConst(geometry->m_managedAttributes)) - geometry->parentGeometry()->removeAttribute(attribute); - geometry->m_managedAttributes.clear(); + return QQmlListProperty(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 attributeList(); private: - static void appendAttribute(QQmlListProperty *list, Qt3DCore::QAttribute *provider); - static Qt3DCore::QAttribute *attributeAt(QQmlListProperty *list, qsizetype index); - static qsizetype attributesCount(QQmlListProperty *list); - static void clearAttributes(QQmlListProperty *list); - QList 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 Quick3DJoint::childJoints() { - return QQmlListProperty(this, 0, - Quick3DJoint::appendJoint, - Quick3DJoint::jointCount, - Quick3DJoint::jointAt, - Quick3DJoint::clearJoints); -} - -void Quick3DJoint::appendJoint(QQmlListProperty *list, QJoint *joint) -{ - Quick3DJoint *jointExtension = qobject_cast(list->object); - jointExtension->parentJoint()->addChildJoint(joint); -} - -QJoint *Quick3DJoint::jointAt(QQmlListProperty *list, qsizetype index) -{ - Quick3DJoint *jointExtension = qobject_cast(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 *list) -{ - Quick3DJoint *jointExtension = qobject_cast(list->object); - return jointExtension->parentJoint()->childJoints().count(); -} + using ListContentType = QJoint; + auto appendFunction = [](QQmlListProperty *list, ListContentType *joint) { + Quick3DJoint *jointExtension = qobject_cast(list->object); + jointExtension->parentJoint()->addChildJoint(joint); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + Quick3DJoint *jointExtension = qobject_cast(list->object); + return jointExtension->parentJoint()->childJoints().count(); + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + Quick3DJoint *jointExtension = qobject_cast(list->object); + return jointExtension->parentJoint()->childJoints().at(index); + }; + auto clearFunction = [](QQmlListProperty *list) { + Quick3DJoint *jointExtension = qobject_cast(list->object); + const auto joints = jointExtension->parentJoint()->childJoints(); + for (QJoint *joint : joints) + jointExtension->parentJoint()->removeChildJoint(joint); + }; -void Quick3DJoint::clearJoints(QQmlListProperty *list) -{ - Quick3DJoint *jointExtension = qobject_cast(list->object); - const auto joints = jointExtension->parentJoint()->childJoints(); - for (QJoint *joint : joints) - jointExtension->parentJoint()->removeChildJoint(joint); + return QQmlListProperty(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 childJoints(); inline QJoint *parentJoint() const { return qobject_cast(parent()); } - -private: - static void appendJoint(QQmlListProperty *list, Qt3DCore::QJoint *obj); - static QJoint *jointAt(QQmlListProperty *list, qsizetype index); - static qsizetype jointCount(QQmlListProperty *list); - static void clearJoints(QQmlListProperty *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 Quick3DNode::data() { - return QQmlListProperty(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 *list, ListContentType *obj) { + if (!obj) + return; + + Quick3DNode *self = static_cast(list->object); + self->childAppended(0, obj); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + Quick3DNode *self = static_cast(list->object); + return self->parentNode()->children().count(); + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + Quick3DNode *self = static_cast(list->object); + return self->parentNode()->children().at(index); + }; + auto clearFunction = [](QQmlListProperty *list) { + Quick3DNode *self = static_cast(list->object); + for (QObject *const child : self->parentNode()->children()) + self->childRemoved(0, child); + }; + + return QQmlListProperty(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } /*! @@ -81,76 +105,44 @@ QQmlListProperty Quick3DNode::data() QQmlListProperty Quick3DNode::childNodes() { - return QQmlListProperty(this, 0, - Quick3DNode::appendChild, - Quick3DNode::childCount, - Quick3DNode::childAt, - Quick3DNode::clearChildren); -} - -void Quick3DNode::appendData(QQmlListProperty *list, QObject *obj) -{ - if (!obj) - return; - - Quick3DNode *self = static_cast(list->object); - self->childAppended(0, obj); -} - -QObject *Quick3DNode::dataAt(QQmlListProperty *list, qsizetype index) -{ - Quick3DNode *self = static_cast(list->object); - return self->parentNode()->children().at(index); -} - -qsizetype Quick3DNode::dataCount(QQmlListProperty *list) -{ - Quick3DNode *self = static_cast(list->object); - return self->parentNode()->children().count(); -} - -void Quick3DNode::clearData(QQmlListProperty *list) -{ - Quick3DNode *self = static_cast(list->object); - for (QObject *const child : self->parentNode()->children()) - self->childRemoved(0, child); -} - -void Quick3DNode::appendChild(QQmlListProperty *list, Qt3DCore::QNode *obj) -{ - if (!obj) - return; - - Quick3DNode *self = static_cast(list->object); - Q_ASSERT(!self->parentNode()->children().contains(obj)); - - self->childAppended(0, obj); -} - -Qt3DCore::QNode *Quick3DNode::childAt(QQmlListProperty *list, qsizetype index) -{ - Quick3DNode *self = static_cast(list->object); - return qobject_cast(self->parentNode()->children().at(index)); -} - -qsizetype Quick3DNode::childCount(QQmlListProperty *list) -{ - Quick3DNode *self = static_cast(list->object); - return self->parentNode()->children().count(); -} - -void Quick3DNode::clearChildren(QQmlListProperty *list) -{ - Quick3DNode *self = static_cast(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 *list, ListContentType *obj) { + if (!obj) + return; + + Quick3DNode *self = static_cast(list->object); + Q_ASSERT(!self->parentNode()->children().contains(obj)); + + self->childAppended(0, obj); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + Quick3DNode *self = static_cast(list->object); + return self->parentNode()->children().count(); + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + Quick3DNode *self = static_cast(list->object); + return qobject_cast(self->parentNode()->children().at(index)); + }; + auto clearFunction = [](QQmlListProperty *list) { + Quick3DNode *self = static_cast(list->object); + for (QObject *const child : self->parentNode()->children()) + self->childRemoved(0, child); + }; + + return QQmlListProperty(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(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(parent()); } -private: - static void appendData(QQmlListProperty *list, QObject *obj); - static QObject *dataAt(QQmlListProperty *list, qsizetype index); - static qsizetype dataCount(QQmlListProperty *list); - static void clearData(QQmlListProperty *list); - - static void appendChild(QQmlListProperty *list, Qt3DCore::QNode *obj); - static QNode *childAt(QQmlListProperty *list, qsizetype index); - static qsizetype childCount(QQmlListProperty *list); - static void clearChildren(QQmlListProperty *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 QQuick3DAnimationController::animationGroups() { - return QQmlListProperty(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 *list, QAnimationGroup *bar) -{ - QQuick3DAnimationController *controller = qobject_cast(list->object); - if (controller) - controller->parentAnimationController()->addAnimationGroup(bar); -} + using ListContentType = QAnimationGroup; + auto appendFunction = [](QQmlListProperty *list, ListContentType *bar) { + QQuick3DAnimationController *controller = qobject_cast(list->object); + if (controller) + controller->parentAnimationController()->addAnimationGroup(bar); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + QQuick3DAnimationController *controller = qobject_cast(list->object); + if (controller) + return controller->parentAnimationController()->animationGroupList().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + QQuick3DAnimationController *controller = qobject_cast(list->object); + if (controller) + return qobject_cast(controller->parentAnimationController()->getGroup(index)); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty *list) { + QQuick3DAnimationController *controller = qobject_cast(list->object); + if (controller) + controller->parentAnimationController()->setAnimationGroups({}); + }; -qsizetype QQuick3DAnimationController::animationGroupCount(QQmlListProperty *list) -{ - QQuick3DAnimationController *controller = qobject_cast(list->object); - if (controller) - return controller->parentAnimationController()->animationGroupList().count(); - return 0; -} - -QAnimationGroup *QQuick3DAnimationController::animationGroupAt(QQmlListProperty *list, qsizetype index) -{ - QQuick3DAnimationController *controller = qobject_cast(list->object); - if (controller) - return qobject_cast(controller->parentAnimationController()->getGroup(index)); - return nullptr; -} - -void QQuick3DAnimationController::clearAnimationGroups(QQmlListProperty *list) -{ - QQuick3DAnimationController *controller = qobject_cast(list->object); - if (controller) { - QList emptyList; - controller->parentAnimationController()->setAnimationGroups(emptyList); - } + return QQmlListProperty(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 animationGroups(); - -private: - - static void appendAnimationGroup(QQmlListProperty *list, Qt3DAnimation::QAnimationGroup *bar); - static QAnimationGroup *animationGroupAt(QQmlListProperty *list, qsizetype index); - static qsizetype animationGroupCount(QQmlListProperty *list); - static void clearAnimationGroups(QQmlListProperty *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 QQuick3DAnimationGroup::animations() { - return QQmlListProperty(this, 0, - &QQuick3DAnimationGroup::appendAnimation, - &QQuick3DAnimationGroup::animationCount, - &QQuick3DAnimationGroup::animationAt, - &QQuick3DAnimationGroup::clearAnimation); -} - - -void QQuick3DAnimationGroup::appendAnimation(QQmlListProperty *list, - Qt3DAnimation::QAbstractAnimation *animation) -{ - QQuick3DAnimationGroup *animationGroup = qobject_cast(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 *list) -{ - QQuick3DAnimationGroup *animationGroup = qobject_cast(list->object); - if (animationGroup) - return animationGroup->parentAnimationGroup()->animationList().count(); - return 0; -} + using ListContentType = Qt3DAnimation::QAbstractAnimation; + auto appendFunction = [](QQmlListProperty *list, ListContentType *animation) { + QQuick3DAnimationGroup *animationGroup = qobject_cast(list->object); + if (animationGroup) + animationGroup->parentAnimationGroup()->addAnimation(animation); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + QQuick3DAnimationGroup *animationGroup = qobject_cast(list->object); + if (animationGroup) + return animationGroup->parentAnimationGroup()->animationList().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + QQuick3DAnimationGroup *animationGroup = qobject_cast(list->object); + if (animationGroup) { + return qobject_cast( + animationGroup->parentAnimationGroup()->animationList().at(index)); + } + return nullptr; + }; + auto clearFunction = [](QQmlListProperty *list) { + QQuick3DAnimationGroup *animationGroup = qobject_cast(list->object); + if (animationGroup) { + QList emptyList; + animationGroup->parentAnimationGroup()->setAnimations(emptyList); + } + }; -Qt3DAnimation::QAbstractAnimation *QQuick3DAnimationGroup::animationAt(QQmlListProperty *list, qsizetype index) -{ - QQuick3DAnimationGroup *animationGroup = qobject_cast(list->object); - if (animationGroup) { - return qobject_cast( - animationGroup->parentAnimationGroup()->animationList().at(index)); - } - return nullptr; + return QQmlListProperty(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } -void QQuick3DAnimationGroup::clearAnimation(QQmlListProperty *list) -{ - QQuick3DAnimationGroup *animationGroup = qobject_cast(list->object); - if (animationGroup) { - QList 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 animations(); - -private: - - static void appendAnimation(QQmlListProperty *list, Qt3DAnimation::QAbstractAnimation *animation); - static Qt3DAnimation::QAbstractAnimation *animationAt(QQmlListProperty *list, qsizetype index); - static qsizetype animationCount(QQmlListProperty *list); - static void clearAnimation(QQmlListProperty *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 Quick3DChannelMapper::qmlMappings() { - return QQmlListProperty(this, 0, - &Quick3DChannelMapper::appendMapping, - &Quick3DChannelMapper::mappingCount, - &Quick3DChannelMapper::mappingAt, - &Quick3DChannelMapper::clearMappings); -} - -void Quick3DChannelMapper::appendMapping(QQmlListProperty *list, QAbstractChannelMapping *mapping) -{ - Quick3DChannelMapper *extension = qobject_cast(list->object); - extension->parentMapper()->addMapping(mapping); -} - -QAbstractChannelMapping *Quick3DChannelMapper::mappingAt(QQmlListProperty *list, qsizetype index) -{ - Quick3DChannelMapper *extension = qobject_cast(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 *list) -{ - Quick3DChannelMapper *extension = qobject_cast(list->object); - return extension->parentMapper()->mappings().count(); -} + using ListContentType = QAbstractChannelMapping; + auto appendFunction = [](QQmlListProperty *list, ListContentType *mapping) { + Quick3DChannelMapper *extension = qobject_cast(list->object); + extension->parentMapper()->addMapping(mapping); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + Quick3DChannelMapper *extension = qobject_cast(list->object); + return extension->parentMapper()->mappings().size(); + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + Quick3DChannelMapper *extension = qobject_cast(list->object); + return extension->parentMapper()->mappings().at(index); + }; + auto clearFunction = [](QQmlListProperty *list) { + Quick3DChannelMapper *extension = qobject_cast(list->object); + const auto mappings = extension->parentMapper()->mappings(); + for (QAbstractChannelMapping *mapping : mappings) + extension->parentMapper()->removeMapping(mapping); + }; -void Quick3DChannelMapper::clearMappings(QQmlListProperty *list) -{ - Quick3DChannelMapper *extension = qobject_cast(list->object); - const auto mappings = extension->parentMapper()->mappings(); - for (QAbstractChannelMapping *mapping : mappings) - extension->parentMapper()->removeMapping(mapping); + return QQmlListProperty(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(parent()); } QQmlListProperty qmlMappings(); - -private: - static void appendMapping(QQmlListProperty *list, QAbstractChannelMapping *mapping); - static QAbstractChannelMapping *mappingAt(QQmlListProperty *list, qsizetype index); - static qsizetype mappingCount(QQmlListProperty *list); - static void clearMappings(QQmlListProperty *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 QQuick3DKeyframeAnimation::keyframes() { - return QQmlListProperty(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 *list, - Qt3DCore::QTransform *transform) -{ - QQuick3DKeyframeAnimation *keyframeAnimation + using ListContentType = Qt3DCore::QTransform; + auto appendFunction = [](QQmlListProperty *list, ListContentType *transform) { + QQuick3DKeyframeAnimation *keyframeAnimation = qobject_cast(list->object); - if (keyframeAnimation) - keyframeAnimation->parentKeyframeAnimation()->addKeyframe(transform); -} - -qsizetype QQuick3DKeyframeAnimation::keyframeCount(QQmlListProperty *list) -{ - QQuick3DKeyframeAnimation *keyframeAnimation + if (keyframeAnimation) + keyframeAnimation->parentKeyframeAnimation()->addKeyframe(transform); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + QQuick3DKeyframeAnimation *keyframeAnimation = qobject_cast(list->object); - if (keyframeAnimation) - return keyframeAnimation->parentKeyframeAnimation()->keyframeList().count(); - return 0; -} - -Qt3DCore::QTransform *QQuick3DKeyframeAnimation::keyframeAt(QQmlListProperty *list, - qsizetype index) -{ - QQuick3DKeyframeAnimation *keyframeAnimation + if (keyframeAnimation) + return keyframeAnimation->parentKeyframeAnimation()->keyframeList().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + QQuick3DKeyframeAnimation *keyframeAnimation = qobject_cast(list->object); - if (keyframeAnimation) { - return qobject_cast( - keyframeAnimation->parentKeyframeAnimation()->keyframeList().at(index)); - } - return nullptr; -} - -void QQuick3DKeyframeAnimation::clearKeyframes(QQmlListProperty *list) -{ - QQuick3DKeyframeAnimation *keyframeAnimation + if (keyframeAnimation) + return qobject_cast(keyframeAnimation->parentKeyframeAnimation()->keyframeList().at(index)); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty *list) { + QQuick3DKeyframeAnimation *keyframeAnimation = qobject_cast(list->object); - if (keyframeAnimation) { - QList emptyList; - keyframeAnimation->parentKeyframeAnimation()->setKeyframes(emptyList); - } + if (keyframeAnimation) { + QList emptyList; + keyframeAnimation->parentKeyframeAnimation()->setKeyframes(emptyList); + } + }; + + return QQmlListProperty(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 keyframes(); - -private: - - static void appendKeyframe(QQmlListProperty *list, - Qt3DCore::QTransform *transform); - static Qt3DCore::QTransform *keyframeAt(QQmlListProperty *list, - qsizetype index); - static qsizetype keyframeCount(QQmlListProperty *list); - static void clearKeyframes(QQmlListProperty *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 QQuick3DMorphingAnimation::morphTargets() { - return QQmlListProperty(this, 0, - &QQuick3DMorphingAnimation::appendMorphTarget, - &QQuick3DMorphingAnimation::morphTargetCount, - &QQuick3DMorphingAnimation::morphTargetAt, - &QQuick3DMorphingAnimation::clearMorphTargets); -} - -void QQuick3DMorphingAnimation::appendMorphTarget(QQmlListProperty *list, - Qt3DAnimation::QMorphTarget *morphTarget) -{ - QQuick3DMorphingAnimation *animation = qobject_cast(list->object); - if (animation) - animation->parentMorphingAnimation()->addMorphTarget(morphTarget); -} - -qsizetype QQuick3DMorphingAnimation::morphTargetCount(QQmlListProperty *list) -{ - QQuick3DMorphingAnimation *animation = qobject_cast(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 *list, - qsizetype index) -{ - QQuick3DMorphingAnimation *animation = qobject_cast(list->object); - if (animation) { - return qobject_cast( - animation->parentMorphingAnimation()->morphTargetList().at(index)); - } - return nullptr; -} + using ListContentType = Qt3DAnimation::QMorphTarget; + auto appendFunction = [](QQmlListProperty *list, ListContentType *morphTarget) { + QQuick3DMorphingAnimation *animation = qobject_cast(list->object); + if (animation) + animation->parentMorphingAnimation()->addMorphTarget(morphTarget); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + QQuick3DMorphingAnimation *animation = qobject_cast(list->object); + if (animation) + return animation->parentMorphingAnimation()->morphTargetList().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + QQuick3DMorphingAnimation *animation = qobject_cast(list->object); + if (animation) { + return qobject_cast( + animation->parentMorphingAnimation()->morphTargetList().at(index)); + } + return nullptr; + }; + auto clearFunction = [](QQmlListProperty *list) { + QQuick3DMorphingAnimation *animation = qobject_cast(list->object); + if (animation) + animation->parentMorphingAnimation()->setMorphTargets({}); + }; -void QQuick3DMorphingAnimation::clearMorphTargets(QQmlListProperty *list) -{ - QQuick3DMorphingAnimation *animation = qobject_cast(list->object); - if (animation) { - QList emptyList; - animation->parentMorphingAnimation()->setMorphTargets(emptyList); - } + return QQmlListProperty(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 morphTargets(); - -private: - - static void appendMorphTarget(QQmlListProperty *list, - Qt3DAnimation::QMorphTarget *morphTarget); - static Qt3DAnimation::QMorphTarget *morphTargetAt(QQmlListProperty *list, - qsizetype index); - static qsizetype morphTargetCount(QQmlListProperty *list); - static void clearMorphTargets(QQmlListProperty *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 QQuick3DMorphTarget::attributes() { - return QQmlListProperty(this, 0, - &QQuick3DMorphTarget::appendAttribute, - &QQuick3DMorphTarget::attributeCount, - &QQuick3DMorphTarget::attributeAt, - &QQuick3DMorphTarget::clearAttributes); -} - -void QQuick3DMorphTarget::appendAttribute(QQmlListProperty *list, Qt3DCore::QAttribute *bar) -{ - QQuick3DMorphTarget *target = qobject_cast(list->object); - if (target) - target->parentMorphTarget()->addAttribute(bar); -} - -qsizetype QQuick3DMorphTarget::attributeCount(QQmlListProperty *list) -{ - QQuick3DMorphTarget *target = qobject_cast(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 *list, qsizetype index) -{ - QQuick3DMorphTarget *target = qobject_cast(list->object); - if (target) - return qobject_cast(target->parentMorphTarget()->attributeList().at(index)); - return nullptr; -} + using ListContentType = Qt3DCore::QAttribute; + auto appendFunction = [](QQmlListProperty *list, ListContentType *bar) { + QQuick3DMorphTarget *target = qobject_cast(list->object); + if (target) + target->parentMorphTarget()->addAttribute(bar); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + QQuick3DMorphTarget *target = qobject_cast(list->object); + if (target) + return target->parentMorphTarget()->attributeList().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + QQuick3DMorphTarget *target = qobject_cast(list->object); + if (target) + return qobject_cast(target->parentMorphTarget()->attributeList().at(index)); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty *list) { + QQuick3DMorphTarget *target = qobject_cast(list->object); + if (target) { + QList emptyList; + target->parentMorphTarget()->setAttributes(emptyList); + } + }; -void QQuick3DMorphTarget::clearAttributes(QQmlListProperty *list) -{ - QQuick3DMorphTarget *target = qobject_cast(list->object); - if (target) { - QList emptyList; - target->parentMorphTarget()->setAttributes(emptyList); - } + return QQmlListProperty(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(parent()); } QQmlListProperty attributes(); - -private: - - static void appendAttribute(QQmlListProperty *list, Qt3DCore::QAttribute *bar); - static Qt3DCore::QAttribute *attributeAt(QQmlListProperty *list, qsizetype index); - static qsizetype attributeCount(QQmlListProperty *list); - static void clearAttributes(QQmlListProperty *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 QQuick3DVertexBlendAnimation::morphTargets() { - return QQmlListProperty(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 *list, - Qt3DAnimation::QMorphTarget *morphTarget) -{ - QQuick3DVertexBlendAnimation *animation + using ListContentType = Qt3DAnimation::QMorphTarget; + auto appendFunction = [](QQmlListProperty *list, ListContentType *morphTarget) { + QQuick3DVertexBlendAnimation *animation = qobject_cast(list->object); - if (animation) - animation->parentVertexBlendAnimation()->addMorphTarget(morphTarget); -} - -qsizetype QQuick3DVertexBlendAnimation::morphTargetCount( - QQmlListProperty *list) -{ - QQuick3DVertexBlendAnimation *animation + if (animation) + animation->parentVertexBlendAnimation()->addMorphTarget(morphTarget); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + QQuick3DVertexBlendAnimation *animation = qobject_cast(list->object); - if (animation) - return animation->parentVertexBlendAnimation()->morphTargetList().count(); - return 0; -} - -Qt3DAnimation::QMorphTarget *QQuick3DVertexBlendAnimation::morphTargetAt( - QQmlListProperty *list, - qsizetype index) -{ - QQuick3DVertexBlendAnimation *animation + if (animation) + return animation->parentVertexBlendAnimation()->morphTargetList().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + QQuick3DVertexBlendAnimation *animation = qobject_cast(list->object); - if (animation) { - return qobject_cast( - animation->parentVertexBlendAnimation()->morphTargetList().at(index)); - } - return nullptr; -} - -void QQuick3DVertexBlendAnimation::clearMorphTargets(QQmlListProperty *list) -{ - QQuick3DVertexBlendAnimation *animation + if (animation) { + return qobject_cast( + animation->parentVertexBlendAnimation()->morphTargetList().at(index)); + } + return nullptr; + }; + auto clearFunction = [](QQmlListProperty *list) { + QQuick3DVertexBlendAnimation *animation = qobject_cast(list->object); - if (animation) { - QList emptyList; - animation->parentVertexBlendAnimation()->setMorphTargets(emptyList); - } + if (animation) + animation->parentVertexBlendAnimation()->setMorphTargets({}); + }; + + return QQmlListProperty(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 morphTargets(); - -private: - - static void appendMorphTarget(QQmlListProperty *list, - Qt3DAnimation::QMorphTarget *morphTarget); - static Qt3DAnimation::QMorphTarget *morphTargetAt(QQmlListProperty *list, - qsizetype index); - static qsizetype morphTargetCount(QQmlListProperty *list); - static void clearMorphTargets(QQmlListProperty *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 Quick3DSpriteSheet::sprites() { - return QQmlListProperty(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 *list, - Qt3DExtras::QSpriteSheetItem *sprite) -{ - Quick3DSpriteSheet *spritesheet = qobject_cast(list->object); - spritesheet->parentSpriteSheet()->addSprite(sprite); -} + using ListContentType = Qt3DExtras::QSpriteSheetItem; + auto appendFunction = [](QQmlListProperty *list, ListContentType *sprite) { + Quick3DSpriteSheet *spritesheet = qobject_cast(list->object); + spritesheet->parentSpriteSheet()->addSprite(sprite); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + Quick3DSpriteSheet *spritesheet = qobject_cast(list->object); + return spritesheet->parentSpriteSheet()->sprites().count(); + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + Quick3DSpriteSheet *spritesheet = qobject_cast(list->object); + return spritesheet->parentSpriteSheet()->sprites().at(index); + }; + auto clearFunction = [](QQmlListProperty *list) { + Quick3DSpriteSheet *spritesheet = qobject_cast(list->object); + const auto sprites = spritesheet->parentSpriteSheet()->sprites(); + for (QSpriteSheetItem *sprite : sprites) + spritesheet->parentSpriteSheet()->removeSprite(sprite); + }; -Qt3DExtras::QSpriteSheetItem *Quick3DSpriteSheet::spriteAt(QQmlListProperty *list, qsizetype index) -{ - Quick3DSpriteSheet *spritesheet = qobject_cast(list->object); - return spritesheet->parentSpriteSheet()->sprites().at(index); -} - -qsizetype Quick3DSpriteSheet::spriteCount(QQmlListProperty *list) -{ - Quick3DSpriteSheet *spritesheet = qobject_cast(list->object); - return spritesheet->parentSpriteSheet()->sprites().count(); -} - -void Quick3DSpriteSheet::clearSprites(QQmlListProperty *list) -{ - Quick3DSpriteSheet *spritesheet = qobject_cast(list->object); - const auto sprites = spritesheet->parentSpriteSheet()->sprites(); - for (QSpriteSheetItem *sprite : sprites) - spritesheet->parentSpriteSheet()->removeSprite(sprite); + return QQmlListProperty(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 sprites(); inline QSpriteSheet *parentSpriteSheet() const { return qobject_cast(parent()); } - -private: - static void appendSprite(QQmlListProperty *list, Qt3DExtras::QSpriteSheetItem *state); - static Qt3DExtras::QSpriteSheetItem *spriteAt(QQmlListProperty *list, qsizetype index); - static qsizetype spriteCount(QQmlListProperty *list); - static void clearSprites(QQmlListProperty *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 Quick3DAction::qmlActionInputs() { - return QQmlListProperty(this, 0, - &Quick3DAction::appendActionInput, - &Quick3DAction::actionInputCount, - &Quick3DAction::actionInputAt, - &Quick3DAction::clearActionInputs); -} - -void Quick3DAction::appendActionInput(QQmlListProperty *list, QAbstractActionInput *input) -{ - Quick3DAction *action = qobject_cast(list->object); - action->parentAction()->addInput(input); -} - -QAbstractActionInput *Quick3DAction::actionInputAt(QQmlListProperty *list, qsizetype index) -{ - Quick3DAction *action = qobject_cast(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 *list) -{ - Quick3DAction *action = qobject_cast(list->object); - return action->parentAction()->inputs().count(); -} + auto appendFunction = [](QQmlListProperty *list, QAbstractActionInput *input) { + Quick3DAction *action = qobject_cast(list->object); + action->parentAction()->addInput(input); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + Quick3DAction *action = qobject_cast(list->object); + return action->parentAction()->inputs().count(); + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> QAbstractActionInput * { + Quick3DAction *action = qobject_cast(list->object); + return action->parentAction()->inputs().at(index); + }; + auto clearFunction = [](QQmlListProperty *list) { + Quick3DAction *action = qobject_cast(list->object); + const auto inputs = action->parentAction()->inputs(); + for (QAbstractActionInput *input : inputs) + action->parentAction()->removeInput(input); + }; -void Quick3DAction::clearActionInputs(QQmlListProperty *list) -{ - Quick3DAction *action = qobject_cast(list->object); - const auto inputs = action->parentAction()->inputs(); - for (QAbstractActionInput *input : inputs) - action->parentAction()->removeInput(input); + return QQmlListProperty(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(parent()); } QQmlListProperty qmlActionInputs(); - -private: - static void appendActionInput(QQmlListProperty *list, QAbstractActionInput *input); - static QAbstractActionInput *actionInputAt(QQmlListProperty *list, qsizetype index); - static qsizetype actionInputCount(QQmlListProperty *list); - static void clearActionInputs(QQmlListProperty *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 Quick3DAxis::qmlAxisInputs() { - return QQmlListProperty(this, 0, - &Quick3DAxis::appendAxisInput, - &Quick3DAxis::axesInputCount, - &Quick3DAxis::axisInputAt, - &Quick3DAxis::clearAxisInputs); -} - -void Quick3DAxis::appendAxisInput(QQmlListProperty *list, QAbstractAxisInput *input) -{ - Quick3DAxis *axis = qobject_cast(list->object); - axis->parentAxis()->addInput(input); -} - -QAbstractAxisInput *Quick3DAxis::axisInputAt(QQmlListProperty *list, qsizetype index) -{ - Quick3DAxis *axis = qobject_cast(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 *list) -{ - Quick3DAxis *axis = qobject_cast(list->object); - return axis->parentAxis()->inputs().count(); -} + using ListContentType = QAbstractAxisInput; + auto appendFunction = [](QQmlListProperty *list, ListContentType *input) { + Quick3DAxis *axis = qobject_cast(list->object); + axis->parentAxis()->addInput(input); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + Quick3DAxis *axis = qobject_cast(list->object); + return axis->parentAxis()->inputs().count(); + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + Quick3DAxis *axis = qobject_cast(list->object); + return axis->parentAxis()->inputs().at(index); + }; + auto clearFunction = [](QQmlListProperty *list) { + Quick3DAxis *axis = qobject_cast(list->object); + const auto inputs = axis->parentAxis()->inputs(); + for (QAbstractAxisInput *input : inputs) + axis->parentAxis()->removeInput(input); + }; -void Quick3DAxis::clearAxisInputs(QQmlListProperty *list) -{ - Quick3DAxis *axis = qobject_cast(list->object); - const auto inputs = axis->parentAxis()->inputs(); - for (QAbstractAxisInput *input : inputs) - axis->parentAxis()->removeInput(input); + return QQmlListProperty(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(parent()); } QQmlListProperty qmlAxisInputs(); - -private: - static void appendAxisInput(QQmlListProperty *list, QAbstractAxisInput *input); - static QAbstractAxisInput *axisInputAt(QQmlListProperty *list, qsizetype index); - static qsizetype axesInputCount(QQmlListProperty *list); - static void clearAxisInputs(QQmlListProperty *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 Quick3DInputChord::qmlActionInputs() { - return QQmlListProperty(this, 0, - &Quick3DInputChord::appendActionInput, - &Quick3DInputChord::actionInputCount, - &Quick3DInputChord::actionInputAt, - &Quick3DInputChord::clearActionInputs); -} - -void Quick3DInputChord::appendActionInput(QQmlListProperty *list, QAbstractActionInput *input) -{ - Quick3DInputChord *action = qobject_cast(list->object); - action->parentChord()->addChord(input); -} - -QAbstractActionInput *Quick3DInputChord::actionInputAt(QQmlListProperty *list, qsizetype index) -{ - Quick3DInputChord *action = qobject_cast(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 *list) -{ - Quick3DInputChord *action = qobject_cast(list->object); - return action->parentChord()->chords().count(); -} + using ListContentType = QAbstractActionInput; + auto appendFunction = [](QQmlListProperty *list, ListContentType *input) { + Quick3DInputChord *action = qobject_cast(list->object); + action->parentChord()->addChord(input); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + Quick3DInputChord *action = qobject_cast(list->object); + return action->parentChord()->chords().count(); + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + Quick3DInputChord *action = qobject_cast(list->object); + return action->parentChord()->chords().at(index); + }; + auto clearFunction = [](QQmlListProperty *list) { + Quick3DInputChord *action = qobject_cast(list->object); + const auto chords = action->parentChord()->chords(); + for (QAbstractActionInput *input : chords) + action->parentChord()->removeChord(input); + }; -void Quick3DInputChord::clearActionInputs(QQmlListProperty *list) -{ - Quick3DInputChord *action = qobject_cast(list->object); - const auto chords = action->parentChord()->chords(); - for (QAbstractActionInput *input : chords) - action->parentChord()->removeChord(input); + return QQmlListProperty(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(parent()); } QQmlListProperty qmlActionInputs(); - -private: - static void appendActionInput(QQmlListProperty *list, QAbstractActionInput *input); - static QAbstractActionInput *actionInputAt(QQmlListProperty *list, qsizetype index); - static qsizetype actionInputCount(QQmlListProperty *list); - static void clearActionInputs(QQmlListProperty *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 Quick3DInputSequence::qmlActionInputs() { - return QQmlListProperty(this, 0, - &Quick3DInputSequence::appendActionInput, - &Quick3DInputSequence::actionInputCount, - &Quick3DInputSequence::actionInputAt, - &Quick3DInputSequence::clearActionInputs); -} - -void Quick3DInputSequence::appendActionInput(QQmlListProperty *list, QAbstractActionInput *input) -{ - Quick3DInputSequence *action = qobject_cast(list->object); - action->parentSequence()->addSequence(input); -} - -QAbstractActionInput *Quick3DInputSequence::actionInputAt(QQmlListProperty *list, qsizetype index) -{ - Quick3DInputSequence *action = qobject_cast(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 *list) -{ - Quick3DInputSequence *action = qobject_cast(list->object); - return action->parentSequence()->sequences().count(); -} + using ListContentType = QAbstractActionInput; + auto appendFunction = [](QQmlListProperty *list, ListContentType *input) { + Quick3DInputSequence *action = qobject_cast(list->object); + action->parentSequence()->addSequence(input); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + Quick3DInputSequence *action = qobject_cast(list->object); + return action->parentSequence()->sequences().count(); + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + Quick3DInputSequence *action = qobject_cast(list->object); + return action->parentSequence()->sequences().at(index); + }; + auto clearFunction = [](QQmlListProperty *list) { + Quick3DInputSequence *action = qobject_cast(list->object); + const auto sequences = action->parentSequence()->sequences(); + for (QAbstractActionInput *input : sequences) + action->parentSequence()->removeSequence(input); + }; -void Quick3DInputSequence::clearActionInputs(QQmlListProperty *list) -{ - Quick3DInputSequence *action = qobject_cast(list->object); - const auto sequences = action->parentSequence()->sequences(); - for (QAbstractActionInput *input : sequences) - action->parentSequence()->removeSequence(input); + return QQmlListProperty(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(parent()); } QQmlListProperty qmlActionInputs(); - -private: - static void appendActionInput(QQmlListProperty *list, QAbstractActionInput *input); - static QAbstractActionInput *actionInputAt(QQmlListProperty *list, qsizetype index); - static qsizetype actionInputCount(QQmlListProperty *list); - static void clearActionInputs(QQmlListProperty *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 Quick3DLogicalDevice::qmlAxes() { - return QQmlListProperty(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 *list, ListContentType *axes) { + Quick3DLogicalDevice *device = qobject_cast(list->object); + device->parentLogicalDevice()->addAxis(axes); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + Quick3DLogicalDevice *device = qobject_cast(list->object); + return device->parentLogicalDevice()->axes().count(); + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + Quick3DLogicalDevice *device = qobject_cast(list->object); + return device->parentLogicalDevice()->axes().at(index); + }; + auto clearFunction = [](QQmlListProperty *list) { + Quick3DLogicalDevice *device = qobject_cast(list->object); + const auto axes = device->parentLogicalDevice()->axes(); + for (QAxis *axis : axes) + device->parentLogicalDevice()->removeAxis(axis); + }; + + return QQmlListProperty(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } QQmlListProperty Quick3DLogicalDevice::qmlActions() { - return QQmlListProperty(this, 0, - &Quick3DLogicalDevice::appendAction, - &Quick3DLogicalDevice::actionCount, - &Quick3DLogicalDevice::actionAt, - &Quick3DLogicalDevice::clearActions); -} - -void Quick3DLogicalDevice::appendAxis(QQmlListProperty *list, QAxis *axes) -{ - Quick3DLogicalDevice *device = qobject_cast(list->object); - device->parentLogicalDevice()->addAxis(axes); -} - -QAxis *Quick3DLogicalDevice::axisAt(QQmlListProperty *list, qsizetype index) -{ - Quick3DLogicalDevice *device = qobject_cast(list->object); - return device->parentLogicalDevice()->axes().at(index); -} - -qsizetype Quick3DLogicalDevice::axesCount(QQmlListProperty *list) -{ - Quick3DLogicalDevice *device = qobject_cast(list->object); - return device->parentLogicalDevice()->axes().count(); -} - -void Quick3DLogicalDevice::clearAxes(QQmlListProperty *list) -{ - Quick3DLogicalDevice *device = qobject_cast(list->object); - const auto axes = device->parentLogicalDevice()->axes(); - for (QAxis *axis : axes) - device->parentLogicalDevice()->removeAxis(axis); -} - -void Quick3DLogicalDevice::appendAction(QQmlListProperty *list, QAction *action) -{ - Quick3DLogicalDevice *device = qobject_cast(list->object); - device->parentLogicalDevice()->addAction(action); -} - -QAction *Quick3DLogicalDevice::actionAt(QQmlListProperty *list, qsizetype index) -{ - Quick3DLogicalDevice *device = qobject_cast(list->object); - return device->parentLogicalDevice()->actions().at(index); -} - -qsizetype Quick3DLogicalDevice::actionCount(QQmlListProperty *list) -{ - Quick3DLogicalDevice *device = qobject_cast(list->object); - return device->parentLogicalDevice()->actions().count(); -} - -void Quick3DLogicalDevice::clearActions(QQmlListProperty *list) -{ - Quick3DLogicalDevice *device = qobject_cast(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 *list, ListContentType *action) { + Quick3DLogicalDevice *device = qobject_cast(list->object); + device->parentLogicalDevice()->addAction(action); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + Quick3DLogicalDevice *device = qobject_cast(list->object); + return device->parentLogicalDevice()->actions().count(); + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + Quick3DLogicalDevice *device = qobject_cast(list->object); + return device->parentLogicalDevice()->actions().at(index); + }; + auto clearFunction = [](QQmlListProperty *list) { + Quick3DLogicalDevice *device = qobject_cast(list->object); + const auto actions = device->parentLogicalDevice()->actions(); + for (QAction *action : actions) + device->parentLogicalDevice()->removeAction(action); + }; + + return QQmlListProperty(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(parent()); } QQmlListProperty qmlAxes(); QQmlListProperty qmlActions(); - -private: - static void appendAxis(QQmlListProperty *list, QAxis *axes); - static QAxis *axisAt(QQmlListProperty *list, qsizetype index); - static qsizetype axesCount(QQmlListProperty *list); - static void clearAxes(QQmlListProperty *list); - - static void appendAction(QQmlListProperty *list, QAction *action); - static QAction *actionAt(QQmlListProperty *list, qsizetype index); - static qsizetype actionCount(QQmlListProperty *list); - static void clearActions(QQmlListProperty *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 Quick3DPhysicalDevice::axisSettings() { - return QQmlListProperty(this, 0, - &Quick3DPhysicalDevice::appendAxisSetting, - &Quick3DPhysicalDevice::axisSettingsCount, - &Quick3DPhysicalDevice::axisSettingAt, - &Quick3DPhysicalDevice::clearAxisSettings); -} - -void Quick3DPhysicalDevice::appendAxisSetting(QQmlListProperty *list, QAxisSetting *axisSetting) -{ - Quick3DPhysicalDevice *device = qobject_cast(list->object); - device->parentPhysicalDevice()->addAxisSetting(axisSetting); -} - -QAxisSetting *Quick3DPhysicalDevice::axisSettingAt(QQmlListProperty *list, qsizetype index) -{ - Quick3DPhysicalDevice *device = qobject_cast(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 *list) -{ - Quick3DPhysicalDevice *device = qobject_cast(list->object); - return device->parentPhysicalDevice()->axisSettings().count(); -} + using ListContentType = QAxisSetting; + auto appendFunction = [](QQmlListProperty *list, ListContentType *axisSetting) { + Quick3DPhysicalDevice *device = qobject_cast(list->object); + device->parentPhysicalDevice()->addAxisSetting(axisSetting); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + Quick3DPhysicalDevice *device = qobject_cast(list->object); + return device->parentPhysicalDevice()->axisSettings().count(); + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + Quick3DPhysicalDevice *device = qobject_cast(list->object); + return device->parentPhysicalDevice()->axisSettings().at(index); + }; + auto clearFunction = [](QQmlListProperty *list) { + Quick3DPhysicalDevice *device = qobject_cast(list->object); + const auto axisSettings = device->parentPhysicalDevice()->axisSettings(); + for (QAxisSetting *axisSetting : axisSettings) + device->parentPhysicalDevice()->removeAxisSetting(axisSetting); + }; -void Quick3DPhysicalDevice::clearAxisSettings(QQmlListProperty *list) -{ - Quick3DPhysicalDevice *device = qobject_cast(list->object); - const auto axisSettings = device->parentPhysicalDevice()->axisSettings(); - for (QAxisSetting *axisSetting : axisSettings) - device->parentPhysicalDevice()->removeAxisSetting(axisSetting); + return QQmlListProperty(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(parent()); } QQmlListProperty axisSettings(); - -private: - static void appendAxisSetting(QQmlListProperty *list, QAxisSetting *axes); - static QAxisSetting *axisSettingAt(QQmlListProperty *list, qsizetype index); - static qsizetype axisSettingsCount(QQmlListProperty *list); - static void clearAxisSettings(QQmlListProperty *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 Quick3DEffect::techniqueList() { - return QQmlListProperty(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 *list, ListContentType *bar) { + Quick3DEffect *eff = qobject_cast(list->object); + if (eff) + eff->parentEffect()->addTechnique(bar); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + Quick3DEffect *eff = qobject_cast(list->object); + if (eff) + return eff->parentEffect()->techniques().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + // TO DO : Return a QAbstractTechnique once properly defined + Quick3DEffect *eff = qobject_cast(list->object); + if (eff) + return qobject_cast(eff->parentEffect()->techniques().at(index)); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty *list) { + Quick3DEffect *eff = qobject_cast(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(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } QQmlListProperty Quick3DEffect::parameterList() { - return QQmlListProperty(this, 0, - &Quick3DEffect::appendParameter, - &Quick3DEffect::parametersCount, - &Quick3DEffect::parameterAt, - &Quick3DEffect::clearParameterList); -} - -void Quick3DEffect::appendTechnique(QQmlListProperty *list, QTechnique *bar) -{ - Quick3DEffect *eff = qobject_cast(list->object); - if (eff) - eff->parentEffect()->addTechnique(bar); -} - -// TO DO : Return a QAbstractTechnique once properly defined -QTechnique *Quick3DEffect::techniqueAt(QQmlListProperty *list, qsizetype index) -{ - Quick3DEffect *eff = qobject_cast(list->object); - if (eff) - return qobject_cast(eff->parentEffect()->techniques().at(index)); - return nullptr; -} - -qsizetype Quick3DEffect::techniqueCount(QQmlListProperty *list) -{ - Quick3DEffect *eff = qobject_cast(list->object); - if (eff) - return eff->parentEffect()->techniques().count(); - return 0; -} - -void Quick3DEffect::clearTechniqueList(QQmlListProperty *list) -{ - Quick3DEffect *eff = qobject_cast(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 *list, QParameter *param) -{ - Quick3DEffect *effect = qobject_cast(list->object); - qobject_cast(effect->parentEffect())->addParameter(param); -} - -QParameter *Quick3DEffect::parameterAt(QQmlListProperty *list, qsizetype index) -{ - Quick3DEffect *effect = qobject_cast(list->object); - return qobject_cast(effect->parentEffect())->parameters().at(index); -} - -qsizetype Quick3DEffect::parametersCount(QQmlListProperty *list) -{ - Quick3DEffect *effect = qobject_cast(list->object); - return qobject_cast(effect->parentEffect())->parameters().count(); -} - -void Quick3DEffect::clearParameterList(QQmlListProperty *list) -{ - Quick3DEffect *effect = qobject_cast(list->object); - const auto parameters = qobject_cast(effect->parentEffect())->parameters(); - for (QParameter *p : parameters) - qobject_cast(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 *list, ListContentType *param) { + Quick3DEffect *effect = qobject_cast(list->object); + qobject_cast(effect->parentEffect())->addParameter(param); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + Quick3DEffect *effect = qobject_cast(list->object); + return qobject_cast(effect->parentEffect())->parameters().count(); + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + Quick3DEffect *effect = qobject_cast(list->object); + return qobject_cast(effect->parentEffect())->parameters().at(index); + }; + auto clearFunction = [](QQmlListProperty *list) { + Quick3DEffect *effect = qobject_cast(list->object); + const auto parameters = qobject_cast(effect->parentEffect())->parameters(); + for (QParameter *p : parameters) + qobject_cast(effect->parentEffect())->removeParameter(p); + }; + + return QQmlListProperty(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 techniqueList(); QQmlListProperty parameterList(); - -private: - static void appendTechnique(QQmlListProperty *list, QTechnique *bar); - static QTechnique *techniqueAt(QQmlListProperty *list, qsizetype index); - static qsizetype techniqueCount(QQmlListProperty *list); - static void clearTechniqueList(QQmlListProperty *list); - - static void appendParameter(QQmlListProperty *list, QParameter *param); - static QParameter *parameterAt(QQmlListProperty *list, qsizetype index); - static qsizetype parametersCount(QQmlListProperty *list); - static void clearParameterList(QQmlListProperty *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 Quick3DLayerFilter::qmlLayers() { - return QQmlListProperty(this, 0, - &Quick3DLayerFilter::appendLayer, - &Quick3DLayerFilter::layerCount, - &Quick3DLayerFilter::layerAt, - &Quick3DLayerFilter::clearLayers); -} - -void Quick3DLayerFilter::appendLayer(QQmlListProperty *list, QLayer *layer) -{ - Quick3DLayerFilter *filter = qobject_cast(list->object); - if (filter) { - filter->parentFilter()->addLayer(layer); - } -} - -QLayer *Quick3DLayerFilter::layerAt(QQmlListProperty *list, qsizetype index) -{ - Quick3DLayerFilter *filter = qobject_cast(list->object); - if (filter) { - return filter->parentFilter()->layers().at(index); - } - return 0; -} - -qsizetype Quick3DLayerFilter::layerCount(QQmlListProperty *list) -{ - Quick3DLayerFilter *filter = qobject_cast(list->object); - if (filter) { - return filter->parentFilter()->layers().count(); - } - return 0; -} - -void Quick3DLayerFilter::clearLayers(QQmlListProperty *list) -{ - Quick3DLayerFilter *filter = qobject_cast(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 *list, ListContentType *layer) { + Quick3DLayerFilter *filter = qobject_cast(list->object); + if (filter) { + filter->parentFilter()->addLayer(layer); + } + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + Quick3DLayerFilter *filter = qobject_cast(list->object); + if (filter) + return filter->parentFilter()->layers().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + Quick3DLayerFilter *filter = qobject_cast(list->object); + if (filter) + return filter->parentFilter()->layers().at(index); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty *list) { + Quick3DLayerFilter *filter = qobject_cast(list->object); + if (filter) { + const auto layers = filter->parentFilter()->layers(); + for (QLayer *layer : layers) + filter->parentFilter()->removeLayer(layer); + } + }; + + return QQmlListProperty(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 layers READ qmlLayers) public: - explicit Quick3DLayerFilter(QObject *parent = 0); + explicit Quick3DLayerFilter(QObject *parent = nullptr); inline QLayerFilter *parentFilter() const { return qobject_cast(parent()); } QQmlListProperty qmlLayers(); - -private: - static void appendLayer(QQmlListProperty *list, QLayer *bar); - static QLayer *layerAt(QQmlListProperty *list, qsizetype index); - static qsizetype layerCount(QQmlListProperty *list); - static void clearLayers(QQmlListProperty *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 Quick3DMaterial::qmlParameters() { - return QQmlListProperty(this, 0, - &Quick3DMaterial::appendParameter, - &Quick3DMaterial::parameterCount, - &Quick3DMaterial::parameterAt, - &Quick3DMaterial::clearParameters); -} - -void Quick3DMaterial::appendParameter(QQmlListProperty *list, QParameter *param) -{ - Quick3DMaterial *mat = qobject_cast(list->object); - if (mat) { - param->setParent(mat->parentMaterial()); - mat->parentMaterial()->addParameter(param); - } -} - -QParameter *Quick3DMaterial::parameterAt(QQmlListProperty *list, qsizetype index) -{ - Quick3DMaterial *mat = qobject_cast(list->object); - if (mat) - return mat->parentMaterial()->parameters().at(index); - return 0; -} - -qsizetype Quick3DMaterial::parameterCount(QQmlListProperty *list) -{ - Quick3DMaterial *mat = qobject_cast(list->object); - if (mat) - return mat->parentMaterial()->parameters().count(); - return 0; -} - -void Quick3DMaterial::clearParameters(QQmlListProperty *list) -{ - Quick3DMaterial *mat = qobject_cast(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 *list, ListContentType *param) { + Quick3DMaterial *mat = qobject_cast(list->object); + if (mat) { + param->setParent(mat->parentMaterial()); + mat->parentMaterial()->addParameter(param); + } + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + Quick3DMaterial *mat = qobject_cast(list->object); + if (mat) + return mat->parentMaterial()->parameters().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + Quick3DMaterial *mat = qobject_cast(list->object); + if (mat) + return mat->parentMaterial()->parameters().at(index); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty *list) { + Quick3DMaterial *mat = qobject_cast(list->object); + if (mat) { + const auto parameters = mat->parentMaterial()->parameters(); + for (QParameter *p : parameters) + mat->parentMaterial()->removeParameter(p); + } + }; + + return QQmlListProperty(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 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(parent()); } QQmlListProperty qmlParameters(); - - -private: - // FIXME - remove when we have a custom QML parser - static void appendParameter(QQmlListProperty *list, QParameter *bar); - static QParameter *parameterAt(QQmlListProperty *list, qsizetype index); - static qsizetype parameterCount(QQmlListProperty *list); - static void clearParameters(QQmlListProperty *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 *list, QLayer *layer) -{ - QAbstractRayCaster *filter = qobject_cast(list->object); - if (filter) - filter->addLayer(layer); -} - -QLayer *Quick3DRayCasterPrivate::layerAt(QQmlListProperty *list, qsizetype index) -{ - QAbstractRayCaster *filter = qobject_cast(list->object); - if (filter) - return filter->layers().at(index); - return nullptr; -} - -qsizetype Quick3DRayCasterPrivate::layerCount(QQmlListProperty *list) -{ - QAbstractRayCaster *filter = qobject_cast(list->object); - if (filter) - return int(filter->layers().size()); - return 0; -} - -void Quick3DRayCasterPrivate::clearLayers(QQmlListProperty *list) -{ - QAbstractRayCaster *filter = qobject_cast(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(parent)) { @@ -89,11 +56,40 @@ Quick3DRayCaster::Quick3DRayCaster(QObject *parent) QQmlListProperty Qt3DRender::Render::Quick::Quick3DRayCaster::qmlLayers() { - return QQmlListProperty(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 *list, ListContentType *layer) { + QAbstractRayCaster *filter = qobject_cast(list->object); + if (filter) + filter->addLayer(layer); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + QAbstractRayCaster *filter = qobject_cast(list->object); + if (filter) + return int(filter->layers().size()); + return 0; + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + QAbstractRayCaster *filter = qobject_cast(list->object); + if (filter) + return filter->layers().at(index); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty *list) { + QAbstractRayCaster *filter = qobject_cast(list->object); + if (filter) { + const auto layers = filter->layers(); + for (QLayer *layer : layers) + filter->removeLayer(layer); + } + }; + + return QQmlListProperty(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 *list, QLayer *bar); - static QLayer *layerAt(QQmlListProperty *list, qsizetype index); - static qsizetype layerCount(QQmlListProperty *list); - static void clearLayers(QQmlListProperty *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 Quick3DRenderPass::filterKeyList() { - return QQmlListProperty(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 *list, ListContentType *filterKey) { + Quick3DRenderPass *rPass = qobject_cast(list->object); + rPass->parentRenderPass()->addFilterKey(filterKey); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + Quick3DRenderPass *rPass = qobject_cast(list->object); + return rPass->parentRenderPass()->filterKeys().count(); + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + Quick3DRenderPass *rPass = qobject_cast(list->object); + return rPass->parentRenderPass()->filterKeys().at(index); + }; + auto clearFunction = [](QQmlListProperty *list) { + Quick3DRenderPass *rPass = qobject_cast(list->object); + const auto keys = rPass->parentRenderPass()->filterKeys(); + for (QFilterKey *c : keys) + rPass->parentRenderPass()->removeFilterKey(c); + }; + + return QQmlListProperty(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } QQmlListProperty Quick3DRenderPass::renderStateList() { - return QQmlListProperty(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 *list, ListContentType *state) { + Quick3DRenderPass *rPass = qobject_cast(list->object); + rPass->parentRenderPass()->addRenderState(state); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + Quick3DRenderPass *rPass = qobject_cast(list->object); + return rPass->parentRenderPass()->renderStates().count(); + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + Quick3DRenderPass *rPass = qobject_cast(list->object); + return rPass->parentRenderPass()->renderStates().at(index); + }; + auto clearFunction = [](QQmlListProperty *list) { + Quick3DRenderPass *rPass = qobject_cast(list->object); + const auto states = rPass->parentRenderPass()->renderStates(); + for (QRenderState *s : states) + rPass->parentRenderPass()->removeRenderState(s); + }; + + return QQmlListProperty(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } QQmlListProperty Quick3DRenderPass::parameterList() { - return QQmlListProperty(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 *list, ListContentType *param) { + Quick3DRenderPass *rPass = qobject_cast(list->object); + rPass->parentRenderPass()->addParameter(param); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + Quick3DRenderPass *rPass = qobject_cast(list->object); + return rPass->parentRenderPass()->parameters().count(); + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + Quick3DRenderPass *rPass = qobject_cast(list->object); + return rPass->parentRenderPass()->parameters().at(index); + }; + auto clearFunction = [](QQmlListProperty *list) { + Quick3DRenderPass *rPass = qobject_cast(list->object); + const auto parameters = rPass->parentRenderPass()->parameters(); + for (QParameter *p : parameters) + rPass->parentRenderPass()->removeParameter(p); + }; + + return QQmlListProperty(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } -void Quick3DRenderPass::appendFilterKey(QQmlListProperty *list, QFilterKey *filterKey) -{ - Quick3DRenderPass *rPass = qobject_cast(list->object); - rPass->parentRenderPass()->addFilterKey(filterKey); -} - -QFilterKey *Quick3DRenderPass::filterKeyAt(QQmlListProperty *list, qsizetype index) -{ - Quick3DRenderPass *rPass = qobject_cast(list->object); - return rPass->parentRenderPass()->filterKeys().at(index); -} - -qsizetype Quick3DRenderPass::filterKeysCount(QQmlListProperty *list) -{ - Quick3DRenderPass *rPass = qobject_cast(list->object); - return rPass->parentRenderPass()->filterKeys().count(); -} - -void Quick3DRenderPass::clearFilterKey(QQmlListProperty *list) -{ - Quick3DRenderPass *rPass = qobject_cast(list->object); - const auto keys = rPass->parentRenderPass()->filterKeys(); - for (QFilterKey *c : keys) - rPass->parentRenderPass()->removeFilterKey(c); -} - -void Quick3DRenderPass::appendRenderState(QQmlListProperty *list, QRenderState *state) -{ - Quick3DRenderPass *rPass = qobject_cast(list->object); - rPass->parentRenderPass()->addRenderState(state); -} - -QRenderState *Quick3DRenderPass::renderStateAt(QQmlListProperty *list, qsizetype index) -{ - Quick3DRenderPass *rPass = qobject_cast(list->object); - return rPass->parentRenderPass()->renderStates().at(index); -} - -qsizetype Quick3DRenderPass::renderStateCount(QQmlListProperty *list) -{ - Quick3DRenderPass *rPass = qobject_cast(list->object); - return rPass->parentRenderPass()->renderStates().count(); -} - -void Quick3DRenderPass::clearRenderStates(QQmlListProperty *list) -{ - Quick3DRenderPass *rPass = qobject_cast(list->object); - const auto states = rPass->parentRenderPass()->renderStates(); - for (QRenderState *s : states) - rPass->parentRenderPass()->removeRenderState(s); -} - -void Quick3DRenderPass::appendParameter(QQmlListProperty *list, QParameter *param) -{ - Quick3DRenderPass *rPass = qobject_cast(list->object); - rPass->parentRenderPass()->addParameter(param); -} - -QParameter *Quick3DRenderPass::parameterAt(QQmlListProperty *list, qsizetype index) -{ - Quick3DRenderPass *rPass = qobject_cast(list->object); - return rPass->parentRenderPass()->parameters().at(index); -} - -qsizetype Quick3DRenderPass::parametersCount(QQmlListProperty *list) -{ - Quick3DRenderPass *rPass = qobject_cast(list->object); - return rPass->parentRenderPass()->parameters().count(); -} - -void Quick3DRenderPass::clearParameterList(QQmlListProperty *list) -{ - Quick3DRenderPass *rPass = qobject_cast(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 parameterList(); inline QRenderPass *parentRenderPass() const { return qobject_cast(parent()); } - -private: - static void appendFilterKey(QQmlListProperty *list, QFilterKey *filterKey); - static QFilterKey *filterKeyAt(QQmlListProperty *list, qsizetype index); - static qsizetype filterKeysCount(QQmlListProperty *list); - static void clearFilterKey(QQmlListProperty *list); - - static void appendRenderState(QQmlListProperty *list, QRenderState *state); - static QRenderState *renderStateAt(QQmlListProperty *list, qsizetype index); - static qsizetype renderStateCount(QQmlListProperty *list); - static void clearRenderStates(QQmlListProperty *list); - - static void appendParameter(QQmlListProperty *list, QParameter *param); - static QParameter *parameterAt(QQmlListProperty *list, qsizetype index); - static qsizetype parametersCount(QQmlListProperty *list); - static void clearParameterList(QQmlListProperty *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 Quick3DRenderPassFilter::includeList() { - return QQmlListProperty(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 *list, QFilterKey *v) { + auto self = qobject_cast(list->object); + if (self) { + v->setParent(self->parentRenderPassFilter()); + self->parentRenderPassFilter()->addMatch(v); + } + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + auto self = qobject_cast(list->object); + if (self) + return self->parentRenderPassFilter()->matchAny().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> QFilterKey * { + auto self = qobject_cast(list->object); + if (self) + return self->parentRenderPassFilter()->matchAny().at(index); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty *list) { + auto self = qobject_cast(list->object); + if (self) { + const auto l = self->parentRenderPassFilter()->matchAny(); + for (auto *v : l) + self->parentRenderPassFilter()->removeMatch(v); + } + }; + + return QQmlListProperty(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } QQmlListProperty Quick3DRenderPassFilter::parameterList() { - return QQmlListProperty(this, 0, - &Quick3DRenderPassFilter::appendParameter, - &Quick3DRenderPassFilter::parametersCount, - &Quick3DRenderPassFilter::parameterAt, - &Quick3DRenderPassFilter::clearParameterList); - -} - -void Quick3DRenderPassFilter::appendInclude(QQmlListProperty *list, QFilterKey *annotation) -{ - Quick3DRenderPassFilter *filter = qobject_cast(list->object); - if (filter) { - annotation->setParent(filter->parentRenderPassFilter()); - filter->parentRenderPassFilter()->addMatch(annotation); - } -} - -QFilterKey *Quick3DRenderPassFilter::includeAt(QQmlListProperty *list, qsizetype index) -{ - Quick3DRenderPassFilter *filter = qobject_cast(list->object); - if (filter) - return filter->parentRenderPassFilter()->matchAny().at(index); - return 0; -} - -qsizetype Quick3DRenderPassFilter::includesCount(QQmlListProperty *list) -{ - Quick3DRenderPassFilter *filter = qobject_cast(list->object); - if (filter) - return filter->parentRenderPassFilter()->matchAny().count(); - return 0; -} - -void Quick3DRenderPassFilter::clearIncludes(QQmlListProperty *list) -{ - Quick3DRenderPassFilter *filter = qobject_cast(list->object); - if (filter) { - const auto criteria = filter->parentRenderPassFilter()->matchAny(); - for (QFilterKey *criterion : criteria) - filter->parentRenderPassFilter()->removeMatch(criterion); - } -} - -void Quick3DRenderPassFilter::appendParameter(QQmlListProperty *list, QParameter *param) -{ - Quick3DRenderPassFilter *rPassFilter = qobject_cast(list->object); - rPassFilter->parentRenderPassFilter()->addParameter(param); -} - -QParameter *Quick3DRenderPassFilter::parameterAt(QQmlListProperty *list, qsizetype index) -{ - Quick3DRenderPassFilter *rPassFilter = qobject_cast(list->object); - return rPassFilter->parentRenderPassFilter()->parameters().at(index); -} - -qsizetype Quick3DRenderPassFilter::parametersCount(QQmlListProperty *list) -{ - Quick3DRenderPassFilter *rPassFilter = qobject_cast(list->object); - return rPassFilter->parentRenderPassFilter()->parameters().count(); -} - -void Quick3DRenderPassFilter::clearParameterList(QQmlListProperty *list) -{ - Quick3DRenderPassFilter *rPassFilter = qobject_cast(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 *list, QParameter *v) { + auto self = qobject_cast(list->object); + if (self) { + self->parentRenderPassFilter()->addParameter(v); + } + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + auto self = qobject_cast(list->object); + if (self) + return self->parentRenderPassFilter()->parameters().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> QParameter * { + auto self = qobject_cast(list->object); + if (self) + return self->parentRenderPassFilter()->parameters().at(index); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty *list) { + auto self = qobject_cast(list->object); + if (self) { + const auto l = self->parentRenderPassFilter()->parameters(); + for (auto *v : l) + self->parentRenderPassFilter()->removeParameter(v); + } + }; + + return QQmlListProperty(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 parameterList(); inline QRenderPassFilter *parentRenderPassFilter() const { return qobject_cast(parent()); } - -private: - static void appendInclude(QQmlListProperty *list, QFilterKey *criterion); - static QFilterKey *includeAt(QQmlListProperty *list, qsizetype index); - static qsizetype includesCount(QQmlListProperty *list); - static void clearIncludes(QQmlListProperty *list); - - static void appendParameter(QQmlListProperty *list, QParameter *param); - static QParameter *parameterAt(QQmlListProperty *list, qsizetype index); - static qsizetype parametersCount(QQmlListProperty *list); - static void clearParameterList(QQmlListProperty *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 Quick3DRenderTargetOutput::qmlAttachments() { - return QQmlListProperty(this, 0, - &Quick3DRenderTargetOutput::appendRenderAttachment, - &Quick3DRenderTargetOutput::renderAttachmentCount, - &Quick3DRenderTargetOutput::renderAttachmentAt, - &Quick3DRenderTargetOutput::clearRenderAttachments); -} - -void Quick3DRenderTargetOutput::appendRenderAttachment(QQmlListProperty *list, QRenderTargetOutput *output) -{ - Quick3DRenderTargetOutput *rT = qobject_cast(list->object); - if (rT) - rT->parentRenderTarget()->addOutput(output); -} - -QRenderTargetOutput *Quick3DRenderTargetOutput::renderAttachmentAt(QQmlListProperty *list, qsizetype index) -{ - Quick3DRenderTargetOutput *rT = qobject_cast(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 *list) -{ - Quick3DRenderTargetOutput *rT = qobject_cast(list->object); - if (rT) - return rT->parentRenderTarget()->outputs().count(); - return -1; -} + using ListContentType = QRenderTargetOutput; + auto appendFunction = [](QQmlListProperty *list, ListContentType *output) { + Quick3DRenderTargetOutput *rT = qobject_cast(list->object); + if (rT) + rT->parentRenderTarget()->addOutput(output); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + Quick3DRenderTargetOutput *rT = qobject_cast(list->object); + if (rT) + return rT->parentRenderTarget()->outputs().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + Quick3DRenderTargetOutput *rT = qobject_cast(list->object); + if (rT) + return rT->parentRenderTarget()->outputs().at(index); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty *list) { + Quick3DRenderTargetOutput *rT = qobject_cast(list->object); + if (rT) { + const auto outputs = rT->parentRenderTarget()->outputs(); + for (QRenderTargetOutput *output : outputs) + rT->parentRenderTarget()->removeOutput(output); + } + }; -void Quick3DRenderTargetOutput::clearRenderAttachments(QQmlListProperty *list) -{ - Quick3DRenderTargetOutput *rT = qobject_cast(list->object); - if (rT) { - const auto outputs = rT->parentRenderTarget()->outputs(); - for (QRenderTargetOutput *output : outputs) - rT->parentRenderTarget()->removeOutput(output); - } + return QQmlListProperty(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 attachments READ qmlAttachments) public: - explicit Quick3DRenderTargetOutput(QObject *parent = 0); + explicit Quick3DRenderTargetOutput(QObject *parent = nullptr); inline QRenderTarget *parentRenderTarget() const { return qobject_cast(parent()); } QQmlListProperty qmlAttachments(); - -private: - static void appendRenderAttachment(QQmlListProperty *list, QRenderTargetOutput *attachment); - static QRenderTargetOutput *renderAttachmentAt(QQmlListProperty *list, qsizetype index); - static qsizetype renderAttachmentCount(QQmlListProperty *list); - static void clearRenderAttachments(QQmlListProperty *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::Render::Quick::Quick3DScreenRayCaster::qmlLayers() { - return QQmlListProperty(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 *list, ListContentType *layer) { + QAbstractRayCaster *filter = qobject_cast(list->object); + if (filter) + filter->addLayer(layer); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + QAbstractRayCaster *filter = qobject_cast(list->object); + if (filter) + return int(filter->layers().size()); + return 0; + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + QAbstractRayCaster *filter = qobject_cast(list->object); + if (filter) + return filter->layers().at(index); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty *list) { + QAbstractRayCaster *filter = qobject_cast(list->object); + if (filter) { + const auto layers = filter->layers(); + for (QLayer *layer : layers) + filter->removeLayer(layer); + } + }; + + return QQmlListProperty(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 Quick3DShaderDataArray::valuesList() { - return QQmlListProperty(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 *list, ListContentType *bar) { + Quick3DShaderDataArray *self = static_cast(list->object); + static_cast(Quick3DShaderDataArrayPrivate::get(self))->m_values.append(bar); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + Quick3DShaderDataArray *self = static_cast(list->object); + return static_cast(Quick3DShaderDataArrayPrivate::get(self))->m_values.count(); + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + Quick3DShaderDataArray *self = static_cast(list->object); + return static_cast(Quick3DShaderDataArrayPrivate::get(self))->m_values.at(index); + }; + auto clearFunction = [](QQmlListProperty *list) { + Quick3DShaderDataArray *self = static_cast(list->object); + static_cast(Quick3DShaderDataArrayPrivate::get(self))->m_values.clear(); + }; + + return QQmlListProperty(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } QList Quick3DShaderDataArray::values() const @@ -85,30 +105,6 @@ QList Quick3DShaderDataArray::values() const // d_func()->m_values.append(static_cast(QNode::clone(v))); //} -void Quick3DShaderDataArray::appendValue(QQmlListProperty *list, QShaderData *bar) -{ - Quick3DShaderDataArray *self = static_cast(list->object); - static_cast(Quick3DShaderDataArrayPrivate::get(self))->m_values.append(bar); -} - -QShaderData *Quick3DShaderDataArray::valueAt(QQmlListProperty *list, qsizetype index) -{ - Quick3DShaderDataArray *self = static_cast(list->object); - return static_cast(Quick3DShaderDataArrayPrivate::get(self))->m_values.at(index); -} - -qsizetype Quick3DShaderDataArray::valueCount(QQmlListProperty *list) -{ - Quick3DShaderDataArray *self = static_cast(list->object); - return static_cast(Quick3DShaderDataArrayPrivate::get(self))->m_values.count(); -} - -void Quick3DShaderDataArray::clearValues(QQmlListProperty *list) -{ - Quick3DShaderDataArray *self = static_cast(list->object); - static_cast(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 valuesList(); QList values() const; private: - static void appendValue(QQmlListProperty *list, QShaderData *bar); - static QShaderData *valueAt(QQmlListProperty *list, qsizetype index); - static qsizetype valueCount(QQmlListProperty *list); - static void clearValues(QQmlListProperty *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 Quick3DStateSet::renderStateList() { - return QQmlListProperty(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 *list, QRenderState *state) -{ - Quick3DStateSet *stateSet = qobject_cast(list->object); - stateSet->parentStateSet()->addRenderState(state); -} + using ListContentType = QRenderState; + auto appendFunction = [](QQmlListProperty *list, ListContentType *state) { + Quick3DStateSet *stateSet = qobject_cast(list->object); + stateSet->parentStateSet()->addRenderState(state); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + Quick3DStateSet *stateSet = qobject_cast(list->object); + return stateSet->parentStateSet()->renderStates().count(); + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + Quick3DStateSet *stateSet = qobject_cast(list->object); + return stateSet->parentStateSet()->renderStates().at(index); + }; + auto clearFunction = [](QQmlListProperty *list) { + Quick3DStateSet *stateSet = qobject_cast(list->object); + const auto states = stateSet->parentStateSet()->renderStates(); + for (QRenderState *s : states) + stateSet->parentStateSet()->removeRenderState(s); + }; -QRenderState *Quick3DStateSet::renderStateAt(QQmlListProperty *list, qsizetype index) -{ - Quick3DStateSet *stateSet = qobject_cast(list->object); - return stateSet->parentStateSet()->renderStates().at(index); -} - -qsizetype Quick3DStateSet::renderStateCount(QQmlListProperty *list) -{ - Quick3DStateSet *stateSet = qobject_cast(list->object); - return stateSet->parentStateSet()->renderStates().count(); -} - -void Quick3DStateSet::clearRenderStates(QQmlListProperty *list) -{ - Quick3DStateSet *stateSet = qobject_cast(list->object); - const auto states = stateSet->parentStateSet()->renderStates(); - for (QRenderState *s : states) - stateSet->parentStateSet()->removeRenderState(s); + return QQmlListProperty(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 renderStates READ renderStateList CONSTANT) public: - explicit Quick3DStateSet(QObject *parent = 0); + explicit Quick3DStateSet(QObject *parent = nullptr); ~Quick3DStateSet(); QQmlListProperty renderStateList(); inline QRenderStateSet *parentStateSet() const { return qobject_cast(parent()); } - -private: - static void appendRenderState(QQmlListProperty *list, QRenderState *state); - static QRenderState *renderStateAt(QQmlListProperty *list, qsizetype index); - static qsizetype renderStateCount(QQmlListProperty *list); - static void clearRenderStates(QQmlListProperty *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 Quick3DTechnique::renderPassList() { - return QQmlListProperty(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 *list, ListContentType *renderPass) { + Quick3DTechnique *technique = qobject_cast(list->object); + if (technique) + technique->parentTechnique()->addRenderPass(renderPass); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + Quick3DTechnique *technique = qobject_cast(list->object); + if (technique) + return technique->parentTechnique()->renderPasses().size(); + return 0; + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + Quick3DTechnique *technique = qobject_cast(list->object); + if (technique) + return qobject_cast(technique->parentTechnique()->renderPasses().at(index)); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty *list) { + Quick3DTechnique *technique = qobject_cast(list->object); + if (technique) { + const auto passes = technique->parentTechnique()->renderPasses(); + for (QRenderPass *pass : passes) + technique->parentTechnique()->removeRenderPass(pass); + } + }; + + return QQmlListProperty(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } QQmlListProperty Quick3DTechnique::parameterList() { - return QQmlListProperty(this, 0, - &Quick3DTechnique::appendParameter, - &Quick3DTechnique::parametersCount, - &Quick3DTechnique::parameterAt, - &Quick3DTechnique::clearParameterList); -} - -void Quick3DTechnique::appendParameter(QQmlListProperty *list, QParameter *param) -{ - Quick3DTechnique *technique = qobject_cast(list->object); - technique->parentTechnique()->addParameter(param); -} - -QParameter *Quick3DTechnique::parameterAt(QQmlListProperty *list, qsizetype index) -{ - Quick3DTechnique *technique = qobject_cast(list->object); - return technique->parentTechnique()->parameters().at(index); -} - -qsizetype Quick3DTechnique::parametersCount(QQmlListProperty *list) -{ - Quick3DTechnique *technique = qobject_cast(list->object); - return technique->parentTechnique()->parameters().count(); -} - -void Quick3DTechnique::clearParameterList(QQmlListProperty *list) -{ - Quick3DTechnique *technique = qobject_cast(list->object); - const auto parameters = technique->parentTechnique()->parameters(); - for (QParameter *p : parameters) - technique->parentTechnique()->removeParameter(p); -} - -void Quick3DTechnique::appendRenderPass(QQmlListProperty *list, QRenderPass *renderPass) -{ - Quick3DTechnique *technique = qobject_cast(list->object); - if (technique) { - technique->parentTechnique()->addRenderPass(renderPass); - } -} - -QRenderPass *Quick3DTechnique::renderPassAt(QQmlListProperty *list, qsizetype index) -{ - Quick3DTechnique *technique = qobject_cast(list->object); - if (technique) - return qobject_cast(technique->parentTechnique()->renderPasses().at(index)); - return 0; -} - -qsizetype Quick3DTechnique::renderPassCount(QQmlListProperty *list) -{ - Quick3DTechnique *technique = qobject_cast(list->object); - if (technique) - return technique->parentTechnique()->renderPasses().size(); - return 0; -} - -void Quick3DTechnique::clearRenderPasses(QQmlListProperty *list) -{ - Quick3DTechnique *technique = qobject_cast(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 *list, ListContentType *param) { + Quick3DTechnique *technique = qobject_cast(list->object); + technique->parentTechnique()->addParameter(param); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + Quick3DTechnique *technique = qobject_cast(list->object); + return technique->parentTechnique()->parameters().count(); + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + Quick3DTechnique *technique = qobject_cast(list->object); + return technique->parentTechnique()->parameters().at(index); + }; + auto clearFunction = [](QQmlListProperty *list) { + Quick3DTechnique *technique = qobject_cast(list->object); + const auto parameters = technique->parentTechnique()->parameters(); + for (QParameter *p : parameters) + technique->parentTechnique()->removeParameter(p); + }; + + return QQmlListProperty(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } QQmlListProperty Quick3DTechnique::filterKeyList() { - return QQmlListProperty(this, 0, - &Quick3DTechnique::appendFilterKey, - &Quick3DTechnique::filterKeyCount, - &Quick3DTechnique::filterKeyAt, - &Quick3DTechnique::clearFilterKeyList); -} - -void Quick3DTechnique::appendFilterKey(QQmlListProperty *list, QFilterKey *filterKey) -{ - Quick3DTechnique *technique = qobject_cast(list->object); - if (technique) { - if (!filterKey->parent()) - filterKey->setParent(technique->parentTechnique()); - technique->parentTechnique()->addFilterKey(filterKey); - } -} - -QFilterKey *Quick3DTechnique::filterKeyAt(QQmlListProperty *list, qsizetype index) -{ - Quick3DTechnique *technique = qobject_cast(list->object); - if (technique) - return technique->parentTechnique()->filterKeys().at(index); - return 0; -} - -qsizetype Quick3DTechnique::filterKeyCount(QQmlListProperty *list) -{ - Quick3DTechnique *technique = qobject_cast(list->object); - if (technique) - return technique->parentTechnique()->filterKeys().size(); - return 0; -} - -void Quick3DTechnique::clearFilterKeyList(QQmlListProperty *list) -{ - Quick3DTechnique *technique = qobject_cast(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 *list, ListContentType *filterKey) { + Quick3DTechnique *technique = qobject_cast(list->object); + if (technique) { + if (!filterKey->parent()) + filterKey->setParent(technique->parentTechnique()); + technique->parentTechnique()->addFilterKey(filterKey); + } + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + Quick3DTechnique *technique = qobject_cast(list->object); + if (technique) + return technique->parentTechnique()->filterKeys().size(); + return 0; + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + Quick3DTechnique *technique = qobject_cast(list->object); + if (technique) + return technique->parentTechnique()->filterKeys().at(index); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty *list) { + Quick3DTechnique *technique = qobject_cast(list->object); + if (technique) { + const auto keys = technique->parentTechnique()->filterKeys(); + for (QFilterKey *a : keys) + technique->parentTechnique()->removeFilterKey(a); + } + }; + + return QQmlListProperty(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(parent()); } - -private: - - static void appendParameter(QQmlListProperty *list, QParameter *param); - static QParameter *parameterAt(QQmlListProperty *list, qsizetype index); - static qsizetype parametersCount(QQmlListProperty *list); - static void clearParameterList(QQmlListProperty *list); - - static void appendFilterKey(QQmlListProperty *list, QFilterKey *filterKey); - static QFilterKey *filterKeyAt(QQmlListProperty *list, qsizetype index); - static qsizetype filterKeyCount(QQmlListProperty *list); - static void clearFilterKeyList(QQmlListProperty *list); - - static void appendRenderPass(QQmlListProperty *list, QRenderPass* renderPass); - static QRenderPass *renderPassAt(QQmlListProperty *list, qsizetype index); - static qsizetype renderPassCount(QQmlListProperty *list); - static void clearRenderPasses( QQmlListProperty *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 Quick3DTechniqueFilter::matchList() { - return QQmlListProperty(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 *list, ListContentType *criterion) { + Quick3DTechniqueFilter *filter = qobject_cast(list->object); + if (filter) { + criterion->setParent(filter->parentTechniqueFilter()); + filter->parentTechniqueFilter()->addMatch(criterion); + } + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + Quick3DTechniqueFilter *filter = qobject_cast(list->object); + if (filter) + return filter->parentTechniqueFilter()->matchAll().size(); + return 0; + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + Quick3DTechniqueFilter *filter = qobject_cast(list->object); + if (filter) + return filter->parentTechniqueFilter()->matchAll().at(index); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty *list) { + Quick3DTechniqueFilter *filter = qobject_cast(list->object); + if (filter) { + const auto criteria = filter->parentTechniqueFilter()->matchAll(); + for (QFilterKey *criterion : criteria) + filter->parentTechniqueFilter()->removeMatch(criterion); + } + }; + + return QQmlListProperty(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } QQmlListProperty Quick3DTechniqueFilter::parameterList() { - return QQmlListProperty(this, 0, - &Quick3DTechniqueFilter::appendParameter, - &Quick3DTechniqueFilter::parametersCount, - &Quick3DTechniqueFilter::parameterAt, - &Quick3DTechniqueFilter::clearParameterList); -} - -void Quick3DTechniqueFilter::appendRequire(QQmlListProperty *list, QFilterKey *criterion) -{ - Quick3DTechniqueFilter *filter = qobject_cast(list->object); - if (filter) { - criterion->setParent(filter->parentTechniqueFilter()); - filter->parentTechniqueFilter()->addMatch(criterion); - } -} - -QFilterKey *Quick3DTechniqueFilter::requireAt(QQmlListProperty *list, qsizetype index) -{ - Quick3DTechniqueFilter *filter = qobject_cast(list->object); - if (filter) - return filter->parentTechniqueFilter()->matchAll().at(index); - return 0; -} - -qsizetype Quick3DTechniqueFilter::requiresCount(QQmlListProperty *list) -{ - Quick3DTechniqueFilter *filter = qobject_cast(list->object); - if (filter) - return filter->parentTechniqueFilter()->matchAll().size(); - return 0; -} - -void Quick3DTechniqueFilter::clearRequires(QQmlListProperty *list) -{ - Quick3DTechniqueFilter *filter = qobject_cast(list->object); - if (filter) { - const auto criteria = filter->parentTechniqueFilter()->matchAll(); - for (QFilterKey *criterion : criteria) - filter->parentTechniqueFilter()->removeMatch(criterion); - } -} - -void Quick3DTechniqueFilter::appendParameter(QQmlListProperty *list, QParameter *param) -{ - Quick3DTechniqueFilter *techniqueFilter = qobject_cast(list->object); - techniqueFilter->parentTechniqueFilter()->addParameter(param); -} - -QParameter *Quick3DTechniqueFilter::parameterAt(QQmlListProperty *list, qsizetype index) -{ - Quick3DTechniqueFilter *techniqueFilter = qobject_cast(list->object); - return techniqueFilter->parentTechniqueFilter()->parameters().at(index); -} - -qsizetype Quick3DTechniqueFilter::parametersCount(QQmlListProperty *list) -{ - Quick3DTechniqueFilter *techniqueFilter = qobject_cast(list->object); - return techniqueFilter->parentTechniqueFilter()->parameters().count(); -} - -void Quick3DTechniqueFilter::clearParameterList(QQmlListProperty *list) -{ - Quick3DTechniqueFilter *techniqueFilter = qobject_cast(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 *list, ListContentType *param) { + Quick3DTechniqueFilter *techniqueFilter = qobject_cast(list->object); + techniqueFilter->parentTechniqueFilter()->addParameter(param); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + Quick3DTechniqueFilter *techniqueFilter = qobject_cast(list->object); + return techniqueFilter->parentTechniqueFilter()->parameters().count(); + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + Quick3DTechniqueFilter *techniqueFilter = qobject_cast(list->object); + return techniqueFilter->parentTechniqueFilter()->parameters().at(index); + }; + auto clearFunction = [](QQmlListProperty *list) { + Quick3DTechniqueFilter *techniqueFilter = qobject_cast(list->object); + const auto parameters = techniqueFilter->parentTechniqueFilter()->parameters(); + for (QParameter *p : parameters) + techniqueFilter->parentTechniqueFilter()->removeParameter(p); + }; + + return QQmlListProperty(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 parameterList(); inline QTechniqueFilter *parentTechniqueFilter() const { return qobject_cast(parent()); } - -private: - static void appendRequire(QQmlListProperty *list, QFilterKey *criterion); - static QFilterKey *requireAt(QQmlListProperty *list, qsizetype index); - static qsizetype requiresCount(QQmlListProperty *list); - static void clearRequires(QQmlListProperty *list); - - static void appendParameter(QQmlListProperty *list, QParameter *param); - static QParameter *parameterAt(QQmlListProperty *list, qsizetype index); - static qsizetype parametersCount(QQmlListProperty *list); - static void clearParameterList(QQmlListProperty *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 Quick3DTextureExtension::textureImages() { - return QQmlListProperty(this, 0, - &Quick3DTextureExtension::appendTextureImage, - &Quick3DTextureExtension::textureImageCount, - &Quick3DTextureExtension::textureImageAt, - &Quick3DTextureExtension::clearTextureImageList); -} - -void Quick3DTextureExtension::appendTextureImage(QQmlListProperty *list, QAbstractTextureImage *textureImage) -{ - Quick3DTextureExtension *self = qobject_cast(list->object); - if (self) - self->parentTexture()->addTextureImage(textureImage); -} - -QAbstractTextureImage *Quick3DTextureExtension::textureImageAt(QQmlListProperty *list, qsizetype index) -{ - Quick3DTextureExtension *self = qobject_cast(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 *list) -{ - Quick3DTextureExtension *self = qobject_cast(list->object); - if (self) - return self->parentTexture()->textureImages().count(); - return 0; -} + using ListContentType = QAbstractTextureImage; + auto appendFunction = [](QQmlListProperty *list, ListContentType *textureImage) { + Quick3DTextureExtension *self = qobject_cast(list->object); + if (self) + self->parentTexture()->addTextureImage(textureImage); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + Quick3DTextureExtension *self = qobject_cast(list->object); + if (self) + return self->parentTexture()->textureImages().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + Quick3DTextureExtension *self = qobject_cast(list->object); + if (self) + return self->parentTexture()->textureImages().at(index); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty *list) { + if (Quick3DTextureExtension *self = qobject_cast(list->object)) { + const auto images = self->parentTexture()->textureImages(); + for (QAbstractTextureImage *img : images) + self->parentTexture()->removeTextureImage(img); + } + }; -void Quick3DTextureExtension::clearTextureImageList(QQmlListProperty *list) -{ - if (Quick3DTextureExtension *self = qobject_cast(list->object)) { - const auto images = self->parentTexture()->textureImages(); - for (QAbstractTextureImage *img : images) - self->parentTexture()->removeTextureImage(img); - } + return QQmlListProperty(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 textureImages(); inline QAbstractTexture *parentTexture() const { return qobject_cast(parent()); } - -private: - static void appendTextureImage(QQmlListProperty *list, QAbstractTextureImage *textureImage); - static QAbstractTextureImage *textureImageAt(QQmlListProperty *list, qsizetype index); - static qsizetype textureImageCount(QQmlListProperty *list); - static void clearTextureImageList(QQmlListProperty *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 QQuick3DScene2D::entities() { - return QQmlListProperty(this, 0, - &QQuick3DScene2D::appendEntity, - &QQuick3DScene2D::entityCount, - &QQuick3DScene2D::entityAt, - &QQuick3DScene2D::clearEntities); -} - -void QQuick3DScene2D::appendEntity(QQmlListProperty *list, - Qt3DCore::QEntity *entity) -{ - QQuick3DScene2D *scene2d = qobject_cast(list->object); - if (scene2d) - scene2d->parentScene2D()->addEntity(entity); -} - -qsizetype QQuick3DScene2D::entityCount(QQmlListProperty *list) -{ - QQuick3DScene2D *scene2d = qobject_cast(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 *list, qsizetype index) -{ - QQuick3DScene2D *scene2d = qobject_cast(list->object); - if (scene2d) { - return qobject_cast( - scene2d->parentScene2D()->entities().at(index)); - } - return nullptr; -} + using ListContentType = Qt3DCore::QEntity; + auto appendFunction = [](QQmlListProperty *list, ListContentType *entity) { + QQuick3DScene2D *scene2d = qobject_cast(list->object); + if (scene2d) + scene2d->parentScene2D()->addEntity(entity); + }; + auto countFunction = [](QQmlListProperty *list) -> qt_size_type { + QQuick3DScene2D *scene2d = qobject_cast(list->object); + if (scene2d) + return scene2d->parentScene2D()->entities().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty *list, qt_size_type index) -> ListContentType * { + QQuick3DScene2D *scene2d = qobject_cast(list->object); + if (scene2d) { + return qobject_cast( + scene2d->parentScene2D()->entities().at(index)); + } + return nullptr; + }; + auto clearFunction = [](QQmlListProperty *list) { + QQuick3DScene2D *scene2d = qobject_cast(list->object); + if (scene2d) { + QList entities = scene2d->parentScene2D()->entities(); + for (Qt3DCore::QEntity *e : entities) + scene2d->parentScene2D()->removeEntity(e); + } + }; -void QQuick3DScene2D::clearEntities(QQmlListProperty *list) -{ - QQuick3DScene2D *scene2d = qobject_cast(list->object); - if (scene2d) { - QList entities = scene2d->parentScene2D()->entities(); - for (Qt3DCore::QEntity *e : entities) - scene2d->parentScene2D()->removeEntity(e); - } + return QQmlListProperty(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 entities(); - -private: - - static void appendEntity(QQmlListProperty *list, Qt3DCore::QEntity *entity); - static Qt3DCore::QEntity *entityAt(QQmlListProperty *list, qsizetype index); - static qsizetype entityCount(QQmlListProperty *list); - static void clearEntities(QQmlListProperty *list); }; } // namespace Quick -- cgit v1.2.3