1// Copyright (C) 2023 basysKom GmbH, opensource@basyskom.com
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 "typedictionary.h"
5
6#include "enumeratedtype.h"
7#include "import.h"
8#include "structuredtype.h"
9#include "visitor.h"
10
11#include <QtCore/qdebug.h>
12
13TypeDictionary::TypeDictionary(bool dependencyTypeDictionary,
14 const QString &defaultByOrder,
15 const QString &targetNamespace,
16 const QMap<QString, QString> &namespaces)
17 : m_dependencyTypeDictionary(dependencyTypeDictionary)
18 , m_defaultByOrder(defaultByOrder)
19 , m_targetNamespace(targetNamespace)
20 , m_namespaces(namespaces)
21{}
22
23TypeDictionary::~TypeDictionary()
24{
25 qDeleteAll(c: m_types);
26}
27
28QMap<QString, QString> TypeDictionary::namespaces() const
29{
30 return m_namespaces;
31}
32
33void TypeDictionary::setNamespaces(const QMap<QString, QString> &namespaces)
34{
35 m_namespaces = namespaces;
36}
37
38QString TypeDictionary::defaultByOrder() const
39{
40 return m_defaultByOrder;
41}
42
43void TypeDictionary::setDefaultByOrder(const QString &defaultByOrder)
44{
45 m_defaultByOrder = defaultByOrder;
46}
47
48QString TypeDictionary::targetNamespace() const
49{
50 return m_targetNamespace;
51}
52
53void TypeDictionary::setTargetNamespace(const QString &targetNamespace)
54{
55 m_targetNamespace = targetNamespace;
56}
57
58QList<const Import *> TypeDictionary::imports() const
59{
60 QList<const Import *> imports;
61 for (auto element : m_types) {
62 Import *import = dynamic_cast<Import *>(element);
63 if (import) {
64 imports.push_back(t: import);
65 }
66 }
67 return imports;
68}
69
70bool TypeDictionary::dependencyTypeDictionary() const
71{
72 return m_dependencyTypeDictionary;
73}
74
75QList<XmlElement *> TypeDictionary::types() const
76{
77 return m_types;
78}
79
80void TypeDictionary::addType(XmlElement *type)
81{
82 m_types.push_back(t: type);
83}
84
85void TypeDictionary::print() const
86{
87 for (auto it = m_namespaces.constBegin(); it != m_namespaces.constEnd(); ++it) {
88 qDebug() << it.key() << ": " << it.value();
89 }
90
91 qDebug() << "defaultByOrder:" << m_defaultByOrder << "\tTargetNamespace:" << m_targetNamespace;
92
93 for (auto element : m_types) {
94 const auto *enumeratedType = dynamic_cast<EnumeratedType *>(element);
95 if (enumeratedType) {
96 enumeratedType->print();
97 } else {
98 const auto *structuredType = dynamic_cast<StructuredType *>(element);
99 if (structuredType) {
100 structuredType->print();
101 } else {
102 const auto *import = dynamic_cast<Import *>(element);
103 if (import) {
104 import->print();
105 }
106 }
107 }
108 }
109}
110
111void TypeDictionary::accept(Visitor *visitor)
112{
113 visitor->visit(typeDictionary: this);
114 for (const auto &element : m_types)
115 element->accept(visitor);
116}
117

Provided by KDAB

Privacy Policy
Start learning QML with our Intro Training
Find out more

source code of qtopcua/tools/datatypecodegenerator/typedictionary.cpp