| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the Qt Data Visualization module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL$ |
| 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 General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 or (at your option) any later version |
| 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
| 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
| 22 | ** included in the packaging of this file. Please review the following |
| 23 | ** information to ensure the GNU General Public License requirements will |
| 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 25 | ** |
| 26 | ** $QT_END_LICENSE$ |
| 27 | ** |
| 28 | ****************************************************************************/ |
| 29 | |
| 30 | #include "q3dobject_p.h" |
| 31 | #include "q3dscene_p.h" |
| 32 | |
| 33 | QT_BEGIN_NAMESPACE_DATAVISUALIZATION |
| 34 | |
| 35 | /*! |
| 36 | \class Q3DObject |
| 37 | \inmodule QtDataVisualization |
| 38 | \brief The Q3DObject class is a simple base class for all the objects in a |
| 39 | 3D scene. |
| 40 | \since QtDataVisualization 1.0 |
| 41 | |
| 42 | Contains position information for an object in a 3D scene. |
| 43 | The object is considered to be a single point in the coordinate space without dimensions. |
| 44 | */ |
| 45 | |
| 46 | /*! |
| 47 | \qmltype Object3D |
| 48 | \inqmlmodule QtDataVisualization |
| 49 | \since QtDataVisualization 1.0 |
| 50 | \ingroup datavisualization_qml |
| 51 | \instantiates Q3DObject |
| 52 | \brief A base type for all the objects in a 3D scene. |
| 53 | |
| 54 | An uncreatable base type that contains position information for an object in |
| 55 | a 3D scene. The object is considered to be a single point in the coordinate space without |
| 56 | dimensions. |
| 57 | */ |
| 58 | |
| 59 | /*! |
| 60 | * \qmlproperty vector3d Object3D::position |
| 61 | * |
| 62 | * The 3D position of the object. |
| 63 | * |
| 64 | * \note Currently setting this property has no effect for Camera3D, as the position is handled |
| 65 | * internally. |
| 66 | */ |
| 67 | |
| 68 | /*! |
| 69 | * Constructs a new 3D object with the position set to origin by default. An |
| 70 | * optional \a parent parameter can be given and is then passed to the QObject |
| 71 | * constructor. |
| 72 | */ |
| 73 | Q3DObject::Q3DObject(QObject *parent) : |
| 74 | QObject(parent), |
| 75 | d_ptr(new Q3DObjectPrivate(this)) |
| 76 | { |
| 77 | } |
| 78 | |
| 79 | /*! |
| 80 | * Destroys the 3D object. |
| 81 | */ |
| 82 | Q3DObject::~Q3DObject() |
| 83 | { |
| 84 | } |
| 85 | |
| 86 | /*! |
| 87 | * Copies the 3D object position from the given \a source 3D object to this 3D object instance. |
| 88 | */ |
| 89 | void Q3DObject::copyValuesFrom(const Q3DObject &source) |
| 90 | { |
| 91 | d_ptr->m_position = source.d_ptr->m_position; |
| 92 | setDirty(true); |
| 93 | } |
| 94 | |
| 95 | /*! |
| 96 | * \property Q3DObject::parentScene |
| 97 | * |
| 98 | * \brief The parent scene as a read only value. |
| 99 | * |
| 100 | * If the object has no parent scene, the value is 0. |
| 101 | */ |
| 102 | Q3DScene *Q3DObject::parentScene() |
| 103 | { |
| 104 | return qobject_cast<Q3DScene *>(object: parent()); |
| 105 | } |
| 106 | |
| 107 | /*! |
| 108 | * \property Q3DObject::position |
| 109 | * |
| 110 | * \brief The 3D position of the object. |
| 111 | * |
| 112 | * \note Currently setting this property has no effect for Q3DCamera, as the position is handled |
| 113 | * internally. |
| 114 | */ |
| 115 | QVector3D Q3DObject::position() const |
| 116 | { |
| 117 | return d_ptr->m_position; |
| 118 | } |
| 119 | |
| 120 | void Q3DObject::setPosition(const QVector3D &position) |
| 121 | { |
| 122 | if (d_ptr->m_position != position) { |
| 123 | d_ptr->m_position = position; |
| 124 | setDirty(true); |
| 125 | emit positionChanged(position: d_ptr->m_position); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | /*! |
| 130 | * Sets \a dirty to \c true if the 3D object has changed since the last update. |
| 131 | */ |
| 132 | void Q3DObject::setDirty(bool dirty) |
| 133 | { |
| 134 | d_ptr->m_isDirty = dirty; |
| 135 | if (parentScene()) |
| 136 | parentScene()->d_ptr->markDirty(); |
| 137 | } |
| 138 | |
| 139 | /*! |
| 140 | * Returns whether the 3D object has changed. |
| 141 | */ |
| 142 | bool Q3DObject::isDirty() const |
| 143 | { |
| 144 | return d_ptr->m_isDirty; |
| 145 | } |
| 146 | |
| 147 | Q3DObjectPrivate::Q3DObjectPrivate(Q3DObject *q) : |
| 148 | q_ptr(q), |
| 149 | m_isDirty(true) |
| 150 | { |
| 151 | } |
| 152 | |
| 153 | Q3DObjectPrivate::~Q3DObjectPrivate() |
| 154 | { |
| 155 | |
| 156 | } |
| 157 | |
| 158 | QT_END_NAMESPACE_DATAVISUALIZATION |
| 159 | |