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_H
41#define QT3DCORE_QABSTRACTASPECT_H
42
43#include <Qt3DCore/qt3dcore_global.h>
44#include <Qt3DCore/qnodeid.h>
45#include <Qt3DCore/qscenechange.h>
46#include <QtCore/QObject>
47#include <QtCore/QSharedPointer>
48
49QT_BEGIN_NAMESPACE
50
51namespace Qt3DCore {
52
53class QAspectEngine;
54class QAspectJob;
55class QAspectManager;
56class QNode;
57class QEntity;
58class QAbstractAspectPrivate;
59class QBackendNodeMapper;
60
61typedef QSharedPointer<QAspectJob> QAspectJobPtr;
62typedef QSharedPointer<QBackendNodeMapper> QBackendNodeMapperPtr;
63
64class Q_3DCORESHARED_EXPORT QAbstractAspect : public QObject
65{
66 Q_OBJECT
67
68public:
69 explicit QAbstractAspect(QObject *parent = nullptr);
70 ~QAbstractAspect();
71
72 void scheduleSingleShotJob(const Qt3DCore::QAspectJobPtr &job);
73
74protected:
75 explicit QAbstractAspect(QAbstractAspectPrivate &dd, QObject *parent = nullptr);
76
77 QNodeId rootEntityId() const Q_DECL_NOEXCEPT;
78
79 template<class Frontend>
80 void registerBackendType(const QBackendNodeMapperPtr &functor);
81 template<class Frontend, bool supportsSyncing>
82 void registerBackendType(const QBackendNodeMapperPtr &functor);
83 void registerBackendType(const QMetaObject &obj, const QBackendNodeMapperPtr &functor);
84 void registerBackendType(const QMetaObject &obj, const QBackendNodeMapperPtr &functor, bool supportsSyncing);
85 template<class Frontend>
86 void unregisterBackendType();
87 void unregisterBackendType(const QMetaObject &);
88
89private:
90 virtual QVariant executeCommand(const QStringList &args);
91
92 virtual QVector<QAspectJobPtr> jobsToExecute(qint64 time);
93
94 virtual void onRegistered();
95 virtual void onUnregistered();
96
97 virtual void onEngineStartup();
98 virtual void onEngineShutdown();
99
100 Q_DECLARE_PRIVATE(QAbstractAspect)
101 friend class QAspectEngine;
102 friend class QAspectManager;
103};
104
105template<class Frontend>
106void QAbstractAspect::registerBackendType(const QBackendNodeMapperPtr &functor)
107{
108 registerBackendType(Frontend::staticMetaObject, functor);
109}
110
111template<class Frontend, bool supportsSyncing>
112void QAbstractAspect::registerBackendType(const QBackendNodeMapperPtr &functor)
113{
114 registerBackendType(Frontend::staticMetaObject, functor, supportsSyncing);
115}
116
117template<class Frontend>
118void QAbstractAspect::unregisterBackendType()
119{
120 unregisterBackendType(Frontend::staticMetaObject);
121}
122
123} // namespace Qt3DCore
124
125QT_END_NAMESPACE
126
127#define QT3D_REGISTER_NAMESPACED_ASPECT(name, AspectNamespace, AspectType) \
128 QT_BEGIN_NAMESPACE \
129 namespace Qt3DCore { \
130 typedef QAbstractAspect *(*AspectCreateFunction)(QObject *); \
131 QT_DEPRECATED Q_3DCORESHARED_EXPORT void qt3d_QAspectFactory_addDefaultFactory(const QString &, const QMetaObject *, AspectCreateFunction); \
132 Q_3DCORESHARED_EXPORT void qt3d_QAspectFactory_addDefaultFactory(const QLatin1String &, const QMetaObject *, AspectCreateFunction); \
133 } \
134 QT_END_NAMESPACE \
135 namespace { \
136 Qt3DCore::QAbstractAspect *qt3d_ ## AspectType ## _createFunction(QObject *parent) \
137 { \
138 using namespace AspectNamespace; \
139 return new AspectType(parent); \
140 } \
141 \
142 void qt3d_ ## AspectType ## _registerFunction() \
143 { \
144 using namespace AspectNamespace; \
145 qt3d_QAspectFactory_addDefaultFactory(QLatin1String(name), &AspectType::staticMetaObject, qt3d_ ## AspectType ## _createFunction); \
146 } \
147 \
148 Q_CONSTRUCTOR_FUNCTION(qt3d_ ## AspectType ## _registerFunction) \
149 }
150
151#define QT3D_REGISTER_ASPECT(name, AspectType) \
152 QT3D_REGISTER_NAMESPACED_ASPECT(name, QT_PREPEND_NAMESPACE(Qt3DCore), AspectType)
153
154#endif // QT3DCORE_ABSTRACTASPECT_H
155

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