1// Copyright (C) 2014 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 "qcameraselector.h"
5#include "qcameraselector_p.h"
6#include <Qt3DCore/qentity.h>
7#include <Qt3DCore/private/qentity_p.h>
8
9QT_BEGIN_NAMESPACE
10
11namespace Qt3DRender {
12
13/*!
14 \class Qt3DRender::QCameraSelector
15 \inmodule Qt3DRender
16 \since 5.5
17 \ingroup framegraph
18
19 \brief Class to allow for selection of camera to be used.
20
21 A Qt3DRender::QCameraSelector can be used to select the camera, which is used
22 by the FrameGraph when drawing the entities.
23 */
24
25/*!
26 \qmltype CameraSelector
27 \inqmlmodule Qt3D.Render
28 \instantiates Qt3DRender::QCameraSelector
29 \inherits FrameGraphNode
30 \since 5.5
31 \brief Class to allow for selection of camera to be used.
32
33 A CameraSelector can be used to select the camera, which is used
34 by the FrameGraph when drawing the entities.
35*/
36
37/*!
38 \qmlproperty Entity Qt3D.Render::CameraSelector::camera
39
40 Holds the currently selected camera.
41*/
42
43/*!
44 \property Qt3DRender::QCameraSelector::camera
45
46 Holds the currently selected camera.
47*/
48
49
50/*! \internal */
51QCameraSelector::QCameraSelector(QCameraSelectorPrivate &dd, QNode *parent)
52 : QFrameGraphNode(dd, parent)
53{
54}
55
56QCameraSelectorPrivate::QCameraSelectorPrivate()
57 : QFrameGraphNodePrivate()
58 , m_camera(nullptr)
59{
60}
61
62/*!
63 The constructor creates an instance with the specified \a parent.
64 */
65QCameraSelector::QCameraSelector(Qt3DCore::QNode *parent)
66 : QFrameGraphNode(*new QCameraSelectorPrivate, parent)
67{
68}
69
70/*! \internal */
71QCameraSelector::~QCameraSelector()
72{
73}
74
75void QCameraSelector::setCamera(Qt3DCore::QEntity *camera)
76{
77 Q_D(QCameraSelector);
78 if (d->m_camera != camera) {
79
80 if (d->m_camera)
81 d->unregisterDestructionHelper(node: d->m_camera);
82
83 // We need to add it as a child of the current node if it has been declared inline
84 // Or not previously added as a child of the current node so that
85 // 1) The backend gets notified about it's creation
86 // 2) When the current node is destroyed, it gets destroyed as well
87 if (camera && !camera->parent())
88 camera->setParent(this);
89 d->m_camera = camera;
90
91 // Ensures proper bookkeeping
92 if (d->m_camera)
93 d->registerDestructionHelper(node: d->m_camera, func: &QCameraSelector::setCamera, d->m_camera);
94
95 emit cameraChanged(camera);
96 }
97}
98
99Qt3DCore::QEntity *QCameraSelector::camera() const
100{
101 Q_D(const QCameraSelector);
102 return d->m_camera;
103}
104
105} // namespace Qt3DRender
106
107QT_END_NAMESPACE
108
109#include "moc_qcameraselector.cpp"
110

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