1// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include <Qt3DRender/qeffect.h>
5
6#include <Qt3DQuickRender/private/quick3deffect_p.h>
7
8QT_BEGIN_NAMESPACE
9
10namespace Qt3DRender {
11namespace Render {
12namespace Quick {
13
14Quick3DEffect::Quick3DEffect(QObject *parent)
15 : QObject(parent)
16{
17}
18
19QQmlListProperty<QTechnique> Quick3DEffect::techniqueList()
20{
21 using qt_size_type = qsizetype;
22 using ListContentType = QTechnique;
23 auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *bar) {
24 Quick3DEffect *eff = qobject_cast<Quick3DEffect*>(object: list->object);
25 if (eff)
26 eff->parentEffect()->addTechnique(t: bar);
27 };
28 auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type {
29 Quick3DEffect *eff = qobject_cast<Quick3DEffect*>(object: list->object);
30 if (eff)
31 return eff->parentEffect()->techniques().size();
32 return 0;
33 };
34 auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * {
35 // TO DO : Return a QAbstractTechnique once properly defined
36 Quick3DEffect *eff = qobject_cast<Quick3DEffect*>(object: list->object);
37 if (eff)
38 return qobject_cast<QTechnique*>(object: eff->parentEffect()->techniques().at(i: index));
39 return nullptr;
40 };
41 auto clearFunction = [](QQmlListProperty<ListContentType> *list) {
42 Quick3DEffect *eff = qobject_cast<Quick3DEffect*>(object: list->object);
43 if (eff) {
44 // Ownership of techniques is handled by the QmlEngine so we shouldn't class clearTechniques
45 // which deletes techniques
46 const auto techniques = eff->parentEffect()->techniques();
47 for (QTechnique *tech : techniques)
48 eff->parentEffect()->removeTechnique(t: tech);
49 }
50 };
51
52 return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction);
53}
54
55QQmlListProperty<QParameter> Quick3DEffect::parameterList()
56{
57 using qt_size_type = qsizetype;
58 using ListContentType = QParameter;
59 auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *param) {
60 Quick3DEffect *effect = qobject_cast<Quick3DEffect *>(object: list->object);
61 qobject_cast<QEffect *>(object: effect->parentEffect())->addParameter(parameter: param);
62 };
63 auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type {
64 Quick3DEffect *effect = qobject_cast<Quick3DEffect *>(object: list->object);
65 return qobject_cast<QEffect *>(object: effect->parentEffect())->parameters().size();
66 };
67 auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * {
68 Quick3DEffect *effect = qobject_cast<Quick3DEffect *>(object: list->object);
69 return qobject_cast<QEffect *>(object: effect->parentEffect())->parameters().at(i: index);
70 };
71 auto clearFunction = [](QQmlListProperty<ListContentType> *list) {
72 Quick3DEffect *effect = qobject_cast<Quick3DEffect *>(object: list->object);
73 const auto parameters = qobject_cast<QEffect *>(object: effect->parentEffect())->parameters();
74 for (QParameter *p : parameters)
75 qobject_cast<QEffect *>(object: effect->parentEffect())->removeParameter(parameter: p);
76 };
77
78 return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction);
79}
80
81} // namespace Quick
82} // namespace Render
83} // namespace Qt3DRender
84
85QT_END_NAMESPACE
86
87#include "moc_quick3deffect_p.cpp"
88

source code of qt3d/src/quick3d/quick3drender/items/quick3deffect.cpp