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 "qmlaccelerometer_p.h" |
5 | #include <QtSensors/QAccelerometer> |
6 | |
7 | /*! |
8 | \qmltype Accelerometer |
9 | //! \instantiates QmlAccelerometer |
10 | \ingroup qml-sensors_type |
11 | \inqmlmodule QtSensors |
12 | \since QtSensors 5.0 |
13 | \inherits Sensor |
14 | \brief The Accelerometer element reports on linear acceleration |
15 | along the X, Y and Z axes. |
16 | |
17 | The Accelerometer element reports on linear acceleration |
18 | along the X, Y and Z axes. |
19 | |
20 | This element wraps the QAccelerometer class. Please see the documentation for |
21 | QAccelerometer for details. |
22 | |
23 | \sa AccelerometerReading |
24 | */ |
25 | |
26 | QmlAccelerometer::QmlAccelerometer(QObject *parent) |
27 | : QmlSensor(parent) |
28 | , m_sensor(new QAccelerometer(this)) |
29 | { |
30 | connect(sender: m_sensor, SIGNAL(accelerationModeChanged(AccelerationMode)), |
31 | receiver: this, SIGNAL(accelerationModeChanged(AccelerationMode))); |
32 | } |
33 | |
34 | QmlAccelerometer::~QmlAccelerometer() |
35 | { |
36 | } |
37 | |
38 | /*! |
39 | \qmlproperty AccelerationMode Accelerometer::accelerationMode |
40 | \since QtSensors 5.1 |
41 | |
42 | This property holds the current acceleration mode. |
43 | |
44 | Please see QAccelerometer::accelerationMode for information about this property. |
45 | */ |
46 | |
47 | QmlAccelerometer::AccelerationMode QmlAccelerometer::accelerationMode() const |
48 | { |
49 | return static_cast<QmlAccelerometer::AccelerationMode>(m_sensor->accelerationMode()); |
50 | } |
51 | |
52 | void QmlAccelerometer::setAccelerationMode(QmlAccelerometer::AccelerationMode accelerationMode) |
53 | { |
54 | m_sensor->setAccelerationMode(static_cast<QAccelerometer::AccelerationMode>(accelerationMode)); |
55 | } |
56 | |
57 | QmlSensorReading *QmlAccelerometer::createReading() const |
58 | { |
59 | return new QmlAccelerometerReading(m_sensor); |
60 | } |
61 | |
62 | QSensor *QmlAccelerometer::sensor() const |
63 | { |
64 | return m_sensor; |
65 | } |
66 | |
67 | /*! |
68 | \qmltype AccelerometerReading |
69 | //! \instantiates QmlAccelerometerReading |
70 | \ingroup qml-sensors_reading |
71 | \inqmlmodule QtSensors |
72 | \since QtSensors 5.0 |
73 | \inherits SensorReading |
74 | \brief The AccelerometerReading element holds the most recent Accelerometer reading. |
75 | |
76 | The AccelerometerReading element holds the most recent Accelerometer reading. |
77 | |
78 | This element wraps the QAccelerometerReading class. Please see the documentation for |
79 | QAccelerometerReading for details. |
80 | |
81 | This element cannot be directly created. |
82 | */ |
83 | |
84 | QmlAccelerometerReading::QmlAccelerometerReading(QAccelerometer *sensor) |
85 | : m_sensor(sensor) |
86 | { |
87 | } |
88 | |
89 | QmlAccelerometerReading::~QmlAccelerometerReading() |
90 | { |
91 | } |
92 | |
93 | /*! |
94 | \qmlproperty qreal AccelerometerReading::x |
95 | This property holds the acceleration on the X axis. |
96 | |
97 | Please see QAccelerometerReading::x for information about this property. |
98 | */ |
99 | |
100 | qreal QmlAccelerometerReading::x() const |
101 | { |
102 | return m_x; |
103 | } |
104 | |
105 | QBindable<qreal> QmlAccelerometerReading::bindableX() const |
106 | { |
107 | return &m_x; |
108 | } |
109 | |
110 | /*! |
111 | \qmlproperty qreal AccelerometerReading::y |
112 | This property holds the acceleration on the Y axis. |
113 | |
114 | Please see QAccelerometerReading::y for information about this property. |
115 | */ |
116 | |
117 | qreal QmlAccelerometerReading::y() const |
118 | { |
119 | return m_y; |
120 | } |
121 | |
122 | QBindable<qreal> QmlAccelerometerReading::bindableY() const |
123 | { |
124 | return &m_y; |
125 | } |
126 | |
127 | /*! |
128 | \qmlproperty qreal AccelerometerReading::z |
129 | This property holds the acceleration on the Z axis. |
130 | |
131 | Please see QAccelerometerReading::z for information about this property. |
132 | */ |
133 | |
134 | qreal QmlAccelerometerReading::z() const |
135 | { |
136 | return m_z; |
137 | } |
138 | |
139 | QBindable<qreal> QmlAccelerometerReading::bindableZ() const |
140 | { |
141 | return &m_z; |
142 | } |
143 | |
144 | QSensorReading *QmlAccelerometerReading::reading() const |
145 | { |
146 | return m_sensor->reading(); |
147 | } |
148 | |
149 | void QmlAccelerometerReading::readingUpdate() |
150 | { |
151 | m_x = m_sensor->reading()->x(); |
152 | m_y = m_sensor->reading()->y(); |
153 | m_z = m_sensor->reading()->z(); |
154 | } |
155 |