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:LGPL$
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 Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qcameraselector.h"
41#include "qcameraselector_p.h"
42#include <Qt3DCore/qentity.h>
43#include <Qt3DCore/private/qentity_p.h>
44#include <Qt3DRender/qframegraphnodecreatedchange.h>
45
46QT_BEGIN_NAMESPACE
47
48namespace Qt3DRender {
49
50/*!
51 \class Qt3DRender::QCameraSelector
52 \inmodule Qt3DRender
53 \since 5.5
54 \ingroup framegraph
55
56 \brief Class to allow for selection of camera to be used.
57
58 A Qt3DRender::QCameraSelector can be used to select the camera, which is used
59 by the FrameGraph when drawing the entities.
60 */
61
62/*!
63 \qmltype CameraSelector
64 \inqmlmodule Qt3D.Render
65 \instantiates Qt3DRender::QCameraSelector
66 \inherits FrameGraphNode
67 \since 5.5
68 \brief Class to allow for selection of camera to be used.
69
70 A CameraSelector can be used to select the camera, which is used
71 by the FrameGraph when drawing the entities.
72*/
73
74/*!
75 \qmlproperty Entity Qt3D.Render::CameraSelector::camera
76
77 Holds the currently selected camera.
78*/
79
80/*!
81 \property Qt3DRender::QCameraSelector::camera
82
83 Holds the currently selected camera.
84*/
85
86
87/*! \internal */
88QCameraSelector::QCameraSelector(QCameraSelectorPrivate &dd, QNode *parent)
89 : QFrameGraphNode(dd, parent)
90{
91}
92
93QCameraSelectorPrivate::QCameraSelectorPrivate()
94 : QFrameGraphNodePrivate()
95 , m_camera(nullptr)
96{
97}
98
99/*!
100 The constructor creates an instance with the specified \a parent.
101 */
102QCameraSelector::QCameraSelector(Qt3DCore::QNode *parent)
103 : QFrameGraphNode(*new QCameraSelectorPrivate, parent)
104{
105}
106
107/*! \internal */
108QCameraSelector::~QCameraSelector()
109{
110}
111
112void QCameraSelector::setCamera(Qt3DCore::QEntity *camera)
113{
114 Q_D(QCameraSelector);
115 if (d->m_camera != camera) {
116
117 if (d->m_camera)
118 d->unregisterDestructionHelper(node: d->m_camera);
119
120 // We need to add it as a child of the current node if it has been declared inline
121 // Or not previously added as a child of the current node so that
122 // 1) The backend gets notified about it's creation
123 // 2) When the current node is destroyed, it gets destroyed as well
124 if (camera && !camera->parent())
125 camera->setParent(this);
126 d->m_camera = camera;
127
128 // Ensures proper bookkeeping
129 if (d->m_camera)
130 d->registerDestructionHelper(node: d->m_camera, func: &QCameraSelector::setCamera, d->m_camera);
131
132 emit cameraChanged(camera);
133 }
134}
135
136Qt3DCore::QEntity *QCameraSelector::camera() const
137{
138 Q_D(const QCameraSelector);
139 return d->m_camera;
140}
141
142Qt3DCore::QNodeCreatedChangeBasePtr QCameraSelector::createNodeCreationChange() const
143{
144 auto creationChange = QFrameGraphNodeCreatedChangePtr<QCameraSelectorData>::create(arguments: this);
145 auto &data = creationChange->data;
146 Q_D(const QCameraSelector);
147 data.cameraId = qIdForNode(node: d->m_camera);
148 return creationChange;
149}
150
151} // namespace Qt3DRender
152
153QT_END_NAMESPACE
154

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