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 "dependencydatatypevalidator.h"
5#include "enumeratedtype.h"
6#include "field.h"
7#include "stringidentifier.h"
8#include "structuredtype.h"
9
10using namespace Qt::Literals::StringLiterals;
11
12DependencyDataTypeValidator::DependencyDataTypeValidator()
13 : m_readResolveDependencies(ReadDependencies)
14{}
15
16void DependencyDataTypeValidator::visit(EnumeratedType *enumeratedType)
17{
18 if (m_readResolveDependencies == DependencyDataTypeValidator::ResolveDependencies) {
19 if (m_unresolvedDependencyStringList.contains(str: enumeratedType->name())) {
20 m_unresolvedDependencyStringList.removeAll(t: enumeratedType->name());
21 m_resolvedDependencyElementList.push_back(t: enumeratedType);
22 }
23 }
24}
25
26void DependencyDataTypeValidator::visit(EnumeratedValue *enumeratedValue)
27{
28 Q_UNUSED(enumeratedValue);
29}
30
31void DependencyDataTypeValidator::visit(Field *field)
32{
33 if (m_readResolveDependencies == DependencyDataTypeValidator::ReadDependencies) {
34 if (!field->typeName().contains(s: "opc:"_L1)) {
35 const auto typeName = field->typeNameSecondPart();
36 for (const auto &precoded : StringIdentifier::opcUaPrecodedTypes) {
37 if (precoded.contains(name: typeName)) {
38 return;
39 }
40 }
41 m_unresolvedDependencyStringList.push_back(t: typeName);
42 }
43 }
44}
45
46void DependencyDataTypeValidator::visit(Import *import)
47{
48 Q_UNUSED(import);
49}
50
51void DependencyDataTypeValidator::visit(StructuredType *structuredType)
52{
53 if (m_readResolveDependencies == DependencyDataTypeValidator::ResolveDependencies) {
54 if (m_unresolvedDependencyStringList.contains(str: structuredType->name())) {
55 m_unresolvedDependencyStringList.removeAll(t: structuredType->name());
56 m_resolvedDependencyElementList.push_back(t: structuredType);
57 const auto tempFields = structuredType->fields();
58 for (const auto &field : tempFields) {
59 const auto typeName = field->typeNameSecondPart();
60
61 if (!StringIdentifier::typeNameDataTypeConverter.contains(key: field->typeName())) {
62 bool isPrecoded = false;
63 for (const auto &precoded : StringIdentifier::opcUaPrecodedTypes) {
64 if (precoded.contains(name: typeName)) {
65 isPrecoded = true;
66 break;
67 }
68 }
69 if (!isPrecoded && !m_unresolvedDependencyStringList.contains(str: typeName)) {
70 bool isResolved = false;
71 for (const auto &type : std::as_const(t&: m_resolvedDependencyElementList)) {
72 if (type->name() == typeName) {
73 isResolved = true;
74 break;
75 }
76 }
77 if (!isResolved)
78 m_unresolvedDependencyStringList.push_back(t: typeName);
79 }
80 }
81 }
82 }
83 }
84}
85
86void DependencyDataTypeValidator::visit(TypeDictionary *typeDictionary)
87{
88 Q_UNUSED(typeDictionary);
89}
90
91void DependencyDataTypeValidator::visit(XmlElement *xmlElement)
92{
93 Q_UNUSED(xmlElement);
94}
95
96QStringList DependencyDataTypeValidator::unresolvedDependencyStringList() const
97{
98 return m_unresolvedDependencyStringList;
99}
100
101QList<XmlElement *> DependencyDataTypeValidator::resolvedDependencyElementList() const
102{
103 return m_resolvedDependencyElementList;
104}
105
106void DependencyDataTypeValidator::setReadResolveDependencies(
107 const ReadResolveDependencies &readResolveDependencies)
108{
109 m_readResolveDependencies = readResolveDependencies;
110}
111

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