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 "qshaderdata.h" |
5 | #include "qshaderdata_p.h" |
6 | |
7 | QT_BEGIN_NAMESPACE |
8 | |
9 | namespace Qt3DRender { |
10 | |
11 | PropertyReaderInterface::~PropertyReaderInterface() |
12 | { |
13 | } |
14 | |
15 | QShaderDataPrivate::QShaderDataPrivate() |
16 | : QComponentPrivate() |
17 | , m_propertyReader(PropertyReaderInterfacePtr(new QShaderDataPropertyReader())) |
18 | { |
19 | } |
20 | |
21 | QShaderDataPrivate::QShaderDataPrivate(PropertyReaderInterfacePtr reader) |
22 | : QComponentPrivate() |
23 | , m_propertyReader(reader) |
24 | { |
25 | } |
26 | |
27 | /*! |
28 | * \class Qt3DRender::QShaderData |
29 | * \inheaderfile Qt3DRender/QShaderData |
30 | * \inmodule Qt3DRender |
31 | * |
32 | * \brief Provides a way of specifying values of a Uniform Block or a shader |
33 | * structure. |
34 | * |
35 | * \note When subclassing and adding properties to QShaderData, note that if |
36 | * you need to nest an inner Qt3DRender::QShaderData, the data type of the |
37 | * property should be Qt3DRender::QShaderData* instead of the name of your |
38 | * subclass. |
39 | * |
40 | * \since 5.5 |
41 | */ |
42 | |
43 | /*! |
44 | \fn Qt3DRender::PropertyReaderInterface::readProperty(const QVariant &v) |
45 | \return the property identified by \a v. |
46 | */ |
47 | |
48 | /*! |
49 | * Constructs a new QShaderData with the specified \a parent. |
50 | */ |
51 | QShaderData::QShaderData(QNode *parent) |
52 | : QComponent(*new QShaderDataPrivate, parent) |
53 | { |
54 | } |
55 | |
56 | /*! \internal */ |
57 | QShaderData::~QShaderData() |
58 | { |
59 | } |
60 | /*! |
61 | * \brief QShaderData::propertyReader |
62 | * Returns the PropertyReaderInterfacePtr for this shader data |
63 | */ |
64 | PropertyReaderInterfacePtr QShaderData::propertyReader() const |
65 | { |
66 | Q_D(const QShaderData); |
67 | return d->m_propertyReader; |
68 | } |
69 | |
70 | /*! \internal */ |
71 | QShaderData::QShaderData(QShaderDataPrivate &dd, QNode *parent) |
72 | : QComponent(dd, parent) |
73 | { |
74 | } |
75 | |
76 | /*! \internal */ |
77 | bool QShaderData::event(QEvent *event) |
78 | { |
79 | Q_D(QShaderData); |
80 | |
81 | if (event->type() == QEvent::DynamicPropertyChange) { |
82 | auto e = static_cast<QDynamicPropertyChangeEvent*>(event); |
83 | const auto propertyName = e->propertyName(); |
84 | |
85 | const QVariant data = property(name: propertyName); |
86 | if (data.canConvert<Qt3DCore::QNode*>()) { |
87 | const auto node = data.value<Qt3DCore::QNode*>(); |
88 | const auto id = node ? node->id() : Qt3DCore::QNodeId(); |
89 | d->notifyDynamicPropertyChange(name: propertyName, value: QVariant::fromValue(value: id)); |
90 | } else { |
91 | d->notifyDynamicPropertyChange(name: propertyName, value: data); |
92 | } |
93 | } |
94 | |
95 | return QComponent::event(event); |
96 | } |
97 | |
98 | } // namespace Qt3DRender |
99 | |
100 | QT_END_NAMESPACE |
101 | |
102 | #include "moc_qshaderdata.cpp" |
103 |