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 | #include <Qt3DQuickRender/private/qt3dquickrendernodefactory_p.h> |
5 | |
6 | QT_BEGIN_NAMESPACE |
7 | |
8 | namespace Qt3DRender { |
9 | |
10 | Q_GLOBAL_STATIC(QuickRenderNodeFactory, quick_render_node_factory) |
11 | |
12 | QuickRenderNodeFactory *QuickRenderNodeFactory::instance() |
13 | { |
14 | return quick_render_node_factory(); |
15 | } |
16 | |
17 | void QuickRenderNodeFactory::registerType(const char *className, const char *quickName, int major, int minor) |
18 | { |
19 | m_types.insert(key: className, value: Type(quickName, major, minor)); |
20 | } |
21 | |
22 | Qt3DCore::QNode *QuickRenderNodeFactory::createNode(const char *type) |
23 | { |
24 | if (!m_types.contains(key: type)) |
25 | return nullptr; |
26 | |
27 | Type &typeInfo(m_types[type]); |
28 | |
29 | if (!typeInfo.resolved) { |
30 | typeInfo.resolved = true; |
31 | typeInfo.t = QQmlMetaType::qmlType(qualifiedName: QString::fromLatin1(ba: typeInfo.quickName), version: QTypeRevision::fromVersion(majorVersion: typeInfo.version.first, minorVersion: typeInfo.version.second)); |
32 | } |
33 | |
34 | return typeInfo.t.isValid() ? qobject_cast<Qt3DCore::QNode *>(object: typeInfo.t.create()) : nullptr; |
35 | } |
36 | |
37 | } // namespace Qt3DRender |
38 | |
39 | QT_END_NAMESPACE |
40 |