summaryrefslogtreecommitdiffstats
path: root/src/sensorsquick/qmlhumiditysensor.cpp
blob: 915e81b6a372bd4338151249f1d56d8d4472d538 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright (C) 2016 Canonical Ltd
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "qmlhumiditysensor_p.h"
#include <QtSensors/QHumiditySensor>

/*!
    \qmltype HumiditySensor
//!    \instantiates QmlHumiditySensor
    \ingroup qml-sensors_type
    \inqmlmodule QtSensors
    \since QtSensors 5.9
    \inherits Sensor
    \brief The HumiditySensor element reports on humidity.

    The HumiditySensor element reports on humidity.

    This element wraps the QHumiditySensor class. Please see the documentation for
    QHumiditySensor for details.

    \sa HumidityReading
*/

QmlHumiditySensor::QmlHumiditySensor(QObject *parent)
    : QmlSensor(parent)
    , m_sensor(new QHumiditySensor(this))
{
}

QmlHumiditySensor::~QmlHumiditySensor()
{
}

QmlSensorReading *QmlHumiditySensor::createReading() const
{
    return new QmlHumidityReading(m_sensor);
}

QSensor *QmlHumiditySensor::sensor() const
{
    return m_sensor;
}

/*!
    \qmltype HumidityReading
//!    \instantiates QmlHumidityReading
    \ingroup qml-sensors_reading
    \inqmlmodule QtSensors
    \since QtSensors 5.9
    \inherits SensorReading
    \brief The HumidityReading element holds the most recent HumiditySensor reading.

    The HumidityReading element holds the most recent HumiditySensor reading.

    This element wraps the QHumidityReading class. Please see the documentation for
    QHumidityReading for details.

    This element cannot be directly created.
*/

QmlHumidityReading::QmlHumidityReading(QHumiditySensor *sensor)
    : m_sensor(sensor)
    , m_relativeHumidity(0)
    , m_absoluteHumidity(0)
{
}

QmlHumidityReading::~QmlHumidityReading()
{
}

/*!
    \qmlproperty qreal HumidityReading::relativeHumidity
    This property holds the relative humidity as a percentage.

    Please see QHumidityReading::relativeHumidity for information about this property.
*/

qreal QmlHumidityReading::relativeHumidity() const
{
    return m_relativeHumidity;
}

QBindable<qreal> QmlHumidityReading::bindableRelativeHumidity() const
{
    return &m_relativeHumidity;
}

/*!
    \qmlproperty qreal HumidityReading::absoluteHumidity
    This property holds the absolute humidity in grams per cubic meter (g/m3).

    Please see QHumidityReading::absoluteHumidity for information about this property.
*/

qreal QmlHumidityReading::absoluteHumidity() const
{
    return m_absoluteHumidity;
}

QBindable<qreal> QmlHumidityReading::bindableAbsoluteHumidity() const
{
    return &m_absoluteHumidity;
}

QSensorReading *QmlHumidityReading::reading() const
{
    return m_sensor->reading();
}

void QmlHumidityReading::readingUpdate()
{
    m_relativeHumidity = m_sensor->reading()->relativeHumidity();
    m_absoluteHumidity = m_sensor->reading()->absoluteHumidity();
}