1// Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
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 "qaspectfactory_p.h"
5
6#include <Qt3DCore/QAbstractAspect>
7#include <QtCore/QDebug>
8#include <QtCore/QtGlobal>
9
10QT_BEGIN_NAMESPACE
11
12namespace Qt3DCore {
13
14typedef QHash<QLatin1String, QAspectFactory::CreateFunction> defaultFactories_t;
15Q_GLOBAL_STATIC(defaultFactories_t, defaultFactories)
16typedef QHash<const QMetaObject*, QLatin1String> defaultAspectNames_t;
17Q_GLOBAL_STATIC(defaultAspectNames_t, defaultAspectNames)
18
19Q_3DCORESHARED_EXPORT void qt3d_QAspectFactory_addDefaultFactory(const QLatin1String &name,
20 const QMetaObject *metaObject,
21 QAspectFactory::CreateFunction factory)
22{
23 defaultFactories->insert(key: name, value: factory);
24 defaultAspectNames->insert(key: metaObject, value: name);
25}
26
27QAspectFactory::QAspectFactory()
28 : m_factories(*defaultFactories),
29 m_aspectNames(*defaultAspectNames)
30{
31}
32
33QAspectFactory::QAspectFactory(const QAspectFactory &other)
34 : m_factories(other.m_factories),
35 m_aspectNames(other.m_aspectNames)
36{
37}
38
39QAspectFactory::~QAspectFactory()
40{
41}
42
43QAspectFactory &QAspectFactory::operator=(const QAspectFactory &other)
44{
45 m_factories = other.m_factories;
46 m_aspectNames = other.m_aspectNames;
47 return *this;
48}
49
50QList<QLatin1String> QAspectFactory::availableFactories() const
51{
52 return m_factories.keys();
53}
54
55QAbstractAspect *QAspectFactory::createAspect(const QLatin1String &aspect, QObject *parent) const
56{
57 if (m_factories.contains(key: aspect)) {
58 return m_factories.value(key: aspect)(parent);
59 } else {
60 qWarning() << "Unsupported aspect name:" << aspect << "please check registrations";
61 return nullptr;
62 }
63}
64
65QLatin1String QAspectFactory::aspectName(QAbstractAspect *aspect) const
66{
67 return m_aspectNames.value(key: aspect->metaObject());
68}
69
70} // namespace Qt3DCore
71
72QT_END_NAMESPACE
73

source code of qt3d/src/core/aspects/qaspectfactory.cpp