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 <QtCore/QMetaProperty> |
5 | |
6 | #include <Qt3DQuickRender/private/quick3dshaderdataarray_p.h> |
7 | #include <Qt3DQuickRender/private/quick3dshaderdata_p.h> |
8 | #include <Qt3DRender/private/qshaderdata_p.h> |
9 | |
10 | QT_BEGIN_NAMESPACE |
11 | |
12 | namespace Qt3DRender { |
13 | namespace Render { |
14 | namespace Quick { |
15 | |
16 | namespace { |
17 | const int quick3DShaderDataArrayTypeId = qMetaTypeId<Quick3DShaderDataArray*>(); |
18 | Q_DECL_UNUSED const int quick3DShaderDataTypeId = qMetaTypeId<Quick3DShaderData*>(); |
19 | |
20 | } |
21 | |
22 | class Quick3DShaderDataPropertyReader : public PropertyReaderInterface |
23 | { |
24 | public: |
25 | Quick3DShaderDataPropertyReader() |
26 | { |
27 | } |
28 | |
29 | QVariant readProperty(const QVariant &v) override |
30 | { |
31 | static const int qjsValueTypeId = qMetaTypeId<QJSValue>(); |
32 | |
33 | // qjsValueTypeId are not compile time constant (no switch) |
34 | if (v.userType() == qjsValueTypeId) { |
35 | QJSValue jsValue = v.value<QJSValue>(); |
36 | if (jsValue.isArray()) |
37 | return v.value<QVariantList>(); |
38 | else if (jsValue.isVariant()) |
39 | return jsValue.toVariant(); |
40 | } else if (v.userType() == quick3DShaderDataArrayTypeId) { |
41 | Quick3DShaderDataArray *array = v.value<Quick3DShaderDataArray *>(); |
42 | QVariantList innerValues; |
43 | if (array) { |
44 | const auto values = array->values(); |
45 | for (QShaderData *d : values) { |
46 | if (d) |
47 | innerValues.append(t: QVariant::fromValue(value: d->id())); |
48 | } |
49 | } |
50 | return innerValues; |
51 | } else if (v.canConvert<Qt3DCore::QNode*>()) { |
52 | const auto node = v.value<Qt3DCore::QNode *>(); |
53 | const auto id = Qt3DCore::qIdForNode(node); |
54 | return QVariant::fromValue(value: id); |
55 | } |
56 | return v; |
57 | } |
58 | }; |
59 | |
60 | Quick3DShaderData::Quick3DShaderData(QNode *parent) |
61 | : QShaderData(*new QShaderDataPrivate(PropertyReaderInterfacePtr(new Quick3DShaderDataPropertyReader())) |
62 | , parent) |
63 | { |
64 | } |
65 | |
66 | } // namespace Quick |
67 | } // namespace Render |
68 | } // namespace Qt3DRender |
69 | |
70 | QT_END_NAMESPACE |
71 | |
72 | #include "moc_quick3dshaderdata_p.cpp" |
73 |