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/qtexture.h> |
5 | |
6 | #include <Qt3DQuickRender/private/quick3dmaterial_p.h> |
7 | |
8 | QT_BEGIN_NAMESPACE |
9 | |
10 | namespace Qt3DRender { |
11 | |
12 | namespace Render { |
13 | |
14 | namespace Quick { |
15 | |
16 | Quick3DMaterial::Quick3DMaterial(QObject *parent) |
17 | : QObject(parent) |
18 | { |
19 | } |
20 | |
21 | QQmlListProperty<QParameter> Quick3DMaterial::qmlParameters() |
22 | { |
23 | using qt_size_type = qsizetype; |
24 | using ListContentType = QParameter; |
25 | auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *param) { |
26 | Quick3DMaterial *mat = qobject_cast<Quick3DMaterial *>(object: list->object); |
27 | if (mat) { |
28 | param->setParent(mat->parentMaterial()); |
29 | mat->parentMaterial()->addParameter(parameter: param); |
30 | } |
31 | }; |
32 | auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { |
33 | Quick3DMaterial *mat = qobject_cast<Quick3DMaterial *>(object: list->object); |
34 | if (mat) |
35 | return mat->parentMaterial()->parameters().size(); |
36 | return 0; |
37 | }; |
38 | auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { |
39 | Quick3DMaterial *mat = qobject_cast<Quick3DMaterial *>(object: list->object); |
40 | if (mat) |
41 | return mat->parentMaterial()->parameters().at(i: index); |
42 | return nullptr; |
43 | }; |
44 | auto clearFunction = [](QQmlListProperty<ListContentType> *list) { |
45 | Quick3DMaterial *mat = qobject_cast<Quick3DMaterial *>(object: list->object); |
46 | if (mat) { |
47 | const auto parameters = mat->parentMaterial()->parameters(); |
48 | for (QParameter *p : parameters) |
49 | mat->parentMaterial()->removeParameter(parameter: p); |
50 | } |
51 | }; |
52 | |
53 | return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); |
54 | } |
55 | |
56 | } // Quick |
57 | |
58 | } // namespace Render |
59 | |
60 | } // Qt3D |
61 | |
62 | QT_END_NAMESPACE |
63 | |
64 | #include "moc_quick3dmaterial_p.cpp" |
65 |