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_QABSTRACTASPECT_P_H
41#define QT3DCORE_QABSTRACTASPECT_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists for the convenience
48// of other Qt classes. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <Qt3DCore/qabstractaspect.h>
55#include <Qt3DCore/qnodedestroyedchange.h>
56
57#include <Qt3DCore/private/qaspectjobproviderinterface_p.h>
58#include <Qt3DCore/private/qbackendnode_p.h>
59#include <Qt3DCore/private/qt3dcore_global_p.h>
60#include <Qt3DCore/private/qscenechange_p.h>
61#include <QtCore/private/qobject_p.h>
62
63#include <QMutex>
64#include <QVector>
65
66QT_BEGIN_NAMESPACE
67
68namespace Qt3DCore {
69
70class QAbstractAspect;
71class QBackendNode;
72class QEntity;
73class QAspectManager;
74class QAbstractAspectJobManager;
75class QChangeArbiter;
76class QServiceLocator;
77
78namespace Debug {
79
80class Q_3DCORE_PRIVATE_EXPORT AsynchronousCommandReply : public QObject
81{
82 Q_OBJECT
83public:
84 explicit AsynchronousCommandReply(const QString &commandName, QObject *parent = nullptr);
85
86 inline QByteArray data() const { return m_data; }
87 inline QString commandName() const { return m_commandName; }
88 inline bool isFinished() const { return m_finished; }
89
90 void setFinished(bool finished);
91 void setData(const QByteArray &data);
92
93Q_SIGNALS:
94 void finished(AsynchronousCommandReply *reply);
95
96private:
97 QByteArray m_data;
98 QString m_commandName;
99 bool m_finished;
100};
101
102} // Debug
103
104struct NodeTreeChange
105{
106 enum NodeTreeChangeType {
107 Added = 0,
108 Removed = 1
109 };
110 Qt3DCore::QNodeId id;
111 const QMetaObject *metaObj;
112 NodeTreeChangeType type;
113 Qt3DCore::QNode *node;
114};
115
116class Q_3DCORE_PRIVATE_EXPORT QAbstractAspectPrivate
117 : public QObjectPrivate
118 , public QAspectJobProviderInterface
119{
120public:
121 QAbstractAspectPrivate();
122 ~QAbstractAspectPrivate();
123
124 void setRootAndCreateNodes(QEntity *rootObject, const QVector<NodeTreeChange> &nodesTreeChanges);
125
126 QServiceLocator *services() const;
127 QAbstractAspectJobManager *jobManager() const;
128
129 QVector<QAspectJobPtr> jobsToExecute(qint64 time) override;
130 void jobsDone() override; // called when all the jobs are completed
131 void frameDone() override; // called when frame is completed (after the jobs), safe to wait until next frame here
132
133 QBackendNode *createBackendNode(const NodeTreeChange &change) const;
134 void clearBackendNode(const NodeTreeChange &change) const;
135 void syncDirtyFrontEndNodes(const QVector<QNode *> &nodes);
136 void syncDirtyFrontEndSubNodes(const QVector<NodeRelationshipChange> &nodes);
137 virtual void syncDirtyFrontEndNode(QNode *node, QBackendNode *backend, bool firstTime) const;
138 void sendPropertyMessages(QNode *node, QBackendNode *backend) const;
139
140 virtual void onEngineAboutToShutdown();
141
142 // TODO: Make these public in 5.8
143 template<class Frontend>
144 void unregisterBackendType();
145 void unregisterBackendType(const QMetaObject &mo);
146
147 Q_DECLARE_PUBLIC(QAbstractAspect)
148
149 enum NodeMapperInfo {
150 DefaultMapper = 0,
151 SupportsSyncing = 1 << 0
152 };
153 using BackendNodeMapperAndInfo = QPair<QBackendNodeMapperPtr, NodeMapperInfo>;
154 BackendNodeMapperAndInfo mapperForNode(const QMetaObject *metaObj) const;
155
156 QEntity *m_root;
157 QNodeId m_rootId;
158 QAspectManager *m_aspectManager;
159 QAbstractAspectJobManager *m_jobManager;
160 QChangeArbiter *m_arbiter;
161 QHash<const QMetaObject*, BackendNodeMapperAndInfo> m_backendCreatorFunctors;
162 QMutex m_singleShotMutex;
163 QVector<QAspectJobPtr> m_singleShotJobs;
164
165 static QAbstractAspectPrivate *get(QAbstractAspect *aspect);
166};
167
168template<class Frontend>
169void QAbstractAspectPrivate::unregisterBackendType()
170{
171 unregisterBackendType(Frontend::staticMetaObject);
172}
173
174} // Qt3DCore
175
176QT_END_NAMESPACE
177
178#endif // QT3DCORE_QABSTRACTASPECT_P_H
179

source code of qt3d/src/core/aspects/qabstractaspect_p.h