1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include "q3dlight_p.h"
5
6QT_BEGIN_NAMESPACE
7
8/*!
9 * \class Q3DLight
10 * \inmodule QtDataVisualization
11 * \brief Representation of a light source in 3D space.
12 * \since QtDataVisualization 1.0
13 *
14 * Q3DLight represents a monochrome light source in 3D space.
15 *
16 * \note Default light has isAutoPosition() \c true.
17 */
18
19/*!
20 * \qmltype Light3D
21 * \inqmlmodule QtDataVisualization
22 * \since QtDataVisualization 1.0
23 * \ingroup datavisualization_qml
24 * \instantiates Q3DLight
25 * \brief Representation of a light source in 3D space.
26 *
27 * Light3D represents a monochrome light source in 3D space.
28 *
29 * \note Default light has autoPosition \c true.
30 */
31
32/*!
33 * \qmlproperty bool Light3D::autoPosition
34 * \since QtDataVisualization 1.3
35 * Defines whether the light position follows the camera automatically.
36 * \note Has no effect if shadows are enabled. Remember to disable shadows before setting light's
37 * position, or it will be overwritten by automatic positioning if this
38 * property is \c false.
39 */
40
41/*!
42 * Constructs a new 3D light located at origin. An optional \a parent parameter can be given
43 * and is then passed to QObject constructor.
44 */
45Q3DLight::Q3DLight(QObject *parent) :
46 Q3DObject(parent),
47 d_ptr(new Q3DLightPrivate(this))
48{
49}
50
51/*!
52 * Destroys the light object.
53 */
54Q3DLight::~Q3DLight()
55{
56}
57
58/*!
59 * \property Q3DLight::autoPosition
60 * \since QtDataVisualization 5.9
61 * \brief Whether the light position follows the camera automatically.
62 * \note Has no effect if shadows are enabled. Remember to disable shadows before setting light's
63 * position, or it will be overwritten by automatic positioning if
64 * \c isAutoPosition() is \c false.
65 */
66void Q3DLight::setAutoPosition(bool enabled)
67{
68 if (enabled != d_ptr->m_automaticLight) {
69 d_ptr->m_automaticLight = enabled;
70 setDirty(true);
71 emit autoPositionChanged(autoPosition: enabled);
72 }
73}
74
75bool Q3DLight::isAutoPosition()
76{
77 return d_ptr->m_automaticLight;
78}
79
80Q3DLightPrivate::Q3DLightPrivate(Q3DLight *q) :
81 q_ptr(q),
82 m_automaticLight(false)
83{
84}
85
86Q3DLightPrivate::~Q3DLightPrivate()
87{
88}
89
90void Q3DLightPrivate::sync(Q3DLight &other)
91{
92 if (q_ptr->isDirty()) {
93 other.setPosition(q_ptr->position());
94 other.setAutoPosition(q_ptr->isAutoPosition());
95 q_ptr->setDirty(false);
96 }
97}
98
99QT_END_NAMESPACE
100

source code of qtdatavis3d/src/datavisualization/engine/q3dlight.cpp