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 <Qt3DCore/qtransform.h>
32
33#include <Qt3DRender/private/nodemanagers_p.h>
34#include <Qt3DRender/private/managers_p.h>
35#include <Qt3DRender/private/entity_p.h>
36#include <Qt3DRender/private/filterentitybycomponentjob_p.h>
37#include <Qt3DRender/qgeometryrenderer.h>
38#include <Qt3DRender/qcameralens.h>
39#include <Qt3DRender/qmaterial.h>
40#include <Qt3DRender/qobjectpicker.h>
41#include <Qt3DRender/qcomputecommand.h>
42
43#include <Qt3DRender/private/transform_p.h>
44#include <Qt3DRender/private/geometryrenderer_p.h>
45#include <Qt3DRender/private/computecommand_p.h>
46#include <Qt3DRender/private/objectpicker_p.h>
47#include <Qt3DRender/private/cameralens_p.h>
48#include <Qt3DRender/private/objectpicker_p.h>
49#include "testaspect.h"
50
51class tst_FilterEntityByComponent : public QObject
52{
53 Q_OBJECT
54private Q_SLOTS:
55
56 void filterEntities()
57 {
58 // GIVEN
59 Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity();
60 Qt3DCore::QEntity *childEntity1 = new Qt3DCore::QEntity(rootEntity);
61 Qt3DCore::QEntity *childEntity2 = new Qt3DCore::QEntity(rootEntity);
62 Qt3DCore::QEntity *childEntity3 = new Qt3DCore::QEntity(rootEntity);
63
64 Qt3DCore::QTransform *transform = new Qt3DCore::QTransform(rootEntity);
65 Qt3DRender::QGeometryRenderer *geomRenderer = new Qt3DRender::QGeometryRenderer(rootEntity);
66 Qt3DRender::QCameraLens *cameraLens = new Qt3DRender::QCameraLens(rootEntity);
67 Qt3DRender::QMaterial *material = new Qt3DRender::QMaterial(rootEntity);
68 Qt3DRender::QObjectPicker *objectPicker = new Qt3DRender::QObjectPicker(rootEntity);
69 Qt3DRender::QComputeCommand *computeCommand = new Qt3DRender::QComputeCommand(rootEntity);
70
71 childEntity1->addComponent(comp: transform);
72 childEntity1->addComponent(comp: geomRenderer);
73 childEntity1->addComponent(comp: material);
74
75 childEntity2->addComponent(comp: cameraLens);
76 childEntity2->addComponent(comp: transform);
77
78 childEntity3->addComponent(comp: objectPicker);
79 childEntity3->addComponent(comp: computeCommand);
80
81 QScopedPointer<Qt3DRender::TestAspect> aspect(new Qt3DRender::TestAspect(rootEntity));
82
83 {
84 // WHEN
85 Qt3DRender::Render::FilterEntityByComponentJob<Qt3DRender::Render::Transform> filterJob;
86 filterJob.setManager(aspect->nodeManagers()->renderNodesManager());
87 filterJob.run();
88
89 // THEN
90 QCOMPARE(filterJob.filteredEntities().size(), 2);
91 QCOMPARE(filterJob.filteredEntities().first()->peerId(), childEntity1->id());
92 QCOMPARE(filterJob.filteredEntities().last()->peerId(), childEntity2->id());
93 }
94
95 {
96 // WHEN
97 Qt3DRender::Render::FilterEntityByComponentJob<Qt3DRender::Render::Transform, Qt3DRender::Render::Material> filterJob;
98 filterJob.setManager(aspect->nodeManagers()->renderNodesManager());
99 filterJob.run();
100
101 // THEN
102 QCOMPARE(filterJob.filteredEntities().size(), 1);
103 QCOMPARE(filterJob.filteredEntities().first()->peerId(), childEntity1->id());
104 }
105
106 {
107 // WHEN
108 Qt3DRender::Render::FilterEntityByComponentJob<Qt3DRender::Render::Transform, Qt3DRender::Render::Material, Qt3DRender::Render::ComputeCommand> filterJob;
109 filterJob.setManager(aspect->nodeManagers()->renderNodesManager());
110 filterJob.run();
111
112 // THEN
113 QCOMPARE(filterJob.filteredEntities().size(), 0);
114 }
115
116 {
117 // WHEN
118 Qt3DRender::Render::FilterEntityByComponentJob<Qt3DRender::Render::ComputeCommand> filterJob;
119 filterJob.setManager(aspect->nodeManagers()->renderNodesManager());
120 filterJob.run();
121
122 // THEN
123 QCOMPARE(filterJob.filteredEntities().size(), 1);
124 QCOMPARE(filterJob.filteredEntities().first()->peerId(), childEntity3->id());
125 }
126 }
127};
128
129QTEST_MAIN(tst_FilterEntityByComponent)
130
131#include "tst_filterentitybycomponent.moc"
132

source code of qt3d/tests/auto/render/filterentitybycomponent/tst_filterentitybycomponent.cpp