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 "qmlmagnetometer.h"
41#include <QtSensors/QMagnetometer>
42
43/*!
44 \qmltype Magnetometer
45 \instantiates QmlMagnetometer
46 \ingroup qml-sensors_type
47 \inqmlmodule QtSensors
48 \since QtSensors 5.0
49 \inherits Sensor
50 \brief The Magnetometer element reports on magnetic field strength
51 along the Z, Y and Z axes.
52
53 The Magnetometer element reports on magnetic field strength
54 along the Z, Y and Z axes.
55
56 This element wraps the QMagnetometer class. Please see the documentation for
57 QMagnetometer for details.
58
59 \sa MagnetometerReading
60*/
61
62QmlMagnetometer::QmlMagnetometer(QObject *parent)
63 : QmlSensor(parent)
64 , m_sensor(new QMagnetometer(this))
65{
66 connect(sender: m_sensor, SIGNAL(returnGeoValuesChanged(bool)),
67 receiver: this, SIGNAL(returnGeoValuesChanged(bool)));
68}
69
70QmlMagnetometer::~QmlMagnetometer()
71{
72}
73
74QmlSensorReading *QmlMagnetometer::createReading() const
75{
76 return new QmlMagnetometerReading(m_sensor);
77}
78
79QSensor *QmlMagnetometer::sensor() const
80{
81 return m_sensor;
82}
83
84/*!
85 \qmlproperty bool Magnetometer::returnGeoValues
86 This property holds a value indicating if geomagnetic values should be returned.
87
88 Please see QMagnetometer::returnGeoValues for information about this property.
89*/
90
91bool QmlMagnetometer::returnGeoValues() const
92{
93 return m_sensor->returnGeoValues();
94}
95
96void QmlMagnetometer::setReturnGeoValues(bool geo)
97{
98 m_sensor->setReturnGeoValues(geo);
99}
100
101/*!
102 \qmltype MagnetometerReading
103 \instantiates QmlMagnetometerReading
104 \ingroup qml-sensors_reading
105 \inqmlmodule QtSensors
106 \since QtSensors 5.0
107 \inherits SensorReading
108 \brief The MagnetometerReading element holds the most recent Magnetometer reading.
109
110 The MagnetometerReading element holds the most recent Magnetometer reading.
111
112 This element wraps the QMagnetometerReading class. Please see the documentation for
113 QMagnetometerReading for details.
114
115 This element cannot be directly created.
116*/
117
118QmlMagnetometerReading::QmlMagnetometerReading(QMagnetometer *sensor)
119 : QmlSensorReading(sensor)
120 , m_sensor(sensor)
121{
122}
123
124QmlMagnetometerReading::~QmlMagnetometerReading()
125{
126}
127
128/*!
129 \qmlproperty qreal MagnetometerReading::x
130 This property holds the raw magnetic flux density on the X axis.
131
132 Please see QMagnetometerReading::x for information about this property.
133*/
134
135qreal QmlMagnetometerReading::x() const
136{
137 return m_x;
138}
139
140/*!
141 \qmlproperty qreal MagnetometerReading::y
142 This property holds the raw magnetic flux density on the Y axis.
143
144 Please see QMagnetometerReading::y for information about this property.
145*/
146
147qreal QmlMagnetometerReading::y() const
148{
149 return m_y;
150}
151
152/*!
153 \qmlproperty qreal MagnetometerReading::z
154 This property holds the raw magnetic flux density on the Z axis.
155
156 Please see QMagnetometerReading::z for information about this property.
157*/
158
159qreal QmlMagnetometerReading::z() const
160{
161 return m_z;
162}
163
164/*!
165 \qmlproperty qreal MagnetometerReading::calibrationLevel
166 This property holds the accuracy of the reading.
167
168 Please see QMagnetometerReading::calibrationLevel for information about this property.
169*/
170
171qreal QmlMagnetometerReading::calibrationLevel() const
172{
173 return m_calibrationLevel;
174}
175
176QSensorReading *QmlMagnetometerReading::reading() const
177{
178 return m_sensor->reading();
179}
180
181void QmlMagnetometerReading::readingUpdate()
182{
183 qreal magX = m_sensor->reading()->x();
184 if (m_x != magX) {
185 m_x = magX;
186 Q_EMIT xChanged();
187 }
188 qreal magY = m_sensor->reading()->y();
189 if (m_y != magY) {
190 m_y = magY;
191 Q_EMIT yChanged();
192 }
193 qreal magZ = m_sensor->reading()->z();
194 if (m_z != magZ) {
195 m_z = magZ;
196 Q_EMIT zChanged();
197 }
198 qreal calLevel = m_sensor->reading()->calibrationLevel();
199 if (m_calibrationLevel != calLevel) {
200 m_calibrationLevel = calLevel;
201 Q_EMIT calibrationLevelChanged();
202 }
203}
204

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