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 "qmlorientationsensor_p.h"
5#include <QtSensors/QOrientationSensor>
6
7/*!
8 \qmltype OrientationSensor
9//! \instantiates QmlOrientationSensor
10 \ingroup qml-sensors_type
11 \inqmlmodule QtSensors
12 \since QtSensors 5.0
13 \inherits Sensor
14 \brief The OrientationSensor element reports device orientation.
15
16 The OrientationSensor element reports device orientation.
17
18 This element wraps the QOrientationSensor class. Please see the documentation for
19 QOrientationSensor for details.
20
21 \sa OrientationReading
22*/
23
24QmlOrientationSensor::QmlOrientationSensor(QObject *parent)
25 : QmlSensor(parent)
26 , m_sensor(new QOrientationSensor(this))
27{
28}
29
30QmlOrientationSensor::~QmlOrientationSensor()
31{
32}
33
34QmlSensorReading *QmlOrientationSensor::createReading() const
35{
36 return new QmlOrientationSensorReading(m_sensor);
37}
38
39QSensor *QmlOrientationSensor::sensor() const
40{
41 return m_sensor;
42}
43
44/*!
45 \qmltype OrientationReading
46//! \instantiates QmlOrientationSensorReading
47 \ingroup qml-sensors_reading
48 \inqmlmodule QtSensors
49 \since QtSensors 5.0
50 \inherits SensorReading
51 \brief The OrientationReading element holds the most recent OrientationSensor reading.
52
53 The OrientationReading element holds the most recent OrientationSensor reading.
54
55 This element wraps the QOrientationReading class. Please see the documentation for
56 QOrientationReading for details.
57
58 This element cannot be directly created.
59*/
60
61QmlOrientationSensorReading::QmlOrientationSensorReading(QOrientationSensor *sensor)
62 : m_sensor(sensor)
63{
64}
65
66QmlOrientationSensorReading::~QmlOrientationSensorReading()
67{
68}
69
70/*!
71 \qmlproperty Orientation OrientationReading::orientation
72 This property holds the orientation of the device.
73
74 Please see QOrientationReading::orientation for information about this property.
75
76 Note that Orientation constants are exposed through the OrientationReading class.
77 \code
78 OrientationSensor {
79 onReadingChanged: {
80 if (reading.orientation == OrientationReading.TopUp)
81 // do something
82 }
83 }
84 \endcode
85*/
86
87QOrientationReading::Orientation QmlOrientationSensorReading::orientation() const
88{
89 return m_orientation;
90}
91
92QBindable<QOrientationReading::Orientation> QmlOrientationSensorReading::bindableOrientation() const
93{
94 return &m_orientation;
95}
96
97QSensorReading *QmlOrientationSensorReading::reading() const
98{
99 return m_sensor->reading();
100}
101
102void QmlOrientationSensorReading::readingUpdate()
103{
104 m_orientation = m_sensor->reading()->orientation();
105}
106

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