1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtSensors module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #include "qmlrotationsensor.h" |
41 | #include <QtSensors/QRotationSensor> |
42 | |
43 | /*! |
44 | \qmltype RotationSensor |
45 | \instantiates QmlRotationSensor |
46 | \ingroup qml-sensors_type |
47 | \inqmlmodule QtSensors |
48 | \since QtSensors 5.0 |
49 | \inherits Sensor |
50 | \brief The RotationSensor element reports on device rotation |
51 | around the X, Y and Z axes. |
52 | |
53 | The RotationSensor element reports on device rotation |
54 | around the X, Y and Z axes. |
55 | |
56 | This element wraps the QRotationSensor class. Please see the documentation for |
57 | QRotationSensor for details. |
58 | |
59 | \sa RotationReading |
60 | */ |
61 | |
62 | QmlRotationSensor::QmlRotationSensor(QObject *parent) |
63 | : QmlSensor(parent) |
64 | , m_sensor(new QRotationSensor(this)) |
65 | { |
66 | connect(sender: m_sensor, SIGNAL(hasZChanged(bool)), receiver: this, SIGNAL(hasZChanged(bool))); |
67 | } |
68 | |
69 | QmlRotationSensor::~QmlRotationSensor() |
70 | { |
71 | } |
72 | |
73 | QmlSensorReading *QmlRotationSensor::createReading() const |
74 | { |
75 | return new QmlRotationSensorReading(m_sensor); |
76 | } |
77 | |
78 | QSensor *QmlRotationSensor::sensor() const |
79 | { |
80 | return m_sensor; |
81 | } |
82 | |
83 | /*! |
84 | \qmlproperty qreal RotationSensor::hasZ |
85 | This property holds a value indicating if the z angle is available. |
86 | |
87 | Please see QRotationSensor::hasZ for information about this property. |
88 | */ |
89 | |
90 | bool QmlRotationSensor::hasZ() const |
91 | { |
92 | return m_sensor->hasZ(); |
93 | } |
94 | |
95 | void QmlRotationSensor::_update() |
96 | { |
97 | } |
98 | |
99 | /*! |
100 | \qmltype RotationReading |
101 | \instantiates QmlRotationSensorReading |
102 | \ingroup qml-sensors_reading |
103 | \inqmlmodule QtSensors |
104 | \since QtSensors 5.0 |
105 | \inherits SensorReading |
106 | \brief The RotationReading element holds the most recent RotationSensor reading. |
107 | |
108 | The RotationReading element holds the most recent RotationSensor reading. |
109 | |
110 | This element wraps the QRotationReading class. Please see the documentation for |
111 | QRotationReading for details. |
112 | |
113 | This element cannot be directly created. |
114 | */ |
115 | |
116 | QmlRotationSensorReading::QmlRotationSensorReading(QRotationSensor *sensor) |
117 | : QmlSensorReading(sensor) |
118 | , m_sensor(sensor) |
119 | { |
120 | } |
121 | |
122 | QmlRotationSensorReading::~QmlRotationSensorReading() |
123 | { |
124 | } |
125 | |
126 | /*! |
127 | \qmlproperty qreal RotationReading::x |
128 | This property holds the rotation around the x axis. |
129 | |
130 | Please see QRotationReading::x for information about this property. |
131 | */ |
132 | |
133 | qreal QmlRotationSensorReading::x() const |
134 | { |
135 | return m_x; |
136 | } |
137 | |
138 | /*! |
139 | \qmlproperty qreal RotationReading::y |
140 | This property holds the rotation around the y axis. |
141 | |
142 | Please see QRotationReading::y for information about this property. |
143 | */ |
144 | |
145 | qreal QmlRotationSensorReading::y() const |
146 | { |
147 | return m_y; |
148 | } |
149 | |
150 | /*! |
151 | \qmlproperty qreal RotationReading::z |
152 | This property holds the rotation around the z axis. |
153 | |
154 | Please see QRotationReading::z for information about this property. |
155 | */ |
156 | |
157 | qreal QmlRotationSensorReading::z() const |
158 | { |
159 | return m_z; |
160 | } |
161 | |
162 | QSensorReading *QmlRotationSensorReading::reading() const |
163 | { |
164 | return m_sensor->reading(); |
165 | } |
166 | |
167 | void QmlRotationSensorReading::readingUpdate() |
168 | { |
169 | qreal rX = m_sensor->reading()->x(); |
170 | if (m_x != rX) { |
171 | m_x = rX; |
172 | Q_EMIT xChanged(); |
173 | } |
174 | qreal rY = m_sensor->reading()->y(); |
175 | if (m_y != rY) { |
176 | m_y = rY; |
177 | Q_EMIT yChanged(); |
178 | } |
179 | qreal rZ = m_sensor->reading()->z(); |
180 | if (m_z != rZ) { |
181 | m_z = rZ; |
182 | Q_EMIT zChanged(); |
183 | } |
184 | } |
185 | |