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 | |
13 | QT_BEGIN_NAMESPACE |
14 | |
15 | namespace Qt3DCore { |
16 | |
17 | class QNode; |
18 | class QNodePrivate; |
19 | class QAspectEngine; |
20 | |
21 | #if defined(QT_BUILD_INTERNAL) |
22 | class QBackendNodeTester; |
23 | #endif |
24 | |
25 | using QNodeVector = QList<QNode *>; |
26 | using QNodePtr = QSharedPointer<QNode>; |
27 | |
28 | class 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) |
33 | public: |
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 | |
48 | public Q_SLOTS: |
49 | void setParent(QNode *parent); |
50 | void setEnabled(bool isEnabled); |
51 | |
52 | Q_SIGNALS: |
53 | void parentChanged(QObject *parent); |
54 | void enabledChanged(bool enabled); |
55 | void nodeDestroyed(); |
56 | |
57 | protected: |
58 | explicit QNode(QNodePrivate &dd, QNode *parent = nullptr); |
59 | |
60 | private: |
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 | |
82 | inline QNodeId qIdForNode(QNode *node){ return node ? node->id() : QNodeId(); } |
83 | |
84 | template<typename T> |
85 | inline 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 | |
94 | struct 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 | }; |
109 | QT3D_DECLARE_TYPEINFO(Qt3DCore, QNodeIdTypePair, Q_PRIMITIVE_TYPE) |
110 | |
111 | } // namespace Qt3DCore |
112 | |
113 | QT_END_NAMESPACE |
114 | |
115 | #endif |
116 | |