1// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QT3DCORE_QNODE_H
5#define QT3DCORE_QNODE_H
6
7#include <Qt3DCore/qnodeid.h>
8#include <Qt3DCore/qt3dcore_global.h>
9#include <QtCore/QObject>
10
11#define Q_NODE_NULLPTR static_cast<Qt3DCore::QNode *>(nullptr)
12
13QT_BEGIN_NAMESPACE
14
15namespace Qt3DCore {
16
17class QNode;
18class QNodePrivate;
19class QAspectEngine;
20
21#if defined(QT_BUILD_INTERNAL)
22class QBackendNodeTester;
23#endif
24
25using QNodeVector = QList<QNode *>;
26using QNodePtr = QSharedPointer<QNode>;
27
28class Q_3DCORESHARED_EXPORT QNode : public QObject
29{
30 Q_OBJECT
31 Q_PROPERTY(Qt3DCore::QNode *parent READ parentNode WRITE setParent NOTIFY parentChanged)
32 Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
33public:
34
35 explicit QNode(QNode *parent = nullptr);
36 virtual ~QNode();
37
38 QNodeId id() const;
39 QNode *parentNode() const;
40
41 bool notificationsBlocked() const;
42 bool blockNotifications(bool block);
43
44 QNodeVector childNodes() const;
45
46 bool isEnabled() const;
47
48public Q_SLOTS:
49 void setParent(QNode *parent);
50 void setEnabled(bool isEnabled);
51
52Q_SIGNALS:
53 void parentChanged(QObject *parent);
54 void enabledChanged(bool enabled);
55 void nodeDestroyed();
56
57protected:
58 explicit QNode(QNodePrivate &dd, QNode *parent = nullptr);
59
60private:
61 Q_DECLARE_PRIVATE(QNode)
62
63 // We only want setParent(QNode *) to be callable
64 // when dealing with QNode objects
65 void setParent(QObject *) = delete;
66
67 Q_PRIVATE_SLOT(d_func(), void _q_postConstructorInit())
68 Q_PRIVATE_SLOT(d_func(), void _q_addChild(Qt3DCore::QNode *))
69 Q_PRIVATE_SLOT(d_func(), void _q_removeChild(Qt3DCore::QNode *))
70 Q_PRIVATE_SLOT(d_func(), void _q_setParentHelper(Qt3DCore::QNode *))
71
72 friend class QAspectEngine;
73 friend class QAspectEnginePrivate;
74 friend class QAbstractAspectPrivate;
75 friend class QScene;
76
77#if defined(QT_BUILD_INTERNAL)
78 friend class QBackendNodeTester;
79#endif
80};
81
82inline QNodeId qIdForNode(QNode *node){ return node ? node->id() : QNodeId(); }
83
84template<typename T>
85inline QNodeIdVector qIdsForNodes(const T &nodes)
86{
87 QNodeIdVector ids;
88 ids.reserve(size: nodes.size());
89 for (const auto n : nodes)
90 ids.push_back(n->id());
91 return ids;
92}
93
94struct QNodeIdTypePair
95{
96 QNodeIdTypePair() noexcept
97 : id()
98 , type(nullptr)
99 {}
100
101 explicit QNodeIdTypePair(QNodeId _id, const QMetaObject *_type) noexcept
102 : id(_id)
103 , type(_type)
104 {}
105
106 QNodeId id;
107 const QMetaObject *type;
108};
109QT3D_DECLARE_TYPEINFO(Qt3DCore, QNodeIdTypePair, Q_PRIMITIVE_TYPE)
110
111} // namespace Qt3DCore
112
113QT_END_NAMESPACE
114
115#endif
116

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