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

source code of qt3d/src/quick3d/quick3dscene2d/qt3dquickscene2dnodefactory.cpp