1// Copyright (C) 2016 The Qt Company Ltd.
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 "qmlmagnetometer_p.h"
5#include <QtSensors/QMagnetometer>
6
7/*!
8 \qmltype Magnetometer
9//! \instantiates QmlMagnetometer
10 \ingroup qml-sensors_type
11 \inqmlmodule QtSensors
12 \since QtSensors 5.0
13 \inherits Sensor
14 \brief The Magnetometer element reports on magnetic field strength
15 along the Z, Y and Z axes.
16
17 The Magnetometer element reports on magnetic field strength
18 along the Z, Y and Z axes.
19
20 This element wraps the QMagnetometer class. Please see the documentation for
21 QMagnetometer for details.
22
23 \sa MagnetometerReading
24*/
25
26QmlMagnetometer::QmlMagnetometer(QObject *parent)
27 : QmlSensor(parent)
28 , m_sensor(new QMagnetometer(this))
29{
30 connect(sender: m_sensor, SIGNAL(returnGeoValuesChanged(bool)),
31 receiver: this, SIGNAL(returnGeoValuesChanged(bool)));
32}
33
34QmlMagnetometer::~QmlMagnetometer()
35{
36}
37
38QmlSensorReading *QmlMagnetometer::createReading() const
39{
40 return new QmlMagnetometerReading(m_sensor);
41}
42
43QSensor *QmlMagnetometer::sensor() const
44{
45 return m_sensor;
46}
47
48/*!
49 \qmlproperty bool Magnetometer::returnGeoValues
50 This property holds a value indicating if geomagnetic values should be returned.
51
52 Please see QMagnetometer::returnGeoValues for information about this property.
53*/
54
55bool QmlMagnetometer::returnGeoValues() const
56{
57 return m_sensor->returnGeoValues();
58}
59
60void QmlMagnetometer::setReturnGeoValues(bool geo)
61{
62 m_sensor->setReturnGeoValues(geo);
63}
64
65/*!
66 \qmltype MagnetometerReading
67//! \instantiates QmlMagnetometerReading
68 \ingroup qml-sensors_reading
69 \inqmlmodule QtSensors
70 \since QtSensors 5.0
71 \inherits SensorReading
72 \brief The MagnetometerReading element holds the most recent Magnetometer reading.
73
74 The MagnetometerReading element holds the most recent Magnetometer reading.
75
76 This element wraps the QMagnetometerReading class. Please see the documentation for
77 QMagnetometerReading for details.
78
79 This element cannot be directly created.
80*/
81
82QmlMagnetometerReading::QmlMagnetometerReading(QMagnetometer *sensor)
83 : m_sensor(sensor)
84{
85}
86
87QmlMagnetometerReading::~QmlMagnetometerReading()
88{
89}
90
91/*!
92 \qmlproperty qreal MagnetometerReading::x
93 This property holds the raw magnetic flux density on the X axis.
94
95 Please see QMagnetometerReading::x for information about this property.
96*/
97
98qreal QmlMagnetometerReading::x() const
99{
100 return m_x;
101}
102
103QBindable<qreal> QmlMagnetometerReading::bindableX() const
104{
105 return &m_x;
106}
107
108/*!
109 \qmlproperty qreal MagnetometerReading::y
110 This property holds the raw magnetic flux density on the Y axis.
111
112 Please see QMagnetometerReading::y for information about this property.
113*/
114
115qreal QmlMagnetometerReading::y() const
116{
117 return m_y;
118}
119
120QBindable<qreal> QmlMagnetometerReading::bindableY() const
121{
122 return &m_y;
123}
124
125/*!
126 \qmlproperty qreal MagnetometerReading::z
127 This property holds the raw magnetic flux density on the Z axis.
128
129 Please see QMagnetometerReading::z for information about this property.
130*/
131
132qreal QmlMagnetometerReading::z() const
133{
134 return m_z;
135}
136
137QBindable<qreal> QmlMagnetometerReading::bindableZ() const
138{
139 return &m_z;
140}
141
142/*!
143 \qmlproperty qreal MagnetometerReading::calibrationLevel
144 This property holds the accuracy of the reading.
145
146 Please see QMagnetometerReading::calibrationLevel for information about this property.
147*/
148
149qreal QmlMagnetometerReading::calibrationLevel() const
150{
151 return m_calibrationLevel;
152}
153
154QBindable<qreal> QmlMagnetometerReading::bindableCalibrationLevel() const
155{
156 return &m_calibrationLevel;
157}
158
159QSensorReading *QmlMagnetometerReading::reading() const
160{
161 return m_sensor->reading();
162}
163
164void QmlMagnetometerReading::readingUpdate()
165{
166 m_x = m_sensor->reading()->x();
167 m_y = m_sensor->reading()->y();
168 m_z = m_sensor->reading()->z();
169 m_calibrationLevel= m_sensor->reading()->calibrationLevel();
170}
171

source code of qtsensors/src/sensorsquick/qmlmagnetometer.cpp