diff options
author | Mike Krus <mike.krus@kdab.com> | 2020-11-23 09:06:01 +0000 |
---|---|---|
committer | Mike Krus <mike.krus@kdab.com> | 2021-01-08 11:32:08 +0000 |
commit | d2fe37b3480cc55cf301426d7fa40475080cc6f9 (patch) | |
tree | 8c0ef31cdc3d2f75f4eed7d851a6d22e793d4c00 /src/quick3d/quick3drender/items | |
parent | eee0fca4abc800883dde40559290403e7e550d14 (diff) |
Update QQMLPropertyList API
Use lambdas with local typedefs for index type
Change-Id: I2876c71d619815e7e777f936e8bb0835b8269336
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/quick3d/quick3drender/items')
25 files changed, 633 insertions, 787 deletions
diff --git a/src/quick3d/quick3drender/items/quick3deffect.cpp b/src/quick3d/quick3drender/items/quick3deffect.cpp index 617b52e85..09045011b 100644 --- a/src/quick3d/quick3drender/items/quick3deffect.cpp +++ b/src/quick3d/quick3drender/items/quick3deffect.cpp @@ -54,82 +54,74 @@ Quick3DEffect::Quick3DEffect(QObject *parent) QQmlListProperty<QTechnique> Quick3DEffect::techniqueList() { - return QQmlListProperty<QTechnique>(this, 0, - &Quick3DEffect::appendTechnique, - &Quick3DEffect::techniqueCount, - &Quick3DEffect::techniqueAt, - &Quick3DEffect::clearTechniqueList); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = QTechnique; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *bar) { + Quick3DEffect *eff = qobject_cast<Quick3DEffect*>(list->object); + if (eff) + eff->parentEffect()->addTechnique(bar); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DEffect *eff = qobject_cast<Quick3DEffect*>(list->object); + if (eff) + return eff->parentEffect()->techniques().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + // TO DO : Return a QAbstractTechnique once properly defined + Quick3DEffect *eff = qobject_cast<Quick3DEffect*>(list->object); + if (eff) + return qobject_cast<QTechnique*>(eff->parentEffect()->techniques().at(index)); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DEffect *eff = qobject_cast<Quick3DEffect*>(list->object); + if (eff) { + // Ownership of techniques is handled by the QmlEngine so we shouldn't class clearTechniques + // which deletes techniques + const auto techniques = eff->parentEffect()->techniques(); + for (QTechnique *tech : techniques) + eff->parentEffect()->removeTechnique(tech); + } + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } QQmlListProperty<QParameter> Quick3DEffect::parameterList() { - return QQmlListProperty<QParameter>(this, 0, - &Quick3DEffect::appendParameter, - &Quick3DEffect::parametersCount, - &Quick3DEffect::parameterAt, - &Quick3DEffect::clearParameterList); -} - -void Quick3DEffect::appendTechnique(QQmlListProperty<QTechnique> *list, QTechnique *bar) -{ - Quick3DEffect *eff = qobject_cast<Quick3DEffect*>(list->object); - if (eff) - eff->parentEffect()->addTechnique(bar); -} - -// TO DO : Return a QAbstractTechnique once properly defined -QTechnique *Quick3DEffect::techniqueAt(QQmlListProperty<QTechnique> *list, qsizetype index) -{ - Quick3DEffect *eff = qobject_cast<Quick3DEffect*>(list->object); - if (eff) - return qobject_cast<QTechnique*>(eff->parentEffect()->techniques().at(index)); - return nullptr; -} - -qsizetype Quick3DEffect::techniqueCount(QQmlListProperty<QTechnique> *list) -{ - Quick3DEffect *eff = qobject_cast<Quick3DEffect*>(list->object); - if (eff) - return eff->parentEffect()->techniques().count(); - return 0; -} - -void Quick3DEffect::clearTechniqueList(QQmlListProperty<QTechnique> *list) -{ - Quick3DEffect *eff = qobject_cast<Quick3DEffect*>(list->object); - if (eff) { - // Ownership of techniques is handled by the QmlEngine so we shouldn't class clearTechniques - // which deletes techniques - const auto techniques = eff->parentEffect()->techniques(); - for (QTechnique *tech : techniques) - eff->parentEffect()->removeTechnique(tech); - } -} - -void Quick3DEffect::appendParameter(QQmlListProperty<QParameter> *list, QParameter *param) -{ - Quick3DEffect *effect = qobject_cast<Quick3DEffect *>(list->object); - qobject_cast<QEffect *>(effect->parentEffect())->addParameter(param); -} - -QParameter *Quick3DEffect::parameterAt(QQmlListProperty<QParameter> *list, qsizetype index) -{ - Quick3DEffect *effect = qobject_cast<Quick3DEffect *>(list->object); - return qobject_cast<QEffect *>(effect->parentEffect())->parameters().at(index); -} - -qsizetype Quick3DEffect::parametersCount(QQmlListProperty<QParameter> *list) -{ - Quick3DEffect *effect = qobject_cast<Quick3DEffect *>(list->object); - return qobject_cast<QEffect *>(effect->parentEffect())->parameters().count(); -} - -void Quick3DEffect::clearParameterList(QQmlListProperty<QParameter> *list) -{ - Quick3DEffect *effect = qobject_cast<Quick3DEffect *>(list->object); - const auto parameters = qobject_cast<QEffect *>(effect->parentEffect())->parameters(); - for (QParameter *p : parameters) - qobject_cast<QEffect *>(effect->parentEffect())->removeParameter(p); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = QParameter; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *param) { + Quick3DEffect *effect = qobject_cast<Quick3DEffect *>(list->object); + qobject_cast<QEffect *>(effect->parentEffect())->addParameter(param); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DEffect *effect = qobject_cast<Quick3DEffect *>(list->object); + return qobject_cast<QEffect *>(effect->parentEffect())->parameters().count(); + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DEffect *effect = qobject_cast<Quick3DEffect *>(list->object); + return qobject_cast<QEffect *>(effect->parentEffect())->parameters().at(index); + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DEffect *effect = qobject_cast<Quick3DEffect *>(list->object); + const auto parameters = qobject_cast<QEffect *>(effect->parentEffect())->parameters(); + for (QParameter *p : parameters) + qobject_cast<QEffect *>(effect->parentEffect())->removeParameter(p); + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3deffect_p.h b/src/quick3d/quick3drender/items/quick3deffect_p.h index fb6fa2bdd..93215cc2c 100644 --- a/src/quick3d/quick3drender/items/quick3deffect_p.h +++ b/src/quick3d/quick3drender/items/quick3deffect_p.h @@ -76,17 +76,6 @@ public: QQmlListProperty<QTechnique> techniqueList(); QQmlListProperty<QParameter> parameterList(); - -private: - static void appendTechnique(QQmlListProperty<QTechnique> *list, QTechnique *bar); - static QTechnique *techniqueAt(QQmlListProperty<QTechnique> *list, qsizetype index); - static qsizetype techniqueCount(QQmlListProperty<QTechnique> *list); - static void clearTechniqueList(QQmlListProperty<QTechnique> *list); - - static void appendParameter(QQmlListProperty<QParameter> *list, QParameter *param); - static QParameter *parameterAt(QQmlListProperty<QParameter> *list, qsizetype index); - static qsizetype parametersCount(QQmlListProperty<QParameter> *list); - static void clearParameterList(QQmlListProperty<QParameter> *list); }; } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3dlayerfilter.cpp b/src/quick3d/quick3drender/items/quick3dlayerfilter.cpp index 505495eb3..431391af6 100644 --- a/src/quick3d/quick3drender/items/quick3dlayerfilter.cpp +++ b/src/quick3d/quick3drender/items/quick3dlayerfilter.cpp @@ -56,47 +56,41 @@ Quick3DLayerFilter::Quick3DLayerFilter(QObject *parent) QQmlListProperty<QLayer> Quick3DLayerFilter::qmlLayers() { - return QQmlListProperty<QLayer>(this, 0, - &Quick3DLayerFilter::appendLayer, - &Quick3DLayerFilter::layerCount, - &Quick3DLayerFilter::layerAt, - &Quick3DLayerFilter::clearLayers); -} - -void Quick3DLayerFilter::appendLayer(QQmlListProperty<QLayer> *list, QLayer *layer) -{ - Quick3DLayerFilter *filter = qobject_cast<Quick3DLayerFilter *>(list->object); - if (filter) { - filter->parentFilter()->addLayer(layer); - } -} - -QLayer *Quick3DLayerFilter::layerAt(QQmlListProperty<QLayer> *list, qsizetype index) -{ - Quick3DLayerFilter *filter = qobject_cast<Quick3DLayerFilter *>(list->object); - if (filter) { - return filter->parentFilter()->layers().at(index); - } - return 0; -} - -qsizetype Quick3DLayerFilter::layerCount(QQmlListProperty<QLayer> *list) -{ - Quick3DLayerFilter *filter = qobject_cast<Quick3DLayerFilter *>(list->object); - if (filter) { - return filter->parentFilter()->layers().count(); - } - return 0; -} - -void Quick3DLayerFilter::clearLayers(QQmlListProperty<QLayer> *list) -{ - Quick3DLayerFilter *filter = qobject_cast<Quick3DLayerFilter *>(list->object); - if (filter) { - const auto layers = filter->parentFilter()->layers(); - for (QLayer *layer : layers) - filter->parentFilter()->removeLayer(layer); - } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = QLayer; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *layer) { + Quick3DLayerFilter *filter = qobject_cast<Quick3DLayerFilter *>(list->object); + if (filter) { + filter->parentFilter()->addLayer(layer); + } + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DLayerFilter *filter = qobject_cast<Quick3DLayerFilter *>(list->object); + if (filter) + return filter->parentFilter()->layers().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DLayerFilter *filter = qobject_cast<Quick3DLayerFilter *>(list->object); + if (filter) + return filter->parentFilter()->layers().at(index); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DLayerFilter *filter = qobject_cast<Quick3DLayerFilter *>(list->object); + if (filter) { + const auto layers = filter->parentFilter()->layers(); + for (QLayer *layer : layers) + filter->parentFilter()->removeLayer(layer); + } + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } } // Quick diff --git a/src/quick3d/quick3drender/items/quick3dlayerfilter_p.h b/src/quick3d/quick3drender/items/quick3dlayerfilter_p.h index 3bcb6aaa2..ab5bf5c55 100644 --- a/src/quick3d/quick3drender/items/quick3dlayerfilter_p.h +++ b/src/quick3d/quick3drender/items/quick3dlayerfilter_p.h @@ -69,17 +69,11 @@ class Q_3DQUICKRENDERSHARED_PRIVATE_EXPORT Quick3DLayerFilter : public QObject Q_PROPERTY(QQmlListProperty<Qt3DRender::QLayer> layers READ qmlLayers) public: - explicit Quick3DLayerFilter(QObject *parent = 0); + explicit Quick3DLayerFilter(QObject *parent = nullptr); inline QLayerFilter *parentFilter() const { return qobject_cast<QLayerFilter*>(parent()); } QQmlListProperty<QLayer> qmlLayers(); - -private: - static void appendLayer(QQmlListProperty<QLayer> *list, QLayer *bar); - static QLayer *layerAt(QQmlListProperty<QLayer> *list, qsizetype index); - static qsizetype layerCount(QQmlListProperty<QLayer> *list); - static void clearLayers(QQmlListProperty<QLayer> *list); }; } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3dmaterial.cpp b/src/quick3d/quick3drender/items/quick3dmaterial.cpp index 4e5cc1947..0e1528fe2 100644 --- a/src/quick3d/quick3drender/items/quick3dmaterial.cpp +++ b/src/quick3d/quick3drender/items/quick3dmaterial.cpp @@ -56,46 +56,42 @@ Quick3DMaterial::Quick3DMaterial(QObject *parent) QQmlListProperty<QParameter> Quick3DMaterial::qmlParameters() { - return QQmlListProperty<QParameter>(this, 0, - &Quick3DMaterial::appendParameter, - &Quick3DMaterial::parameterCount, - &Quick3DMaterial::parameterAt, - &Quick3DMaterial::clearParameters); -} - -void Quick3DMaterial::appendParameter(QQmlListProperty<QParameter> *list, QParameter *param) -{ - Quick3DMaterial *mat = qobject_cast<Quick3DMaterial *>(list->object); - if (mat) { - param->setParent(mat->parentMaterial()); - mat->parentMaterial()->addParameter(param); - } -} - -QParameter *Quick3DMaterial::parameterAt(QQmlListProperty<QParameter> *list, qsizetype index) -{ - Quick3DMaterial *mat = qobject_cast<Quick3DMaterial *>(list->object); - if (mat) - return mat->parentMaterial()->parameters().at(index); - return 0; -} - -qsizetype Quick3DMaterial::parameterCount(QQmlListProperty<QParameter> *list) -{ - Quick3DMaterial *mat = qobject_cast<Quick3DMaterial *>(list->object); - if (mat) - return mat->parentMaterial()->parameters().count(); - return 0; -} - -void Quick3DMaterial::clearParameters(QQmlListProperty<QParameter> *list) -{ - Quick3DMaterial *mat = qobject_cast<Quick3DMaterial *>(list->object); - if (mat) { - const auto parameters = mat->parentMaterial()->parameters(); - for (QParameter *p : parameters) - mat->parentMaterial()->removeParameter(p); - } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = QParameter; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *param) { + Quick3DMaterial *mat = qobject_cast<Quick3DMaterial *>(list->object); + if (mat) { + param->setParent(mat->parentMaterial()); + mat->parentMaterial()->addParameter(param); + } + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DMaterial *mat = qobject_cast<Quick3DMaterial *>(list->object); + if (mat) + return mat->parentMaterial()->parameters().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DMaterial *mat = qobject_cast<Quick3DMaterial *>(list->object); + if (mat) + return mat->parentMaterial()->parameters().at(index); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DMaterial *mat = qobject_cast<Quick3DMaterial *>(list->object); + if (mat) { + const auto parameters = mat->parentMaterial()->parameters(); + for (QParameter *p : parameters) + mat->parentMaterial()->removeParameter(p); + } + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } } // Quick diff --git a/src/quick3d/quick3drender/items/quick3dmaterial_p.h b/src/quick3d/quick3drender/items/quick3dmaterial_p.h index adb0d066b..a8d07ac32 100644 --- a/src/quick3d/quick3drender/items/quick3dmaterial_p.h +++ b/src/quick3d/quick3drender/items/quick3dmaterial_p.h @@ -72,20 +72,12 @@ class Q_3DQUICKRENDERSHARED_PRIVATE_EXPORT Quick3DMaterial : public QObject Q_PROPERTY(QQmlListProperty<Qt3DRender::QParameter> parameters READ qmlParameters) public: - explicit Quick3DMaterial(QObject *parent = 0); + explicit Quick3DMaterial(QObject *parent = nullptr); // TO DO : replace by QAbstractMaterial later on inline QMaterial *parentMaterial() const { return qobject_cast<QMaterial*>(parent()); } QQmlListProperty<QParameter> qmlParameters(); - - -private: - // FIXME - remove when we have a custom QML parser - static void appendParameter(QQmlListProperty<QParameter> *list, QParameter *bar); - static QParameter *parameterAt(QQmlListProperty<QParameter> *list, qsizetype index); - static qsizetype parameterCount(QQmlListProperty<QParameter> *list); - static void clearParameters(QQmlListProperty<QParameter> *list); }; } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3draycaster.cpp b/src/quick3d/quick3drender/items/quick3draycaster.cpp index dad28bbbe..4e901c82b 100644 --- a/src/quick3d/quick3drender/items/quick3draycaster.cpp +++ b/src/quick3d/quick3drender/items/quick3draycaster.cpp @@ -49,39 +49,6 @@ namespace Qt3DRender { namespace Render { namespace Quick { -void Quick3DRayCasterPrivate::appendLayer(QQmlListProperty<QLayer> *list, QLayer *layer) -{ - QAbstractRayCaster *filter = qobject_cast<QAbstractRayCaster *>(list->object); - if (filter) - filter->addLayer(layer); -} - -QLayer *Quick3DRayCasterPrivate::layerAt(QQmlListProperty<QLayer> *list, qsizetype index) -{ - QAbstractRayCaster *filter = qobject_cast<QAbstractRayCaster *>(list->object); - if (filter) - return filter->layers().at(index); - return nullptr; -} - -qsizetype Quick3DRayCasterPrivate::layerCount(QQmlListProperty<QLayer> *list) -{ - QAbstractRayCaster *filter = qobject_cast<QAbstractRayCaster *>(list->object); - if (filter) - return int(filter->layers().size()); - return 0; -} - -void Quick3DRayCasterPrivate::clearLayers(QQmlListProperty<QLayer> *list) -{ - QAbstractRayCaster *filter = qobject_cast<QAbstractRayCaster *>(list->object); - if (filter) { - const auto layers = filter->layers(); - for (QLayer *layer : layers) - filter->removeLayer(layer); - } -} - Quick3DRayCaster::Quick3DRayCaster(QObject *parent) : QRayCaster(*new Quick3DRayCasterPrivate(), qobject_cast<Qt3DCore::QNode *>(parent)) { @@ -89,11 +56,40 @@ Quick3DRayCaster::Quick3DRayCaster(QObject *parent) QQmlListProperty<Qt3DRender::QLayer> Qt3DRender::Render::Quick::Quick3DRayCaster::qmlLayers() { - return QQmlListProperty<QLayer>(this, nullptr, - &Quick3DRayCasterPrivate::appendLayer, - &Quick3DRayCasterPrivate::layerCount, - &Quick3DRayCasterPrivate::layerAt, - &Quick3DRayCasterPrivate::clearLayers); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = Qt3DRender::QLayer; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *layer) { + QAbstractRayCaster *filter = qobject_cast<QAbstractRayCaster *>(list->object); + if (filter) + filter->addLayer(layer); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + QAbstractRayCaster *filter = qobject_cast<QAbstractRayCaster *>(list->object); + if (filter) + return int(filter->layers().size()); + return 0; + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + QAbstractRayCaster *filter = qobject_cast<QAbstractRayCaster *>(list->object); + if (filter) + return filter->layers().at(index); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + QAbstractRayCaster *filter = qobject_cast<QAbstractRayCaster *>(list->object); + if (filter) { + const auto layers = filter->layers(); + for (QLayer *layer : layers) + filter->removeLayer(layer); + } + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3draycaster_p_p.h b/src/quick3d/quick3drender/items/quick3draycaster_p_p.h index 096cae351..dd4c10e62 100644 --- a/src/quick3d/quick3drender/items/quick3draycaster_p_p.h +++ b/src/quick3d/quick3drender/items/quick3draycaster_p_p.h @@ -68,11 +68,6 @@ class Q_3DQUICKRENDERSHARED_PRIVATE_EXPORT Quick3DRayCasterPrivate : public QAbs public: explicit Quick3DRayCasterPrivate() : QAbstractRayCasterPrivate() { } - static void appendLayer(QQmlListProperty<QLayer> *list, QLayer *bar); - static QLayer *layerAt(QQmlListProperty<QLayer> *list, qsizetype index); - static qsizetype layerCount(QQmlListProperty<QLayer> *list); - static void clearLayers(QQmlListProperty<QLayer> *list); - Q_DECLARE_PUBLIC(Quick3DRayCaster) }; diff --git a/src/quick3d/quick3drender/items/quick3drenderpass.cpp b/src/quick3d/quick3drender/items/quick3drenderpass.cpp index e05bd9c74..0006191a5 100644 --- a/src/quick3d/quick3drender/items/quick3drenderpass.cpp +++ b/src/quick3d/quick3drender/items/quick3drenderpass.cpp @@ -53,110 +53,97 @@ Quick3DRenderPass::Quick3DRenderPass(QObject *parent) QQmlListProperty<QFilterKey> Quick3DRenderPass::filterKeyList() { - return QQmlListProperty<QFilterKey>(this, 0, - &Quick3DRenderPass::appendFilterKey, - &Quick3DRenderPass::filterKeysCount, - &Quick3DRenderPass::filterKeyAt, - &Quick3DRenderPass::clearFilterKey); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = QFilterKey; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *filterKey) { + Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); + rPass->parentRenderPass()->addFilterKey(filterKey); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); + return rPass->parentRenderPass()->filterKeys().count(); + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); + return rPass->parentRenderPass()->filterKeys().at(index); + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); + const auto keys = rPass->parentRenderPass()->filterKeys(); + for (QFilterKey *c : keys) + rPass->parentRenderPass()->removeFilterKey(c); + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } QQmlListProperty<QRenderState> Quick3DRenderPass::renderStateList() { - return QQmlListProperty<QRenderState>(this, 0, - &Quick3DRenderPass::appendRenderState, - &Quick3DRenderPass::renderStateCount, - &Quick3DRenderPass::renderStateAt, - &Quick3DRenderPass::clearRenderStates); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = QRenderState; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *state) { + Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); + rPass->parentRenderPass()->addRenderState(state); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); + return rPass->parentRenderPass()->renderStates().count(); + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); + return rPass->parentRenderPass()->renderStates().at(index); + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); + const auto states = rPass->parentRenderPass()->renderStates(); + for (QRenderState *s : states) + rPass->parentRenderPass()->removeRenderState(s); + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } QQmlListProperty<QParameter> Quick3DRenderPass::parameterList() { - return QQmlListProperty<QParameter>(this, 0, - &Quick3DRenderPass::appendParameter, - &Quick3DRenderPass::parametersCount, - &Quick3DRenderPass::parameterAt, - &Quick3DRenderPass::clearParameterList); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = QParameter; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *param) { + Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); + rPass->parentRenderPass()->addParameter(param); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); + return rPass->parentRenderPass()->parameters().count(); + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); + return rPass->parentRenderPass()->parameters().at(index); + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); + const auto parameters = rPass->parentRenderPass()->parameters(); + for (QParameter *p : parameters) + rPass->parentRenderPass()->removeParameter(p); + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } -void Quick3DRenderPass::appendFilterKey(QQmlListProperty<QFilterKey> *list, QFilterKey *filterKey) -{ - Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); - rPass->parentRenderPass()->addFilterKey(filterKey); -} - -QFilterKey *Quick3DRenderPass::filterKeyAt(QQmlListProperty<QFilterKey> *list, qsizetype index) -{ - Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); - return rPass->parentRenderPass()->filterKeys().at(index); -} - -qsizetype Quick3DRenderPass::filterKeysCount(QQmlListProperty<QFilterKey> *list) -{ - Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); - return rPass->parentRenderPass()->filterKeys().count(); -} - -void Quick3DRenderPass::clearFilterKey(QQmlListProperty<QFilterKey> *list) -{ - Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); - const auto keys = rPass->parentRenderPass()->filterKeys(); - for (QFilterKey *c : keys) - rPass->parentRenderPass()->removeFilterKey(c); -} - -void Quick3DRenderPass::appendRenderState(QQmlListProperty<QRenderState> *list, QRenderState *state) -{ - Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); - rPass->parentRenderPass()->addRenderState(state); -} - -QRenderState *Quick3DRenderPass::renderStateAt(QQmlListProperty<QRenderState> *list, qsizetype index) -{ - Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); - return rPass->parentRenderPass()->renderStates().at(index); -} - -qsizetype Quick3DRenderPass::renderStateCount(QQmlListProperty<QRenderState> *list) -{ - Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); - return rPass->parentRenderPass()->renderStates().count(); -} - -void Quick3DRenderPass::clearRenderStates(QQmlListProperty<QRenderState> *list) -{ - Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); - const auto states = rPass->parentRenderPass()->renderStates(); - for (QRenderState *s : states) - rPass->parentRenderPass()->removeRenderState(s); -} - -void Quick3DRenderPass::appendParameter(QQmlListProperty<QParameter> *list, QParameter *param) -{ - Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); - rPass->parentRenderPass()->addParameter(param); -} - -QParameter *Quick3DRenderPass::parameterAt(QQmlListProperty<QParameter> *list, qsizetype index) -{ - Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); - return rPass->parentRenderPass()->parameters().at(index); -} - -qsizetype Quick3DRenderPass::parametersCount(QQmlListProperty<QParameter> *list) -{ - Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); - return rPass->parentRenderPass()->parameters().count(); -} - -void Quick3DRenderPass::clearParameterList(QQmlListProperty<QParameter> *list) -{ - Quick3DRenderPass *rPass = qobject_cast<Quick3DRenderPass *>(list->object); - const auto parameters = rPass->parentRenderPass()->parameters(); - for (QParameter *p : parameters) - rPass->parentRenderPass()->removeParameter(p); -} - - } // namespace Quick } // namespace Render } // namespace Qt3DRender diff --git a/src/quick3d/quick3drender/items/quick3drenderpass_p.h b/src/quick3d/quick3drender/items/quick3drenderpass_p.h index 58ef251ff..a67605239 100644 --- a/src/quick3d/quick3drender/items/quick3drenderpass_p.h +++ b/src/quick3d/quick3drender/items/quick3drenderpass_p.h @@ -77,22 +77,6 @@ public: QQmlListProperty<QParameter> parameterList(); inline QRenderPass *parentRenderPass() const { return qobject_cast<QRenderPass *>(parent()); } - -private: - static void appendFilterKey(QQmlListProperty<QFilterKey> *list, QFilterKey *filterKey); - static QFilterKey *filterKeyAt(QQmlListProperty<QFilterKey> *list, qsizetype index); - static qsizetype filterKeysCount(QQmlListProperty<QFilterKey> *list); - static void clearFilterKey(QQmlListProperty<QFilterKey> *list); - - static void appendRenderState(QQmlListProperty<QRenderState> *list, QRenderState *state); - static QRenderState *renderStateAt(QQmlListProperty<QRenderState> *list, qsizetype index); - static qsizetype renderStateCount(QQmlListProperty<QRenderState> *list); - static void clearRenderStates(QQmlListProperty<QRenderState> *list); - - static void appendParameter(QQmlListProperty<QParameter> *list, QParameter *param); - static QParameter *parameterAt(QQmlListProperty<QParameter> *list, qsizetype index); - static qsizetype parametersCount(QQmlListProperty<QParameter> *list); - static void clearParameterList(QQmlListProperty<QParameter> *list); }; } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3drenderpassfilter.cpp b/src/quick3d/quick3drender/items/quick3drenderpassfilter.cpp index 5cf45b4a8..6323911b4 100644 --- a/src/quick3d/quick3drender/items/quick3drenderpassfilter.cpp +++ b/src/quick3d/quick3drender/items/quick3drenderpassfilter.cpp @@ -52,82 +52,79 @@ Quick3DRenderPassFilter::Quick3DRenderPassFilter(QObject *parent) QQmlListProperty<QFilterKey> Quick3DRenderPassFilter::includeList() { - return QQmlListProperty<QFilterKey>(this, 0, - &Quick3DRenderPassFilter::appendInclude, - &Quick3DRenderPassFilter::includesCount, - &Quick3DRenderPassFilter::includeAt, - &Quick3DRenderPassFilter::clearIncludes); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + auto appendFunction = [](QQmlListProperty<QFilterKey> *list, QFilterKey *v) { + auto self = qobject_cast<Quick3DRenderPassFilter *>(list->object); + if (self) { + v->setParent(self->parentRenderPassFilter()); + self->parentRenderPassFilter()->addMatch(v); + } + }; + auto countFunction = [](QQmlListProperty<QFilterKey> *list) -> qt_size_type { + auto self = qobject_cast<Quick3DRenderPassFilter *>(list->object); + if (self) + return self->parentRenderPassFilter()->matchAny().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty<QFilterKey> *list, qt_size_type index) -> QFilterKey * { + auto self = qobject_cast<Quick3DRenderPassFilter *>(list->object); + if (self) + return self->parentRenderPassFilter()->matchAny().at(index); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty<QFilterKey> *list) { + auto self = qobject_cast<Quick3DRenderPassFilter *>(list->object); + if (self) { + const auto l = self->parentRenderPassFilter()->matchAny(); + for (auto *v : l) + self->parentRenderPassFilter()->removeMatch(v); + } + }; + + return QQmlListProperty<QFilterKey>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } QQmlListProperty<QParameter> Quick3DRenderPassFilter::parameterList() { - return QQmlListProperty<QParameter>(this, 0, - &Quick3DRenderPassFilter::appendParameter, - &Quick3DRenderPassFilter::parametersCount, - &Quick3DRenderPassFilter::parameterAt, - &Quick3DRenderPassFilter::clearParameterList); - -} - -void Quick3DRenderPassFilter::appendInclude(QQmlListProperty<QFilterKey> *list, QFilterKey *annotation) -{ - Quick3DRenderPassFilter *filter = qobject_cast<Quick3DRenderPassFilter *>(list->object); - if (filter) { - annotation->setParent(filter->parentRenderPassFilter()); - filter->parentRenderPassFilter()->addMatch(annotation); - } -} - -QFilterKey *Quick3DRenderPassFilter::includeAt(QQmlListProperty<QFilterKey> *list, qsizetype index) -{ - Quick3DRenderPassFilter *filter = qobject_cast<Quick3DRenderPassFilter *>(list->object); - if (filter) - return filter->parentRenderPassFilter()->matchAny().at(index); - return 0; -} - -qsizetype Quick3DRenderPassFilter::includesCount(QQmlListProperty<QFilterKey> *list) -{ - Quick3DRenderPassFilter *filter = qobject_cast<Quick3DRenderPassFilter *>(list->object); - if (filter) - return filter->parentRenderPassFilter()->matchAny().count(); - return 0; -} - -void Quick3DRenderPassFilter::clearIncludes(QQmlListProperty<QFilterKey> *list) -{ - Quick3DRenderPassFilter *filter = qobject_cast<Quick3DRenderPassFilter *>(list->object); - if (filter) { - const auto criteria = filter->parentRenderPassFilter()->matchAny(); - for (QFilterKey *criterion : criteria) - filter->parentRenderPassFilter()->removeMatch(criterion); - } -} - -void Quick3DRenderPassFilter::appendParameter(QQmlListProperty<QParameter> *list, QParameter *param) -{ - Quick3DRenderPassFilter *rPassFilter = qobject_cast<Quick3DRenderPassFilter *>(list->object); - rPassFilter->parentRenderPassFilter()->addParameter(param); -} - -QParameter *Quick3DRenderPassFilter::parameterAt(QQmlListProperty<QParameter> *list, qsizetype index) -{ - Quick3DRenderPassFilter *rPassFilter = qobject_cast<Quick3DRenderPassFilter *>(list->object); - return rPassFilter->parentRenderPassFilter()->parameters().at(index); -} - -qsizetype Quick3DRenderPassFilter::parametersCount(QQmlListProperty<QParameter> *list) -{ - Quick3DRenderPassFilter *rPassFilter = qobject_cast<Quick3DRenderPassFilter *>(list->object); - return rPassFilter->parentRenderPassFilter()->parameters().count(); -} - -void Quick3DRenderPassFilter::clearParameterList(QQmlListProperty<QParameter> *list) -{ - Quick3DRenderPassFilter *rPassFilter = qobject_cast<Quick3DRenderPassFilter *>(list->object); - const auto parameters = rPassFilter->parentRenderPassFilter()->parameters(); - for (QParameter *p : parameters) - rPassFilter->parentRenderPassFilter()->removeParameter(p); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + auto appendFunction = [](QQmlListProperty<QParameter> *list, QParameter *v) { + auto self = qobject_cast<Quick3DRenderPassFilter *>(list->object); + if (self) { + self->parentRenderPassFilter()->addParameter(v); + } + }; + auto countFunction = [](QQmlListProperty<QParameter> *list) -> qt_size_type { + auto self = qobject_cast<Quick3DRenderPassFilter *>(list->object); + if (self) + return self->parentRenderPassFilter()->parameters().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty<QParameter> *list, qt_size_type index) -> QParameter * { + auto self = qobject_cast<Quick3DRenderPassFilter *>(list->object); + if (self) + return self->parentRenderPassFilter()->parameters().at(index); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty<QParameter> *list) { + auto self = qobject_cast<Quick3DRenderPassFilter *>(list->object); + if (self) { + const auto l = self->parentRenderPassFilter()->parameters(); + for (auto *v : l) + self->parentRenderPassFilter()->removeParameter(v); + } + }; + + return QQmlListProperty<QParameter>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3drenderpassfilter_p.h b/src/quick3d/quick3drender/items/quick3drenderpassfilter_p.h index 1f13f1d2f..03e435edb 100644 --- a/src/quick3d/quick3drender/items/quick3drenderpassfilter_p.h +++ b/src/quick3d/quick3drender/items/quick3drenderpassfilter_p.h @@ -77,17 +77,6 @@ public: QQmlListProperty<QParameter> parameterList(); inline QRenderPassFilter *parentRenderPassFilter() const { return qobject_cast<Qt3DRender::QRenderPassFilter*>(parent()); } - -private: - static void appendInclude(QQmlListProperty<QFilterKey> *list, QFilterKey *criterion); - static QFilterKey *includeAt(QQmlListProperty<QFilterKey> *list, qsizetype index); - static qsizetype includesCount(QQmlListProperty<QFilterKey> *list); - static void clearIncludes(QQmlListProperty<QFilterKey> *list); - - static void appendParameter(QQmlListProperty<QParameter> *list, QParameter *param); - static QParameter *parameterAt(QQmlListProperty<QParameter> *list, qsizetype index); - static qsizetype parametersCount(QQmlListProperty<QParameter> *list); - static void clearParameterList(QQmlListProperty<QParameter> *list); }; } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3drendertargetoutput.cpp b/src/quick3d/quick3drender/items/quick3drendertargetoutput.cpp index 5d35e7e00..810ded8b0 100644 --- a/src/quick3d/quick3drender/items/quick3drendertargetoutput.cpp +++ b/src/quick3d/quick3drender/items/quick3drendertargetoutput.cpp @@ -52,44 +52,40 @@ Quick3DRenderTargetOutput::Quick3DRenderTargetOutput(QObject * parent) QQmlListProperty<QRenderTargetOutput> Quick3DRenderTargetOutput::qmlAttachments() { - return QQmlListProperty<QRenderTargetOutput>(this, 0, - &Quick3DRenderTargetOutput::appendRenderAttachment, - &Quick3DRenderTargetOutput::renderAttachmentCount, - &Quick3DRenderTargetOutput::renderAttachmentAt, - &Quick3DRenderTargetOutput::clearRenderAttachments); -} - -void Quick3DRenderTargetOutput::appendRenderAttachment(QQmlListProperty<QRenderTargetOutput> *list, QRenderTargetOutput *output) -{ - Quick3DRenderTargetOutput *rT = qobject_cast<Quick3DRenderTargetOutput *>(list->object); - if (rT) - rT->parentRenderTarget()->addOutput(output); -} - -QRenderTargetOutput *Quick3DRenderTargetOutput::renderAttachmentAt(QQmlListProperty<QRenderTargetOutput> *list, qsizetype index) -{ - Quick3DRenderTargetOutput *rT = qobject_cast<Quick3DRenderTargetOutput *>(list->object); - if (rT) - return rT->parentRenderTarget()->outputs().at(index); - return nullptr; -} +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif -qsizetype Quick3DRenderTargetOutput::renderAttachmentCount(QQmlListProperty<QRenderTargetOutput> *list) -{ - Quick3DRenderTargetOutput *rT = qobject_cast<Quick3DRenderTargetOutput *>(list->object); - if (rT) - return rT->parentRenderTarget()->outputs().count(); - return -1; -} + using ListContentType = QRenderTargetOutput; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *output) { + Quick3DRenderTargetOutput *rT = qobject_cast<Quick3DRenderTargetOutput *>(list->object); + if (rT) + rT->parentRenderTarget()->addOutput(output); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DRenderTargetOutput *rT = qobject_cast<Quick3DRenderTargetOutput *>(list->object); + if (rT) + return rT->parentRenderTarget()->outputs().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DRenderTargetOutput *rT = qobject_cast<Quick3DRenderTargetOutput *>(list->object); + if (rT) + return rT->parentRenderTarget()->outputs().at(index); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DRenderTargetOutput *rT = qobject_cast<Quick3DRenderTargetOutput *>(list->object); + if (rT) { + const auto outputs = rT->parentRenderTarget()->outputs(); + for (QRenderTargetOutput *output : outputs) + rT->parentRenderTarget()->removeOutput(output); + } + }; -void Quick3DRenderTargetOutput::clearRenderAttachments(QQmlListProperty<QRenderTargetOutput> *list) -{ - Quick3DRenderTargetOutput *rT = qobject_cast<Quick3DRenderTargetOutput *>(list->object); - if (rT) { - const auto outputs = rT->parentRenderTarget()->outputs(); - for (QRenderTargetOutput *output : outputs) - rT->parentRenderTarget()->removeOutput(output); - } + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3drendertargetoutput_p.h b/src/quick3d/quick3drender/items/quick3drendertargetoutput_p.h index 076d034ed..df250929e 100644 --- a/src/quick3d/quick3drender/items/quick3drendertargetoutput_p.h +++ b/src/quick3d/quick3drender/items/quick3drendertargetoutput_p.h @@ -68,16 +68,10 @@ class Q_3DQUICKRENDERSHARED_PRIVATE_EXPORT Quick3DRenderTargetOutput : public QO Q_OBJECT Q_PROPERTY(QQmlListProperty<Qt3DRender::QRenderTargetOutput> attachments READ qmlAttachments) public: - explicit Quick3DRenderTargetOutput(QObject *parent = 0); + explicit Quick3DRenderTargetOutput(QObject *parent = nullptr); inline QRenderTarget *parentRenderTarget() const { return qobject_cast<QRenderTarget *>(parent()); } QQmlListProperty<QRenderTargetOutput> qmlAttachments(); - -private: - static void appendRenderAttachment(QQmlListProperty<QRenderTargetOutput> *list, QRenderTargetOutput *attachment); - static QRenderTargetOutput *renderAttachmentAt(QQmlListProperty<QRenderTargetOutput> *list, qsizetype index); - static qsizetype renderAttachmentCount(QQmlListProperty<QRenderTargetOutput> *list); - static void clearRenderAttachments(QQmlListProperty<QRenderTargetOutput> *list); }; } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3dscreenraycaster.cpp b/src/quick3d/quick3drender/items/quick3dscreenraycaster.cpp index 03d6268c3..206073426 100644 --- a/src/quick3d/quick3drender/items/quick3dscreenraycaster.cpp +++ b/src/quick3d/quick3drender/items/quick3dscreenraycaster.cpp @@ -60,11 +60,40 @@ Quick3DScreenRayCaster::Quick3DScreenRayCaster(QObject *parent) QQmlListProperty<Qt3DRender::QLayer> Qt3DRender::Render::Quick::Quick3DScreenRayCaster::qmlLayers() { - return QQmlListProperty<QLayer>(this, nullptr, - &Quick3DRayCasterPrivate::appendLayer, - &Quick3DRayCasterPrivate::layerCount, - &Quick3DRayCasterPrivate::layerAt, - &Quick3DRayCasterPrivate::clearLayers); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = Qt3DRender::QLayer; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *layer) { + QAbstractRayCaster *filter = qobject_cast<QAbstractRayCaster *>(list->object); + if (filter) + filter->addLayer(layer); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + QAbstractRayCaster *filter = qobject_cast<QAbstractRayCaster *>(list->object); + if (filter) + return int(filter->layers().size()); + return 0; + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + QAbstractRayCaster *filter = qobject_cast<QAbstractRayCaster *>(list->object); + if (filter) + return filter->layers().at(index); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + QAbstractRayCaster *filter = qobject_cast<QAbstractRayCaster *>(list->object); + if (filter) { + const auto layers = filter->layers(); + for (QLayer *layer : layers) + filter->removeLayer(layer); + } + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3dshaderdataarray.cpp b/src/quick3d/quick3drender/items/quick3dshaderdataarray.cpp index 51e8911a6..146a17477 100644 --- a/src/quick3d/quick3drender/items/quick3dshaderdataarray.cpp +++ b/src/quick3d/quick3drender/items/quick3dshaderdataarray.cpp @@ -63,11 +63,31 @@ Quick3DShaderDataArray::Quick3DShaderDataArray(QNode *parent) QQmlListProperty<QShaderData> Quick3DShaderDataArray::valuesList() { - return QQmlListProperty<QShaderData>(this, 0, - &Quick3DShaderDataArray::appendValue, - &Quick3DShaderDataArray::valueCount, - &Quick3DShaderDataArray::valueAt, - &Quick3DShaderDataArray::clearValues); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = QShaderData; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *bar) { + Quick3DShaderDataArray *self = static_cast<Quick3DShaderDataArray *>(list->object); + static_cast<Quick3DShaderDataArrayPrivate *>(Quick3DShaderDataArrayPrivate::get(self))->m_values.append(bar); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DShaderDataArray *self = static_cast<Quick3DShaderDataArray *>(list->object); + return static_cast<Quick3DShaderDataArrayPrivate *>(Quick3DShaderDataArrayPrivate::get(self))->m_values.count(); + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DShaderDataArray *self = static_cast<Quick3DShaderDataArray *>(list->object); + return static_cast<Quick3DShaderDataArrayPrivate *>(Quick3DShaderDataArrayPrivate::get(self))->m_values.at(index); + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DShaderDataArray *self = static_cast<Quick3DShaderDataArray *>(list->object); + static_cast<Quick3DShaderDataArrayPrivate *>(Quick3DShaderDataArrayPrivate::get(self))->m_values.clear(); + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } QList<QShaderData *> Quick3DShaderDataArray::values() const @@ -85,30 +105,6 @@ QList<QShaderData *> Quick3DShaderDataArray::values() const // d_func()->m_values.append(static_cast<QShaderData *>(QNode::clone(v))); //} -void Quick3DShaderDataArray::appendValue(QQmlListProperty<QShaderData> *list, QShaderData *bar) -{ - Quick3DShaderDataArray *self = static_cast<Quick3DShaderDataArray *>(list->object); - static_cast<Quick3DShaderDataArrayPrivate *>(Quick3DShaderDataArrayPrivate::get(self))->m_values.append(bar); -} - -QShaderData *Quick3DShaderDataArray::valueAt(QQmlListProperty<QShaderData> *list, qsizetype index) -{ - Quick3DShaderDataArray *self = static_cast<Quick3DShaderDataArray *>(list->object); - return static_cast<Quick3DShaderDataArrayPrivate *>(Quick3DShaderDataArrayPrivate::get(self))->m_values.at(index); -} - -qsizetype Quick3DShaderDataArray::valueCount(QQmlListProperty<QShaderData> *list) -{ - Quick3DShaderDataArray *self = static_cast<Quick3DShaderDataArray *>(list->object); - return static_cast<Quick3DShaderDataArrayPrivate *>(Quick3DShaderDataArrayPrivate::get(self))->m_values.count(); -} - -void Quick3DShaderDataArray::clearValues(QQmlListProperty<QShaderData> *list) -{ - Quick3DShaderDataArray *self = static_cast<Quick3DShaderDataArray *>(list->object); - static_cast<Quick3DShaderDataArrayPrivate *>(Quick3DShaderDataArrayPrivate::get(self))->m_values.clear(); -} - } // namespace Quick } // namespace Render } // namespace Qt3DRender diff --git a/src/quick3d/quick3drender/items/quick3dshaderdataarray_p.h b/src/quick3d/quick3drender/items/quick3dshaderdataarray_p.h index 4a1347cf8..6e800328a 100644 --- a/src/quick3d/quick3drender/items/quick3dshaderdataarray_p.h +++ b/src/quick3d/quick3drender/items/quick3dshaderdataarray_p.h @@ -76,15 +76,11 @@ class Q_3DQUICKRENDERSHARED_PRIVATE_EXPORT Quick3DShaderDataArray : public Qt3DC Q_CLASSINFO("DefaultProperty", "values") public: - explicit Quick3DShaderDataArray(Qt3DCore::QNode *parent = 0); + explicit Quick3DShaderDataArray(Qt3DCore::QNode *parent = nullptr); QQmlListProperty<QShaderData> valuesList(); QList<QShaderData *> values() const; private: - static void appendValue(QQmlListProperty<QShaderData> *list, QShaderData *bar); - static QShaderData *valueAt(QQmlListProperty<QShaderData> *list, qsizetype index); - static qsizetype valueCount(QQmlListProperty<QShaderData> *list); - static void clearValues(QQmlListProperty<QShaderData> *list); Q_DECLARE_PRIVATE(Quick3DShaderDataArray) }; diff --git a/src/quick3d/quick3drender/items/quick3dstateset.cpp b/src/quick3d/quick3drender/items/quick3dstateset.cpp index 49fa0b96a..396fab309 100644 --- a/src/quick3d/quick3drender/items/quick3dstateset.cpp +++ b/src/quick3d/quick3drender/items/quick3dstateset.cpp @@ -56,38 +56,33 @@ Quick3DStateSet::~Quick3DStateSet() QQmlListProperty<QRenderState> Quick3DStateSet::renderStateList() { - return QQmlListProperty<QRenderState>(this, 0, - &Quick3DStateSet::appendRenderState, - &Quick3DStateSet::renderStateCount, - &Quick3DStateSet::renderStateAt, - &Quick3DStateSet::clearRenderStates); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif -} - -void Quick3DStateSet::appendRenderState(QQmlListProperty<QRenderState> *list, QRenderState *state) -{ - Quick3DStateSet *stateSet = qobject_cast<Quick3DStateSet *>(list->object); - stateSet->parentStateSet()->addRenderState(state); -} + using ListContentType = QRenderState; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *state) { + Quick3DStateSet *stateSet = qobject_cast<Quick3DStateSet *>(list->object); + stateSet->parentStateSet()->addRenderState(state); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DStateSet *stateSet = qobject_cast<Quick3DStateSet *>(list->object); + return stateSet->parentStateSet()->renderStates().count(); + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DStateSet *stateSet = qobject_cast<Quick3DStateSet *>(list->object); + return stateSet->parentStateSet()->renderStates().at(index); + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DStateSet *stateSet = qobject_cast<Quick3DStateSet *>(list->object); + const auto states = stateSet->parentStateSet()->renderStates(); + for (QRenderState *s : states) + stateSet->parentStateSet()->removeRenderState(s); + }; -QRenderState *Quick3DStateSet::renderStateAt(QQmlListProperty<QRenderState> *list, qsizetype index) -{ - Quick3DStateSet *stateSet = qobject_cast<Quick3DStateSet *>(list->object); - return stateSet->parentStateSet()->renderStates().at(index); -} - -qsizetype Quick3DStateSet::renderStateCount(QQmlListProperty<QRenderState> *list) -{ - Quick3DStateSet *stateSet = qobject_cast<Quick3DStateSet *>(list->object); - return stateSet->parentStateSet()->renderStates().count(); -} - -void Quick3DStateSet::clearRenderStates(QQmlListProperty<QRenderState> *list) -{ - Quick3DStateSet *stateSet = qobject_cast<Quick3DStateSet *>(list->object); - const auto states = stateSet->parentStateSet()->renderStates(); - for (QRenderState *s : states) - stateSet->parentStateSet()->removeRenderState(s); + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3dstateset_p.h b/src/quick3d/quick3drender/items/quick3dstateset_p.h index 4d060e149..f4bd13cd2 100644 --- a/src/quick3d/quick3drender/items/quick3dstateset_p.h +++ b/src/quick3d/quick3drender/items/quick3dstateset_p.h @@ -67,17 +67,11 @@ class Q_3DQUICKRENDERSHARED_PRIVATE_EXPORT Quick3DStateSet : public QObject Q_OBJECT Q_PROPERTY(QQmlListProperty<Qt3DRender::QRenderState> renderStates READ renderStateList CONSTANT) public: - explicit Quick3DStateSet(QObject *parent = 0); + explicit Quick3DStateSet(QObject *parent = nullptr); ~Quick3DStateSet(); QQmlListProperty<QRenderState> renderStateList(); inline QRenderStateSet *parentStateSet() const { return qobject_cast<QRenderStateSet *>(parent()); } - -private: - static void appendRenderState(QQmlListProperty<QRenderState> *list, QRenderState *state); - static QRenderState *renderStateAt(QQmlListProperty<QRenderState> *list, qsizetype index); - static qsizetype renderStateCount(QQmlListProperty<QRenderState> *list); - static void clearRenderStates(QQmlListProperty<QRenderState> *list); }; } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3dtechnique.cpp b/src/quick3d/quick3drender/items/quick3dtechnique.cpp index 805748a1c..edc6f3da2 100644 --- a/src/quick3d/quick3drender/items/quick3dtechnique.cpp +++ b/src/quick3d/quick3drender/items/quick3dtechnique.cpp @@ -52,125 +52,112 @@ Quick3DTechnique::Quick3DTechnique(QObject *parent) QQmlListProperty<QRenderPass> Quick3DTechnique::renderPassList() { - return QQmlListProperty<QRenderPass>(this, 0, - &Quick3DTechnique::appendRenderPass, - &Quick3DTechnique::renderPassCount, - &Quick3DTechnique::renderPassAt, - &Quick3DTechnique::clearRenderPasses); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = QRenderPass; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *renderPass) { + Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); + if (technique) + technique->parentTechnique()->addRenderPass(renderPass); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); + if (technique) + return technique->parentTechnique()->renderPasses().size(); + return 0; + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); + if (technique) + return qobject_cast<QRenderPass *>(technique->parentTechnique()->renderPasses().at(index)); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); + if (technique) { + const auto passes = technique->parentTechnique()->renderPasses(); + for (QRenderPass *pass : passes) + technique->parentTechnique()->removeRenderPass(pass); + } + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } QQmlListProperty<QParameter> Quick3DTechnique::parameterList() { - return QQmlListProperty<QParameter>(this, 0, - &Quick3DTechnique::appendParameter, - &Quick3DTechnique::parametersCount, - &Quick3DTechnique::parameterAt, - &Quick3DTechnique::clearParameterList); -} - -void Quick3DTechnique::appendParameter(QQmlListProperty<QParameter> *list, QParameter *param) -{ - Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); - technique->parentTechnique()->addParameter(param); -} - -QParameter *Quick3DTechnique::parameterAt(QQmlListProperty<QParameter> *list, qsizetype index) -{ - Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); - return technique->parentTechnique()->parameters().at(index); -} - -qsizetype Quick3DTechnique::parametersCount(QQmlListProperty<QParameter> *list) -{ - Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); - return technique->parentTechnique()->parameters().count(); -} - -void Quick3DTechnique::clearParameterList(QQmlListProperty<QParameter> *list) -{ - Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); - const auto parameters = technique->parentTechnique()->parameters(); - for (QParameter *p : parameters) - technique->parentTechnique()->removeParameter(p); -} - -void Quick3DTechnique::appendRenderPass(QQmlListProperty<QRenderPass> *list, QRenderPass *renderPass) -{ - Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); - if (technique) { - technique->parentTechnique()->addRenderPass(renderPass); - } -} - -QRenderPass *Quick3DTechnique::renderPassAt(QQmlListProperty<QRenderPass> *list, qsizetype index) -{ - Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); - if (technique) - return qobject_cast<QRenderPass *>(technique->parentTechnique()->renderPasses().at(index)); - return 0; -} - -qsizetype Quick3DTechnique::renderPassCount(QQmlListProperty<QRenderPass> *list) -{ - Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); - if (technique) - return technique->parentTechnique()->renderPasses().size(); - return 0; -} - -void Quick3DTechnique::clearRenderPasses(QQmlListProperty<QRenderPass> *list) -{ - Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); - if (technique) { - const auto passes = technique->parentTechnique()->renderPasses(); - for (QRenderPass *pass : passes) - technique->parentTechnique()->removeRenderPass(pass); - } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = QParameter; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *param) { + Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); + technique->parentTechnique()->addParameter(param); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); + return technique->parentTechnique()->parameters().count(); + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); + return technique->parentTechnique()->parameters().at(index); + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); + const auto parameters = technique->parentTechnique()->parameters(); + for (QParameter *p : parameters) + technique->parentTechnique()->removeParameter(p); + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } QQmlListProperty<QFilterKey> Quick3DTechnique::filterKeyList() { - return QQmlListProperty<QFilterKey>(this, 0, - &Quick3DTechnique::appendFilterKey, - &Quick3DTechnique::filterKeyCount, - &Quick3DTechnique::filterKeyAt, - &Quick3DTechnique::clearFilterKeyList); -} - -void Quick3DTechnique::appendFilterKey(QQmlListProperty<QFilterKey> *list, QFilterKey *filterKey) -{ - Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); - if (technique) { - if (!filterKey->parent()) - filterKey->setParent(technique->parentTechnique()); - technique->parentTechnique()->addFilterKey(filterKey); - } -} - -QFilterKey *Quick3DTechnique::filterKeyAt(QQmlListProperty<QFilterKey> *list, qsizetype index) -{ - Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); - if (technique) - return technique->parentTechnique()->filterKeys().at(index); - return 0; -} - -qsizetype Quick3DTechnique::filterKeyCount(QQmlListProperty<QFilterKey> *list) -{ - Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); - if (technique) - return technique->parentTechnique()->filterKeys().size(); - return 0; -} - -void Quick3DTechnique::clearFilterKeyList(QQmlListProperty<QFilterKey> *list) -{ - Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); - if (technique) { - const auto keys = technique->parentTechnique()->filterKeys(); - for (QFilterKey *a : keys) - technique->parentTechnique()->removeFilterKey(a); - } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = QFilterKey; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *filterKey) { + Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); + if (technique) { + if (!filterKey->parent()) + filterKey->setParent(technique->parentTechnique()); + technique->parentTechnique()->addFilterKey(filterKey); + } + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); + if (technique) + return technique->parentTechnique()->filterKeys().size(); + return 0; + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); + if (technique) + return technique->parentTechnique()->filterKeys().at(index); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DTechnique *technique = qobject_cast<Quick3DTechnique *>(list->object); + if (technique) { + const auto keys = technique->parentTechnique()->filterKeys(); + for (QFilterKey *a : keys) + technique->parentTechnique()->removeFilterKey(a); + } + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3dtechnique_p.h b/src/quick3d/quick3drender/items/quick3dtechnique_p.h index 425eb0b25..e8b2fbc0b 100644 --- a/src/quick3d/quick3drender/items/quick3dtechnique_p.h +++ b/src/quick3d/quick3drender/items/quick3dtechnique_p.h @@ -77,23 +77,6 @@ public: // Use QAbstractTechnique when it has been properly defined inline QTechnique *parentTechnique() const { return qobject_cast<QTechnique*>(parent()); } - -private: - - static void appendParameter(QQmlListProperty<QParameter> *list, QParameter *param); - static QParameter *parameterAt(QQmlListProperty<QParameter> *list, qsizetype index); - static qsizetype parametersCount(QQmlListProperty<QParameter> *list); - static void clearParameterList(QQmlListProperty<QParameter> *list); - - static void appendFilterKey(QQmlListProperty<QFilterKey> *list, QFilterKey *filterKey); - static QFilterKey *filterKeyAt(QQmlListProperty<QFilterKey> *list, qsizetype index); - static qsizetype filterKeyCount(QQmlListProperty<QFilterKey> *list); - static void clearFilterKeyList(QQmlListProperty<QFilterKey> *list); - - static void appendRenderPass(QQmlListProperty<QRenderPass> *list, QRenderPass* renderPass); - static QRenderPass *renderPassAt(QQmlListProperty<QRenderPass> *list, qsizetype index); - static qsizetype renderPassCount(QQmlListProperty<QRenderPass> *list); - static void clearRenderPasses( QQmlListProperty<QRenderPass> *list); }; } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3dtechniquefilter.cpp b/src/quick3d/quick3drender/items/quick3dtechniquefilter.cpp index 01e114fab..0de7fe5ba 100644 --- a/src/quick3d/quick3drender/items/quick3dtechniquefilter.cpp +++ b/src/quick3d/quick3drender/items/quick3dtechniquefilter.cpp @@ -52,81 +52,73 @@ Quick3DTechniqueFilter::Quick3DTechniqueFilter(QObject *parent) QQmlListProperty<QFilterKey> Quick3DTechniqueFilter::matchList() { - return QQmlListProperty<QFilterKey>(this, 0, - &Quick3DTechniqueFilter::appendRequire, - &Quick3DTechniqueFilter::requiresCount, - &Quick3DTechniqueFilter::requireAt, - &Quick3DTechniqueFilter::clearRequires); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = QFilterKey; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *criterion) { + Quick3DTechniqueFilter *filter = qobject_cast<Quick3DTechniqueFilter *>(list->object); + if (filter) { + criterion->setParent(filter->parentTechniqueFilter()); + filter->parentTechniqueFilter()->addMatch(criterion); + } + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DTechniqueFilter *filter = qobject_cast<Quick3DTechniqueFilter *>(list->object); + if (filter) + return filter->parentTechniqueFilter()->matchAll().size(); + return 0; + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DTechniqueFilter *filter = qobject_cast<Quick3DTechniqueFilter *>(list->object); + if (filter) + return filter->parentTechniqueFilter()->matchAll().at(index); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DTechniqueFilter *filter = qobject_cast<Quick3DTechniqueFilter *>(list->object); + if (filter) { + const auto criteria = filter->parentTechniqueFilter()->matchAll(); + for (QFilterKey *criterion : criteria) + filter->parentTechniqueFilter()->removeMatch(criterion); + } + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } QQmlListProperty<QParameter> Quick3DTechniqueFilter::parameterList() { - return QQmlListProperty<QParameter>(this, 0, - &Quick3DTechniqueFilter::appendParameter, - &Quick3DTechniqueFilter::parametersCount, - &Quick3DTechniqueFilter::parameterAt, - &Quick3DTechniqueFilter::clearParameterList); -} - -void Quick3DTechniqueFilter::appendRequire(QQmlListProperty<QFilterKey> *list, QFilterKey *criterion) -{ - Quick3DTechniqueFilter *filter = qobject_cast<Quick3DTechniqueFilter *>(list->object); - if (filter) { - criterion->setParent(filter->parentTechniqueFilter()); - filter->parentTechniqueFilter()->addMatch(criterion); - } -} - -QFilterKey *Quick3DTechniqueFilter::requireAt(QQmlListProperty<QFilterKey> *list, qsizetype index) -{ - Quick3DTechniqueFilter *filter = qobject_cast<Quick3DTechniqueFilter *>(list->object); - if (filter) - return filter->parentTechniqueFilter()->matchAll().at(index); - return 0; -} - -qsizetype Quick3DTechniqueFilter::requiresCount(QQmlListProperty<QFilterKey> *list) -{ - Quick3DTechniqueFilter *filter = qobject_cast<Quick3DTechniqueFilter *>(list->object); - if (filter) - return filter->parentTechniqueFilter()->matchAll().size(); - return 0; -} - -void Quick3DTechniqueFilter::clearRequires(QQmlListProperty<QFilterKey> *list) -{ - Quick3DTechniqueFilter *filter = qobject_cast<Quick3DTechniqueFilter *>(list->object); - if (filter) { - const auto criteria = filter->parentTechniqueFilter()->matchAll(); - for (QFilterKey *criterion : criteria) - filter->parentTechniqueFilter()->removeMatch(criterion); - } -} - -void Quick3DTechniqueFilter::appendParameter(QQmlListProperty<QParameter> *list, QParameter *param) -{ - Quick3DTechniqueFilter *techniqueFilter = qobject_cast<Quick3DTechniqueFilter *>(list->object); - techniqueFilter->parentTechniqueFilter()->addParameter(param); -} - -QParameter *Quick3DTechniqueFilter::parameterAt(QQmlListProperty<QParameter> *list, qsizetype index) -{ - Quick3DTechniqueFilter *techniqueFilter = qobject_cast<Quick3DTechniqueFilter *>(list->object); - return techniqueFilter->parentTechniqueFilter()->parameters().at(index); -} - -qsizetype Quick3DTechniqueFilter::parametersCount(QQmlListProperty<QParameter> *list) -{ - Quick3DTechniqueFilter *techniqueFilter = qobject_cast<Quick3DTechniqueFilter *>(list->object); - return techniqueFilter->parentTechniqueFilter()->parameters().count(); -} - -void Quick3DTechniqueFilter::clearParameterList(QQmlListProperty<QParameter> *list) -{ - Quick3DTechniqueFilter *techniqueFilter = qobject_cast<Quick3DTechniqueFilter *>(list->object); - const auto parameters = techniqueFilter->parentTechniqueFilter()->parameters(); - for (QParameter *p : parameters) - techniqueFilter->parentTechniqueFilter()->removeParameter(p); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif + + using ListContentType = QParameter; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *param) { + Quick3DTechniqueFilter *techniqueFilter = qobject_cast<Quick3DTechniqueFilter *>(list->object); + techniqueFilter->parentTechniqueFilter()->addParameter(param); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DTechniqueFilter *techniqueFilter = qobject_cast<Quick3DTechniqueFilter *>(list->object); + return techniqueFilter->parentTechniqueFilter()->parameters().count(); + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DTechniqueFilter *techniqueFilter = qobject_cast<Quick3DTechniqueFilter *>(list->object); + return techniqueFilter->parentTechniqueFilter()->parameters().at(index); + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + Quick3DTechniqueFilter *techniqueFilter = qobject_cast<Quick3DTechniqueFilter *>(list->object); + const auto parameters = techniqueFilter->parentTechniqueFilter()->parameters(); + for (QParameter *p : parameters) + techniqueFilter->parentTechniqueFilter()->removeParameter(p); + }; + + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3dtechniquefilter_p.h b/src/quick3d/quick3drender/items/quick3dtechniquefilter_p.h index 9a2b396ac..22900d175 100644 --- a/src/quick3d/quick3drender/items/quick3dtechniquefilter_p.h +++ b/src/quick3d/quick3drender/items/quick3dtechniquefilter_p.h @@ -77,17 +77,6 @@ public: QQmlListProperty<QParameter> parameterList(); inline QTechniqueFilter *parentTechniqueFilter() const { return qobject_cast<QTechniqueFilter*>(parent()); } - -private: - static void appendRequire(QQmlListProperty<QFilterKey> *list, QFilterKey *criterion); - static QFilterKey *requireAt(QQmlListProperty<QFilterKey> *list, qsizetype index); - static qsizetype requiresCount(QQmlListProperty<QFilterKey> *list); - static void clearRequires(QQmlListProperty<QFilterKey> *list); - - static void appendParameter(QQmlListProperty<QParameter> *list, QParameter *param); - static QParameter *parameterAt(QQmlListProperty<QParameter> *list, qsizetype index); - static qsizetype parametersCount(QQmlListProperty<QParameter> *list); - static void clearParameterList(QQmlListProperty<QParameter> *list); }; } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3dtexture.cpp b/src/quick3d/quick3drender/items/quick3dtexture.cpp index 01f36542d..8e1deed1c 100644 --- a/src/quick3d/quick3drender/items/quick3dtexture.cpp +++ b/src/quick3d/quick3drender/items/quick3dtexture.cpp @@ -54,43 +54,39 @@ Quick3DTextureExtension::Quick3DTextureExtension(QObject *parent) QQmlListProperty<QAbstractTextureImage> Quick3DTextureExtension::textureImages() { - return QQmlListProperty<QAbstractTextureImage>(this, 0, - &Quick3DTextureExtension::appendTextureImage, - &Quick3DTextureExtension::textureImageCount, - &Quick3DTextureExtension::textureImageAt, - &Quick3DTextureExtension::clearTextureImageList); -} - -void Quick3DTextureExtension::appendTextureImage(QQmlListProperty<QAbstractTextureImage> *list, QAbstractTextureImage *textureImage) -{ - Quick3DTextureExtension *self = qobject_cast<Quick3DTextureExtension *>(list->object); - if (self) - self->parentTexture()->addTextureImage(textureImage); -} - -QAbstractTextureImage *Quick3DTextureExtension::textureImageAt(QQmlListProperty<QAbstractTextureImage> *list, qsizetype index) -{ - Quick3DTextureExtension *self = qobject_cast<Quick3DTextureExtension *>(list->object); - if (self) - return self->parentTexture()->textureImages().at(index); - return nullptr; -} +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + using qt_size_type = qsizetype; +#else + using qt_size_type = int; +#endif -qsizetype Quick3DTextureExtension::textureImageCount(QQmlListProperty<QAbstractTextureImage> *list) -{ - Quick3DTextureExtension *self = qobject_cast<Quick3DTextureExtension *>(list->object); - if (self) - return self->parentTexture()->textureImages().count(); - return 0; -} + using ListContentType = QAbstractTextureImage; + auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *textureImage) { + Quick3DTextureExtension *self = qobject_cast<Quick3DTextureExtension *>(list->object); + if (self) + self->parentTexture()->addTextureImage(textureImage); + }; + auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { + Quick3DTextureExtension *self = qobject_cast<Quick3DTextureExtension *>(list->object); + if (self) + return self->parentTexture()->textureImages().count(); + return 0; + }; + auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { + Quick3DTextureExtension *self = qobject_cast<Quick3DTextureExtension *>(list->object); + if (self) + return self->parentTexture()->textureImages().at(index); + return nullptr; + }; + auto clearFunction = [](QQmlListProperty<ListContentType> *list) { + if (Quick3DTextureExtension *self = qobject_cast<Quick3DTextureExtension *>(list->object)) { + const auto images = self->parentTexture()->textureImages(); + for (QAbstractTextureImage *img : images) + self->parentTexture()->removeTextureImage(img); + } + }; -void Quick3DTextureExtension::clearTextureImageList(QQmlListProperty<QAbstractTextureImage> *list) -{ - if (Quick3DTextureExtension *self = qobject_cast<Quick3DTextureExtension *>(list->object)) { - const auto images = self->parentTexture()->textureImages(); - for (QAbstractTextureImage *img : images) - self->parentTexture()->removeTextureImage(img); - } + return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); } } // namespace Quick diff --git a/src/quick3d/quick3drender/items/quick3dtexture_p.h b/src/quick3d/quick3drender/items/quick3dtexture_p.h index 2f22d404e..a401a6932 100644 --- a/src/quick3d/quick3drender/items/quick3dtexture_p.h +++ b/src/quick3d/quick3drender/items/quick3dtexture_p.h @@ -70,16 +70,10 @@ class Q_3DQUICKRENDERSHARED_PRIVATE_EXPORT Quick3DTextureExtension : public QObj Q_CLASSINFO("DefaultProperty", "textureImages") public: - explicit Quick3DTextureExtension(QObject *parent = 0); + explicit Quick3DTextureExtension(QObject *parent = nullptr); QQmlListProperty<QAbstractTextureImage> textureImages(); inline QAbstractTexture *parentTexture() const { return qobject_cast<QAbstractTexture *>(parent()); } - -private: - static void appendTextureImage(QQmlListProperty<QAbstractTextureImage> *list, QAbstractTextureImage *textureImage); - static QAbstractTextureImage *textureImageAt(QQmlListProperty<QAbstractTextureImage> *list, qsizetype index); - static qsizetype textureImageCount(QQmlListProperty<QAbstractTextureImage> *list); - static void clearTextureImageList(QQmlListProperty<QAbstractTextureImage> *list); }; } // namespace Quick |