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
16static void initScene2dPlugin()
17{
18 Qt3DRender::QRenderAspectPrivate::configurePlugin(plugin: QLatin1String("scene2d"));
19}
20
21Q_COREAPP_STARTUP_FUNCTION(initScene2dPlugin)
22
23QuickScene2DNodeFactory *QuickScene2DNodeFactory::instance()
24{
25 return quick_scene2d_node_factory();
26}
27
28void QuickScene2DNodeFactory::registerType(const char *className, const char *quickName,
29 int major, int minor)
30{
31 m_types.insert(key: className, value: Type(quickName, major, minor));
32}
33
34Qt3DCore::QNode *QuickScene2DNodeFactory::createNode(const char *type)
35{
36 if (!m_types.contains(key: type))
37 return nullptr;
38
39 Type &typeInfo(m_types[type]);
40
41 if (!typeInfo.resolved) {
42 typeInfo.resolved = true;
43 typeInfo.t = QQmlMetaType::qmlType(qualifiedName: QString::fromLatin1(ba: typeInfo.quickName), version: QTypeRevision::fromVersion(majorVersion: typeInfo.version.first, minorVersion: typeInfo.version.second));
44 }
45
46 return typeInfo.t.isValid() ? qobject_cast<Qt3DCore::QNode *>(object: typeInfo.t.create()) : nullptr;
47}
48
49} // namespace Qt3DRender
50
51QT_END_NAMESPACE
52

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