1 | // Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). |
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 QABSTRACTNODEFACTORY_P_H |
5 | #define QABSTRACTNODEFACTORY_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 <Qt3DCore/qnode.h> |
19 | |
20 | #include <Qt3DCore/private/qt3dcore_global_p.h> |
21 | |
22 | QT_BEGIN_NAMESPACE |
23 | |
24 | namespace Qt3DCore { |
25 | |
26 | class Q_3DCORE_PRIVATE_EXPORT QAbstractNodeFactory |
27 | { |
28 | public: |
29 | virtual ~QAbstractNodeFactory(); |
30 | |
31 | virtual QNode *createNode(const char *type) = 0; |
32 | |
33 | static void registerNodeFactory(QAbstractNodeFactory *factory); |
34 | static QList<QAbstractNodeFactory *> nodeFactories(); |
35 | |
36 | template<class T> static T *createNode(const char *type) |
37 | { |
38 | const auto factories = QAbstractNodeFactory::nodeFactories(); |
39 | for (QAbstractNodeFactory *f : factories) { |
40 | QNode *n = f->createNode(type); |
41 | if (n) |
42 | return qobject_cast<T *>(n); |
43 | } |
44 | return new T; |
45 | } |
46 | }; |
47 | |
48 | } // namespace Qt3DCore |
49 | |
50 | QT_END_NAMESPACE |
51 | |
52 | #endif // QABSTRACTNODEFACTORY_P_H |
53 | |