1 | // Copyright (C) 2023 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include "q3dobject_p.h" |
5 | #include "q3dscene_p.h" |
6 | |
7 | QT_BEGIN_NAMESPACE |
8 | |
9 | /*! |
10 | \class Q3DObject |
11 | \inmodule QtGraphs |
12 | \brief The Q3DObject class is a simple base class for all the objects in a |
13 | 3D scene. |
14 | |
15 | Contains position information for an object in a 3D scene. |
16 | The object is considered to be a single point in the coordinate space without dimensions. |
17 | */ |
18 | |
19 | /*! |
20 | \qmltype Object3D |
21 | \inqmlmodule QtGraphs |
22 | \ingroup graphs_qml |
23 | \instantiates Q3DObject |
24 | \brief A base type for all the objects in a 3D scene. |
25 | |
26 | An uncreatable base type that contains position information for an object in |
27 | a 3D scene. The object is considered to be a single point in the coordinate space without |
28 | dimensions. |
29 | */ |
30 | |
31 | /*! |
32 | * \qmlproperty vector3d Object3D::position |
33 | * |
34 | * The 3D position of the object. |
35 | * |
36 | * \note Currently setting this property has no effect for Camera3D, as the position is handled |
37 | * internally. |
38 | */ |
39 | |
40 | /*! |
41 | * \internal |
42 | */ |
43 | Q3DObject::Q3DObject(Q3DObjectPrivate *d, QObject *parent) : |
44 | QObject(parent), |
45 | d_ptr(d) |
46 | { |
47 | } |
48 | |
49 | /*! |
50 | * Constructs a new 3D object with the position set to origin by default. An |
51 | * optional \a parent parameter can be given and is then passed to the QObject |
52 | * constructor. |
53 | */ |
54 | Q3DObject::Q3DObject(QObject *parent) : |
55 | QObject(parent) |
56 | { |
57 | } |
58 | |
59 | /*! |
60 | * Destroys the 3D object. |
61 | */ |
62 | Q3DObject::~Q3DObject() |
63 | { |
64 | } |
65 | |
66 | /*! |
67 | * Copies the 3D object position from the given \a source 3D object to this 3D object instance. |
68 | */ |
69 | void Q3DObject::copyValuesFrom(const Q3DObject &source) |
70 | { |
71 | Q_D(Q3DObject); |
72 | d->m_position = source.d_func()->m_position; |
73 | setDirty(true); |
74 | } |
75 | |
76 | /*! |
77 | * \property Q3DObject::parentScene |
78 | * |
79 | * \brief The parent scene as a read only value. |
80 | * |
81 | * If the object has no parent scene, the value is 0. |
82 | */ |
83 | Q3DScene *Q3DObject::parentScene() |
84 | { |
85 | return qobject_cast<Q3DScene *>(object: parent()); |
86 | } |
87 | |
88 | /*! |
89 | * \property Q3DObject::position |
90 | * |
91 | * \brief The 3D position of the object. |
92 | * |
93 | * \note Currently setting this property has no effect for Q3DCamera, as the position is handled |
94 | * internally. |
95 | */ |
96 | QVector3D Q3DObject::position() const |
97 | { |
98 | const Q_D(Q3DObject); |
99 | return d->m_position; |
100 | } |
101 | |
102 | void Q3DObject::setPosition(const QVector3D &position) |
103 | { |
104 | Q_D(Q3DObject); |
105 | if (d->m_position != position) { |
106 | d->m_position = position; |
107 | setDirty(true); |
108 | emit positionChanged(position: d->m_position); |
109 | } |
110 | } |
111 | |
112 | /*! |
113 | * Sets \a dirty to \c true if the 3D object has changed since the last update. |
114 | */ |
115 | void Q3DObject::setDirty(bool dirty) |
116 | { |
117 | Q_D(Q3DObject); |
118 | d->m_isDirty = dirty; |
119 | if (parentScene()) |
120 | parentScene()->d_func()->markDirty(); |
121 | } |
122 | |
123 | /*! |
124 | * Returns whether the 3D object has changed. |
125 | */ |
126 | bool Q3DObject::isDirty() const |
127 | { |
128 | const Q_D(Q3DObject); |
129 | return d->m_isDirty; |
130 | } |
131 | |
132 | Q3DObjectPrivate::Q3DObjectPrivate(Q3DObject *q) : |
133 | m_isDirty(true), |
134 | q_ptr(q) |
135 | { |
136 | } |
137 | |
138 | Q3DObjectPrivate::~Q3DObjectPrivate() |
139 | { |
140 | |
141 | } |
142 | |
143 | QT_END_NAMESPACE |
144 | |