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 | |
49 | QT_BEGIN_NAMESPACE |
50 | |
51 | namespace Qt3DCore { |
52 | |
53 | class QAspectEngine; |
54 | class QAspectJob; |
55 | class QAspectManager; |
56 | class QNode; |
57 | class QEntity; |
58 | class QAbstractAspectPrivate; |
59 | class QBackendNodeMapper; |
60 | |
61 | typedef QSharedPointer<QAspectJob> QAspectJobPtr; |
62 | typedef QSharedPointer<QBackendNodeMapper> QBackendNodeMapperPtr; |
63 | |
64 | class Q_3DCORESHARED_EXPORT QAbstractAspect : public QObject |
65 | { |
66 | Q_OBJECT |
67 | |
68 | public: |
69 | explicit QAbstractAspect(QObject *parent = nullptr); |
70 | ~QAbstractAspect(); |
71 | |
72 | void scheduleSingleShotJob(const Qt3DCore::QAspectJobPtr &job); |
73 | |
74 | protected: |
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 | |
89 | private: |
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 | |
105 | template<class Frontend> |
106 | void QAbstractAspect::registerBackendType(const QBackendNodeMapperPtr &functor) |
107 | { |
108 | registerBackendType(Frontend::staticMetaObject, functor); |
109 | } |
110 | |
111 | template<class Frontend, bool supportsSyncing> |
112 | void QAbstractAspect::registerBackendType(const QBackendNodeMapperPtr &functor) |
113 | { |
114 | registerBackendType(Frontend::staticMetaObject, functor, supportsSyncing); |
115 | } |
116 | |
117 | template<class Frontend> |
118 | void QAbstractAspect::unregisterBackendType() |
119 | { |
120 | unregisterBackendType(Frontend::staticMetaObject); |
121 | } |
122 | |
123 | } // namespace Qt3DCore |
124 | |
125 | QT_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 | |