1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtSensors module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QMLSENSOR_H
41#define QMLSENSOR_H
42
43#include <QObject>
44#include <QQmlParserStatus>
45#include <QQmlListProperty>
46#include "qmlsensorrange.h"
47
48QT_BEGIN_NAMESPACE
49
50class QSensor;
51class QSensorReading;
52
53class QmlSensorReading;
54
55class QmlSensorPrivate;
56class QmlSensor : public QObject, public QQmlParserStatus
57{
58 Q_OBJECT
59 Q_DECLARE_PRIVATE(QmlSensor)
60 Q_ENUMS(AxesOrientationMode)
61 Q_INTERFACES(QQmlParserStatus)
62 Q_PROPERTY(QString identifier READ identifier WRITE setIdentifier NOTIFY identifierChanged)
63 Q_PROPERTY(QString type READ type NOTIFY typeChanged)
64 Q_PROPERTY(bool connectedToBackend READ isConnectedToBackend NOTIFY connectedToBackendChanged)
65 Q_PROPERTY(QQmlListProperty<QmlSensorRange> availableDataRates READ availableDataRates NOTIFY availableDataRatesChanged)
66 Q_PROPERTY(int dataRate READ dataRate WRITE setDataRate NOTIFY dataRateChanged)
67 Q_PROPERTY(QmlSensorReading* reading READ reading NOTIFY readingChanged)
68 Q_PROPERTY(bool busy READ isBusy)
69 Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged)
70 Q_PROPERTY(QQmlListProperty<QmlSensorOutputRange> outputRanges READ outputRanges NOTIFY outputRangesChanged)
71 Q_PROPERTY(int outputRange READ outputRange WRITE setOutputRange NOTIFY outputRangeChanged)
72 Q_PROPERTY(QString description READ description NOTIFY descriptionChanged)
73 Q_PROPERTY(int error READ error NOTIFY errorChanged)
74 Q_PROPERTY(bool alwaysOn READ isAlwaysOn WRITE setAlwaysOn NOTIFY alwaysOnChanged)
75 Q_PROPERTY(bool skipDuplicates READ skipDuplicates WRITE setSkipDuplicates NOTIFY skipDuplicatesChanged REVISION 1)
76 Q_PROPERTY(AxesOrientationMode axesOrientationMode READ axesOrientationMode WRITE setAxesOrientationMode NOTIFY axesOrientationModeChanged REVISION 1)
77 Q_PROPERTY(int currentOrientation READ currentOrientation NOTIFY currentOrientationChanged REVISION 1)
78 Q_PROPERTY(int userOrientation READ userOrientation WRITE setUserOrientation NOTIFY userOrientationChanged REVISION 1)
79 Q_PROPERTY(int maxBufferSize READ maxBufferSize NOTIFY maxBufferSizeChanged REVISION 1)
80 Q_PROPERTY(int efficientBufferSize READ efficientBufferSize NOTIFY efficientBufferSizeChanged REVISION 1)
81 Q_PROPERTY(int bufferSize READ bufferSize WRITE setBufferSize NOTIFY bufferSizeChanged REVISION 1)
82
83public:
84 // Keep in sync with QSensor::AxesOrientationMode
85 enum AxesOrientationMode {
86 FixedOrientation,
87 AutomaticOrientation,
88 UserOrientation
89 };
90
91 explicit QmlSensor(QObject *parent = 0);
92 ~QmlSensor();
93
94 QString identifier() const;
95 void setIdentifier(const QString &identifier);
96
97 QString type() const;
98
99 bool isConnectedToBackend() const;
100
101 bool isBusy() const;
102
103 void setActive(bool active);
104 bool isActive() const;
105
106 bool isAlwaysOn() const;
107 void setAlwaysOn(bool alwaysOn);
108
109 bool skipDuplicates() const;
110 void setSkipDuplicates(bool skipDuplicates);
111
112 QQmlListProperty<QmlSensorRange> availableDataRates() const;
113 int dataRate() const;
114 void setDataRate(int rate);
115
116 QQmlListProperty<QmlSensorOutputRange> outputRanges() const;
117 int outputRange() const;
118 void setOutputRange(int index);
119
120 QString description() const;
121 int error() const;
122
123 QmlSensorReading *reading() const;
124
125 AxesOrientationMode axesOrientationMode() const;
126 void setAxesOrientationMode(AxesOrientationMode axesOrientationMode);
127
128 int currentOrientation() const;
129
130 int userOrientation() const;
131 void setUserOrientation(int userOrientation);
132
133 int maxBufferSize() const;
134
135 int efficientBufferSize() const;
136
137 int bufferSize() const;
138 void setBufferSize(int bufferSize);
139
140public Q_SLOTS:
141 bool start();
142 void stop();
143
144Q_SIGNALS:
145 void identifierChanged();
146 void typeChanged();
147 void connectedToBackendChanged();
148 void availableDataRatesChanged();
149 void dataRateChanged();
150 void readingChanged();
151 void activeChanged();
152 void outputRangesChanged();
153 void outputRangeChanged();
154 void descriptionChanged();
155 void errorChanged();
156 void alwaysOnChanged();
157 Q_REVISION(1) void skipDuplicatesChanged(bool skipDuplicates);
158 Q_REVISION(1) void axesOrientationModeChanged(AxesOrientationMode axesOrientationMode);
159 Q_REVISION(1) void currentOrientationChanged(int currentOrientation);
160 Q_REVISION(1) void userOrientationChanged(int userOrientation);
161 Q_REVISION(1) void maxBufferSizeChanged(int maxBufferSize);
162 Q_REVISION(1) void efficientBufferSizeChanged(int efficientBufferSize);
163 Q_REVISION(1) void bufferSizeChanged(int bufferSize);
164
165protected:
166 virtual QSensor *sensor() const = 0;
167 virtual QmlSensorReading *createReading() const = 0;
168
169private Q_SLOTS:
170 void updateReading();
171
172protected Q_SLOTS:
173 void componentComplete() override;
174
175private:
176 void classBegin() override;
177 virtual void _update();
178 bool m_parsed;
179 bool m_active;
180 QString m_identifier;
181 QmlSensorReading *m_reading;
182};
183
184class QmlSensorReading : public QObject
185{
186 Q_OBJECT
187 Q_PROPERTY(quint64 timestamp READ timestamp NOTIFY timestampChanged)
188public:
189 explicit QmlSensorReading(QSensor *sensor);
190 ~QmlSensorReading();
191
192 quint64 timestamp() const;
193 void update();
194
195Q_SIGNALS:
196 void timestampChanged();
197
198private:
199 virtual QSensorReading *reading() const = 0;
200 virtual void readingUpdate() = 0;
201 quint64 m_timestamp;
202};
203
204QT_END_NAMESPACE
205
206#endif
207

source code of qtsensors/src/imports/sensors/qmlsensor.h