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_QABSTRACTASPECT_P_H
5#define QT3DCORE_QABSTRACTASPECT_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of other Qt classes. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/QHash>
19#include <Qt3DCore/qabstractaspect.h>
20
21#include <Qt3DCore/private/qaspectjobproviderinterface_p.h>
22#include <Qt3DCore/private/qbackendnode_p.h>
23#include <Qt3DCore/private/qt3dcore_global_p.h>
24#include <Qt3DCore/private/qchangearbiter_p.h>
25#include <QtCore/private/qobject_p.h>
26
27#include <QMutex>
28#include <QList>
29
30QT_BEGIN_NAMESPACE
31
32namespace Qt3DCore {
33
34class QAbstractAspect;
35class QBackendNode;
36class QEntity;
37class QAspectManager;
38class QAbstractAspectJobManager;
39class QServiceLocator;
40
41namespace Debug {
42
43class Q_3DCORE_PRIVATE_EXPORT AsynchronousCommandReply : public QObject
44{
45 Q_OBJECT
46public:
47 explicit AsynchronousCommandReply(const QString &commandName, QObject *parent = nullptr);
48
49 inline QByteArray data() const { return m_data; }
50 inline QString commandName() const { return m_commandName; }
51 inline bool isFinished() const { return m_finished; }
52
53 void setFinished(bool finished);
54 void setData(const QByteArray &data);
55
56Q_SIGNALS:
57 void finished(AsynchronousCommandReply *reply);
58
59private:
60 QByteArray m_data;
61 QString m_commandName;
62 bool m_finished;
63};
64
65} // Debug
66
67struct NodeTreeChange
68{
69 enum NodeTreeChangeType {
70 Added = 0,
71 Removed = 1
72 };
73 Qt3DCore::QNodeId id;
74 const QMetaObject *metaObj;
75 NodeTreeChangeType type;
76 Qt3DCore::QNode *node;
77};
78
79class Q_3DCORE_PRIVATE_EXPORT QAbstractAspectPrivate
80 : public QObjectPrivate
81 , public QAspectJobProviderInterface
82{
83public:
84 QAbstractAspectPrivate();
85 ~QAbstractAspectPrivate();
86
87 void setRootAndCreateNodes(QEntity *rootObject, const QList<NodeTreeChange> &nodesTreeChanges);
88
89 QServiceLocator *services() const;
90 QAbstractAspectJobManager *jobManager() const;
91
92 std::vector<QAspectJobPtr> jobsToExecute(qint64 time) override;
93 void jobsDone() override; // called when all the jobs are completed
94 void frameDone() override; // called when frame is completed (after the jobs), safe to wait until next frame here
95
96 QBackendNode *createBackendNode(const NodeTreeChange &change) const;
97 void clearBackendNode(const NodeTreeChange &change) const;
98 void syncDirtyFrontEndNodes(const QList<QNode *> &nodes);
99 void syncDirtyEntityComponentNodes(const QList<ComponentRelationshipChange> &nodes);
100 virtual void syncDirtyFrontEndNode(QNode *node, QBackendNode *backend, bool firstTime) const;
101
102 virtual void onEngineAboutToShutdown();
103
104 // TODO: Make these public in 5.8
105 template<class Frontend>
106 void unregisterBackendType();
107 void unregisterBackendType(const QMetaObject &mo);
108
109 Q_DECLARE_PUBLIC(QAbstractAspect)
110
111 QBackendNodeMapperPtr mapperForNode(const QMetaObject *metaObj) const;
112
113 QEntity *m_root;
114 QNodeId m_rootId;
115 QAspectManager *m_aspectManager;
116 QAbstractAspectJobManager *m_jobManager;
117 QChangeArbiter *m_arbiter;
118 QHash<const QMetaObject*, QBackendNodeMapperPtr> m_backendCreatorFunctors;
119 QMutex m_singleShotMutex;
120 std::vector<QAspectJobPtr> m_singleShotJobs;
121
122 static QAbstractAspectPrivate *get(QAbstractAspect *aspect);
123};
124
125template<class Frontend>
126void QAbstractAspectPrivate::unregisterBackendType()
127{
128 unregisterBackendType(Frontend::staticMetaObject);
129}
130
131} // Qt3DCore
132
133QT_END_NAMESPACE
134
135#endif // QT3DCORE_QABSTRACTASPECT_P_H
136

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