1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 BlackBerry Limited. All rights reserved.
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#include <qdistancesensor.h>
41#include "qdistancesensor_p.h"
42
43QT_BEGIN_NAMESPACE
44
45IMPLEMENT_READING(QDistanceReading)
46
47/*!
48 \class QDistanceReading
49 \ingroup sensors_reading
50 \inmodule QtSensors
51 \since 5.4
52
53 \brief The QDistanceReading class holds distance reading in cm from the proximity sensor.
54
55 The QDistanceReading class holds distance reading in cm from the proximity sensor.
56 Note: Some proximity sensor only support two values for distance, a near and far value.
57 In this case, the sensor should report its maximum range value to represent the far state,
58 and a lesser value to represent the near state.
59
60 \section2 QDistanceReading Units
61 The distance is measured in cm
62
63 The distance sensor is typically located in the front face of a device, and thus will
64 measure the distance of an object from the device's front face.
65*/
66
67/*!
68 \property QDistanceReading::distance
69 \brief distance of object from front face of device
70
71 \sa {QDistanceReading Units}
72*/
73
74qreal QDistanceReading::distance() const
75{
76 return d->distance;
77}
78
79/*!
80 Sets distance to \a distance.
81*/
82void QDistanceReading::setDistance(qreal distance)
83{
84 d->distance = distance;
85}
86
87// =====================================================================
88
89/*!
90 \class QDistanceFilter
91 \ingroup sensors_filter
92 \inmodule QtSensors
93 \since 5.4
94
95 \brief The QDistanceFilter class is a convenience wrapper around QSensorFilter.
96
97 The only difference is that the filter() method features a pointer to QDistanceReading
98 instead of QSensorReading.
99*/
100
101/*!
102 \fn QDistanceFilter::filter(QDistanceReading *reading)
103
104 Called when \a reading changes. Returns false to prevent the reading from propagating.
105
106 \sa QSensorFilter::filter()
107*/
108
109bool QDistanceFilter::filter(QSensorReading *reading)
110{
111 return filter(reading: static_cast<QDistanceReading*>(reading));
112}
113
114char const * const QDistanceSensor::type("QDistanceSensor");
115
116/*!
117 \class QDistanceSensor
118 \ingroup sensors_type
119 \inmodule QtSensors
120 \since 5.4
121
122 \brief The QDistanceSensor class is a convenience wrapper around QSensor.
123
124 The only behavioral difference is that this class sets the type properly.
125
126 This class also features a reading() function that returns a QDistanceReading instead of a QSensorReading.
127
128 For details about how the sensor works, see \l QDistanceReading.
129
130 \sa QDistanceReading
131*/
132
133/*!
134 Construct the sensor as a child of \a parent.
135*/
136QDistanceSensor::QDistanceSensor(QObject *parent)
137 : QSensor(QDistanceSensor::type, parent)
138{
139}
140
141/*!
142 Destroy the sensor. Stops the sensor if it has not already been stopped.
143*/
144QDistanceSensor::~QDistanceSensor()
145{
146}
147
148/*!
149 \fn QDistanceSensor::reading() const
150
151 Returns the reading class for this sensor.
152
153 \sa QSensor::reading()
154*/
155
156QDistanceReading *QDistanceSensor::reading() const
157{
158 return static_cast<QDistanceReading*>(QSensor::reading());
159}
160
161QT_END_NAMESPACE
162
163#include "moc_qdistancesensor.cpp"
164

source code of qtsensors/src/sensors/qdistancesensor.cpp