1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt3D module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #include "quick3dnodev9_p.h" |
41 | #include <QtQml/QJSValueIterator> |
42 | |
43 | QT_BEGIN_NAMESPACE |
44 | |
45 | namespace Qt3DCore { |
46 | namespace Quick { |
47 | |
48 | Quick3DNodeV9::Quick3DNodeV9(QObject *parent) |
49 | : QObject(parent) |
50 | { |
51 | } |
52 | |
53 | /*! |
54 | \qmlproperty QJSValue Qt3DCore::Node::propertyTrackingOverrides |
55 | |
56 | Assuming a Qt3DCore::Node needs to override the PropertyTrackingMode on two |
57 | properties (enabled and displacement), the value should be set as shown |
58 | below. |
59 | |
60 | \badcode |
61 | propertyTrackingOverrides: { |
62 | "enabled": Entity.DontTrackValues, |
63 | "displacement": Entity.TrackFinalValues |
64 | } |
65 | \endcode |
66 | |
67 | By default, there are no override values set. |
68 | \since 2.9 |
69 | */ |
70 | |
71 | QJSValue Quick3DNodeV9::propertyTrackingOverrides() const |
72 | { |
73 | return m_propertyTrackingOverrides; |
74 | } |
75 | |
76 | void Quick3DNodeV9::setPropertyTrackingOverrides(const QJSValue &value) |
77 | { |
78 | m_propertyTrackingOverrides = value; |
79 | |
80 | QNode *parentNode = this->parentNode(); |
81 | parentNode->clearPropertyTrackings(); |
82 | |
83 | if (value.isObject()) { |
84 | QJSValueIterator it(value); |
85 | while (it.hasNext()) { |
86 | it.next(); |
87 | parentNode->setPropertyTracking(propertyName: it.name(), trackMode: static_cast<QNode::PropertyTrackingMode>(it.value().toInt())); |
88 | } |
89 | } |
90 | emit propertyTrackingOverridesChanged(value); |
91 | } |
92 | |
93 | QQmlListProperty<QObject> Quick3DNodeV9::data() |
94 | { |
95 | return QQmlListProperty<QObject>(this, 0, |
96 | Quick3DNodeV9::appendData, |
97 | Quick3DNodeV9::dataCount, |
98 | Quick3DNodeV9::dataAt, |
99 | Quick3DNodeV9::clearData); |
100 | } |
101 | |
102 | QQmlListProperty<QNode> Quick3DNodeV9::childNodes() |
103 | { |
104 | return QQmlListProperty<QNode>(this, 0, |
105 | Quick3DNodeV9::appendChild, |
106 | Quick3DNodeV9::childCount, |
107 | Quick3DNodeV9::childAt, |
108 | Quick3DNodeV9::clearChildren); |
109 | } |
110 | |
111 | void Quick3DNodeV9::appendData(QQmlListProperty<QObject> *list, QObject *obj) |
112 | { |
113 | if (!obj) |
114 | return; |
115 | |
116 | Quick3DNodeV9 *self = static_cast<Quick3DNodeV9 *>(list->object); |
117 | self->childAppended(idx: 0, child: obj); |
118 | } |
119 | |
120 | QObject *Quick3DNodeV9::dataAt(QQmlListProperty<QObject> *list, int index) |
121 | { |
122 | Quick3DNodeV9 *self = static_cast<Quick3DNodeV9 *>(list->object); |
123 | return self->parentNode()->children().at(i: index); |
124 | } |
125 | |
126 | int Quick3DNodeV9::dataCount(QQmlListProperty<QObject> *list) |
127 | { |
128 | Quick3DNodeV9 *self = static_cast<Quick3DNodeV9 *>(list->object); |
129 | return self->parentNode()->children().count(); |
130 | } |
131 | |
132 | void Quick3DNodeV9::clearData(QQmlListProperty<QObject> *list) |
133 | { |
134 | Quick3DNodeV9 *self = static_cast<Quick3DNodeV9 *>(list->object); |
135 | for (QObject *const child : self->parentNode()->children()) |
136 | self->childRemoved(idx: 0, child); |
137 | } |
138 | |
139 | void Quick3DNodeV9::appendChild(QQmlListProperty<Qt3DCore::QNode> *list, Qt3DCore::QNode *obj) |
140 | { |
141 | if (!obj) |
142 | return; |
143 | |
144 | Quick3DNodeV9 *self = static_cast<Quick3DNodeV9 *>(list->object); |
145 | Q_ASSERT(!self->parentNode()->children().contains(obj)); |
146 | |
147 | self->childAppended(idx: 0, child: obj); |
148 | } |
149 | |
150 | Qt3DCore::QNode *Quick3DNodeV9::childAt(QQmlListProperty<Qt3DCore::QNode> *list, int index) |
151 | { |
152 | Quick3DNodeV9 *self = static_cast<Quick3DNodeV9 *>(list->object); |
153 | return qobject_cast<QNode *>(object: self->parentNode()->children().at(i: index)); |
154 | } |
155 | |
156 | int Quick3DNodeV9::childCount(QQmlListProperty<Qt3DCore::QNode> *list) |
157 | { |
158 | Quick3DNodeV9 *self = static_cast<Quick3DNodeV9 *>(list->object); |
159 | return self->parentNode()->children().count(); |
160 | } |
161 | |
162 | void Quick3DNodeV9::clearChildren(QQmlListProperty<Qt3DCore::QNode> *list) |
163 | { |
164 | Quick3DNodeV9 *self = static_cast<Quick3DNodeV9 *>(list->object); |
165 | for (QObject *const child : self->parentNode()->children()) |
166 | self->childRemoved(idx: 0, child); |
167 | } |
168 | |
169 | void Quick3DNodeV9::childAppended(int, QObject *obj) |
170 | { |
171 | QNode *parentNode = this->parentNode(); |
172 | if (obj->parent() == parentNode) |
173 | obj->setParent(0); |
174 | // Set after otherwise addChild might not work |
175 | if (QNode *n = qobject_cast<QNode *>(object: obj)) |
176 | n->setParent(parentNode); |
177 | else |
178 | obj->setParent(parentNode); |
179 | } |
180 | |
181 | void Quick3DNodeV9::childRemoved(int, QObject *obj) |
182 | { |
183 | if (QNode *n = qobject_cast<QNode *>(object: obj)) |
184 | n->setParent(Q_NODE_NULLPTR); |
185 | else |
186 | obj->setParent(nullptr); |
187 | } |
188 | |
189 | |
190 | } // namespace Quick |
191 | } // namespace Qt3DCore |
192 | |
193 | QT_END_NAMESPACE |
194 | |