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 "qopcuaxvalue.h" |
5 | |
6 | QT_BEGIN_NAMESPACE |
7 | |
8 | /*! |
9 | \class QOpcUaXValue |
10 | \inmodule QtOpcUa |
11 | \brief The OPC UA XVType. |
12 | |
13 | This is the Qt OPC UA representation for the OPC UA XVType type defined in OPC-UA part 8, 5.6.8. |
14 | This type is used to position values of float precision on an axis with double precision. |
15 | */ |
16 | |
17 | class QOpcUaXValueData : public QSharedData |
18 | { |
19 | public: |
20 | double x{0}; |
21 | float value{0}; |
22 | }; |
23 | |
24 | QOpcUaXValue::QOpcUaXValue() |
25 | : data(new QOpcUaXValueData) |
26 | { |
27 | } |
28 | |
29 | /*! |
30 | Constructs an XValue from \a rhs. |
31 | */ |
32 | QOpcUaXValue::QOpcUaXValue(const QOpcUaXValue &rhs) |
33 | : data(rhs.data) |
34 | { |
35 | } |
36 | |
37 | /*! |
38 | Constructs an XValue with position \a x and value \a value. |
39 | */ |
40 | QOpcUaXValue::QOpcUaXValue(double x, float value) |
41 | : data(new QOpcUaXValueData) |
42 | { |
43 | data->x = x; |
44 | data->value = value; |
45 | } |
46 | |
47 | /*! |
48 | Sets the values from \a rhs in this XValue. |
49 | */ |
50 | QOpcUaXValue &QOpcUaXValue::operator=(const QOpcUaXValue &rhs) |
51 | { |
52 | if (this != &rhs) |
53 | data.operator=(o: rhs.data); |
54 | return *this; |
55 | } |
56 | |
57 | /*! |
58 | Returns \c true if this XValue has the same value as \a rhs. |
59 | */ |
60 | bool QOpcUaXValue::operator==(const QOpcUaXValue &rhs) const |
61 | { |
62 | return qFloatDistance(a: data->x, b: rhs.x()) == 0 && |
63 | qFloatDistance(a: data->value, b: rhs.value()) == 0; |
64 | } |
65 | |
66 | /*! |
67 | Converts this XValue to \l QVariant. |
68 | */ |
69 | QOpcUaXValue::operator QVariant() const |
70 | { |
71 | return QVariant::fromValue(value: *this); |
72 | } |
73 | |
74 | QOpcUaXValue::~QOpcUaXValue() |
75 | { |
76 | } |
77 | |
78 | /*! |
79 | Returns the value for position x. |
80 | */ |
81 | float QOpcUaXValue::value() const |
82 | { |
83 | return data->value; |
84 | } |
85 | |
86 | /*! |
87 | Sets the value for position x to \a value. |
88 | */ |
89 | void QOpcUaXValue::setValue(float value) |
90 | { |
91 | data->value = value; |
92 | } |
93 | |
94 | /*! |
95 | Returns the position of the value on the axis. |
96 | */ |
97 | double QOpcUaXValue::x() const |
98 | { |
99 | return data->x; |
100 | } |
101 | |
102 | /*! |
103 | Sets the position of the value on the axis to \a x. |
104 | */ |
105 | void QOpcUaXValue::setX(double x) |
106 | { |
107 | data->x = x; |
108 | } |
109 | |
110 | QT_END_NAMESPACE |
111 |