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#ifndef QT3DCORE_QNODE_H
41#define QT3DCORE_QNODE_H
42
43#include <Qt3DCore/qnodecreatedchange.h>
44#include <Qt3DCore/qnodeid.h>
45#include <Qt3DCore/qnodecommand.h>
46#include <Qt3DCore/qscenechange.h>
47#include <Qt3DCore/qt3dcore_global.h>
48#include <QtCore/QObject>
49
50#define Q_NODE_NULLPTR static_cast<Qt3DCore::QNode *>(nullptr)
51
52QT_BEGIN_NAMESPACE
53
54namespace Qt3DCore {
55
56class QNode;
57class QNodePrivate;
58class QEntity;
59class QAspectEngine;
60
61#if defined(QT_BUILD_INTERNAL)
62class QBackendNodeTester;
63#endif
64
65typedef QVector<QNode *> QNodeVector;
66typedef QSharedPointer<QNode> QNodePtr;
67
68class Q_3DCORESHARED_EXPORT QNode : public QObject
69{
70 Q_OBJECT
71 Q_PROPERTY(Qt3DCore::QNode *parent READ parentNode WRITE setParent NOTIFY parentChanged)
72 Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
73 Q_PROPERTY(PropertyTrackingMode defaultPropertyTrackingMode READ defaultPropertyTrackingMode WRITE setDefaultPropertyTrackingMode NOTIFY defaultPropertyTrackingModeChanged REVISION 9)
74public:
75
76 enum PropertyTrackingMode : quint16 {
77 TrackFinalValues,
78 DontTrackValues,
79 TrackAllValues
80 };
81 Q_ENUM(PropertyTrackingMode)
82
83 explicit QNode(QNode *parent = nullptr);
84 virtual ~QNode();
85
86 QNodeId id() const;
87 QNode *parentNode() const;
88
89 bool notificationsBlocked() const;
90 bool blockNotifications(bool block);
91
92 QNodeVector childNodes() const;
93
94 bool isEnabled() const;
95 PropertyTrackingMode defaultPropertyTrackingMode() const;
96
97 void setPropertyTracking(const QString &propertyName, PropertyTrackingMode trackMode);
98 PropertyTrackingMode propertyTracking(const QString &propertyName) const;
99 void clearPropertyTracking(const QString &propertyName);
100 void clearPropertyTrackings();
101
102 Q3D_DECL_DEPRECATED QNodeCommand::CommandId sendCommand(const QString &name, const QVariant &data = QVariant(),
103 QNodeCommand::CommandId replyTo = QNodeCommand::CommandId());
104 Q3D_DECL_DEPRECATED void sendReply(const QNodeCommandPtr &command);
105
106public Q_SLOTS:
107 void setParent(QNode *parent);
108 void setEnabled(bool isEnabled);
109 void setDefaultPropertyTrackingMode(PropertyTrackingMode mode);
110
111Q_SIGNALS:
112 void parentChanged(QObject *parent);
113 void enabledChanged(bool enabled);
114 void defaultPropertyTrackingModeChanged(PropertyTrackingMode mode);
115 void nodeDestroyed();
116
117protected:
118 explicit QNode(QNodePrivate &dd, QNode *parent = nullptr);
119 Q3D_DECL_DEPRECATED void notifyObservers(const QSceneChangePtr &change);
120 Q3D_DECL_DEPRECATED virtual void sceneChangeEvent(const QSceneChangePtr &change);
121
122private:
123 Q_DECLARE_PRIVATE(QNode)
124 Q3D_DECL_DEPRECATED virtual QNodeCreatedChangeBasePtr createNodeCreationChange() const;
125
126 // We only want setParent(QNode *) to be callable
127 // when dealing with QNode objects
128 void setParent(QObject *) Q_DECL_EQ_DELETE;
129
130 Q_PRIVATE_SLOT(d_func(), void _q_postConstructorInit())
131 Q_PRIVATE_SLOT(d_func(), void _q_addChild(Qt3DCore::QNode *))
132 Q_PRIVATE_SLOT(d_func(), void _q_removeChild(Qt3DCore::QNode *))
133 Q_PRIVATE_SLOT(d_func(), void _q_setParentHelper(Qt3DCore::QNode *))
134
135 friend class QAspectEngine;
136 friend class QAspectEnginePrivate;
137 friend class QAbstractAspectPrivate;
138 friend class QNodeCreatedChangeGenerator;
139 friend class QPostman;
140 friend class QScene;
141
142#if defined(QT_BUILD_INTERNAL)
143 friend class QBackendNodeTester;
144#endif
145};
146
147inline QNodeId qIdForNode(QNode *node){ return node ? node->id() : QNodeId(); }
148
149template<typename T>
150inline QNodeIdVector qIdsForNodes(const T &nodes)
151{
152 QNodeIdVector ids;
153 ids.reserve(size: nodes.size());
154 for (const auto n : nodes)
155 ids.push_back(n->id());
156 return ids;
157}
158
159struct QNodeIdTypePair
160{
161 QNodeIdTypePair() Q_DECL_NOTHROW
162 : id()
163 , type(nullptr)
164 {}
165
166 explicit QNodeIdTypePair(QNodeId _id, const QMetaObject *_type) Q_DECL_NOTHROW
167 : id(_id)
168 , type(_type)
169 {}
170
171 QNodeId id;
172 const QMetaObject *type;
173};
174QT3D_DECLARE_TYPEINFO(Qt3DCore, QNodeIdTypePair, Q_PRIMITIVE_TYPE)
175
176} // namespace Qt3DCore
177
178QT_END_NAMESPACE
179
180#endif
181

source code of qt3d/src/core/nodes/qnode.h