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 "qmlgyroscope.h"
41#include <QtSensors/QGyroscope>
42
43/*!
44 \qmltype Gyroscope
45 \instantiates QmlGyroscope
46 \ingroup qml-sensors_type
47 \inqmlmodule QtSensors
48 \since QtSensors 5.0
49 \inherits Sensor
50 \brief The Gyroscope element reports on rotational acceleration
51 around the X, Y and Z axes.
52
53 This element wraps the QGyroscope class. Please see the documentation for
54 QGyroscope for details.
55
56 \sa GyroscopeReading
57*/
58
59QmlGyroscope::QmlGyroscope(QObject *parent)
60 : QmlSensor(parent)
61 , m_sensor(new QGyroscope(this))
62{
63}
64
65QmlGyroscope::~QmlGyroscope()
66{
67}
68
69QmlSensorReading *QmlGyroscope::createReading() const
70{
71 return new QmlGyroscopeReading(m_sensor);
72}
73
74QSensor *QmlGyroscope::sensor() const
75{
76 return m_sensor;
77}
78
79/*!
80 \qmltype GyroscopeReading
81 \instantiates QmlGyroscopeReading
82 \ingroup qml-sensors_reading
83 \inqmlmodule QtSensors
84 \since QtSensors 5.0
85 \inherits SensorReading
86 \brief The GyroscopeReading element holds the most recent Gyroscope reading.
87
88 The GyroscopeReading element holds the most recent Gyroscope reading.
89
90 This element wraps the QGyroscopeReading class. Please see the documentation for
91 QGyroscopeReading for details.
92
93 This element cannot be directly created.
94*/
95
96QmlGyroscopeReading::QmlGyroscopeReading(QGyroscope *sensor)
97 : QmlSensorReading(sensor)
98 , m_sensor(sensor)
99{
100}
101
102QmlGyroscopeReading::~QmlGyroscopeReading()
103{
104}
105
106/*!
107 \qmlproperty qreal GyroscopeReading::x
108 This property holds the angular velocity around the x axis.
109
110 Please see QGyroscopeReading::x for information about this property.
111*/
112
113qreal QmlGyroscopeReading::x() const
114{
115 return m_x;
116}
117
118/*!
119 \qmlproperty qreal GyroscopeReading::y
120 This property holds the angular velocity around the y axis.
121
122 Please see QGyroscopeReading::y for information about this property.
123*/
124
125qreal QmlGyroscopeReading::y() const
126{
127 return m_y;
128}
129
130/*!
131 \qmlproperty qreal GyroscopeReading::z
132 This property holds the angular velocity around the z axis.
133
134 Please see QGyroscopeReading::z for information about this property.
135*/
136
137qreal QmlGyroscopeReading::z() const
138{
139 return m_z;
140}
141
142QSensorReading *QmlGyroscopeReading::reading() const
143{
144 return m_sensor->reading();
145}
146
147void QmlGyroscopeReading::readingUpdate()
148{
149 qreal gx = m_sensor->reading()->x();
150 if (m_x != gx) {
151 m_x = gx;
152 Q_EMIT xChanged();
153 }
154 qreal gy = m_sensor->reading()->y();
155 if (m_y != gy) {
156 m_y = gy;
157 Q_EMIT yChanged();
158 }
159 qreal gz = m_sensor->reading()->z();
160 if (m_z != gz) {
161 m_z = gz;
162 Q_EMIT zChanged();
163 }
164}
165

source code of qtsensors/src/imports/sensors/qmlgyroscope.cpp