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 "qmlhumiditysensor_p.h"
5#include <QtSensors/QHumiditySensor>
6
7/*!
8 \qmltype HumiditySensor
9//! \instantiates QmlHumiditySensor
10 \ingroup qml-sensors_type
11 \inqmlmodule QtSensors
12 \since QtSensors 5.9
13 \inherits Sensor
14 \brief The HumiditySensor element reports on humidity.
15
16 The HumiditySensor element reports on humidity.
17
18 This element wraps the QHumiditySensor class. Please see the documentation for
19 QHumiditySensor for details.
20
21 \sa HumidityReading
22*/
23
24QmlHumiditySensor::QmlHumiditySensor(QObject *parent)
25 : QmlSensor(parent)
26 , m_sensor(new QHumiditySensor(this))
27{
28}
29
30QmlHumiditySensor::~QmlHumiditySensor()
31{
32}
33
34QmlSensorReading *QmlHumiditySensor::createReading() const
35{
36 return new QmlHumidityReading(m_sensor);
37}
38
39QSensor *QmlHumiditySensor::sensor() const
40{
41 return m_sensor;
42}
43
44/*!
45 \qmltype HumidityReading
46//! \instantiates QmlHumidityReading
47 \ingroup qml-sensors_reading
48 \inqmlmodule QtSensors
49 \since QtSensors 5.9
50 \inherits SensorReading
51 \brief The HumidityReading element holds the most recent HumiditySensor reading.
52
53 The HumidityReading element holds the most recent HumiditySensor reading.
54
55 This element wraps the QHumidityReading class. Please see the documentation for
56 QHumidityReading for details.
57
58 This element cannot be directly created.
59*/
60
61QmlHumidityReading::QmlHumidityReading(QHumiditySensor *sensor)
62 : m_sensor(sensor)
63 , m_relativeHumidity(0)
64 , m_absoluteHumidity(0)
65{
66}
67
68QmlHumidityReading::~QmlHumidityReading()
69{
70}
71
72/*!
73 \qmlproperty qreal HumidityReading::relativeHumidity
74 This property holds the relative humidity as a percentage.
75
76 Please see QHumidityReading::relativeHumidity for information about this property.
77*/
78
79qreal QmlHumidityReading::relativeHumidity() const
80{
81 return m_relativeHumidity;
82}
83
84QBindable<qreal> QmlHumidityReading::bindableRelativeHumidity() const
85{
86 return &m_relativeHumidity;
87}
88
89/*!
90 \qmlproperty qreal HumidityReading::absoluteHumidity
91 This property holds the absolute humidity in grams per cubic meter (g/m3).
92
93 Please see QHumidityReading::absoluteHumidity for information about this property.
94*/
95
96qreal QmlHumidityReading::absoluteHumidity() const
97{
98 return m_absoluteHumidity;
99}
100
101QBindable<qreal> QmlHumidityReading::bindableAbsoluteHumidity() const
102{
103 return &m_absoluteHumidity;
104}
105
106QSensorReading *QmlHumidityReading::reading() const
107{
108 return m_sensor->reading();
109}
110
111void QmlHumidityReading::readingUpdate()
112{
113 m_relativeHumidity = m_sensor->reading()->relativeHumidity();
114 m_absoluteHumidity = m_sensor->reading()->absoluteHumidity();
115}
116

source code of qtsensors/src/sensorsquick/qmlhumiditysensor.cpp