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_H
5#define QT3DCORE_QABSTRACTASPECT_H
6
7#include <Qt3DCore/qt3dcore_global.h>
8#include <Qt3DCore/qnodeid.h>
9#include <QtCore/QObject>
10#include <QtCore/QSharedPointer>
11
12QT_BEGIN_NAMESPACE
13
14namespace Qt3DCore {
15
16class QAspectEngine;
17class QAspectJob;
18class QAspectManager;
19class QNode;
20class QEntity;
21class QAbstractAspectPrivate;
22class QBackendNodeMapper;
23
24typedef QSharedPointer<QAspectJob> QAspectJobPtr;
25typedef QSharedPointer<QBackendNodeMapper> QBackendNodeMapperPtr;
26
27class Q_3DCORESHARED_EXPORT QAbstractAspect : public QObject
28{
29 Q_OBJECT
30
31public:
32 explicit QAbstractAspect(QObject *parent = nullptr);
33 ~QAbstractAspect();
34
35 void scheduleSingleShotJob(const Qt3DCore::QAspectJobPtr &job);
36 virtual QStringList dependencies() const;
37
38protected:
39 explicit QAbstractAspect(QAbstractAspectPrivate &dd, QObject *parent = nullptr);
40
41 QNodeId rootEntityId() const noexcept;
42
43 template<class Frontend>
44 void registerBackendType(const QBackendNodeMapperPtr &functor);
45 void registerBackendType(const QMetaObject &obj, const QBackendNodeMapperPtr &functor);
46 template<class Frontend>
47 void unregisterBackendType();
48 void unregisterBackendType(const QMetaObject &);
49
50private:
51 virtual QVariant executeCommand(const QStringList &args);
52
53 virtual std::vector<QAspectJobPtr> jobsToExecute(qint64 time);
54
55 virtual void onRegistered();
56 virtual void onUnregistered();
57
58 virtual void onEngineStartup();
59 virtual void onEngineShutdown();
60
61 virtual void jobsDone();
62 virtual void frameDone();
63
64 Q_DECLARE_PRIVATE(QAbstractAspect)
65 friend class QAspectEngine;
66 friend class QAspectManager;
67 friend class QScheduler;
68};
69
70template<class Frontend>
71void QAbstractAspect::registerBackendType(const QBackendNodeMapperPtr &functor)
72{
73 registerBackendType(Frontend::staticMetaObject, functor);
74}
75
76template<class Frontend>
77void QAbstractAspect::unregisterBackendType()
78{
79 unregisterBackendType(Frontend::staticMetaObject);
80}
81
82} // namespace Qt3DCore
83
84QT_END_NAMESPACE
85
86#define QT3D_REGISTER_NAMESPACED_ASPECT(name, AspectNamespace, AspectType) \
87 QT_BEGIN_NAMESPACE \
88 namespace Qt3DCore { \
89 typedef QAbstractAspect *(*AspectCreateFunction)(QObject *); \
90 Q_3DCORESHARED_EXPORT void qt3d_QAspectFactory_addDefaultFactory(const QLatin1String &, const QMetaObject *, AspectCreateFunction); \
91 } \
92 QT_END_NAMESPACE \
93 namespace { \
94 Qt3DCore::QAbstractAspect *qt3d_ ## AspectType ## _createFunction(QObject *parent) \
95 { \
96 using namespace AspectNamespace; \
97 return new AspectType(parent); \
98 } \
99 \
100 void qt3d_ ## AspectType ## _registerFunction() \
101 { \
102 using namespace AspectNamespace; \
103 qt3d_QAspectFactory_addDefaultFactory(QLatin1String(name), &AspectType::staticMetaObject, qt3d_ ## AspectType ## _createFunction); \
104 } \
105 \
106 Q_CONSTRUCTOR_FUNCTION(qt3d_ ## AspectType ## _registerFunction) \
107 }
108
109#define QT3D_REGISTER_ASPECT(name, AspectType) \
110 QT3D_REGISTER_NAMESPACED_ASPECT(name, QT_PREPEND_NAMESPACE(Qt3DCore), AspectType)
111
112#endif // QT3DCORE_ABSTRACTASPECT_H
113

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