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#ifndef QMLACCELEROMETER_P_H
5#define QMLACCELEROMETER_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "qmlsensor_p.h"
19
20QT_BEGIN_NAMESPACE
21
22class QAccelerometer;
23
24class Q_SENSORSQUICK_PRIVATE_EXPORT QmlAccelerometer : public QmlSensor
25{
26 Q_OBJECT
27 Q_PROPERTY(AccelerationMode accelerationMode READ accelerationMode WRITE setAccelerationMode
28 NOTIFY accelerationModeChanged REVISION 1)
29 QML_NAMED_ELEMENT(Accelerometer)
30 QML_ADDED_IN_VERSION(5,0)
31public:
32 explicit QmlAccelerometer(QObject *parent = 0);
33 ~QmlAccelerometer();
34
35 // Keep this enum in sync with QAccelerometer::AccelerationMode
36 enum AccelerationMode {
37 Combined,
38 Gravity,
39 User
40 };
41 Q_ENUM(AccelerationMode)
42
43 AccelerationMode accelerationMode() const;
44 void setAccelerationMode(AccelerationMode accelerationMode);
45
46 QSensor *sensor() const override;
47
48signals:
49 Q_REVISION(1) void accelerationModeChanged(AccelerationMode accelerationMode);
50
51private:
52 QAccelerometer *m_sensor;
53 QmlSensorReading *createReading() const override;
54};
55
56class Q_SENSORSQUICK_PRIVATE_EXPORT QmlAccelerometerReading : public QmlSensorReading
57{
58 Q_OBJECT
59 Q_PROPERTY(qreal x READ x NOTIFY xChanged BINDABLE bindableX)
60 Q_PROPERTY(qreal y READ y NOTIFY yChanged BINDABLE bindableY)
61 Q_PROPERTY(qreal z READ z NOTIFY zChanged BINDABLE bindableZ)
62 QML_NAMED_ELEMENT(AccelerometerReading)
63 QML_UNCREATABLE("Cannot create AccelerometerReading")
64 QML_ADDED_IN_VERSION(5,0)
65public:
66 explicit QmlAccelerometerReading(QAccelerometer *sensor);
67 ~QmlAccelerometerReading();
68
69 qreal x() const;
70 QBindable<qreal> bindableX() const;
71 qreal y() const;
72 QBindable<qreal> bindableY() const;
73 qreal z() const;
74 QBindable<qreal> bindableZ() const;
75
76Q_SIGNALS:
77 void xChanged();
78 void yChanged();
79 void zChanged();
80
81private:
82 QSensorReading *reading() const override;
83 void readingUpdate() override;
84 QAccelerometer *m_sensor;
85 Q_OBJECT_BINDABLE_PROPERTY(QmlAccelerometerReading, qreal,
86 m_x, &QmlAccelerometerReading::xChanged)
87 Q_OBJECT_BINDABLE_PROPERTY(QmlAccelerometerReading, qreal,
88 m_y, &QmlAccelerometerReading::yChanged)
89 Q_OBJECT_BINDABLE_PROPERTY(QmlAccelerometerReading, qreal,
90 m_z, &QmlAccelerometerReading::zChanged)
91};
92
93QT_END_NAMESPACE
94#endif
95

source code of qtsensors/src/sensorsquick/qmlaccelerometer_p.h