| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 Research In Motion |
| 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 | #include "qmlholstersensor.h" |
| 40 | #include <QtSensors/QHolsterSensor> |
| 41 | |
| 42 | /*! |
| 43 | \qmltype HolsterSensor |
| 44 | \instantiates QmlHolsterSensor |
| 45 | \ingroup qml-sensors_type |
| 46 | \inqmlmodule QtSensors |
| 47 | \since QtSensors 5.1 |
| 48 | \inherits Sensor |
| 49 | \brief The HolsterSensor element reports on whether a device is holstered. |
| 50 | |
| 51 | The HolsterSensor element reports on whether a device is holstered. |
| 52 | |
| 53 | This element wraps the QHolsterSensor class. Please see the documentation for |
| 54 | QHolsterSensor for details. |
| 55 | |
| 56 | \sa HolsterReading |
| 57 | */ |
| 58 | |
| 59 | QmlHolsterSensor::QmlHolsterSensor(QObject *parent) |
| 60 | : QmlSensor(parent) |
| 61 | , m_sensor(new QHolsterSensor(this)) |
| 62 | { |
| 63 | } |
| 64 | |
| 65 | QmlHolsterSensor::~QmlHolsterSensor() |
| 66 | { |
| 67 | } |
| 68 | |
| 69 | QmlSensorReading *QmlHolsterSensor::createReading() const |
| 70 | { |
| 71 | return new QmlHolsterReading(m_sensor); |
| 72 | } |
| 73 | |
| 74 | QSensor *QmlHolsterSensor::sensor() const |
| 75 | { |
| 76 | return m_sensor; |
| 77 | } |
| 78 | |
| 79 | /*! |
| 80 | \qmltype HolsterReading |
| 81 | \instantiates QmlHolsterReading |
| 82 | \ingroup qml-sensors_reading |
| 83 | \inqmlmodule QtSensors |
| 84 | \since QtSensors 5.1 |
| 85 | \inherits SensorReading |
| 86 | \brief The HolsterReading element holds the most recent HolsterSensor reading. |
| 87 | |
| 88 | The HolsterReading element holds the most recent HolsterSensor reading. |
| 89 | |
| 90 | This element wraps the QHolsterReading class. Please see the documentation for |
| 91 | QHolsterReading for details. |
| 92 | |
| 93 | This element cannot be directly created. |
| 94 | */ |
| 95 | |
| 96 | QmlHolsterReading::QmlHolsterReading(QHolsterSensor *sensor) |
| 97 | : QmlSensorReading(sensor) |
| 98 | , m_sensor(sensor) |
| 99 | , m_holstered(false) |
| 100 | { |
| 101 | } |
| 102 | |
| 103 | QmlHolsterReading::~QmlHolsterReading() |
| 104 | { |
| 105 | } |
| 106 | |
| 107 | /*! |
| 108 | \qmlproperty qreal HolsterReading::holstered |
| 109 | This property holds whether the device is holstered. |
| 110 | |
| 111 | Please see QHolsterReading::holstered for information about this property. |
| 112 | */ |
| 113 | |
| 114 | bool QmlHolsterReading::holstered() const |
| 115 | { |
| 116 | return m_holstered; |
| 117 | } |
| 118 | |
| 119 | QSensorReading *QmlHolsterReading::reading() const |
| 120 | { |
| 121 | return m_sensor->reading(); |
| 122 | } |
| 123 | |
| 124 | void QmlHolsterReading::readingUpdate() |
| 125 | { |
| 126 | const bool holstered = m_sensor->reading()->holstered(); |
| 127 | if (m_holstered != holstered) { |
| 128 | m_holstered = holstered; |
| 129 | Q_EMIT holsteredChanged(); |
| 130 | } |
| 131 | } |
| 132 | |