1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2014 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:GPL-EXCEPT$ |
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 General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | |
29 | // TODO Remove in Qt6 |
30 | #include <QtCore/qcompilerdetection.h> |
31 | QT_WARNING_DISABLE_DEPRECATED |
32 | |
33 | #include <QtTest/QtTest> |
34 | #include <Qt3DCore/private/qscene_p.h> |
35 | #include <Qt3DCore/qnode.h> |
36 | #include <Qt3DCore/qentity.h> |
37 | #include <Qt3DCore/qcomponent.h> |
38 | #include <Qt3DCore/private/qobservableinterface_p.h> |
39 | #include <Qt3DCore/private/qlockableobserverinterface_p.h> |
40 | #include <private/qnode_p.h> |
41 | #include "testpostmanarbiter.h" |
42 | |
43 | class tst_QScene : public QObject |
44 | { |
45 | Q_OBJECT |
46 | public: |
47 | tst_QScene() : QObject() {} |
48 | ~tst_QScene() {} |
49 | |
50 | private slots: |
51 | void addObservable(); |
52 | void addNodeObservable(); |
53 | void removeObservable(); |
54 | void removeNodeObservable(); |
55 | void addChildNode(); |
56 | void deleteChildNode(); |
57 | void removeChildNode(); |
58 | void addEntityForComponent(); |
59 | void removeEntityForComponent(); |
60 | void hasEntityForComponent(); |
61 | void setPropertyTrackData(); |
62 | void lookupNodePropertyTrackData(); |
63 | void removePropertyTrackData(); |
64 | void nodeSetAndUnsetPropertyTrackData(); |
65 | void nodeUpdatePropertyTrackData(); |
66 | }; |
67 | |
68 | class tst_Observable : public Qt3DCore::QObservableInterface |
69 | { |
70 | public: |
71 | void setArbiter(Qt3DCore::QLockableObserverInterface *observer) |
72 | { |
73 | m_arbiter = observer; |
74 | } |
75 | |
76 | protected: |
77 | void notifyObservers(const Qt3DCore::QSceneChangePtr &) {} |
78 | |
79 | private: |
80 | Qt3DCore::QLockableObserverInterface *m_arbiter; |
81 | }; |
82 | |
83 | class tst_Node : public Qt3DCore::QNode |
84 | { |
85 | Q_OBJECT |
86 | public: |
87 | tst_Node() : Qt3DCore::QNode() |
88 | {} |
89 | }; |
90 | |
91 | class tst_Component : public Qt3DCore::QComponent |
92 | { |
93 | Q_OBJECT |
94 | public: |
95 | tst_Component() : Qt3DCore::QComponent() |
96 | {} |
97 | }; |
98 | |
99 | void tst_QScene::addObservable() |
100 | { |
101 | // GIVEN |
102 | Qt3DCore::QNode *node1 = new tst_Node(); |
103 | Qt3DCore::QNode *node2 = new tst_Node(); |
104 | |
105 | QList<tst_Observable *> observables; |
106 | |
107 | for (int i = 0; i < 10; i++) |
108 | observables.append(t: new tst_Observable()); |
109 | |
110 | Qt3DCore::QScene *scene = new Qt3DCore::QScene; |
111 | scene->setArbiter(new TestArbiter); |
112 | |
113 | // WHEN |
114 | for (int i = 0; i < 5; i++) |
115 | scene->addObservable(observable: observables.at(i), id: node1->id()); |
116 | |
117 | for (int i = 0; i < 5; i++) |
118 | scene->addObservable(observable: observables.at(i: i + 5), id: node2->id()); |
119 | |
120 | const Qt3DCore::QObservableList obs1 = scene->lookupObservables(id: node1->id()); |
121 | const Qt3DCore::QObservableList obs2 = scene->lookupObservables(id: node2->id()); |
122 | |
123 | // THEN |
124 | QCOMPARE(obs1.count(), 5); |
125 | QCOMPARE(obs2.count(), obs1.count()); |
126 | |
127 | for (Qt3DCore::QObservableInterface *o : obs1) { |
128 | QVERIFY(scene->nodeIdFromObservable(o) == node1->id()); |
129 | QVERIFY(scene->lookupNode(node1->id()) == nullptr); |
130 | } |
131 | for (Qt3DCore::QObservableInterface *o : obs2) { |
132 | QVERIFY(scene->nodeIdFromObservable(o) == node2->id()); |
133 | QVERIFY(scene->lookupNode(node2->id()) == nullptr); |
134 | } |
135 | } |
136 | |
137 | void tst_QScene::addNodeObservable() |
138 | { |
139 | // GIBEN |
140 | QList<Qt3DCore::QNode *> nodes; |
141 | |
142 | for (int i = 0; i < 10; i++) |
143 | nodes.append(t: new tst_Node()); |
144 | |
145 | Qt3DCore::QScene *scene = new Qt3DCore::QScene; |
146 | scene->setArbiter(new TestArbiter); |
147 | |
148 | // WHEN |
149 | for (int i = 0; i < 10; i++) |
150 | scene->addObservable(observable: nodes.at(i)); |
151 | |
152 | // THEN |
153 | for (Qt3DCore::QNode *n : qAsConst(t&: nodes)) { |
154 | QVERIFY(n == scene->lookupNode(n->id())); |
155 | QVERIFY(scene->lookupObservables(n->id()).isEmpty()); |
156 | } |
157 | } |
158 | |
159 | void tst_QScene::removeObservable() |
160 | { |
161 | // GIVEN |
162 | Qt3DCore::QNode *node1 = new tst_Node(); |
163 | Qt3DCore::QNode *node2 = new tst_Node(); |
164 | |
165 | QList<tst_Observable *> observables; |
166 | |
167 | for (int i = 0; i < 10; i++) |
168 | observables.append(t: new tst_Observable()); |
169 | |
170 | Qt3DCore::QScene *scene = new Qt3DCore::QScene; |
171 | scene->setArbiter(new TestArbiter); |
172 | |
173 | // WHEN |
174 | for (int i = 0; i < 5; i++) |
175 | scene->addObservable(observable: observables.at(i), id: node1->id()); |
176 | |
177 | for (int i = 0; i < 5; i++) |
178 | scene->addObservable(observable: observables.at(i: i + 5), id: node2->id()); |
179 | |
180 | Qt3DCore::QObservableList obs1 = scene->lookupObservables(id: node1->id()); |
181 | Qt3DCore::QObservableList obs2 = scene->lookupObservables(id: node2->id()); |
182 | |
183 | // THEN |
184 | QCOMPARE(obs1.count(), 5); |
185 | QCOMPARE(obs2.count(), obs1.count()); |
186 | |
187 | // WHEN |
188 | scene->removeObservable(observable: observables.at(i: 0), id: node1->id()); |
189 | // THEN |
190 | QCOMPARE(scene->lookupObservables(node1->id()).count(), 4); |
191 | |
192 | // WHEN |
193 | scene->removeObservable(observable: observables.at(i: 0), id: node1->id()); |
194 | // THEN |
195 | QCOMPARE(scene->lookupObservables(node1->id()).count(), 4); |
196 | |
197 | // WHEN |
198 | scene->removeObservable(observable: observables.at(i: 6), id: node1->id()); |
199 | // THEN |
200 | QCOMPARE(scene->lookupObservables(node1->id()).count(), 4); |
201 | QCOMPARE(scene->lookupObservables(node2->id()).count(), 5); |
202 | |
203 | // WHEN |
204 | scene->removeObservable(observable: observables.at(i: 0), id: node2->id()); |
205 | // THEN |
206 | QCOMPARE(scene->lookupObservables(node2->id()).count(), 5); |
207 | QVERIFY(scene->nodeIdFromObservable(observables.at(0)) == Qt3DCore::QNodeId()); |
208 | } |
209 | |
210 | void tst_QScene::removeNodeObservable() |
211 | { |
212 | // GIVEN |
213 | Qt3DCore::QNode *node1 = new tst_Node(); |
214 | Qt3DCore::QNode *node2 = new tst_Node(); |
215 | |
216 | QList<tst_Observable *> observables; |
217 | |
218 | for (int i = 0; i < 10; i++) |
219 | observables.append(t: new tst_Observable()); |
220 | |
221 | Qt3DCore::QScene *scene = new Qt3DCore::QScene; |
222 | scene->setArbiter(new TestArbiter); |
223 | |
224 | // WHEN |
225 | scene->addObservable(observable: node1); |
226 | scene->addObservable(observable: node2); |
227 | |
228 | for (int i = 0; i < 5; i++) |
229 | scene->addObservable(observable: observables.at(i), id: node1->id()); |
230 | |
231 | for (int i = 0; i < 5; i++) |
232 | scene->addObservable(observable: observables.at(i: i + 5), id: node2->id()); |
233 | |
234 | // THEN |
235 | Qt3DCore::QObservableList obs1 = scene->lookupObservables(id: node1->id()); |
236 | Qt3DCore::QObservableList obs2 = scene->lookupObservables(id: node2->id()); |
237 | |
238 | QCOMPARE(obs1.count(), 5); |
239 | QCOMPARE(obs2.count(), obs1.count()); |
240 | |
241 | // WHEN |
242 | scene->removeObservable(observable: node1); |
243 | |
244 | // THEN |
245 | QVERIFY(scene->lookupNode(node1->id()) == nullptr); |
246 | QVERIFY(scene->lookupObservables(node1->id()).empty()); |
247 | QVERIFY(scene->nodeIdFromObservable(observables.at(0)) == Qt3DCore::QNodeId()); |
248 | |
249 | QVERIFY(scene->lookupNode(node2->id()) == node2); |
250 | QCOMPARE(scene->lookupObservables(node2->id()).count(), 5); |
251 | QVERIFY(scene->nodeIdFromObservable(observables.at(9)) == node2->id()); |
252 | } |
253 | |
254 | void tst_QScene::addChildNode() |
255 | { |
256 | // GIVEN |
257 | Qt3DCore::QScene *scene = new Qt3DCore::QScene; |
258 | |
259 | QList<Qt3DCore::QNode *> nodes; |
260 | |
261 | Qt3DCore::QNode *root = new tst_Node(); |
262 | Qt3DCore::QNodePrivate::get(q: root)->setScene(scene); |
263 | |
264 | // WHEN |
265 | scene->addObservable(observable: root); |
266 | // THEN |
267 | QVERIFY(scene->lookupNode(root->id()) == root); |
268 | |
269 | // WHEN |
270 | for (int i = 0; i < 10; i++) { |
271 | Qt3DCore::QNode *child = new tst_Node(); |
272 | if (nodes.isEmpty()) |
273 | child->setParent(root); |
274 | else |
275 | child->setParent(nodes.last()); |
276 | nodes.append(t: child); |
277 | } |
278 | QCoreApplication::processEvents(); |
279 | |
280 | // THEN |
281 | for (Qt3DCore::QNode *n : qAsConst(t&: nodes)) { |
282 | QVERIFY(scene->lookupNode(n->id()) == n); |
283 | } |
284 | } |
285 | |
286 | void tst_QScene::deleteChildNode() |
287 | { |
288 | // GIVEN |
289 | Qt3DCore::QScene *scene = new Qt3DCore::QScene; |
290 | |
291 | QList<Qt3DCore::QNode *> nodes1, nodes2; |
292 | |
293 | Qt3DCore::QNode *root1 = new tst_Node(); |
294 | Qt3DCore::QNode *root2 = new tst_Node(); |
295 | Qt3DCore::QNodePrivate::get(q: root1)->setScene(scene); |
296 | Qt3DCore::QNodePrivate::get(q: root2)->setScene(scene); |
297 | Qt3DCore::QNodePrivate::get(q: root1)->m_hasBackendNode = true; |
298 | Qt3DCore::QNodePrivate::get(q: root2)->m_hasBackendNode = true; |
299 | |
300 | // WHEN |
301 | scene->addObservable(observable: root1); |
302 | scene->addObservable(observable: root2); |
303 | // THEN |
304 | QVERIFY(scene->lookupNode(root1->id()) == root1); |
305 | QVERIFY(scene->lookupNode(root2->id()) == root2); |
306 | |
307 | // WHEN |
308 | for (int i = 0; i < 10; i++) { |
309 | Qt3DCore::QNode *child1 = new tst_Node(); |
310 | child1->setParent(nodes1.isEmpty() ? root1 : nodes1.last()); |
311 | Qt3DCore::QNodePrivate::get(q: child1)->m_hasBackendNode = true; |
312 | nodes1.append(t: child1); |
313 | |
314 | Qt3DCore::QNode *child2 = new tst_Node(); |
315 | child2->setParent(nodes2.isEmpty() ? root2 : nodes2.last()); |
316 | Qt3DCore::QNodePrivate::get(q: child2)->m_hasBackendNode = true; |
317 | nodes2.append(t: child2); |
318 | } |
319 | QCoreApplication::processEvents(); |
320 | |
321 | // THEN |
322 | for (Qt3DCore::QNode *n : qAsConst(t&: nodes1)) { |
323 | QVERIFY(scene->lookupNode(n->id()) == n); |
324 | } |
325 | for (Qt3DCore::QNode *n : qAsConst(t&: nodes2)) { |
326 | QVERIFY(scene->lookupNode(n->id()) == n); |
327 | } |
328 | |
329 | // gather node IDs |
330 | Qt3DCore::QNodeIdVector root1ChildIds; |
331 | for (Qt3DCore::QNode *n : qAsConst(t&: nodes1)) |
332 | root1ChildIds << n->id(); |
333 | |
334 | // WHEN |
335 | delete root1; |
336 | QCoreApplication::processEvents(); |
337 | |
338 | // THEN |
339 | for (Qt3DCore::QNodeId id : qAsConst(t&: root1ChildIds)) { |
340 | QVERIFY(scene->lookupNode(id) == nullptr); |
341 | } |
342 | |
343 | // WHEN |
344 | nodes2.first()->setParent(static_cast<Qt3DCore::QNode*>(nullptr)); |
345 | QCoreApplication::processEvents(); |
346 | |
347 | // THEN |
348 | for (Qt3DCore::QNode *n : qAsConst(t&: nodes2)) { |
349 | QVERIFY(scene->lookupNode(n->id()) == nullptr); |
350 | } |
351 | } |
352 | |
353 | void tst_QScene::removeChildNode() |
354 | { |
355 | // GIVEN |
356 | Qt3DCore::QScene *scene = new Qt3DCore::QScene; |
357 | |
358 | QList<Qt3DCore::QNode *> nodes; |
359 | |
360 | Qt3DCore::QNode *root = new tst_Node; |
361 | Qt3DCore::QNodePrivate::get(q: root)->setScene(scene); |
362 | Qt3DCore::QNodePrivate::get(q: root)->m_hasBackendNode = true; |
363 | scene->addObservable(observable: root); |
364 | |
365 | // WHEN |
366 | for (int i = 0; i < 10; i++) { |
367 | Qt3DCore::QNode *child = new tst_Node; |
368 | if (nodes.isEmpty()) |
369 | child->setParent(root); |
370 | else |
371 | child->setParent(nodes.last()); |
372 | Qt3DCore::QNodePrivate::get(q: child)->m_hasBackendNode = true; |
373 | nodes.append(t: child); |
374 | } |
375 | |
376 | // THEN |
377 | while (!nodes.isEmpty()) { |
378 | Qt3DCore::QNode *lst = nodes.takeLast(); |
379 | QVERIFY(scene->lookupNode(lst->id()) == lst); |
380 | if (lst->parentNode() != nullptr) { |
381 | lst->setParent(Q_NODE_NULLPTR); |
382 | QCoreApplication::processEvents(); |
383 | QVERIFY(scene->lookupNode(lst->id()) == nullptr); |
384 | } |
385 | } |
386 | } |
387 | |
388 | void tst_QScene::addEntityForComponent() |
389 | { |
390 | // GIVEN |
391 | Qt3DCore::QScene *scene = new Qt3DCore::QScene; |
392 | |
393 | QList<Qt3DCore::QEntity *> entities; |
394 | QList<Qt3DCore::QComponent *> components; |
395 | |
396 | for (int i = 0; i < 10; i++) { |
397 | Qt3DCore::QEntity *entity = new Qt3DCore::QEntity(); |
398 | Qt3DCore::QComponent *comp = new tst_Component(); |
399 | |
400 | Qt3DCore::QNodePrivate::get(q: entity)->setScene(scene); |
401 | Qt3DCore::QNodePrivate::get(q: comp)->setScene(scene); |
402 | entities << entity; |
403 | components << comp; |
404 | } |
405 | |
406 | // WHEN |
407 | for (int i = 0; i < 10; i++) { |
408 | Qt3DCore::QEntity *e = entities.at(i); |
409 | for (int j = 0; j < 10; j++) { |
410 | e->addComponent(comp: components.at(i: j)); |
411 | } |
412 | } |
413 | |
414 | // THEN |
415 | for (int i = 0; i < 10; i++) { |
416 | QVector<Qt3DCore::QNodeId> ids = scene->entitiesForComponent(id: components.at(i)->id()); |
417 | QCOMPARE(ids.count(), 10); |
418 | } |
419 | } |
420 | |
421 | void tst_QScene::removeEntityForComponent() |
422 | { |
423 | // GIVEN |
424 | Qt3DCore::QScene *scene = new Qt3DCore::QScene; |
425 | |
426 | QList<Qt3DCore::QEntity *> entities; |
427 | QList<Qt3DCore::QComponent *> components; |
428 | |
429 | for (int i = 0; i < 10; i++) { |
430 | Qt3DCore::QEntity *entity = new Qt3DCore::QEntity(); |
431 | Qt3DCore::QComponent *comp = new tst_Component(); |
432 | |
433 | Qt3DCore::QNodePrivate::get(q: entity)->setScene(scene); |
434 | Qt3DCore::QNodePrivate::get(q: comp)->setScene(scene); |
435 | entities << entity; |
436 | components << comp; |
437 | } |
438 | |
439 | // WHEN |
440 | for (int i = 0; i < 10; i++) { |
441 | Qt3DCore::QEntity *e = entities.at(i); |
442 | for (int j = 0; j < 10; j++) { |
443 | e->addComponent(comp: components.at(i: j)); |
444 | } |
445 | } |
446 | |
447 | // THEN |
448 | for (int i = 0; i < 10; i++) { |
449 | Qt3DCore::QEntity *e = entities.at(i); |
450 | for (int j = 0; j < 10; j++) { |
451 | e->removeComponent(comp: components.at(i: j)); |
452 | QCOMPARE(scene->entitiesForComponent(components.at(j)->id()).count(), 10 - (i + 1)); |
453 | } |
454 | } |
455 | } |
456 | |
457 | void tst_QScene::hasEntityForComponent() |
458 | { |
459 | // GIVEN |
460 | Qt3DCore::QScene *scene = new Qt3DCore::QScene; |
461 | |
462 | QList<Qt3DCore::QEntity *> entities; |
463 | QList<Qt3DCore::QComponent *> components; |
464 | |
465 | for (int i = 0; i < 10; i++) { |
466 | Qt3DCore::QEntity *entity = new Qt3DCore::QEntity(); |
467 | Qt3DCore::QComponent *comp = new tst_Component(); |
468 | |
469 | Qt3DCore::QNodePrivate::get(q: entity)->setScene(scene); |
470 | Qt3DCore::QNodePrivate::get(q: comp)->setScene(scene); |
471 | entities << entity; |
472 | components << comp; |
473 | } |
474 | |
475 | // WHEN |
476 | for (int i = 0; i < 10; i++) { |
477 | Qt3DCore::QEntity *e = entities.at(i); |
478 | for (int j = 0; j < 10; j++) { |
479 | e->addComponent(comp: components.at(i: j)); |
480 | } |
481 | } |
482 | |
483 | // THEN |
484 | for (int i = 0; i < 10; i++) |
485 | QVERIFY(scene->hasEntityForComponent(components.at(i)->id(), entities.at(i)->id())); |
486 | } |
487 | |
488 | void tst_QScene::setPropertyTrackData() |
489 | { |
490 | // GIVEN |
491 | Qt3DCore::QNodeId fakeNodeId = Qt3DCore::QNodeId::createId(); |
492 | QScopedPointer<Qt3DCore::QScene> scene(new Qt3DCore::QScene); |
493 | QHash<QString, Qt3DCore::QNode::PropertyTrackingMode> overridenTrackedProperties; |
494 | overridenTrackedProperties.insert(QStringLiteral("1340" ), value: Qt3DCore::QNode::TrackAllValues); |
495 | |
496 | // WHEN |
497 | { |
498 | Qt3DCore::QScene::NodePropertyTrackData trackData; |
499 | trackData.trackedPropertiesOverrides = overridenTrackedProperties; |
500 | trackData.defaultTrackMode = Qt3DCore::QNode::DontTrackValues; |
501 | scene->setPropertyTrackDataForNode(id: fakeNodeId, data: trackData); |
502 | } |
503 | |
504 | // THEN |
505 | { |
506 | Qt3DCore::QScene::NodePropertyTrackData trackData = scene->lookupNodePropertyTrackData(id: fakeNodeId); |
507 | QCOMPARE(trackData.trackedPropertiesOverrides, overridenTrackedProperties); |
508 | QCOMPARE(trackData.defaultTrackMode, Qt3DCore::QNode::DontTrackValues); |
509 | } |
510 | |
511 | // WHEN |
512 | { |
513 | Qt3DCore::QScene::NodePropertyTrackData trackData; |
514 | trackData.trackedPropertiesOverrides.clear(); |
515 | trackData.defaultTrackMode = Qt3DCore::QNode::TrackFinalValues; |
516 | scene->setPropertyTrackDataForNode(id: fakeNodeId, data: trackData); |
517 | } |
518 | |
519 | // THEN |
520 | { |
521 | Qt3DCore::QScene::NodePropertyTrackData trackData = scene->lookupNodePropertyTrackData(id: fakeNodeId); |
522 | QCOMPARE(trackData.trackedPropertiesOverrides.size(), 0); |
523 | QCOMPARE(trackData.defaultTrackMode, Qt3DCore::QNode::TrackFinalValues); |
524 | } |
525 | } |
526 | |
527 | void tst_QScene::lookupNodePropertyTrackData() |
528 | { |
529 | // GIVEN |
530 | QScopedPointer<Qt3DCore::QScene> scene(new Qt3DCore::QScene); |
531 | Qt3DCore::QNodeId fakeNodeId = Qt3DCore::QNodeId::createId(); |
532 | |
533 | // THEN -> default value for non existent id |
534 | Qt3DCore::QScene::NodePropertyTrackData trackData = scene->lookupNodePropertyTrackData(id: fakeNodeId); |
535 | QCOMPARE(trackData.trackedPropertiesOverrides.size(), 0); |
536 | QCOMPARE(trackData.defaultTrackMode, Qt3DCore::QNode::TrackFinalValues); |
537 | |
538 | // WHEN |
539 | trackData.trackedPropertiesOverrides.insert(QStringLiteral("383" ), value: Qt3DCore::QNode::TrackAllValues); |
540 | trackData.defaultTrackMode = Qt3DCore::QNode::DontTrackValues; |
541 | scene->setPropertyTrackDataForNode(id: fakeNodeId, data: trackData); |
542 | |
543 | trackData = scene->lookupNodePropertyTrackData(id: fakeNodeId); |
544 | QCOMPARE(trackData.trackedPropertiesOverrides.size(), 1); |
545 | QCOMPARE(trackData.defaultTrackMode, Qt3DCore::QNode::DontTrackValues); |
546 | } |
547 | |
548 | void tst_QScene::removePropertyTrackData() |
549 | { |
550 | // GIVEN |
551 | QScopedPointer<Qt3DCore::QScene> scene(new Qt3DCore::QScene); |
552 | Qt3DCore::QNodeId fakeNodeId = Qt3DCore::QNodeId::createId(); |
553 | |
554 | // WHEN |
555 | Qt3DCore::QScene::NodePropertyTrackData trackData; |
556 | trackData.trackedPropertiesOverrides.insert(QStringLiteral("1584" ), value: Qt3DCore::QNode::TrackAllValues); |
557 | trackData.defaultTrackMode = Qt3DCore::QNode::DontTrackValues; |
558 | scene->setPropertyTrackDataForNode(id: fakeNodeId, data: trackData); |
559 | scene->removePropertyTrackDataForNode(id: fakeNodeId); |
560 | |
561 | // THEN -> default value for non existent id |
562 | trackData = scene->lookupNodePropertyTrackData(id: fakeNodeId); |
563 | QCOMPARE(trackData.trackedPropertiesOverrides.size(), 0); |
564 | QCOMPARE(trackData.defaultTrackMode, Qt3DCore::QNode::TrackFinalValues); |
565 | } |
566 | |
567 | void tst_QScene::nodeSetAndUnsetPropertyTrackData() |
568 | { |
569 | // GIVEN |
570 | QScopedPointer<Qt3DCore::QScene> scene(new Qt3DCore::QScene); |
571 | Qt3DCore::QNode parentNode; |
572 | Qt3DCore::QNodePrivate::get(q: &parentNode)->setScene(scene.data()); |
573 | |
574 | Qt3DCore::QNode *childNode = new Qt3DCore::QNode(); |
575 | childNode->setPropertyTracking(QStringLiteral("883" ), trackMode: Qt3DCore::QNode::TrackAllValues); |
576 | childNode->setDefaultPropertyTrackingMode(Qt3DCore::QNode::DontTrackValues); |
577 | |
578 | // WHEN |
579 | childNode->setParent(&parentNode); |
580 | QCoreApplication::processEvents(); |
581 | |
582 | // THEN |
583 | QCOMPARE(Qt3DCore::QNodePrivate::get(childNode)->m_scene, scene.data()); |
584 | Qt3DCore::QScene::NodePropertyTrackData trackData = scene->lookupNodePropertyTrackData(id: childNode->id()); |
585 | QCOMPARE(trackData.defaultTrackMode, Qt3DCore::QNode::DontTrackValues); |
586 | QCOMPARE(trackData.trackedPropertiesOverrides.size(), 1); |
587 | QCOMPARE(trackData.trackedPropertiesOverrides[QStringLiteral("883" )], Qt3DCore::QNode::TrackAllValues); |
588 | |
589 | // WHEN |
590 | const Qt3DCore::QNodeId childNodeId = childNode->id(); |
591 | delete childNode; |
592 | QCoreApplication::processEvents(); |
593 | |
594 | // THEN -> default value for non existent id |
595 | trackData = scene->lookupNodePropertyTrackData(id: childNodeId); |
596 | QCOMPARE(trackData.trackedPropertiesOverrides.size(), 0); |
597 | QCOMPARE(trackData.defaultTrackMode, Qt3DCore::QNode::TrackFinalValues); |
598 | } |
599 | |
600 | void tst_QScene::nodeUpdatePropertyTrackData() |
601 | { |
602 | // GIVEN |
603 | QScopedPointer<Qt3DCore::QScene> scene(new Qt3DCore::QScene); |
604 | Qt3DCore::QNode parentNode; |
605 | Qt3DCore::QNodePrivate::get(q: &parentNode)->setScene(scene.data()); |
606 | |
607 | Qt3DCore::QNode *childNode = new Qt3DCore::QNode(); |
608 | const QString propertyName = QStringLiteral("883" ); |
609 | childNode->setPropertyTracking(propertyName, trackMode: Qt3DCore::QNode::TrackFinalValues); |
610 | childNode->setDefaultPropertyTrackingMode(Qt3DCore::QNode::DontTrackValues); |
611 | |
612 | // WHEN |
613 | childNode->setParent(&parentNode); |
614 | QCoreApplication::processEvents(); |
615 | |
616 | // THEN |
617 | QCOMPARE(Qt3DCore::QNodePrivate::get(childNode)->m_scene, scene.data()); |
618 | Qt3DCore::QScene::NodePropertyTrackData trackData = scene->lookupNodePropertyTrackData(id: childNode->id()); |
619 | QCOMPARE(trackData.defaultTrackMode, Qt3DCore::QNode::DontTrackValues); |
620 | QCOMPARE(trackData.trackedPropertiesOverrides.size(), 1); |
621 | QCOMPARE(trackData.trackedPropertiesOverrides[propertyName], Qt3DCore::QNode::TrackFinalValues); |
622 | |
623 | // WHEN |
624 | childNode->setDefaultPropertyTrackingMode(Qt3DCore::QNode::TrackAllValues); |
625 | |
626 | // THEN |
627 | trackData = scene->lookupNodePropertyTrackData(id: childNode->id()); |
628 | QCOMPARE(trackData.defaultTrackMode, Qt3DCore::QNode::TrackAllValues); |
629 | |
630 | // WHEN |
631 | const QString propertyName2 = QStringLiteral("Viper" ); |
632 | childNode->setPropertyTracking(propertyName: propertyName2, trackMode: Qt3DCore::QNode::DontTrackValues); |
633 | |
634 | // THEN |
635 | trackData = scene->lookupNodePropertyTrackData(id: childNode->id()); |
636 | QCOMPARE(trackData.trackedPropertiesOverrides.size(), 2); |
637 | QCOMPARE(trackData.trackedPropertiesOverrides[propertyName], Qt3DCore::QNode::TrackFinalValues); |
638 | QCOMPARE(trackData.trackedPropertiesOverrides[propertyName2], Qt3DCore::QNode::DontTrackValues); |
639 | } |
640 | |
641 | QTEST_MAIN(tst_QScene) |
642 | |
643 | #include "tst_qscene.moc" |
644 | |