1// Copyright (C) 2017 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 "qproximityfilter.h"
5#include "qproximityfilter_p.h"
6#include <Qt3DCore/qentity.h>
7
8QT_BEGIN_NAMESPACE
9
10namespace Qt3DRender {
11
12QProximityFilterPrivate::QProximityFilterPrivate()
13 : QFrameGraphNodePrivate()
14 , m_entity(nullptr)
15 , m_distanceThreshold(0.0f)
16{
17}
18
19/*!
20 \class Qt3DRender::QProximityFilter
21 \inmodule Qt3DRender
22 \since 5.10
23
24 \brief Select entities which are within a distance threshold of a target
25 entity.
26
27 A \l Qt3DRender::QProximityFilter can be used to select entities to render
28 when they are placed within a given distance threshold of another entity.
29*/
30
31/*!
32 \property Qt3DRender::QProximityFilter::entity
33
34 Holds the entity against which we should compare the distance to.
35*/
36
37/*!
38 \property Qt3DRender::QProximityFilter::distanceThreshold
39
40 Holds the distance to the target entity above which entities are filtered
41 out.
42*/
43
44/*!
45 \qmltype ProximityFilter
46 \instantiates Qt3DRender::QProximityFilter
47 \inherits FrameGraphNode
48 \inqmlmodule Qt3D.Render
49 \since 5.10
50
51 \brief Select entities which are within a distance threshold of a target
52 entity.
53
54 A \l ProximityFilter can be used to select entities to render
55 when they are placed within a given distance threshold of another entity.
56
57 \badcode
58 import Qt3DRender 2.10
59 ...
60 RenderSetting {
61 Viewport {
62 CameraSelector {
63 camera: mainCamera
64 ProximityFilter {
65 entity: mainCamera
66 distanceThreshold: 50 // select entities within 50m metre radius of mainCamera
67 }
68 }
69 }
70 }
71 \endcode
72*/
73
74/*!
75 \qmlproperty Entity Qt3D.Render::ProximityFilter::entity
76
77 Holds the entity against which we should compare the distance to.
78 */
79
80/*!
81 \qmlproperty real Qt3D.Render::ProximityFilter::distanceThreshold
82
83 Holds the distance to the target entity above which entities are filtered
84 out.
85 */
86
87
88QProximityFilter::QProximityFilter(Qt3DCore::QNode *parent)
89 : QFrameGraphNode(*new QProximityFilterPrivate, parent)
90{
91
92}
93
94/*! \internal */
95QProximityFilter::QProximityFilter(QProximityFilterPrivate &dd, QNode *parent)
96 : QFrameGraphNode(dd, parent)
97{
98}
99
100/*! \internal */
101QProximityFilter::~QProximityFilter()
102{
103}
104
105Qt3DCore::QEntity *QProximityFilter::entity() const
106{
107 Q_D(const QProximityFilter);
108 return d->m_entity;
109}
110
111float QProximityFilter::distanceThreshold() const
112{
113 Q_D(const QProximityFilter);
114 return d->m_distanceThreshold;
115}
116
117void QProximityFilter::setEntity(Qt3DCore::QEntity *entity)
118{
119 Q_D(QProximityFilter);
120 if (d->m_entity != entity) {
121
122 if (d->m_entity)
123 d->unregisterDestructionHelper(node: d->m_entity);
124
125 if (entity && !entity->parent())
126 entity->setParent(this);
127
128 d->m_entity = entity;
129
130 if (d->m_entity)
131 d->registerDestructionHelper(node: d->m_entity, func: &QProximityFilter::setEntity, d->m_entity);
132
133 emit entityChanged(entity);
134 }
135}
136
137void QProximityFilter::setDistanceThreshold(float distanceThreshold)
138{
139 Q_D(QProximityFilter);
140 if (d->m_distanceThreshold == distanceThreshold)
141 return;
142
143 d->m_distanceThreshold = distanceThreshold;
144 emit distanceThresholdChanged(distanceThreshold);
145}
146
147} // Qt3DRender
148
149QT_END_NAMESPACE
150
151#include "moc_qproximityfilter.cpp"
152

source code of qt3d/src/render/framegraph/qproximityfilter.cpp