1 | // Copyright (C) 2015 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 "qopcualocalizedtext.h" |
5 | |
6 | QT_BEGIN_NAMESPACE |
7 | |
8 | /*! |
9 | \class QOpcUaLocalizedText |
10 | \inmodule QtOpcUa |
11 | \brief The OPC UA LocalizedText type. |
12 | |
13 | This is the Qt OPC UA representation for the OPC UA LocalizedText type defined in OPC UA 1.05 part 3, 8.5. |
14 | A LocalizedText value contains a text string with associated locale information in a second string (e. g. "en" or "en-US"). |
15 | The format of the locale information string is <language>[-<country/region>]. Language is usually given as ISO 639 two letter code, |
16 | country/region as ISO 3166 two letter code. Custom codes are also allowed (see OPC UA 1.05 part 3, 8.4). |
17 | It can be used to provide multiple text strings in different languages for a value using an array of LocalizedText elements. |
18 | */ |
19 | |
20 | /*! |
21 | \qmltype LocalizedText |
22 | \inqmlmodule QtOpcUa |
23 | \brief Contains a text with associated locale. |
24 | \since QtOpcUa 5.12 |
25 | |
26 | The two members of this type contain the actual text and the locale of the text. |
27 | */ |
28 | |
29 | /*! |
30 | \property QOpcUaLocalizedText::text |
31 | |
32 | Textual content. |
33 | */ |
34 | |
35 | /*! |
36 | \qmlproperty string LocalizedText::text |
37 | |
38 | Textual content. |
39 | */ |
40 | |
41 | /*! |
42 | \property QOpcUaLocalizedText::locale |
43 | |
44 | Locale of the contained text. |
45 | This has to be in a modified ISO standard notation, for example \c en-US. |
46 | See OPC UA specification 1.05 part 3, 8.4 for details. |
47 | */ |
48 | |
49 | /*! |
50 | \qmlproperty string LocalizedText::locale |
51 | |
52 | Locale of the contained text. |
53 | This has to be in a modified ISO standard notation, for example \c en-US. |
54 | See OPC UA specification 1.05 part 3, 8.4 for details. |
55 | */ |
56 | |
57 | class QOpcUaLocalizedTextData : public QSharedData |
58 | { |
59 | public: |
60 | QString locale; |
61 | QString text; |
62 | }; |
63 | |
64 | /*! |
65 | Default constructs a localized text with no parameters set. |
66 | */ |
67 | QOpcUaLocalizedText::QOpcUaLocalizedText() |
68 | : data(new QOpcUaLocalizedTextData) |
69 | { |
70 | } |
71 | |
72 | /*! |
73 | Constructs a localized text from \a rhs. |
74 | */ |
75 | QOpcUaLocalizedText::QOpcUaLocalizedText(const QOpcUaLocalizedText &rhs) |
76 | : data(rhs.data) |
77 | { |
78 | } |
79 | |
80 | /*! |
81 | Constructs a localized text with the locale \a locale and the text \a text. |
82 | */ |
83 | QOpcUaLocalizedText::QOpcUaLocalizedText(const QString &locale, const QString &text) |
84 | : data(new QOpcUaLocalizedTextData) |
85 | { |
86 | data->locale = locale; |
87 | data->text = text; |
88 | } |
89 | |
90 | /*! |
91 | Sets the values from \a rhs in this localized text. |
92 | */ |
93 | QOpcUaLocalizedText &QOpcUaLocalizedText::operator=(const QOpcUaLocalizedText &rhs) |
94 | { |
95 | if (this != &rhs) |
96 | data.operator=(o: rhs.data); |
97 | return *this; |
98 | } |
99 | |
100 | /*! |
101 | Returns \c true if this localized text has the same value as \a rhs. |
102 | */ |
103 | bool QOpcUaLocalizedText::operator==(const QOpcUaLocalizedText &rhs) const |
104 | { |
105 | return data->locale == rhs.locale() && |
106 | data->text == rhs.text(); |
107 | } |
108 | |
109 | /*! |
110 | Converts this localized text to \l QVariant. |
111 | */ |
112 | QOpcUaLocalizedText::operator QVariant() const |
113 | { |
114 | return QVariant::fromValue(value: *this); |
115 | } |
116 | |
117 | QOpcUaLocalizedText::~QOpcUaLocalizedText() |
118 | { |
119 | } |
120 | |
121 | /*! |
122 | Returns the text. |
123 | */ |
124 | QString QOpcUaLocalizedText::text() const |
125 | { |
126 | return data->text; |
127 | } |
128 | |
129 | /*! |
130 | Sets the text to \a text. |
131 | */ |
132 | void QOpcUaLocalizedText::setText(const QString &text) |
133 | { |
134 | data->text = text; |
135 | } |
136 | |
137 | /*! |
138 | Returns the locale. |
139 | */ |
140 | QString QOpcUaLocalizedText::locale() const |
141 | { |
142 | return data->locale; |
143 | } |
144 | |
145 | /*! |
146 | Sets the locale to \a locale. |
147 | */ |
148 | void QOpcUaLocalizedText::setLocale(const QString &locale) |
149 | { |
150 | data->locale = locale; |
151 | } |
152 | |
153 | #ifndef QT_NO_DEBUG_STREAM |
154 | |
155 | /*! |
156 | \fn QDebug QOpcUaLocalizedText::operator<<(QDebug debug, const QOpcUaLocalizedText &text) |
157 | \since 6.3 |
158 | |
159 | Writes the localized \a text to the \a debug output. |
160 | |
161 | \sa QDebug |
162 | */ |
163 | QDebug operator<<(QDebug debug, const QOpcUaLocalizedText <) |
164 | { |
165 | QDebugStateSaver saver(debug); |
166 | debug.nospace().quote() << "QOpcUaLocalizedText(" << lt.locale() << ", " << lt.text() << ")" ; |
167 | return debug; |
168 | } |
169 | |
170 | #endif |
171 | |
172 | QT_END_NAMESPACE |
173 | |