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