1// Copyright (C) 2016 Canonical 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 <qhumiditysensor.h>
5#include "qhumiditysensor_p.h"
6
7QT_BEGIN_NAMESPACE
8
9IMPLEMENT_READING(QHumidityReading)
10
11/*!
12 \class QHumidityReading
13 \ingroup sensors_reading
14 \inmodule QtSensors
15 \since 5.9
16
17 \brief The QHumidityReading class holds readings from the humidity sensor.
18
19 \section2 QHumidityReading Units
20
21 The humidity sensor returns the relative humidity as a percentage, and absolute humidity in
22 grams per cubic meter (g/m3).
23 Note that some sensors may not support absolute humidity, 0 will be returned in this case.
24*/
25
26/*!
27 \property QHumidityReading::relativeHumidity
28 \brief Relative humidity
29 Returned as a percentage.
30
31 \sa {QHumidityReading Units}
32*/
33
34qreal QHumidityReading::relativeHumidity() const
35{
36 return d->relativeHumidity;
37}
38
39/*!
40 Sets relativeHumidity to \a humidity.
41*/
42void QHumidityReading::setRelativeHumidity(qreal humidity)
43{
44 d->relativeHumidity = humidity;
45}
46
47/*!
48 \property QHumidityReading::absoluteHumidity
49 \brief Absolute humidity
50 Measured in grams per cubic meter.
51 Note that some sensors may not support absolute humidity.
52
53 \sa {QHumidityReading Units}
54*/
55
56qreal QHumidityReading::absoluteHumidity() const
57{
58 return d->absoluteHumidity;
59}
60
61/*!
62 Sets absoluteHumidity to \a value.
63*/
64void QHumidityReading::setAbsoluteHumidity(qreal value)
65{
66 d->absoluteHumidity = value;
67}
68
69// =====================================================================
70
71/*!
72 \class QHumidityFilter
73 \ingroup sensors_filter
74 \inmodule QtSensors
75 \since 5.9
76
77 \brief The QHumidityFilter class is a convenience wrapper around QSensorFilter.
78
79 The only difference is that the filter() method features a pointer to QHumidityReading
80 instead of QSensorReading.
81*/
82
83/*!
84 \fn QHumidityFilter::filter(QHumidityReading *reading)
85
86 Called when \a reading changes. Returns false to prevent the reading from propagating.
87
88 \sa QSensorFilter::filter()
89*/
90
91bool QHumidityFilter::filter(QSensorReading *reading)
92{
93 return filter(reading: static_cast<QHumidityReading*>(reading));
94}
95
96char const * const QHumiditySensor::sensorType("QHumiditySensor");
97
98
99/*!
100 \class QHumiditySensor
101 \ingroup sensors_type
102 \inmodule QtSensors
103 \since 5.9
104
105 \brief The QHumiditySensor class is a convenience wrapper around QSensor.
106
107 The only behavioural difference is that this class sets the type properly.
108
109 This class also features a reading() function that returns a QHumidityReading instead of a QSensorReading.
110
111 For details about how the sensor works, see \l QHumidityReading.
112
113 \sa QHumidityReading
114*/
115
116/*!
117 Construct the sensor as a child of \a parent.
118*/
119QHumiditySensor::QHumiditySensor(QObject *parent)
120 : QSensor(QHumiditySensor::sensorType, parent)
121{
122}
123
124/*!
125 Destroy the sensor. Stops the sensor if it has not already been stopped.
126*/
127QHumiditySensor::~QHumiditySensor()
128{
129}
130
131/*!
132 \fn QHumiditySensor::reading() const
133
134 Returns the reading class for this sensor.
135
136 \sa QSensor::reading()
137*/
138
139QHumidityReading *QHumiditySensor::reading() const
140{
141 return static_cast<QHumidityReading*>(QSensor::reading());
142}
143
144QT_END_NAMESPACE
145
146#include "moc_qhumiditysensor.cpp"
147

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