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 "qmlcompass_p.h"
5#include <QtSensors/QCompass>
6
7/*!
8 \qmltype Compass
9//! \instantiates QmlCompass
10 \ingroup qml-sensors_type
11 \inqmlmodule QtSensors
12 \since QtSensors 5.0
13 \inherits Sensor
14 \brief The Compass element reports on heading using magnetic north as a reference.
15
16 The Compass element reports on heading using magnetic north as a reference.
17
18 This element wraps the QCompass class. Please see the documentation for
19 QCompass for details.
20
21 \sa CompassReading
22*/
23
24QmlCompass::QmlCompass(QObject *parent)
25 : QmlSensor(parent)
26 , m_sensor(new QCompass(this))
27{
28}
29
30QmlCompass::~QmlCompass()
31{
32}
33
34QmlSensorReading *QmlCompass::createReading() const
35{
36 return new QmlCompassReading(m_sensor);
37}
38
39QSensor *QmlCompass::sensor() const
40{
41 return m_sensor;
42}
43
44/*!
45 \qmltype CompassReading
46//! \instantiates QmlCompassReading
47 \ingroup qml-sensors_reading
48 \inqmlmodule QtSensors
49 \since QtSensors 5.0
50 \inherits SensorReading
51 \brief The CompassReading element holds the most recent Compass reading.
52
53 The CompassReading element holds the most recent Compass reading.
54
55 This element wraps the QCompassReading class. Please see the documentation for
56 QCompassReading for details.
57
58 This element cannot be directly created.
59*/
60
61QmlCompassReading::QmlCompassReading(QCompass *sensor)
62 : m_sensor(sensor)
63{
64}
65
66QmlCompassReading::~QmlCompassReading()
67{
68}
69
70/*!
71 \qmlproperty qreal CompassReading::azimuth
72 This property holds the azimuth of the device.
73
74 Please see QCompassReading::azimuth for information about this property.
75*/
76
77qreal QmlCompassReading::azimuth() const
78{
79 return m_azimuth;
80}
81
82QBindable<qreal> QmlCompassReading::bindableAzimuth() const
83{
84 return &m_azimuth;
85}
86
87/*!
88 \qmlproperty qreal CompassReading::calibrationLevel
89 This property holds the calibration level of the reading.
90
91 Please see QCompassReading::calibrationLevel for information about this property.
92*/
93
94qreal QmlCompassReading::calibrationLevel() const
95{
96 return m_calibrationLevel;
97}
98
99QBindable<qreal> QmlCompassReading::bindableCalibrationLevel() const
100{
101 return &m_calibrationLevel;
102}
103
104QSensorReading *QmlCompassReading::reading() const
105{
106 return m_sensor->reading();
107}
108
109void QmlCompassReading::readingUpdate()
110{
111 m_azimuth = m_sensor->reading()->azimuth();
112 m_calibrationLevel = m_sensor->reading()->calibrationLevel();
113}
114

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