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 1.05 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 | /*! |
25 | Default constructs a XValue object with no parameters set. |
26 | */ |
27 | QOpcUaXValue::QOpcUaXValue() |
28 | : data(new QOpcUaXValueData) |
29 | { |
30 | } |
31 | |
32 | /*! |
33 | Constructs an XValue from \a rhs. |
34 | */ |
35 | QOpcUaXValue::QOpcUaXValue(const QOpcUaXValue &rhs) |
36 | : data(rhs.data) |
37 | { |
38 | } |
39 | |
40 | /*! |
41 | Constructs an XValue with position \a x and value \a value. |
42 | */ |
43 | QOpcUaXValue::QOpcUaXValue(double x, float value) |
44 | : data(new QOpcUaXValueData) |
45 | { |
46 | data->x = x; |
47 | data->value = value; |
48 | } |
49 | |
50 | /*! |
51 | Sets the values from \a rhs in this XValue. |
52 | */ |
53 | QOpcUaXValue &QOpcUaXValue::operator=(const QOpcUaXValue &rhs) |
54 | { |
55 | if (this != &rhs) |
56 | data.operator=(o: rhs.data); |
57 | return *this; |
58 | } |
59 | |
60 | /*! |
61 | Returns \c true if this XValue has the same value as \a rhs. |
62 | */ |
63 | bool QOpcUaXValue::operator==(const QOpcUaXValue &rhs) const |
64 | { |
65 | return qFloatDistance(a: data->x, b: rhs.x()) == 0 && |
66 | qFloatDistance(a: data->value, b: rhs.value()) == 0; |
67 | } |
68 | |
69 | /*! |
70 | Converts this XValue to \l QVariant. |
71 | */ |
72 | QOpcUaXValue::operator QVariant() const |
73 | { |
74 | return QVariant::fromValue(value: *this); |
75 | } |
76 | |
77 | QOpcUaXValue::~QOpcUaXValue() |
78 | { |
79 | } |
80 | |
81 | /*! |
82 | Returns the value for position x. |
83 | */ |
84 | float QOpcUaXValue::value() const |
85 | { |
86 | return data->value; |
87 | } |
88 | |
89 | /*! |
90 | Sets the value for position x to \a value. |
91 | */ |
92 | void QOpcUaXValue::setValue(float value) |
93 | { |
94 | data->value = value; |
95 | } |
96 | |
97 | /*! |
98 | Returns the position of the value on the axis. |
99 | */ |
100 | double QOpcUaXValue::x() const |
101 | { |
102 | return data->x; |
103 | } |
104 | |
105 | /*! |
106 | Sets the position of the value on the axis to \a x. |
107 | */ |
108 | void QOpcUaXValue::setX(double x) |
109 | { |
110 | data->x = x; |
111 | } |
112 | |
113 | QT_END_NAMESPACE |
114 |