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 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 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 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 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 | QOpcUaLocalizedText::QOpcUaLocalizedText() |
65 | : data(new QOpcUaLocalizedTextData) |
66 | { |
67 | } |
68 | |
69 | /*! |
70 | Constructs a localized text from \a rhs. |
71 | */ |
72 | QOpcUaLocalizedText::QOpcUaLocalizedText(const QOpcUaLocalizedText &rhs) |
73 | : data(rhs.data) |
74 | { |
75 | } |
76 | |
77 | /*! |
78 | Constructs a localized text with the locale \a locale and the text \a text. |
79 | */ |
80 | QOpcUaLocalizedText::QOpcUaLocalizedText(const QString &locale, const QString &text) |
81 | : data(new QOpcUaLocalizedTextData) |
82 | { |
83 | data->locale = locale; |
84 | data->text = text; |
85 | } |
86 | |
87 | /*! |
88 | Sets the values from \a rhs in this localized text. |
89 | */ |
90 | QOpcUaLocalizedText &QOpcUaLocalizedText::operator=(const QOpcUaLocalizedText &rhs) |
91 | { |
92 | if (this != &rhs) |
93 | data.operator=(o: rhs.data); |
94 | return *this; |
95 | } |
96 | |
97 | /*! |
98 | Returns \c true if this localized text has the same value as \a rhs. |
99 | */ |
100 | bool QOpcUaLocalizedText::operator==(const QOpcUaLocalizedText &rhs) const |
101 | { |
102 | return data->locale == rhs.locale() && |
103 | data->text == rhs.text(); |
104 | } |
105 | |
106 | /*! |
107 | Converts this localized text to \l QVariant. |
108 | */ |
109 | QOpcUaLocalizedText::operator QVariant() const |
110 | { |
111 | return QVariant::fromValue(value: *this); |
112 | } |
113 | |
114 | QOpcUaLocalizedText::~QOpcUaLocalizedText() |
115 | { |
116 | } |
117 | |
118 | /*! |
119 | Returns the text. |
120 | */ |
121 | QString QOpcUaLocalizedText::text() const |
122 | { |
123 | return data->text; |
124 | } |
125 | |
126 | /*! |
127 | Sets the text to \a text. |
128 | */ |
129 | void QOpcUaLocalizedText::setText(const QString &text) |
130 | { |
131 | data->text = text; |
132 | } |
133 | |
134 | /*! |
135 | Returns the locale. |
136 | */ |
137 | QString QOpcUaLocalizedText::locale() const |
138 | { |
139 | return data->locale; |
140 | } |
141 | |
142 | /*! |
143 | Sets the locale to \a locale. |
144 | */ |
145 | void QOpcUaLocalizedText::setLocale(const QString &locale) |
146 | { |
147 | data->locale = locale; |
148 | } |
149 | |
150 | #ifndef QT_NO_DEBUG_STREAM |
151 | |
152 | /*! |
153 | \fn QDebug QOpcUaLocalizedText::operator<<(QDebug debug, const QOpcUaLocalizedText &text) |
154 | \since 6.3 |
155 | |
156 | Writes the localized \a text to the \a debug output. |
157 | |
158 | \sa QDebug |
159 | */ |
160 | QDebug operator<<(QDebug debug, const QOpcUaLocalizedText <) |
161 | { |
162 | QDebugStateSaver saver(debug); |
163 | debug.nospace().quote() << "QOpcUaLocalizedText(" << lt.locale() << ", " << lt.text() << ")" ; |
164 | return debug; |
165 | } |
166 | |
167 | #endif |
168 | |
169 | QT_END_NAMESPACE |
170 | |