1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 Paul Lemire |
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 | #include <QtTest/QTest> |
30 | #include <Qt3DCore/qentity.h> |
31 | #include <Qt3DRender/private/nodemanagers_p.h> |
32 | #include <Qt3DRender/private/managers_p.h> |
33 | #include <Qt3DRender/private/entity_p.h> |
34 | #include <Qt3DRender/private/filterlayerentityjob_p.h> |
35 | #include <Qt3DRender/private/updateentitylayersjob_p.h> |
36 | #include <Qt3DRender/private/updatetreeenabledjob_p.h> |
37 | #include <Qt3DRender/qlayer.h> |
38 | #include <Qt3DRender/qlayerfilter.h> |
39 | #include "testaspect.h" |
40 | |
41 | class tst_LayerFiltering : public QObject |
42 | { |
43 | Q_OBJECT |
44 | private Q_SLOTS: |
45 | |
46 | void checkInitialState() |
47 | { |
48 | // GIVEN |
49 | Qt3DRender::Render::FilterLayerEntityJob filterJob; |
50 | Qt3DRender::Render::UpdateEntityLayersJob updateEntityLayerJob; |
51 | Qt3DRender::QLayer frontendLayer; |
52 | |
53 | // THEN |
54 | QVERIFY(updateEntityLayerJob.manager() == nullptr); |
55 | QCOMPARE(filterJob.hasLayerFilter(), false); |
56 | QCOMPARE(filterJob.filteredEntities().size(), 0); |
57 | QCOMPARE(filterJob.layerFilters().size(), 0); |
58 | QCOMPARE(frontendLayer.recursive(), false); |
59 | } |
60 | |
61 | void filterEntities_data() |
62 | { |
63 | QTest::addColumn<Qt3DCore::QEntity *>(name: "entitySubtree" ); |
64 | QTest::addColumn<Qt3DCore::QNodeIdVector>(name: "layerFilterIds" ); |
65 | QTest::addColumn<Qt3DCore::QNodeIdVector>(name: "expectedSelectedEntities" ); |
66 | |
67 | |
68 | { |
69 | Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity(); |
70 | Qt3DCore::QEntity *childEntity1 = new Qt3DCore::QEntity(rootEntity); |
71 | Qt3DCore::QEntity *childEntity2 = new Qt3DCore::QEntity(rootEntity); |
72 | Qt3DCore::QEntity *childEntity3 = new Qt3DCore::QEntity(rootEntity); |
73 | |
74 | Q_UNUSED(childEntity1); |
75 | Q_UNUSED(childEntity2); |
76 | Q_UNUSED(childEntity3); |
77 | |
78 | QTest::newRow(dataTag: "EntitiesNoLayerNoLayerFilterNoDiscardNoRecursive-ShouldSelectAll" ) << rootEntity |
79 | << Qt3DCore::QNodeIdVector() |
80 | << (Qt3DCore::QNodeIdVector() |
81 | << rootEntity->id() |
82 | << childEntity1->id() |
83 | << childEntity2->id() |
84 | << childEntity3->id() |
85 | ); |
86 | } |
87 | |
88 | { |
89 | Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity(); |
90 | Qt3DCore::QEntity *childEntity1 = new Qt3DCore::QEntity(rootEntity); |
91 | Qt3DCore::QEntity *childEntity2 = new Qt3DCore::QEntity(rootEntity); |
92 | Qt3DCore::QEntity *childEntity3 = new Qt3DCore::QEntity(rootEntity); |
93 | |
94 | Qt3DRender::QLayerFilter *layerFilter = new Qt3DRender::QLayerFilter(rootEntity); |
95 | |
96 | Q_UNUSED(childEntity1); |
97 | Q_UNUSED(childEntity2); |
98 | Q_UNUSED(childEntity3); |
99 | |
100 | QTest::newRow(dataTag: "EntityNoLayerWithLayerFilterWithNoFilter-ShouldSelectNone" ) << rootEntity |
101 | << (Qt3DCore::QNodeIdVector() << layerFilter->id()) |
102 | << Qt3DCore::QNodeIdVector(); |
103 | } |
104 | |
105 | { |
106 | Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity(); |
107 | Qt3DCore::QEntity *childEntity1 = new Qt3DCore::QEntity(rootEntity); |
108 | Qt3DCore::QEntity *childEntity2 = new Qt3DCore::QEntity(rootEntity); |
109 | Qt3DCore::QEntity *childEntity3 = new Qt3DCore::QEntity(rootEntity); |
110 | |
111 | Q_UNUSED(childEntity1); |
112 | Q_UNUSED(childEntity2); |
113 | Q_UNUSED(childEntity3); |
114 | |
115 | Qt3DRender::QLayer *layer = new Qt3DRender::QLayer(rootEntity); |
116 | Qt3DRender::QLayerFilter *layerFilter = new Qt3DRender::QLayerFilter(rootEntity); |
117 | layerFilter->addLayer(layer); |
118 | |
119 | |
120 | QTest::newRow(dataTag: "AcceptAny-NoLayerWithLayerFilterWithFilter-ShouldSelectNone" ) << rootEntity |
121 | << (Qt3DCore::QNodeIdVector() << layerFilter->id()) |
122 | << Qt3DCore::QNodeIdVector(); |
123 | } |
124 | |
125 | { |
126 | Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity(); |
127 | Qt3DCore::QEntity *childEntity1 = new Qt3DCore::QEntity(rootEntity); |
128 | Qt3DCore::QEntity *childEntity2 = new Qt3DCore::QEntity(rootEntity); |
129 | Qt3DCore::QEntity *childEntity3 = new Qt3DCore::QEntity(rootEntity); |
130 | |
131 | |
132 | Qt3DRender::QLayer *layer = new Qt3DRender::QLayer(rootEntity); |
133 | childEntity1->addComponent(comp: layer); |
134 | childEntity2->addComponent(comp: layer); |
135 | childEntity3->addComponent(comp: layer); |
136 | |
137 | Qt3DRender::QLayerFilter *layerFilter = new Qt3DRender::QLayerFilter(rootEntity); |
138 | layerFilter->addLayer(layer); |
139 | |
140 | QTest::newRow(dataTag: "AcceptAny-LayerWithLayerFilterWithFilter-ShouldSelectAllButRoot" ) << rootEntity |
141 | << (Qt3DCore::QNodeIdVector() << layerFilter->id()) |
142 | << (Qt3DCore::QNodeIdVector() << childEntity1->id() << childEntity2->id() << childEntity3->id()); |
143 | } |
144 | |
145 | { |
146 | Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity(); |
147 | Qt3DCore::QEntity *childEntity1 = new Qt3DCore::QEntity(rootEntity); |
148 | Qt3DCore::QEntity *childEntity2 = new Qt3DCore::QEntity(rootEntity); |
149 | Qt3DCore::QEntity *childEntity3 = new Qt3DCore::QEntity(rootEntity); |
150 | |
151 | Q_UNUSED(childEntity1) |
152 | |
153 | Qt3DRender::QLayer *layer = new Qt3DRender::QLayer(rootEntity); |
154 | Qt3DRender::QLayer *layer2 = new Qt3DRender::QLayer(rootEntity); |
155 | childEntity2->addComponent(comp: layer2); |
156 | childEntity3->addComponent(comp: layer); |
157 | |
158 | Qt3DRender::QLayerFilter *layerFilter = new Qt3DRender::QLayerFilter(rootEntity); |
159 | layerFilter->addLayer(layer); |
160 | layerFilter->addLayer(layer: layer2); |
161 | |
162 | QTest::newRow(dataTag: "AcceptAny-LayerWithLayerFilterWithFilter-ShouldSelectChild2And3" ) << rootEntity |
163 | << (Qt3DCore::QNodeIdVector() << layerFilter->id()) |
164 | << (Qt3DCore::QNodeIdVector() << childEntity2->id() << childEntity3->id()); |
165 | } |
166 | |
167 | { |
168 | Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity(); |
169 | Qt3DCore::QEntity *childEntity1 = new Qt3DCore::QEntity(rootEntity); |
170 | Qt3DCore::QEntity *childEntity2 = new Qt3DCore::QEntity(rootEntity); |
171 | Qt3DCore::QEntity *childEntity3 = new Qt3DCore::QEntity(rootEntity); |
172 | |
173 | |
174 | Qt3DRender::QLayer *layer = new Qt3DRender::QLayer(rootEntity); |
175 | Qt3DRender::QLayer *layer2 = new Qt3DRender::QLayer(rootEntity); |
176 | childEntity1->addComponent(comp: layer); |
177 | childEntity2->addComponent(comp: layer); |
178 | childEntity3->addComponent(comp: layer); |
179 | |
180 | Qt3DRender::QLayerFilter *layerFilter = new Qt3DRender::QLayerFilter(rootEntity); |
181 | layerFilter->addLayer(layer: layer2); |
182 | |
183 | QTest::newRow(dataTag: "AcceptAny-LayerWithLayerFilterWithFilter-ShouldSelectNone" ) << rootEntity |
184 | << (Qt3DCore::QNodeIdVector() << layerFilter->id()) |
185 | << Qt3DCore::QNodeIdVector(); |
186 | } |
187 | |
188 | { |
189 | Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity(); |
190 | Qt3DCore::QEntity *childEntity1 = new Qt3DCore::QEntity(rootEntity); |
191 | Qt3DCore::QEntity *childEntity2 = new Qt3DCore::QEntity(rootEntity); |
192 | Qt3DCore::QEntity *childEntity3 = new Qt3DCore::QEntity(rootEntity); |
193 | |
194 | childEntity1->setEnabled(false); |
195 | |
196 | Qt3DRender::QLayer *layer = new Qt3DRender::QLayer(rootEntity); |
197 | childEntity1->addComponent(comp: layer); |
198 | childEntity2->addComponent(comp: layer); |
199 | childEntity3->addComponent(comp: layer); |
200 | |
201 | Qt3DRender::QLayerFilter *layerFilter = new Qt3DRender::QLayerFilter(rootEntity); |
202 | layerFilter->addLayer(layer); |
203 | |
204 | QTest::newRow(dataTag: "AcceptAny-LayerWithEntityDisabled-ShouldSelectOnlyEntityEnabled" ) << rootEntity |
205 | << (Qt3DCore::QNodeIdVector() << layerFilter->id()) |
206 | << (Qt3DCore::QNodeIdVector() << childEntity2->id() << childEntity3->id()); |
207 | } |
208 | |
209 | { |
210 | Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity(); |
211 | Qt3DCore::QEntity *childEntity1 = new Qt3DCore::QEntity(rootEntity); |
212 | Qt3DCore::QEntity *childEntity2 = new Qt3DCore::QEntity(rootEntity); |
213 | Qt3DCore::QEntity *childEntity3 = new Qt3DCore::QEntity(rootEntity); |
214 | |
215 | Qt3DRender::QLayer *layer = new Qt3DRender::QLayer(rootEntity); |
216 | layer->setRecursive(true); |
217 | rootEntity->addComponent(comp: layer); |
218 | |
219 | Qt3DRender::QLayerFilter *layerFilter = new Qt3DRender::QLayerFilter(rootEntity); |
220 | layerFilter->addLayer(layer); |
221 | |
222 | QTest::newRow(dataTag: "AcceptAny-RecursiveLayerOnRoot-ShouldSelectAll" ) << rootEntity |
223 | << (Qt3DCore::QNodeIdVector() << layerFilter->id()) |
224 | << (Qt3DCore::QNodeIdVector() |
225 | << rootEntity->id() |
226 | << childEntity1->id() |
227 | << childEntity2->id() |
228 | << childEntity3->id()); |
229 | } |
230 | |
231 | { |
232 | Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity(); |
233 | Qt3DCore::QEntity *childEntity1 = new Qt3DCore::QEntity(rootEntity); |
234 | Qt3DCore::QEntity *childEntity2 = new Qt3DCore::QEntity(rootEntity); |
235 | Qt3DCore::QEntity *childEntity3 = new Qt3DCore::QEntity(rootEntity); |
236 | |
237 | Q_UNUSED(childEntity1); |
238 | Q_UNUSED(childEntity2); |
239 | Q_UNUSED(childEntity3); |
240 | |
241 | Qt3DRender::QLayer *layer = new Qt3DRender::QLayer(rootEntity); |
242 | layer->setRecursive(true); |
243 | rootEntity->addComponent(comp: layer); |
244 | |
245 | Qt3DRender::QLayerFilter *layerFilter = new Qt3DRender::QLayerFilter(rootEntity); |
246 | layerFilter->setFilterMode(Qt3DRender::QLayerFilter::DiscardAnyMatchingLayers); |
247 | layerFilter->addLayer(layer); |
248 | |
249 | QTest::newRow(dataTag: "DiscardAny-RecursiveLayerLayerFilterDiscardOnRoot-ShouldSelectNone" ) << rootEntity |
250 | << (Qt3DCore::QNodeIdVector() << layerFilter->id()) |
251 | << (Qt3DCore::QNodeIdVector()); |
252 | } |
253 | |
254 | { |
255 | Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity(); |
256 | Qt3DCore::QEntity *childEntity1 = new Qt3DCore::QEntity(rootEntity); |
257 | Qt3DCore::QEntity *childEntity2 = new Qt3DCore::QEntity(rootEntity); |
258 | Qt3DCore::QEntity *childEntity3 = new Qt3DCore::QEntity(rootEntity); |
259 | |
260 | Qt3DRender::QLayer *layer = new Qt3DRender::QLayer(rootEntity); |
261 | rootEntity->addComponent(comp: layer); |
262 | |
263 | Qt3DRender::QLayerFilter *layerFilter = new Qt3DRender::QLayerFilter(rootEntity); |
264 | layerFilter->setFilterMode(Qt3DRender::QLayerFilter::DiscardAnyMatchingLayers); |
265 | layerFilter->addLayer(layer); |
266 | |
267 | QTest::newRow(dataTag: "DiscardAny-LayerLayerFilterDiscardOnRoot-ShouldSelectAllButRoot" ) << rootEntity |
268 | << (Qt3DCore::QNodeIdVector() << layerFilter->id()) |
269 | << (Qt3DCore::QNodeIdVector() |
270 | << childEntity1->id() |
271 | << childEntity2->id() |
272 | << childEntity3->id()); |
273 | } |
274 | |
275 | { |
276 | Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity(); |
277 | Qt3DCore::QEntity *childEntity1 = new Qt3DCore::QEntity(rootEntity); |
278 | Qt3DCore::QEntity *childEntity2 = new Qt3DCore::QEntity(rootEntity); |
279 | Qt3DCore::QEntity *childEntity3 = new Qt3DCore::QEntity(rootEntity); |
280 | |
281 | Qt3DRender::QLayer *layer = new Qt3DRender::QLayer(rootEntity); |
282 | Qt3DRender::QLayer *layer2 = new Qt3DRender::QLayer(rootEntity); |
283 | Qt3DRender::QLayer *layer3 = new Qt3DRender::QLayer(rootEntity); |
284 | rootEntity->addComponent(comp: layer); |
285 | |
286 | childEntity1->addComponent(comp: layer2); |
287 | |
288 | childEntity2->addComponent(comp: layer3); |
289 | |
290 | childEntity3->addComponent(comp: layer2); |
291 | childEntity3->addComponent(comp: layer3); |
292 | childEntity3->addComponent(comp: layer); |
293 | |
294 | Qt3DRender::QLayerFilter *layerFilter = new Qt3DRender::QLayerFilter(rootEntity); |
295 | layerFilter->setFilterMode(Qt3DRender::QLayerFilter::DiscardAnyMatchingLayers); |
296 | layerFilter->addLayer(layer: layer2); |
297 | layerFilter->addLayer(layer: layer3); |
298 | |
299 | QTest::newRow(dataTag: "DiscardAny-LayerLayerFilterDiscardOnRoot-ShouldSelectRoot" ) << rootEntity |
300 | << (Qt3DCore::QNodeIdVector() << layerFilter->id()) |
301 | << (Qt3DCore::QNodeIdVector() |
302 | << rootEntity->id()); |
303 | } |
304 | |
305 | { |
306 | Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity(); |
307 | Qt3DCore::QEntity *childEntity1 = new Qt3DCore::QEntity(rootEntity); |
308 | Qt3DCore::QEntity *childEntity2 = new Qt3DCore::QEntity(rootEntity); |
309 | Qt3DCore::QEntity *childEntity3 = new Qt3DCore::QEntity(rootEntity); |
310 | |
311 | Qt3DRender::QLayer *layer = new Qt3DRender::QLayer(rootEntity); |
312 | Qt3DRender::QLayer *layer2 = new Qt3DRender::QLayer(rootEntity); |
313 | Qt3DRender::QLayer *layer3 = new Qt3DRender::QLayer(rootEntity); |
314 | |
315 | rootEntity->addComponent(comp: layer); |
316 | |
317 | childEntity1->addComponent(comp: layer3); |
318 | childEntity1->addComponent(comp: layer2); |
319 | |
320 | childEntity2->addComponent(comp: layer); |
321 | childEntity2->addComponent(comp: layer3); |
322 | |
323 | childEntity3->addComponent(comp: layer); |
324 | childEntity3->addComponent(comp: layer2); |
325 | |
326 | Qt3DRender::QLayerFilter *layerFilter = new Qt3DRender::QLayerFilter(rootEntity); |
327 | layerFilter->setFilterMode(Qt3DRender::QLayerFilter::AcceptAllMatchingLayers); |
328 | layerFilter->addLayer(layer: layer2); |
329 | layerFilter->addLayer(layer: layer3); |
330 | |
331 | QTest::newRow(dataTag: "AcceptAll-LayerFilterWith2LayersNonRecursive-ShouldSelectChild1" ) << rootEntity |
332 | << (Qt3DCore::QNodeIdVector() << layerFilter->id()) |
333 | << (Qt3DCore::QNodeIdVector() |
334 | << childEntity1->id()); |
335 | } |
336 | |
337 | { |
338 | Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity(); |
339 | Qt3DCore::QEntity *childEntity1 = new Qt3DCore::QEntity(rootEntity); |
340 | Qt3DCore::QEntity *childEntity2 = new Qt3DCore::QEntity(rootEntity); |
341 | Qt3DCore::QEntity *childEntity3 = new Qt3DCore::QEntity(rootEntity); |
342 | |
343 | Qt3DRender::QLayer *layer = new Qt3DRender::QLayer(rootEntity); |
344 | layer->setRecursive(true); |
345 | |
346 | Qt3DRender::QLayer *layer2 = new Qt3DRender::QLayer(rootEntity); |
347 | Qt3DRender::QLayer *layer3 = new Qt3DRender::QLayer(rootEntity); |
348 | |
349 | rootEntity->addComponent(comp: layer); |
350 | |
351 | childEntity1->addComponent(comp: layer3); |
352 | childEntity1->addComponent(comp: layer2); |
353 | |
354 | childEntity2->addComponent(comp: layer3); |
355 | |
356 | childEntity3->addComponent(comp: layer2); |
357 | |
358 | Qt3DRender::QLayerFilter *layerFilter = new Qt3DRender::QLayerFilter(rootEntity); |
359 | layerFilter->setFilterMode(Qt3DRender::QLayerFilter::AcceptAllMatchingLayers); |
360 | layerFilter->addLayer(layer); |
361 | layerFilter->addLayer(layer: layer3); |
362 | |
363 | QTest::newRow(dataTag: "AcceptAll-LayerFilterWith2LayersRecursive-ShouldSelectChild12" ) << rootEntity |
364 | << (Qt3DCore::QNodeIdVector() << layerFilter->id()) |
365 | << (Qt3DCore::QNodeIdVector() |
366 | << childEntity1->id() |
367 | << childEntity2->id()); |
368 | } |
369 | |
370 | { |
371 | Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity(); |
372 | Qt3DCore::QEntity *childEntity1 = new Qt3DCore::QEntity(rootEntity); |
373 | Qt3DCore::QEntity *childEntity2 = new Qt3DCore::QEntity(rootEntity); |
374 | Qt3DCore::QEntity *childEntity3 = new Qt3DCore::QEntity(rootEntity); |
375 | |
376 | Qt3DRender::QLayer *layer = new Qt3DRender::QLayer(rootEntity); |
377 | layer->setRecursive(true); |
378 | |
379 | Qt3DRender::QLayer *layer2 = new Qt3DRender::QLayer(rootEntity); |
380 | Qt3DRender::QLayer *layer3 = new Qt3DRender::QLayer(rootEntity); |
381 | |
382 | rootEntity->addComponent(comp: layer); |
383 | |
384 | childEntity1->addComponent(comp: layer3); |
385 | childEntity1->addComponent(comp: layer2); |
386 | |
387 | childEntity2->addComponent(comp: layer); |
388 | childEntity2->addComponent(comp: layer3); |
389 | |
390 | childEntity3->addComponent(comp: layer2); |
391 | |
392 | Qt3DRender::QLayerFilter *layerFilter = new Qt3DRender::QLayerFilter(rootEntity); |
393 | layerFilter->setFilterMode(Qt3DRender::QLayerFilter::AcceptAllMatchingLayers); |
394 | layerFilter->addLayer(layer); |
395 | layerFilter->addLayer(layer: layer3); |
396 | |
397 | QTest::newRow(dataTag: "AcceptAll-LayerFilterWith2LayersRecursiveAndDirectReferenceToRecursiveLayer-ShouldSelectChild12" ) << rootEntity |
398 | << (Qt3DCore::QNodeIdVector() << layerFilter->id()) |
399 | << (Qt3DCore::QNodeIdVector() |
400 | << childEntity1->id() |
401 | << childEntity2->id()); |
402 | } |
403 | |
404 | { |
405 | Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity(); |
406 | Qt3DCore::QEntity *childEntity1 = new Qt3DCore::QEntity(rootEntity); |
407 | Qt3DCore::QEntity *childEntity2 = new Qt3DCore::QEntity(rootEntity); |
408 | Qt3DCore::QEntity *childEntity3 = new Qt3DCore::QEntity(rootEntity); |
409 | |
410 | Qt3DRender::QLayer *layer = new Qt3DRender::QLayer(rootEntity); |
411 | Qt3DRender::QLayer *layer2 = new Qt3DRender::QLayer(rootEntity); |
412 | Qt3DRender::QLayer *layer3 = new Qt3DRender::QLayer(rootEntity); |
413 | |
414 | rootEntity->addComponent(comp: layer); |
415 | |
416 | childEntity1->addComponent(comp: layer); |
417 | childEntity1->addComponent(comp: layer2); |
418 | |
419 | childEntity2->addComponent(comp: layer); |
420 | childEntity2->addComponent(comp: layer3); |
421 | |
422 | childEntity3->addComponent(comp: layer2); |
423 | childEntity3->addComponent(comp: layer3); |
424 | |
425 | Qt3DRender::QLayerFilter *layerFilter = new Qt3DRender::QLayerFilter(rootEntity); |
426 | layerFilter->setFilterMode(Qt3DRender::QLayerFilter::DiscardAllMatchingLayers); |
427 | layerFilter->addLayer(layer: layer2); |
428 | layerFilter->addLayer(layer: layer3); |
429 | |
430 | QTest::newRow(dataTag: "DiscardAll-LayerFilterWith2Layers-ShouldSelectRootAndChild12" ) << rootEntity |
431 | << (Qt3DCore::QNodeIdVector() << layerFilter->id()) |
432 | << (Qt3DCore::QNodeIdVector() |
433 | << rootEntity->id() |
434 | << childEntity1->id() |
435 | << childEntity2->id()); |
436 | } |
437 | |
438 | { |
439 | Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity(); |
440 | Qt3DCore::QEntity *childEntity1 = new Qt3DCore::QEntity(rootEntity); |
441 | Qt3DCore::QEntity *childEntity2 = new Qt3DCore::QEntity(rootEntity); |
442 | Qt3DCore::QEntity *childEntity3 = new Qt3DCore::QEntity(rootEntity); |
443 | |
444 | Qt3DRender::QLayer *layer = new Qt3DRender::QLayer(rootEntity); |
445 | layer->setRecursive(true); |
446 | |
447 | Qt3DRender::QLayer *layer2 = new Qt3DRender::QLayer(rootEntity); |
448 | Qt3DRender::QLayer *layer3 = new Qt3DRender::QLayer(rootEntity); |
449 | |
450 | rootEntity->addComponent(comp: layer); |
451 | |
452 | childEntity1->addComponent(comp: layer2); |
453 | |
454 | childEntity2->addComponent(comp: layer3); |
455 | |
456 | childEntity3->addComponent(comp: layer3); |
457 | |
458 | Qt3DRender::QLayerFilter *layerFilter = new Qt3DRender::QLayerFilter(rootEntity); |
459 | layerFilter->setFilterMode(Qt3DRender::QLayerFilter::DiscardAllMatchingLayers); |
460 | layerFilter->addLayer(layer); |
461 | layerFilter->addLayer(layer: layer3); |
462 | |
463 | QTest::newRow(dataTag: "DiscardAll-LayerFilterWith2LayersRecursive-ShouldSelectRootAndChild1" ) << rootEntity |
464 | << (Qt3DCore::QNodeIdVector() << layerFilter->id()) |
465 | << (Qt3DCore::QNodeIdVector() |
466 | << rootEntity->id() |
467 | << childEntity1->id()); |
468 | } |
469 | |
470 | { |
471 | Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity(); |
472 | Qt3DCore::QEntity *childEntity1 = new Qt3DCore::QEntity(rootEntity); |
473 | Qt3DCore::QEntity *childEntity2 = new Qt3DCore::QEntity(rootEntity); |
474 | Qt3DCore::QEntity *childEntity3 = new Qt3DCore::QEntity(rootEntity); |
475 | |
476 | Qt3DRender::QLayer *layer = new Qt3DRender::QLayer(rootEntity); |
477 | layer->setRecursive(true); |
478 | |
479 | Qt3DRender::QLayer *layer2 = new Qt3DRender::QLayer(rootEntity); |
480 | Qt3DRender::QLayer *layer3 = new Qt3DRender::QLayer(rootEntity); |
481 | |
482 | rootEntity->addComponent(comp: layer); |
483 | |
484 | childEntity1->addComponent(comp: layer2); |
485 | childEntity1->addComponent(comp: layer); |
486 | |
487 | childEntity2->addComponent(comp: layer3); |
488 | |
489 | childEntity3->addComponent(comp: layer3); |
490 | |
491 | Qt3DRender::QLayerFilter *layerFilter = new Qt3DRender::QLayerFilter(rootEntity); |
492 | layerFilter->setFilterMode(Qt3DRender::QLayerFilter::DiscardAllMatchingLayers); |
493 | layerFilter->addLayer(layer); |
494 | layerFilter->addLayer(layer: layer3); |
495 | |
496 | QTest::newRow(dataTag: "DiscardAll-LayerFilterWith2LayersRecursiveAndDirectReference-ShouldSelectRootAndChild1" ) << rootEntity |
497 | << (Qt3DCore::QNodeIdVector() << layerFilter->id()) |
498 | << (Qt3DCore::QNodeIdVector() |
499 | << rootEntity->id() |
500 | << childEntity1->id()); |
501 | } |
502 | |
503 | { |
504 | Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity(); |
505 | Qt3DCore::QEntity *childEntity1 = new Qt3DCore::QEntity(rootEntity); |
506 | Qt3DCore::QEntity *childEntity2 = new Qt3DCore::QEntity(rootEntity); |
507 | Qt3DCore::QEntity *childEntity3 = new Qt3DCore::QEntity(rootEntity); |
508 | |
509 | Qt3DRender::QLayer *layer = new Qt3DRender::QLayer(rootEntity); |
510 | layer->setRecursive(true); |
511 | |
512 | Qt3DRender::QLayer *layer2 = new Qt3DRender::QLayer(rootEntity); |
513 | Qt3DRender::QLayer *layer3 = new Qt3DRender::QLayer(rootEntity); |
514 | Qt3DRender::QLayer *layer4 = new Qt3DRender::QLayer(rootEntity); |
515 | Qt3DRender::QLayer *layer5 = new Qt3DRender::QLayer(rootEntity); |
516 | |
517 | rootEntity->addComponent(comp: layer); |
518 | |
519 | childEntity1->addComponent(comp: layer2); |
520 | childEntity1->addComponent(comp: layer3); |
521 | |
522 | childEntity2->addComponent(comp: layer2); |
523 | childEntity2->addComponent(comp: layer3); |
524 | childEntity2->addComponent(comp: layer4); |
525 | childEntity2->addComponent(comp: layer5); |
526 | |
527 | childEntity3->addComponent(comp: layer2); |
528 | childEntity3->addComponent(comp: layer3); |
529 | childEntity3->addComponent(comp: layer5); |
530 | |
531 | Qt3DRender::QLayerFilter *layerFilter = new Qt3DRender::QLayerFilter(rootEntity); |
532 | layerFilter->setFilterMode(Qt3DRender::QLayerFilter::AcceptAllMatchingLayers); |
533 | layerFilter->addLayer(layer); |
534 | layerFilter->addLayer(layer: layer2); |
535 | layerFilter->addLayer(layer: layer3); |
536 | |
537 | Qt3DRender::QLayerFilter *layerFilter2 = new Qt3DRender::QLayerFilter(rootEntity); |
538 | layerFilter2->setFilterMode(Qt3DRender::QLayerFilter::DiscardAnyMatchingLayers); |
539 | layerFilter2->addLayer(layer: layer4); |
540 | layerFilter2->addLayer(layer: layer5); |
541 | |
542 | QTest::newRow(dataTag: "NestedFiltering-SelectAllOfLayer123AndNoneOf45-ShouldChild1" ) << rootEntity |
543 | << (Qt3DCore::QNodeIdVector() << layerFilter->id() << layerFilter2->id()) |
544 | << (Qt3DCore::QNodeIdVector() |
545 | << childEntity1->id()); |
546 | } |
547 | |
548 | { |
549 | Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity(); |
550 | Qt3DCore::QEntity *childEntity1 = new Qt3DCore::QEntity(rootEntity); |
551 | Qt3DCore::QEntity *childEntity2 = new Qt3DCore::QEntity(rootEntity); |
552 | Qt3DCore::QEntity *childEntity3 = new Qt3DCore::QEntity(rootEntity); |
553 | Qt3DCore::QEntity *childEntity4 = new Qt3DCore::QEntity(rootEntity); |
554 | Qt3DCore::QEntity *childEntity5 = new Qt3DCore::QEntity(rootEntity); |
555 | |
556 | Qt3DRender::QLayer *layer = new Qt3DRender::QLayer(rootEntity); |
557 | layer->setRecursive(true); |
558 | |
559 | Qt3DRender::QLayer *layer2 = new Qt3DRender::QLayer(rootEntity); |
560 | Qt3DRender::QLayer *layer3 = new Qt3DRender::QLayer(rootEntity); |
561 | Qt3DRender::QLayer *layer4 = new Qt3DRender::QLayer(rootEntity); |
562 | Qt3DRender::QLayer *layer5 = new Qt3DRender::QLayer(rootEntity); |
563 | Qt3DRender::QLayer *layer6 = new Qt3DRender::QLayer(rootEntity); |
564 | |
565 | rootEntity->addComponent(comp: layer); |
566 | |
567 | childEntity1->addComponent(comp: layer2); |
568 | childEntity1->addComponent(comp: layer3); |
569 | |
570 | childEntity2->addComponent(comp: layer2); |
571 | childEntity2->addComponent(comp: layer3); |
572 | childEntity2->addComponent(comp: layer4); |
573 | childEntity2->addComponent(comp: layer5); |
574 | |
575 | childEntity3->addComponent(comp: layer2); |
576 | childEntity3->addComponent(comp: layer5); |
577 | |
578 | childEntity4->addComponent(comp: layer2); |
579 | childEntity4->addComponent(comp: layer); |
580 | childEntity4->addComponent(comp: layer3); |
581 | childEntity4->addComponent(comp: layer6); |
582 | |
583 | childEntity5->addComponent(comp: layer3); |
584 | childEntity5->addComponent(comp: layer4); |
585 | childEntity5->addComponent(comp: layer6); |
586 | |
587 | Qt3DRender::QLayerFilter *layerFilter = new Qt3DRender::QLayerFilter(rootEntity); |
588 | layerFilter->setFilterMode(Qt3DRender::QLayerFilter::DiscardAnyMatchingLayers); |
589 | layerFilter->addLayer(layer: layer5); |
590 | layerFilter->addLayer(layer: layer4); |
591 | |
592 | Qt3DRender::QLayerFilter *layerFilter2 = new Qt3DRender::QLayerFilter(rootEntity); |
593 | layerFilter2->setFilterMode(Qt3DRender::QLayerFilter::AcceptAnyMatchingLayers); |
594 | layerFilter2->addLayer(layer: layer2); |
595 | layerFilter2->addLayer(layer: layer3); |
596 | |
597 | Qt3DRender::QLayerFilter *layerFilter3 = new Qt3DRender::QLayerFilter(rootEntity); |
598 | layerFilter3->setFilterMode(Qt3DRender::QLayerFilter::AcceptAllMatchingLayers); |
599 | layerFilter3->addLayer(layer); |
600 | layerFilter3->addLayer(layer: layer6); |
601 | |
602 | QTest::newRow(dataTag: "NestedFiltering-SelectAllNoneOfAnyLayer45AndAnyOf23AndAllOf16-ShouldSelectChild4-Step1" ) << rootEntity |
603 | << (Qt3DCore::QNodeIdVector() << layerFilter->id()) |
604 | << (Qt3DCore::QNodeIdVector() |
605 | << rootEntity->id() |
606 | << childEntity1->id() |
607 | << childEntity4->id() |
608 | ); |
609 | |
610 | QTest::newRow(dataTag: "NestedFiltering-SelectAllNoneOfAnyLayer45AndAnyOf23AndAllOf16-ShouldSelectChild4-Step2" ) << rootEntity |
611 | << (Qt3DCore::QNodeIdVector() << layerFilter->id() << layerFilter2->id()) |
612 | << (Qt3DCore::QNodeIdVector() |
613 | << childEntity1->id() |
614 | << childEntity4->id()); |
615 | |
616 | QTest::newRow(dataTag: "NestedFiltering-SelectAllNoneOfAnyLayer45AndAnyOf23AndAllOf16-ShouldSelectChild4-Step3" ) << rootEntity |
617 | << (Qt3DCore::QNodeIdVector() << layerFilter->id() << layerFilter2->id() << layerFilter3->id()) |
618 | << (Qt3DCore::QNodeIdVector() |
619 | << childEntity4->id()); |
620 | } |
621 | } |
622 | |
623 | void filterEntities() |
624 | { |
625 | //QSKIP("Skipping until TestAspect can be registered"); |
626 | QFETCH(Qt3DCore::QEntity *, entitySubtree); |
627 | QFETCH(Qt3DCore::QNodeIdVector, layerFilterIds); |
628 | QFETCH(Qt3DCore::QNodeIdVector, expectedSelectedEntities); |
629 | |
630 | |
631 | // GIVEN |
632 | QScopedPointer<Qt3DRender::TestAspect> aspect(new Qt3DRender::TestAspect(entitySubtree)); |
633 | |
634 | // WHEN |
635 | Qt3DRender::Render::Entity *backendRoot = aspect->nodeManagers()->renderNodesManager()->getOrCreateResource(id: entitySubtree->id()); |
636 | |
637 | Qt3DRender::Render::UpdateTreeEnabledJob updateTreeEnabledJob; |
638 | updateTreeEnabledJob.setRoot(backendRoot); |
639 | updateTreeEnabledJob.setManagers(aspect->nodeManagers()); |
640 | updateTreeEnabledJob.run(); |
641 | |
642 | // WHEN |
643 | Qt3DRender::Render::UpdateEntityLayersJob updateLayerEntityJob; |
644 | updateLayerEntityJob.setManager(aspect->nodeManagers()); |
645 | updateLayerEntityJob.run(); |
646 | |
647 | Qt3DRender::Render::FilterLayerEntityJob filterJob; |
648 | filterJob.setLayerFilters(layerFilterIds); |
649 | filterJob.setManager(aspect->nodeManagers()); |
650 | filterJob.run(); |
651 | |
652 | // THEN |
653 | const QVector<Qt3DRender::Render::Entity *> filterEntities = filterJob.filteredEntities(); |
654 | QCOMPARE(filterEntities.size(), expectedSelectedEntities.size()); |
655 | for (auto i = 0, m = expectedSelectedEntities.size(); i < m; ++i) |
656 | QCOMPARE(filterEntities.at(i)->peerId(), expectedSelectedEntities.at(i)); |
657 | } |
658 | }; |
659 | |
660 | QTEST_MAIN(tst_LayerFiltering) |
661 | |
662 | #include "tst_layerfiltering.moc" |
663 | |