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