diff options
author | Juha Vuolle <juha.vuolle@insta.fi> | 2021-05-21 10:01:56 +0300 |
---|---|---|
committer | Juha Vuolle <juha.vuolle@insta.fi> | 2021-05-26 09:48:04 +0300 |
commit | 0193d164e79845f7a2b5a388ed2818854c77399f (patch) | |
tree | 68d05a426a53d39c0bce34705dd91fbbbc9c24e5 /src/sensorsquick | |
parent | cf21f9074be72e9d5a1c45638bf6762edad7a73f (diff) |
Split the Sensors QML plugin into a library and a plugin
The main changes:
- Introduction of new SensorsQuick library with private exports
- The original QML plugin loads this new library and does little else
- Renamed original 'sensors' plugin as 'declarative_sensors' to provide
an idea what it relates to
- Renamed library headers as private "_p.h" and added "We mean it"
- Changed qmlRegister* calls to QML_ELEMENT macros
- Removed files that are generated in Qt6 (qmldir, plugins.qmltypes)
Task-number: QTBUG-92530
Change-Id: I18f849adabcc79ac47e67305f78aefeee82801bc
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/sensorsquick')
48 files changed, 6608 insertions, 0 deletions
diff --git a/src/sensorsquick/CMakeLists.txt b/src/sensorsquick/CMakeLists.txt new file mode 100644 index 00000000..703974e1 --- /dev/null +++ b/src/sensorsquick/CMakeLists.txt @@ -0,0 +1,45 @@ +qt_internal_add_module(SensorsQuick + SOURCES + qmlaccelerometer.cpp qmlaccelerometer_p.h + qmlaltimeter.cpp qmlaltimeter_p.h + qmlambientlightsensor.cpp qmlambientlightsensor_p.h + qmlambienttemperaturesensor.cpp qmlambienttemperaturesensor_p.h + qmlcompass.cpp qmlcompass_p.h + qmldistancesensor.cpp qmldistancesensor_p.h + qmlgyroscope.cpp qmlgyroscope_p.h + qmlholstersensor.cpp qmlholstersensor_p.h + qmlhumiditysensor.cpp qmlhumiditysensor_p.h + qmlirproximitysensor.cpp qmlirproximitysensor_p.h + qmllidsensor.cpp qmllidsensor_p.h + qmllightsensor.cpp qmllightsensor_p.h + qmlmagnetometer.cpp qmlmagnetometer_p.h + qmlorientationsensor.cpp qmlorientationsensor_p.h + qmlpressuresensor.cpp qmlpressuresensor_p.h + qmlproximitysensor.cpp qmlproximitysensor_p.h + qmlrotationsensor.cpp qmlrotationsensor_p.h + qmlsensor.cpp qmlsensor_p.h + qmlsensorgesture.cpp qmlsensorgesture_p.h + qmlsensorglobal.cpp qmlsensorglobal_p.h + qmlsensorrange.cpp qmlsensorrange_p.h + qmltapsensor.cpp qmltapsensor_p.h + qmltiltsensor.cpp qmltiltsensor_p.h + qsensorsquickglobal_p.h + DEFINES + QT_BUILD_SENSORSQUICK_LIB + PUBLIC_LIBRARIES + Qt::Core + Qt::Qml + Qt::Sensors + LIBRARIES + Qt::CorePrivate +) + +set_target_properties(SensorsQuick PROPERTIES + QT_QML_MODULE_INSTALL_QMLTYPES TRUE + QT_QML_MODULE_VERSION ${PROJECT_VERSION} + QT_QML_MODULE_URI QtSensors + QT_QMLTYPES_FILENAME plugins.qmltypes + QT_QML_MODULE_INSTALL_DIR "${INSTALL_QMLDIR}/QtSensors" +) + +qt6_qml_type_registration(SensorsQuick) diff --git a/src/sensorsquick/qmlaccelerometer.cpp b/src/sensorsquick/qmlaccelerometer.cpp new file mode 100644 index 00000000..fc013837 --- /dev/null +++ b/src/sensorsquick/qmlaccelerometer.cpp @@ -0,0 +1,188 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmlaccelerometer_p.h" +#include <QtSensors/QAccelerometer> + +/*! + \qmltype Accelerometer + \instantiates QmlAccelerometer + \ingroup qml-sensors_type + \inqmlmodule QtSensors + \since QtSensors 5.0 + \inherits Sensor + \brief The Accelerometer element reports on linear acceleration + along the X, Y and Z axes. + + The Accelerometer element reports on linear acceleration + along the X, Y and Z axes. + + This element wraps the QAccelerometer class. Please see the documentation for + QAccelerometer for details. + + \sa AccelerometerReading +*/ + +QmlAccelerometer::QmlAccelerometer(QObject *parent) + : QmlSensor(parent) + , m_sensor(new QAccelerometer(this)) +{ + connect(m_sensor, SIGNAL(accelerationModeChanged(AccelerationMode)), + this, SIGNAL(accelerationModeChanged(AccelerationMode))); +} + +QmlAccelerometer::~QmlAccelerometer() +{ +} + +/*! + \qmlproperty AccelerationMode Accelerometer::accelerationMode + \since QtSensors 5.1 + + This property holds the current acceleration mode. + + Please see QAccelerometer::accelerationMode for information about this property. +*/ + +QmlAccelerometer::AccelerationMode QmlAccelerometer::accelerationMode() const +{ + return static_cast<QmlAccelerometer::AccelerationMode>(m_sensor->accelerationMode()); +} + +void QmlAccelerometer::setAccelerationMode(QmlAccelerometer::AccelerationMode accelerationMode) +{ + m_sensor->setAccelerationMode(static_cast<QAccelerometer::AccelerationMode>(accelerationMode)); +} + +QmlSensorReading *QmlAccelerometer::createReading() const +{ + return new QmlAccelerometerReading(m_sensor); +} + +QSensor *QmlAccelerometer::sensor() const +{ + return m_sensor; +} + +/*! + \qmltype AccelerometerReading + \instantiates QmlAccelerometerReading + \ingroup qml-sensors_reading + \inqmlmodule QtSensors + \since QtSensors 5.0 + \inherits SensorReading + \brief The AccelerometerReading element holds the most recent Accelerometer reading. + + The AccelerometerReading element holds the most recent Accelerometer reading. + + This element wraps the QAccelerometerReading class. Please see the documentation for + QAccelerometerReading for details. + + This element cannot be directly created. +*/ + +QmlAccelerometerReading::QmlAccelerometerReading(QAccelerometer *sensor) + : QmlSensorReading(sensor) + , m_sensor(sensor) +{ +} + +QmlAccelerometerReading::~QmlAccelerometerReading() +{ +} + +/*! + \qmlproperty qreal AccelerometerReading::x + This property holds the acceleration on the X axis. + + Please see QAccelerometerReading::x for information about this property. +*/ + +qreal QmlAccelerometerReading::x() const +{ + return m_x; +} + +/*! + \qmlproperty qreal AccelerometerReading::y + This property holds the acceleration on the Y axis. + + Please see QAccelerometerReading::y for information about this property. +*/ + +qreal QmlAccelerometerReading::y() const +{ + return m_y; +} + +/*! + \qmlproperty qreal AccelerometerReading::z + This property holds the acceleration on the Z axis. + + Please see QAccelerometerReading::z for information about this property. +*/ + +qreal QmlAccelerometerReading::z() const +{ + return m_z; +} + +QSensorReading *QmlAccelerometerReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlAccelerometerReading::readingUpdate() +{ + qreal aX = m_sensor->reading()->x(); + if (m_x != aX) { + m_x = aX; + Q_EMIT xChanged(); + } + qreal aY = m_sensor->reading()->y(); + if (m_y != aY) { + m_y = aY; + Q_EMIT yChanged(); + } + qreal aZ = m_sensor->reading()->z(); + if (m_z != aZ) { + m_z = aZ; + Q_EMIT zChanged(); + } +} diff --git a/src/sensorsquick/qmlaccelerometer_p.h b/src/sensorsquick/qmlaccelerometer_p.h new file mode 100644 index 00000000..9dcb2692 --- /dev/null +++ b/src/sensorsquick/qmlaccelerometer_p.h @@ -0,0 +1,123 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLACCELEROMETER_P_H +#define QMLACCELEROMETER_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qmlsensor_p.h" + +QT_BEGIN_NAMESPACE + +class QAccelerometer; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlAccelerometer : public QmlSensor +{ + Q_OBJECT + Q_ENUMS(AccelerationMode) + Q_PROPERTY(AccelerationMode accelerationMode READ accelerationMode WRITE setAccelerationMode + NOTIFY accelerationModeChanged REVISION 1) + QML_NAMED_ELEMENT(Accelerometer) + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlAccelerometer(QObject *parent = 0); + ~QmlAccelerometer(); + + // Keep this enum in sync with QAccelerometer::AccelerationMode + enum AccelerationMode { + Combined, + Gravity, + User + }; + + AccelerationMode accelerationMode() const; + void setAccelerationMode(AccelerationMode accelerationMode); + +signals: + Q_REVISION(1) void accelerationModeChanged(AccelerationMode accelerationMode); + +private: + QSensor *sensor() const override; + QAccelerometer *m_sensor; + QmlSensorReading *createReading() const override; +}; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlAccelerometerReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal x READ x NOTIFY xChanged) + Q_PROPERTY(qreal y READ y NOTIFY yChanged) + Q_PROPERTY(qreal z READ z NOTIFY zChanged) + QML_NAMED_ELEMENT(AccelerometerReading) + QML_UNCREATABLE("Cannot create AccelerometerReading") + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlAccelerometerReading(QAccelerometer *sensor); + ~QmlAccelerometerReading(); + + qreal x() const; + qreal y() const; + qreal z() const; + +Q_SIGNALS: + void xChanged(); + void yChanged(); + void zChanged(); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + QAccelerometer *m_sensor; + qreal m_x; + qreal m_y; + qreal m_z; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qmlaltimeter.cpp b/src/sensorsquick/qmlaltimeter.cpp new file mode 100644 index 00000000..8ee3ccde --- /dev/null +++ b/src/sensorsquick/qmlaltimeter.cpp @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Research In Motion +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qmlaltimeter_p.h" +#include <QtSensors/QAltimeter> + +/*! + \qmltype Altimeter + \instantiates QmlAltimeter + \ingroup qml-sensors_type + \inqmlmodule QtSensors + \since QtSensors 5.1 + \inherits Sensor + \brief The Altimeter element reports on altitude. + + The Altimeter element reports on altitude. + + This element wraps the QAltimeter class. Please see the documentation for + QAltimeter for details. + + \sa AltimeterReading +*/ + +QmlAltimeter::QmlAltimeter(QObject *parent) + : QmlSensor(parent) + , m_sensor(new QAltimeter(this)) +{ +} + +QmlAltimeter::~QmlAltimeter() +{ +} + +QmlSensorReading *QmlAltimeter::createReading() const +{ + return new QmlAltimeterReading(m_sensor); +} + +QSensor *QmlAltimeter::sensor() const +{ + return m_sensor; +} + +/*! + \qmltype AltimeterReading + \instantiates QmlAltimeterReading + \ingroup qml-sensors_reading + \inqmlmodule QtSensors + \since QtSensors 5.1 + \inherits SensorReading + \brief The AltimeterReading element holds the most recent Altimeter reading. + + The AltimeterReading element holds the most recent Altimeter reading. + + This element wraps the QAltimeterReading class. Please see the documentation for + QAltimeterReading for details. + + This element cannot be directly created. +*/ + +QmlAltimeterReading::QmlAltimeterReading(QAltimeter *sensor) + : QmlSensorReading(sensor) + , m_sensor(sensor) + , m_altitude(0) +{ +} + +QmlAltimeterReading::~QmlAltimeterReading() +{ +} + +/*! + \qmlproperty qreal AltimeterReading::altitude + This property holds the altitude of the device. + + Please see QAltimeterReading::altitude for information about this property. +*/ + +qreal QmlAltimeterReading::altitude() const +{ + return m_altitude; +} + +QSensorReading *QmlAltimeterReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlAltimeterReading::readingUpdate() +{ + qreal altitude = m_sensor->reading()->altitude(); + if (m_altitude != altitude) { + m_altitude = altitude; + Q_EMIT altitudeChanged(); + } +} diff --git a/src/sensorsquick/qmlaltimeter_p.h b/src/sensorsquick/qmlaltimeter_p.h new file mode 100644 index 00000000..322fbdfb --- /dev/null +++ b/src/sensorsquick/qmlaltimeter_p.h @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Research In Motion +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QMLALTIMETER_P_H +#define QMLALTIMETER_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qmlsensor_p.h" + +QT_BEGIN_NAMESPACE + +class QAltimeter; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlAltimeter : public QmlSensor +{ + Q_OBJECT + QML_NAMED_ELEMENT(Altimeter) + QML_ADDED_IN_VERSION(5,1) +public: + explicit QmlAltimeter(QObject *parent = 0); + ~QmlAltimeter(); + +private: + QSensor *sensor() const override; + QmlSensorReading *createReading() const override; + + QAltimeter *m_sensor; +}; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlAltimeterReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal altitude READ altitude NOTIFY altitudeChanged) + QML_NAMED_ELEMENT(AltimeterReading) + QML_UNCREATABLE("Cannot create AltimeterReading") + QML_ADDED_IN_VERSION(5,1) +public: + explicit QmlAltimeterReading(QAltimeter *sensor); + ~QmlAltimeterReading(); + + qreal altitude() const; + +Q_SIGNALS: + void altitudeChanged(); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + + QAltimeter *m_sensor; + qreal m_altitude; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qmlambientlightsensor.cpp b/src/sensorsquick/qmlambientlightsensor.cpp new file mode 100644 index 00000000..a114f8b3 --- /dev/null +++ b/src/sensorsquick/qmlambientlightsensor.cpp @@ -0,0 +1,141 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmlambientlightsensor_p.h" +#include <QtSensors/QAmbientLightSensor> + +/*! + \qmltype AmbientLightSensor + \instantiates QmlAmbientLightSensor + \ingroup qml-sensors_type + \inqmlmodule QtSensors + \since QtSensors 5.0 + \inherits Sensor + \brief The AmbientLightSensor element repors on ambient lighting conditions. + + The AmbientLightSensor element repors on ambient lighting conditions. + + This element wraps the QAmbientLightSensor class. Please see the documentation for + QAmbientLightSensor for details. + + \sa AmbientLightReading +*/ + +QmlAmbientLightSensor::QmlAmbientLightSensor(QObject *parent) + : QmlSensor(parent) + , m_sensor(new QAmbientLightSensor(this)) +{ +} + +QmlAmbientLightSensor::~QmlAmbientLightSensor() +{ +} + +QmlSensorReading *QmlAmbientLightSensor::createReading() const +{ + return new QmlAmbientLightSensorReading(m_sensor); +} + +QSensor *QmlAmbientLightSensor::sensor() const +{ + return m_sensor; +} + +/*! + \qmltype AmbientLightReading + \instantiates QmlAmbientLightSensorReading + \ingroup qml-sensors_reading + \inqmlmodule QtSensors + \since QtSensors 5.0 + \inherits SensorReading + \brief The AmbientLightReading element holds the most AmbientLightSensor reading. + + The AmbientLightReading element holds the most AmbientLightSensor reading. + + This element wraps the QAmbientLightReading class. Please see the documentation for + QAmbientLightReading for details. + + This element cannot be directly created. +*/ + +QmlAmbientLightSensorReading::QmlAmbientLightSensorReading(QAmbientLightSensor *sensor) + : QmlSensorReading(sensor) + , m_sensor(sensor) +{ +} + +QmlAmbientLightSensorReading::~QmlAmbientLightSensorReading() +{ +} + +/*! + \qmlproperty LightLevel AmbientLightReading::lightLevel + This property holds the ambient light level. + + Please see QAmbientLightReading::lightLevel for information about this property. + + Note that LightLevel constants are exposed through the AmbientLightReading class. + \code + AmbientLightSensor { + onReadingChanged: { + if (reading.lightLevel == AmbientLightReading.Dark) + // do something + } + } + \endcode +*/ + +QAmbientLightReading::LightLevel QmlAmbientLightSensorReading::lightLevel() const +{ + return m_lightLevel; +} + +QSensorReading *QmlAmbientLightSensorReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlAmbientLightSensorReading::readingUpdate() +{ + QAmbientLightReading::LightLevel ll = m_sensor->reading()->lightLevel(); + if (m_lightLevel != ll) { + m_lightLevel = ll; + Q_EMIT lightLevelChanged(); + } +} diff --git a/src/sensorsquick/qmlambientlightsensor_p.h b/src/sensorsquick/qmlambientlightsensor_p.h new file mode 100644 index 00000000..356a1128 --- /dev/null +++ b/src/sensorsquick/qmlambientlightsensor_p.h @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLAMBIENTLIGHTSENSOR_P_H +#define QMLAMBIENTLIGHTSENSOR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qmlsensor_p.h" +#include <QtSensors/QAmbientLightSensor> + +QT_BEGIN_NAMESPACE + +class QAmbientLightSensor; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlAmbientLightSensor : public QmlSensor +{ + Q_OBJECT + QML_NAMED_ELEMENT(AmbientLightSensor) + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlAmbientLightSensor(QObject *parent = 0); + ~QmlAmbientLightSensor(); + +private: + QSensor *sensor() const override; + QAmbientLightSensor *m_sensor; + QmlSensorReading *createReading() const override; + +}; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlAmbientLightSensorReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(QAmbientLightReading::LightLevel lightLevel READ lightLevel NOTIFY lightLevelChanged) + QML_NAMED_ELEMENT(AmbientLightReading) + QML_UNCREATABLE("Cannot create AmbientLightReading") + QML_ADDED_IN_VERSION(5,0) +public: + + explicit QmlAmbientLightSensorReading(QAmbientLightSensor *sensor); + ~QmlAmbientLightSensorReading(); + + QAmbientLightReading::LightLevel lightLevel() const; + +Q_SIGNALS: + void lightLevelChanged(); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + QAmbientLightSensor *m_sensor; + QAmbientLightReading::LightLevel m_lightLevel; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qmlambienttemperaturesensor.cpp b/src/sensorsquick/qmlambienttemperaturesensor.cpp new file mode 100644 index 00000000..3f1a4679 --- /dev/null +++ b/src/sensorsquick/qmlambienttemperaturesensor.cpp @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Research In Motion +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qmlambienttemperaturesensor_p.h" +#include <QtSensors/QAmbientTemperatureSensor> + +/*! + \qmltype AmbientTemperatureSensor + \instantiates QmlAmbientTemperatureSensor + \ingroup qml-sensors_type + \inqmlmodule QtSensors + \since QtSensors 5.1 + \inherits Sensor + \brief The AmbientTemperatureSensor element reports on the ambient temperature. + + The AmbientTemperatureSensor element reports on the ambient temperature. + + This element wraps the QAmbientTemperatureSensor class. Please see the documentation for + QAmbientTemperatureSensor for details. + + \sa AmbientTemperatureReading +*/ + +QmlAmbientTemperatureSensor::QmlAmbientTemperatureSensor(QObject *parent) + : QmlSensor(parent) + , m_sensor(new QAmbientTemperatureSensor(this)) +{ +} + +QmlAmbientTemperatureSensor::~QmlAmbientTemperatureSensor() +{ +} + +QmlSensorReading *QmlAmbientTemperatureSensor::createReading() const +{ + return new QmlAmbientTemperatureReading(m_sensor); +} + +QSensor *QmlAmbientTemperatureSensor::sensor() const +{ + return m_sensor; +} + +/*! + \qmltype AmbientTemperatureReading + \instantiates QmlAmbientTemperatureReading + \ingroup qml-sensors_reading + \inqmlmodule QtSensors + \since QtSensors 5.1 + \inherits SensorReading + \brief The AmbientTemperatureReading element holds the most recent temperature reading. + + The AmbientTemperatureReading element holds the most recent temperature reading. + + This element wraps the QAmbientTemperatureReading class. Please see the documentation for + QAmbientTemperatureReading for details. + + This element cannot be directly created. +*/ + +QmlAmbientTemperatureReading::QmlAmbientTemperatureReading(QAmbientTemperatureSensor *sensor) + : QmlSensorReading(sensor) + , m_sensor(sensor) + , m_temperature(0) +{ +} + +QmlAmbientTemperatureReading::~QmlAmbientTemperatureReading() +{ +} + +/*! + \qmlproperty qreal AmbientTemperatureReading::temperature + This property holds the ambient temperature in degree Celsius. + + Please see QAmbientTemperatureReading::temperature for information about this property. +*/ + +qreal QmlAmbientTemperatureReading::temperature() const +{ + return m_temperature; +} + +QSensorReading *QmlAmbientTemperatureReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlAmbientTemperatureReading::readingUpdate() +{ + const qreal temperature = m_sensor->reading()->temperature(); + if (m_temperature != temperature) { + m_temperature = temperature; + Q_EMIT temperatureChanged(); + } +} diff --git a/src/sensorsquick/qmlambienttemperaturesensor_p.h b/src/sensorsquick/qmlambienttemperaturesensor_p.h new file mode 100644 index 00000000..45183ee7 --- /dev/null +++ b/src/sensorsquick/qmlambienttemperaturesensor_p.h @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Research In Motion +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QMLAMBIENTTEMPERATURESENSOR_P_H +#define QMLAMBIENTTEMPERATURESENSOR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qmlsensor_p.h" + +QT_BEGIN_NAMESPACE + +class QAmbientTemperatureSensor; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlAmbientTemperatureSensor : public QmlSensor +{ + Q_OBJECT + QML_NAMED_ELEMENT(AmbientTemperatureSensor) + QML_ADDED_IN_VERSION(5,1) +public: + explicit QmlAmbientTemperatureSensor(QObject *parent = 0); + ~QmlAmbientTemperatureSensor(); + +private: + QSensor *sensor() const override; + QmlSensorReading *createReading() const override; + + QAmbientTemperatureSensor *m_sensor; +}; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlAmbientTemperatureReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal temperature READ temperature NOTIFY temperatureChanged) + QML_NAMED_ELEMENT(AmbientTemperatureReading) + QML_UNCREATABLE("Cannot create AmbientTemperatureReading") + QML_ADDED_IN_VERSION(5,1) +public: + explicit QmlAmbientTemperatureReading(QAmbientTemperatureSensor *sensor); + ~QmlAmbientTemperatureReading(); + + qreal temperature() const; + +Q_SIGNALS: + void temperatureChanged(); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + + QAmbientTemperatureSensor *m_sensor; + qreal m_temperature; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qmlcompass.cpp b/src/sensorsquick/qmlcompass.cpp new file mode 100644 index 00000000..b3620d6c --- /dev/null +++ b/src/sensorsquick/qmlcompass.cpp @@ -0,0 +1,148 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmlcompass_p.h" +#include <QtSensors/QCompass> + +/*! + \qmltype Compass + \instantiates QmlCompass + \ingroup qml-sensors_type + \inqmlmodule QtSensors + \since QtSensors 5.0 + \inherits Sensor + \brief The Compass element reports on heading using magnetic north as a reference. + + The Compass element reports on heading using magnetic north as a reference. + + This element wraps the QCompass class. Please see the documentation for + QCompass for details. + + \sa CompassReading +*/ + +QmlCompass::QmlCompass(QObject *parent) + : QmlSensor(parent) + , m_sensor(new QCompass(this)) +{ +} + +QmlCompass::~QmlCompass() +{ +} + +QmlSensorReading *QmlCompass::createReading() const +{ + return new QmlCompassReading(m_sensor); +} + +QSensor *QmlCompass::sensor() const +{ + return m_sensor; +} + +/*! + \qmltype CompassReading + \instantiates QmlCompassReading + \ingroup qml-sensors_reading + \inqmlmodule QtSensors + \since QtSensors 5.0 + \inherits SensorReading + \brief The CompassReading element holds the most recent Compass reading. + + The CompassReading element holds the most recent Compass reading. + + This element wraps the QCompassReading class. Please see the documentation for + QCompassReading for details. + + This element cannot be directly created. +*/ + +QmlCompassReading::QmlCompassReading(QCompass *sensor) + : QmlSensorReading(sensor) + , m_sensor(sensor) +{ +} + +QmlCompassReading::~QmlCompassReading() +{ +} + +/*! + \qmlproperty qreal CompassReading::azimuth + This property holds the azimuth of the device. + + Please see QCompassReading::azimuth for information about this property. +*/ + +qreal QmlCompassReading::azimuth() const +{ + return m_azimuth; +} + +/*! + \qmlproperty qreal CompassReading::calibrationLevel + This property holds the calibration level of the reading. + + Please see QCompassReading::calibrationLevel for information about this property. +*/ + +qreal QmlCompassReading::calibrationLevel() const +{ + return m_calibrationLevel; +} + +QSensorReading *QmlCompassReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlCompassReading::readingUpdate() +{ + qreal azm = m_sensor->reading()->azimuth(); + if (m_azimuth != azm) { + m_azimuth = azm; + Q_EMIT azimuthChanged(); + } + qreal calLevel = m_sensor->reading()->calibrationLevel(); + if (m_calibrationLevel != calLevel) { + m_calibrationLevel = calLevel; + Q_EMIT calibrationLevelChanged(); + } +} diff --git a/src/sensorsquick/qmlcompass_p.h b/src/sensorsquick/qmlcompass_p.h new file mode 100644 index 00000000..42c1b15c --- /dev/null +++ b/src/sensorsquick/qmlcompass_p.h @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLCOMPASS_P_H +#define QMLCOMPASS_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qmlsensor_p.h" + +QT_BEGIN_NAMESPACE + +class QCompass; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlCompass : public QmlSensor +{ + Q_OBJECT + QML_NAMED_ELEMENT(Compass) + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlCompass(QObject *parent = 0); + ~QmlCompass(); + + +private: + QSensor *sensor() const override; + QCompass *m_sensor; + QmlSensorReading *createReading() const override; +}; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlCompassReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal azimuth READ azimuth NOTIFY azimuthChanged) + Q_PROPERTY(qreal calibrationLevel READ calibrationLevel NOTIFY calibrationLevelChanged) + QML_NAMED_ELEMENT(CompassReading) + QML_UNCREATABLE("Cannot create CompassReading") + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlCompassReading(QCompass *sensor); + ~QmlCompassReading(); + + qreal azimuth() const; + qreal calibrationLevel() const; + +Q_SIGNALS: + void azimuthChanged(); + void calibrationLevelChanged(); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + QCompass *m_sensor; + qreal m_azimuth; + qreal m_calibrationLevel; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qmldistancesensor.cpp b/src/sensorsquick/qmldistancesensor.cpp new file mode 100644 index 00000000..b1d9f6bb --- /dev/null +++ b/src/sensorsquick/qmldistancesensor.cpp @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** Copyright (C) 2016 BlackBerry Limited. All rights reserved. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qmldistancesensor_p.h" +#include <QDistanceSensor> + +/*! + \qmltype DistanceSensor + \instantiates QmlDistanceSensor + \ingroup qml-sensors_type + \inqmlmodule QtSensors + \since QtSensors 5.4 + \inherits Sensor + \brief The DistanceSensor element reports the distance in cm from an object to the device. + + The DistanceSensor element reports the distance in cm from an object to the device. + + This element wraps the QDistanceSensor class. Please see the documentation for + QDistanceSensor for details. + + \sa DistanceReading +*/ + +QmlDistanceSensor::QmlDistanceSensor(QObject *parent) + : QmlSensor(parent) + , m_sensor(new QDistanceSensor(this)) +{ +} + +QmlDistanceSensor::~QmlDistanceSensor() +{ +} + +QmlSensorReading *QmlDistanceSensor::createReading() const +{ + return new QmlDistanceReading(m_sensor); +} + +QSensor *QmlDistanceSensor::sensor() const +{ + return m_sensor; +} + +/*! + \qmltype DistanceReading + \instantiates QmlDistanceReading + \ingroup qml-sensors_reading + \inqmlmodule QtSensors + \since QtSensors 5.4 + \inherits SensorReading + \brief The DistanceReading element holds the most recent DistanceSensor reading. + + The DistanceReading element holds the most recent DistanceSensor reading. + + This element wraps the QDistanceReading class. Please see the documentation for + QDistanceReading for details. + + This element cannot be directly created. +*/ + +QmlDistanceReading::QmlDistanceReading(QDistanceSensor *sensor) + : QmlSensorReading(sensor) + , m_sensor(sensor) + , m_distance(0.0) +{ +} + +QmlDistanceReading::~QmlDistanceReading() +{ +} + +/*! + \qmlproperty qreal DistanceReading::distance + This property holds the distance measurement + + Please see QDistanceReading::distance for information about this property. +*/ + +qreal QmlDistanceReading::distance() const +{ + return m_distance; +} + +QSensorReading *QmlDistanceReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlDistanceReading::readingUpdate() +{ + qreal distance = m_sensor->reading()->distance(); + if (m_distance != distance) { + m_distance = distance; + Q_EMIT distanceChanged(); + } +} diff --git a/src/sensorsquick/qmldistancesensor_p.h b/src/sensorsquick/qmldistancesensor_p.h new file mode 100644 index 00000000..1f9d9425 --- /dev/null +++ b/src/sensorsquick/qmldistancesensor_p.h @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2016 BlackBerry Limited. All rights reserved. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLDISTANCESENSOR_P_H +#define QMLDISTANCESENSOR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qmlsensor_p.h" + +QT_BEGIN_NAMESPACE + +class QDistanceSensor; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlDistanceSensor : public QmlSensor +{ + Q_OBJECT + QML_NAMED_ELEMENT(DistanceSensor) + QML_ADDED_IN_VERSION(5,4) +public: + explicit QmlDistanceSensor(QObject *parent = 0); + ~QmlDistanceSensor(); + +private: + QSensor *sensor() const override; + QmlSensorReading *createReading() const override; + + QDistanceSensor *m_sensor; +}; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlDistanceReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal distance READ distance NOTIFY distanceChanged) + QML_NAMED_ELEMENT(DistanceReading) + QML_UNCREATABLE("Cannot create DistanceReading") + QML_ADDED_IN_VERSION(5,4) +public: + explicit QmlDistanceReading(QDistanceSensor *sensor); + ~QmlDistanceReading(); + + qreal distance() const; + +Q_SIGNALS: + void distanceChanged(); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + + QDistanceSensor *m_sensor; + qreal m_distance; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qmlgyroscope.cpp b/src/sensorsquick/qmlgyroscope.cpp new file mode 100644 index 00000000..9983564a --- /dev/null +++ b/src/sensorsquick/qmlgyroscope.cpp @@ -0,0 +1,164 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmlgyroscope_p.h" +#include <QtSensors/QGyroscope> + +/*! + \qmltype Gyroscope + \instantiates QmlGyroscope + \ingroup qml-sensors_type + \inqmlmodule QtSensors + \since QtSensors 5.0 + \inherits Sensor + \brief The Gyroscope element reports on rotational acceleration + around the X, Y and Z axes. + + This element wraps the QGyroscope class. Please see the documentation for + QGyroscope for details. + + \sa GyroscopeReading +*/ + +QmlGyroscope::QmlGyroscope(QObject *parent) + : QmlSensor(parent) + , m_sensor(new QGyroscope(this)) +{ +} + +QmlGyroscope::~QmlGyroscope() +{ +} + +QmlSensorReading *QmlGyroscope::createReading() const +{ + return new QmlGyroscopeReading(m_sensor); +} + +QSensor *QmlGyroscope::sensor() const +{ + return m_sensor; +} + +/*! + \qmltype GyroscopeReading + \instantiates QmlGyroscopeReading + \ingroup qml-sensors_reading + \inqmlmodule QtSensors + \since QtSensors 5.0 + \inherits SensorReading + \brief The GyroscopeReading element holds the most recent Gyroscope reading. + + The GyroscopeReading element holds the most recent Gyroscope reading. + + This element wraps the QGyroscopeReading class. Please see the documentation for + QGyroscopeReading for details. + + This element cannot be directly created. +*/ + +QmlGyroscopeReading::QmlGyroscopeReading(QGyroscope *sensor) + : QmlSensorReading(sensor) + , m_sensor(sensor) +{ +} + +QmlGyroscopeReading::~QmlGyroscopeReading() +{ +} + +/*! + \qmlproperty qreal GyroscopeReading::x + This property holds the angular velocity around the x axis. + + Please see QGyroscopeReading::x for information about this property. +*/ + +qreal QmlGyroscopeReading::x() const +{ + return m_x; +} + +/*! + \qmlproperty qreal GyroscopeReading::y + This property holds the angular velocity around the y axis. + + Please see QGyroscopeReading::y for information about this property. +*/ + +qreal QmlGyroscopeReading::y() const +{ + return m_y; +} + +/*! + \qmlproperty qreal GyroscopeReading::z + This property holds the angular velocity around the z axis. + + Please see QGyroscopeReading::z for information about this property. +*/ + +qreal QmlGyroscopeReading::z() const +{ + return m_z; +} + +QSensorReading *QmlGyroscopeReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlGyroscopeReading::readingUpdate() +{ + qreal gx = m_sensor->reading()->x(); + if (m_x != gx) { + m_x = gx; + Q_EMIT xChanged(); + } + qreal gy = m_sensor->reading()->y(); + if (m_y != gy) { + m_y = gy; + Q_EMIT yChanged(); + } + qreal gz = m_sensor->reading()->z(); + if (m_z != gz) { + m_z = gz; + Q_EMIT zChanged(); + } +} diff --git a/src/sensorsquick/qmlgyroscope_p.h b/src/sensorsquick/qmlgyroscope_p.h new file mode 100644 index 00000000..549a67e4 --- /dev/null +++ b/src/sensorsquick/qmlgyroscope_p.h @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLGYROSCOPE_P_H +#define QMLGYROSCOPE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qmlsensor_p.h" + +QT_BEGIN_NAMESPACE + +class QGyroscope; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlGyroscope : public QmlSensor +{ + Q_OBJECT + QML_NAMED_ELEMENT(Gyroscope) + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlGyroscope(QObject *parent = 0); + ~QmlGyroscope(); + + +private: + QSensor *sensor() const override; + QGyroscope *m_sensor; + QmlSensorReading *createReading() const override; +}; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlGyroscopeReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal x READ x NOTIFY xChanged) + Q_PROPERTY(qreal y READ y NOTIFY yChanged) + Q_PROPERTY(qreal z READ z NOTIFY zChanged) + QML_NAMED_ELEMENT(GyroscopeReading) + QML_UNCREATABLE("Cannot create GyroscopeReading") + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlGyroscopeReading(QGyroscope *sensor); + ~QmlGyroscopeReading(); + + qreal x() const; + qreal y() const; + qreal z() const; + +Q_SIGNALS: + void xChanged(); + void yChanged(); + void zChanged(); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + QGyroscope *m_sensor; + qreal m_x; + qreal m_y; + qreal m_z; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qmlholstersensor.cpp b/src/sensorsquick/qmlholstersensor.cpp new file mode 100644 index 00000000..cdefd683 --- /dev/null +++ b/src/sensorsquick/qmlholstersensor.cpp @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Research In Motion +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qmlholstersensor_p.h" +#include <QtSensors/QHolsterSensor> + +/*! + \qmltype HolsterSensor + \instantiates QmlHolsterSensor + \ingroup qml-sensors_type + \inqmlmodule QtSensors + \since QtSensors 5.1 + \inherits Sensor + \brief The HolsterSensor element reports on whether a device is holstered. + + The HolsterSensor element reports on whether a device is holstered. + + This element wraps the QHolsterSensor class. Please see the documentation for + QHolsterSensor for details. + + \sa HolsterReading +*/ + +QmlHolsterSensor::QmlHolsterSensor(QObject *parent) + : QmlSensor(parent) + , m_sensor(new QHolsterSensor(this)) +{ +} + +QmlHolsterSensor::~QmlHolsterSensor() +{ +} + +QmlSensorReading *QmlHolsterSensor::createReading() const +{ + return new QmlHolsterReading(m_sensor); +} + +QSensor *QmlHolsterSensor::sensor() const +{ + return m_sensor; +} + +/*! + \qmltype HolsterReading + \instantiates QmlHolsterReading + \ingroup qml-sensors_reading + \inqmlmodule QtSensors + \since QtSensors 5.1 + \inherits SensorReading + \brief The HolsterReading element holds the most recent HolsterSensor reading. + + The HolsterReading element holds the most recent HolsterSensor reading. + + This element wraps the QHolsterReading class. Please see the documentation for + QHolsterReading for details. + + This element cannot be directly created. +*/ + +QmlHolsterReading::QmlHolsterReading(QHolsterSensor *sensor) + : QmlSensorReading(sensor) + , m_sensor(sensor) + , m_holstered(false) +{ +} + +QmlHolsterReading::~QmlHolsterReading() +{ +} + +/*! + \qmlproperty qreal HolsterReading::holstered + This property holds whether the device is holstered. + + Please see QHolsterReading::holstered for information about this property. +*/ + +bool QmlHolsterReading::holstered() const +{ + return m_holstered; +} + +QSensorReading *QmlHolsterReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlHolsterReading::readingUpdate() +{ + const bool holstered = m_sensor->reading()->holstered(); + if (m_holstered != holstered) { + m_holstered = holstered; + Q_EMIT holsteredChanged(); + } +} diff --git a/src/sensorsquick/qmlholstersensor_p.h b/src/sensorsquick/qmlholstersensor_p.h new file mode 100644 index 00000000..a64e2d12 --- /dev/null +++ b/src/sensorsquick/qmlholstersensor_p.h @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Research In Motion +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QMLHOLSTERSENSOR_P_H +#define QMLHOLSTERSENSOR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qmlsensor_p.h" + +QT_BEGIN_NAMESPACE + +class QHolsterSensor; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlHolsterSensor : public QmlSensor +{ + Q_OBJECT + QML_NAMED_ELEMENT(HolsterSensor) + QML_ADDED_IN_VERSION(5,1) +public: + explicit QmlHolsterSensor(QObject *parent = 0); + ~QmlHolsterSensor(); + +private: + QSensor *sensor() const override; + QmlSensorReading *createReading() const override; + + QHolsterSensor *m_sensor; +}; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlHolsterReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(bool holstered READ holstered NOTIFY holsteredChanged) + QML_NAMED_ELEMENT(HolsterReading) + QML_UNCREATABLE("Cannot create HolsterReading") + QML_ADDED_IN_VERSION(5,1) +public: + explicit QmlHolsterReading(QHolsterSensor *sensor); + ~QmlHolsterReading(); + + bool holstered() const; + +Q_SIGNALS: + void holsteredChanged(); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + + QHolsterSensor *m_sensor; + bool m_holstered; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qmlhumiditysensor.cpp b/src/sensorsquick/qmlhumiditysensor.cpp new file mode 100644 index 00000000..37bf7a18 --- /dev/null +++ b/src/sensorsquick/qmlhumiditysensor.cpp @@ -0,0 +1,150 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Canonical Ltd +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#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) + : QmlSensorReading(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; +} + +/*! + \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; +} + +QSensorReading *QmlHumidityReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlHumidityReading::readingUpdate() +{ + qreal humidity = m_sensor->reading()->relativeHumidity(); + if (m_relativeHumidity != humidity) { + m_relativeHumidity = humidity; + Q_EMIT relativeHumidityChanged(); + } + qreal abs = m_sensor->reading()->absoluteHumidity(); + if (m_absoluteHumidity != abs) { + m_absoluteHumidity = abs; + Q_EMIT absoluteHumidityChanged(); + } +} diff --git a/src/sensorsquick/qmlhumiditysensor_p.h b/src/sensorsquick/qmlhumiditysensor_p.h new file mode 100644 index 00000000..7a940b7c --- /dev/null +++ b/src/sensorsquick/qmlhumiditysensor_p.h @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Canonical Ltd +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLHUMIDITYSENSOR_P_H +#define QMLHUMIDITYSENSOR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qmlsensor_p.h" + +QT_BEGIN_NAMESPACE + +class QHumiditySensor; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlHumiditySensor : public QmlSensor +{ + Q_OBJECT + + QML_NAMED_ELEMENT(HumiditySensor) + QML_ADDED_IN_VERSION(5,9) +public: + explicit QmlHumiditySensor(QObject *parent = Q_NULLPTR); + ~QmlHumiditySensor(); + +private: + QSensor *sensor() const override; + QmlSensorReading *createReading() const override; + + QHumiditySensor *m_sensor; +}; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlHumidityReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal relativeHumidity READ relativeHumidity NOTIFY relativeHumidityChanged) + Q_PROPERTY(qreal absoluteHumidity READ absoluteHumidity NOTIFY absoluteHumidityChanged) + QML_NAMED_ELEMENT(HumidityReading) + QML_UNCREATABLE("Cannot create HumidityReading") + QML_ADDED_IN_VERSION(5,9) +public: + explicit QmlHumidityReading(QHumiditySensor *sensor); + ~QmlHumidityReading(); + + qreal relativeHumidity() const; + qreal absoluteHumidity() const; + +Q_SIGNALS: + void relativeHumidityChanged(); + void absoluteHumidityChanged(); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + + QHumiditySensor *m_sensor; + qreal m_relativeHumidity; + qreal m_absoluteHumidity; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qmlirproximitysensor.cpp b/src/sensorsquick/qmlirproximitysensor.cpp new file mode 100644 index 00000000..42e9cfe9 --- /dev/null +++ b/src/sensorsquick/qmlirproximitysensor.cpp @@ -0,0 +1,129 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmlirproximitysensor_p.h" +#include <QtSensors/QIRProximitySensor> + +/*! + \qmltype IRProximitySensor + \instantiates QmlIRProximitySensor + \ingroup qml-sensors_type + \inqmlmodule QtSensors + \since QtSensors 5.0 + \inherits Sensor + \brief The IRProximitySensor element reports on infra-red reflectance values. + + This element wraps the QIRProximitySensor class. Please see the documentation for + QIRProximitySensor for details. + + \sa IRProximityReading +*/ + +QmlIRProximitySensor::QmlIRProximitySensor(QObject *parent) + : QmlSensor(parent) + , m_sensor(new QIRProximitySensor(this)) +{ +} + +QmlIRProximitySensor::~QmlIRProximitySensor() +{ +} + +QmlSensorReading *QmlIRProximitySensor::createReading() const +{ + return new QmlIRProximitySensorReading(m_sensor); +} + +QSensor *QmlIRProximitySensor::sensor() const +{ + return m_sensor; +} + +/*! + \qmltype IRProximityReading + \instantiates QmlIRProximitySensorReading + \ingroup qml-sensors_reading + \inqmlmodule QtSensors + \since QtSensors 5.0 + \inherits SensorReading + \brief The IRProximityReading element holds the most recent IR proximity reading. + + The IRProximityReading element holds the most recent IR proximity reading. + + This element wraps the QIRProximityReading class. Please see the documentation for + QIRProximityReading for details. + + This element cannot be directly created. +*/ + +QmlIRProximitySensorReading::QmlIRProximitySensorReading(QIRProximitySensor *sensor) + : QmlSensorReading(sensor) + , m_sensor(sensor) +{ +} + +QmlIRProximitySensorReading::~QmlIRProximitySensorReading() +{ +} + +/*! + \qmlproperty qreal IRProximityReading::reflectance + This property holds the reflectance value. + + Please see QIRProximityReading::reflectance for information about this property. +*/ + +qreal QmlIRProximitySensorReading::reflectance() const +{ + return m_reflectance; +} + +QSensorReading *QmlIRProximitySensorReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlIRProximitySensorReading::readingUpdate() +{ + qreal fl = m_sensor->reading()->reflectance(); + if (m_reflectance != fl) { + m_reflectance = fl; + Q_EMIT reflectanceChanged(); + } +} diff --git a/src/sensorsquick/qmlirproximitysensor_p.h b/src/sensorsquick/qmlirproximitysensor_p.h new file mode 100644 index 00000000..6039794d --- /dev/null +++ b/src/sensorsquick/qmlirproximitysensor_p.h @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLIRPROXIMITYSENSOR_P_H +#define QMLIRPROXIMITYSENSOR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qmlsensor_p.h" + +QT_BEGIN_NAMESPACE + +class QIRProximitySensor; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlIRProximitySensor : public QmlSensor +{ + Q_OBJECT + QML_NAMED_ELEMENT(IRProximitySensor) + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlIRProximitySensor(QObject *parent = 0); + ~QmlIRProximitySensor(); + +private: + QSensor *sensor() const override; + QIRProximitySensor *m_sensor; + QmlSensorReading *createReading() const override; +}; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlIRProximitySensorReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal reflectance READ reflectance NOTIFY reflectanceChanged) + QML_NAMED_ELEMENT(IRProximityReading) + QML_UNCREATABLE("Cannot create IRProximityReading") + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlIRProximitySensorReading(QIRProximitySensor *sensor); + ~QmlIRProximitySensorReading(); + + qreal reflectance() const; + +Q_SIGNALS: + void reflectanceChanged(); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + QIRProximitySensor *m_sensor; + qreal m_reflectance; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qmllidsensor.cpp b/src/sensorsquick/qmllidsensor.cpp new file mode 100644 index 00000000..3725f0ca --- /dev/null +++ b/src/sensorsquick/qmllidsensor.cpp @@ -0,0 +1,149 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Canonical, Ltd +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qmllidsensor_p.h" +#include <QtSensors/QLidSensor> + +/*! + \qmltype LidSensor + \instantiates QmlLidSensor + \ingroup qml-sensors_type + \inqmlmodule QtSensors + \since QtSensors 5.9 + \inherits Sensor + \brief The LidSensor element reports on whether a device is closed. + + The LidSensor element reports on whether a device is closed. + + This element wraps the QLidSensor class. Please see the documentation for + QLidSensor for details. + + \sa LidReading +*/ + +QmlLidSensor::QmlLidSensor(QObject *parent) + : QmlSensor(parent) + , m_sensor(new QLidSensor(this)) +{ +} + +QmlLidSensor::~QmlLidSensor() +{ +} + +QmlSensorReading *QmlLidSensor::createReading() const +{ + return new QmlLidReading(m_sensor); +} + +QSensor *QmlLidSensor::sensor() const +{ + return m_sensor; +} + +/*! + \qmltype LidReading + \instantiates QmlLidReading + \ingroup qml-sensors_reading + \inqmlmodule QtSensors + \since QtSensors 5.9 + \inherits SensorReading + \brief The LidReading element holds the most recent LidSensor reading. + + The LidReading element holds the most recent LidSensor reading. + + This element wraps the QLidReading class. Please see the documentation for + QLidReading for details. + + This element cannot be directly created. +*/ + +QmlLidReading::QmlLidReading(QLidSensor *sensor) + : QmlSensorReading(sensor) + , m_sensor(sensor) + , m_backClosed(false) + , m_frontClosed(true) +{ +} + +QmlLidReading::~QmlLidReading() +{ +} + +/*! + \qmlproperty qreal LidReading::backLidClosed + This property holds whether the back lid is closed. + + Please see QLidReading::backLidClosed for information about this property. +*/ + +bool QmlLidReading::backLidChanged() const +{ + return m_backClosed; +} + +/*! + \qmlproperty qreal LidReading::frontLidClosed + This property holds whether the front lid is closed. + + Please see QLidReading::frontLidClosed for information about this property. +*/ + +bool QmlLidReading::frontLidClosed() const +{ + return m_frontClosed; +} + +QSensorReading *QmlLidReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlLidReading::readingUpdate() +{ + const bool backClosed = m_sensor->reading()->backLidClosed(); + if (m_backClosed != backClosed) { + m_backClosed = backClosed; + Q_EMIT backLidChanged(m_backClosed); + } + const bool frontClosed = m_sensor->reading()->frontLidClosed(); + if (m_frontClosed != frontClosed) { + m_frontClosed = frontClosed; + Q_EMIT frontLidChanged(m_frontClosed); + } +} diff --git a/src/sensorsquick/qmllidsensor_p.h b/src/sensorsquick/qmllidsensor_p.h new file mode 100644 index 00000000..6a58ce53 --- /dev/null +++ b/src/sensorsquick/qmllidsensor_p.h @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Canonical, Ltd +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QMLLIDSENSOR_P_H +#define QMLLIDSENSOR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qmlsensor_p.h" + +QT_BEGIN_NAMESPACE + +class QLidSensor; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlLidSensor : public QmlSensor +{ + Q_OBJECT + QML_NAMED_ELEMENT(LidSensor) + QML_ADDED_IN_VERSION(5,9) +public: + explicit QmlLidSensor(QObject *parent = 0); + ~QmlLidSensor(); + +private: + QSensor *sensor() const override; + QmlSensorReading *createReading() const override; + + QLidSensor *m_sensor; +}; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlLidReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(bool backLidChanged READ backLidChanged NOTIFY backLidChanged) + Q_PROPERTY(bool frontLidClosed READ frontLidClosed NOTIFY frontLidChanged) + QML_NAMED_ELEMENT(LidReading) + QML_UNCREATABLE("Cannot create LidReading") + QML_ADDED_IN_VERSION(5,9) +public: + explicit QmlLidReading(QLidSensor *sensor); + ~QmlLidReading(); + + bool backLidChanged() const; + bool frontLidClosed() const; + +Q_SIGNALS: + void backLidChanged(bool closed); + bool frontLidChanged(bool closed); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + + QLidSensor *m_sensor; + bool m_backClosed; + bool m_frontClosed; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qmllightsensor.cpp b/src/sensorsquick/qmllightsensor.cpp new file mode 100644 index 00000000..f60390bf --- /dev/null +++ b/src/sensorsquick/qmllightsensor.cpp @@ -0,0 +1,145 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmllightsensor_p.h" +#include <QtSensors/QLightSensor> + +/*! + \qmltype LightSensor + \instantiates QmlLightSensor + \ingroup qml-sensors_type + \inqmlmodule QtSensors + \since QtSensors 5.0 + \inherits Sensor + \brief The LightSensor element reports on light levels using LUX. + + The LightSensor element reports on light levels using LUX. + + This element wraps the QLightSensor class. Please see the documentation for + QLightSensor for details. + + \sa LightReading +*/ + +QmlLightSensor::QmlLightSensor(QObject *parent) + : QmlSensor(parent) + , m_sensor(new QLightSensor(this)) +{ + connect(m_sensor, SIGNAL(fieldOfViewChanged(qreal)), + this, SIGNAL(fieldOfViewChanged(qreal))); +} + +QmlLightSensor::~QmlLightSensor() +{ +} + +QmlSensorReading *QmlLightSensor::createReading() const +{ + return new QmlLightSensorReading(m_sensor); +} + +QSensor *QmlLightSensor::sensor() const +{ + return m_sensor; +} + +/*! + \qmlproperty qreal LightSensor::fieldOfView + This property holds a value indicating the field of view. + + Please see QLightSensor::fieldOfView for information about this property. +*/ + +qreal QmlLightSensor::fieldOfView() const +{ + return m_sensor->fieldOfView(); +} + +/*! + \qmltype LightReading + \instantiates QmlLightSensorReading + \ingroup qml-sensors_reading + \inqmlmodule QtSensors + \since QtSensors 5.0 + \inherits SensorReading + \brief The LightReading element holds the most recent LightSensor reading. + + The LightReading element holds the most recent LightSensor reading. + + This element wraps the QLightReading class. Please see the documentation for + QLightReading for details. + + This element cannot be directly created. +*/ + +QmlLightSensorReading::QmlLightSensorReading(QLightSensor *sensor) + : QmlSensorReading(sensor) + , m_sensor(sensor) +{ +} + +QmlLightSensorReading::~QmlLightSensorReading() +{ +} + +/*! + \qmlproperty qreal LightReading::illuminance + This property holds the light level. + + Please see QLightReading::illuminance for information about this property. +*/ + +qreal QmlLightSensorReading::illuminance() const +{ + return m_illuminance; +} + +QSensorReading *QmlLightSensorReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlLightSensorReading::readingUpdate() +{ + qreal ill = m_sensor->reading()->lux(); + if (m_illuminance != ill) { + m_illuminance = ill; + Q_EMIT illuminanceChanged(); + } +} diff --git a/src/sensorsquick/qmllightsensor_p.h b/src/sensorsquick/qmllightsensor_p.h new file mode 100644 index 00000000..137be444 --- /dev/null +++ b/src/sensorsquick/qmllightsensor_p.h @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLLIGHTSENSOR_P_H +#define QMLLIGHTSENSOR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qmlsensor_p.h" + +QT_BEGIN_NAMESPACE + +class QLightSensor; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlLightSensor : public QmlSensor +{ + Q_OBJECT + Q_PROPERTY(qreal fieldOfView READ fieldOfView NOTIFY fieldOfViewChanged) + QML_NAMED_ELEMENT(LightSensor) + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlLightSensor(QObject *parent = 0); + ~QmlLightSensor(); + + qreal fieldOfView() const; + +Q_SIGNALS: + void fieldOfViewChanged(qreal fieldOfView); + +private: + QSensor *sensor() const override; + QLightSensor *m_sensor; + QmlSensorReading *createReading() const override; +}; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlLightSensorReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal illuminance READ illuminance NOTIFY illuminanceChanged) + QML_NAMED_ELEMENT(LightReading) + QML_UNCREATABLE("Cannot create LightReading") + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlLightSensorReading(QLightSensor *sensor); + ~QmlLightSensorReading(); + + qreal illuminance() const; + +Q_SIGNALS: + void illuminanceChanged(); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + QLightSensor *m_sensor; + qreal m_illuminance; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qmlmagnetometer.cpp b/src/sensorsquick/qmlmagnetometer.cpp new file mode 100644 index 00000000..e911d583 --- /dev/null +++ b/src/sensorsquick/qmlmagnetometer.cpp @@ -0,0 +1,203 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmlmagnetometer_p.h" +#include <QtSensors/QMagnetometer> + +/*! + \qmltype Magnetometer + \instantiates QmlMagnetometer + \ingroup qml-sensors_type + \inqmlmodule QtSensors + \since QtSensors 5.0 + \inherits Sensor + \brief The Magnetometer element reports on magnetic field strength + along the Z, Y and Z axes. + + The Magnetometer element reports on magnetic field strength + along the Z, Y and Z axes. + + This element wraps the QMagnetometer class. Please see the documentation for + QMagnetometer for details. + + \sa MagnetometerReading +*/ + +QmlMagnetometer::QmlMagnetometer(QObject *parent) + : QmlSensor(parent) + , m_sensor(new QMagnetometer(this)) +{ + connect(m_sensor, SIGNAL(returnGeoValuesChanged(bool)), + this, SIGNAL(returnGeoValuesChanged(bool))); +} + +QmlMagnetometer::~QmlMagnetometer() +{ +} + +QmlSensorReading *QmlMagnetometer::createReading() const +{ + return new QmlMagnetometerReading(m_sensor); +} + +QSensor *QmlMagnetometer::sensor() const +{ + return m_sensor; +} + +/*! + \qmlproperty bool Magnetometer::returnGeoValues + This property holds a value indicating if geomagnetic values should be returned. + + Please see QMagnetometer::returnGeoValues for information about this property. +*/ + +bool QmlMagnetometer::returnGeoValues() const +{ + return m_sensor->returnGeoValues(); +} + +void QmlMagnetometer::setReturnGeoValues(bool geo) +{ + m_sensor->setReturnGeoValues(geo); +} + +/*! + \qmltype MagnetometerReading + \instantiates QmlMagnetometerReading + \ingroup qml-sensors_reading + \inqmlmodule QtSensors + \since QtSensors 5.0 + \inherits SensorReading + \brief The MagnetometerReading element holds the most recent Magnetometer reading. + + The MagnetometerReading element holds the most recent Magnetometer reading. + + This element wraps the QMagnetometerReading class. Please see the documentation for + QMagnetometerReading for details. + + This element cannot be directly created. +*/ + +QmlMagnetometerReading::QmlMagnetometerReading(QMagnetometer *sensor) + : QmlSensorReading(sensor) + , m_sensor(sensor) +{ +} + +QmlMagnetometerReading::~QmlMagnetometerReading() +{ +} + +/*! + \qmlproperty qreal MagnetometerReading::x + This property holds the raw magnetic flux density on the X axis. + + Please see QMagnetometerReading::x for information about this property. +*/ + +qreal QmlMagnetometerReading::x() const +{ + return m_x; +} + +/*! + \qmlproperty qreal MagnetometerReading::y + This property holds the raw magnetic flux density on the Y axis. + + Please see QMagnetometerReading::y for information about this property. +*/ + +qreal QmlMagnetometerReading::y() const +{ + return m_y; +} + +/*! + \qmlproperty qreal MagnetometerReading::z + This property holds the raw magnetic flux density on the Z axis. + + Please see QMagnetometerReading::z for information about this property. +*/ + +qreal QmlMagnetometerReading::z() const +{ + return m_z; +} + +/*! + \qmlproperty qreal MagnetometerReading::calibrationLevel + This property holds the accuracy of the reading. + + Please see QMagnetometerReading::calibrationLevel for information about this property. +*/ + +qreal QmlMagnetometerReading::calibrationLevel() const +{ + return m_calibrationLevel; +} + +QSensorReading *QmlMagnetometerReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlMagnetometerReading::readingUpdate() +{ + qreal magX = m_sensor->reading()->x(); + if (m_x != magX) { + m_x = magX; + Q_EMIT xChanged(); + } + qreal magY = m_sensor->reading()->y(); + if (m_y != magY) { + m_y = magY; + Q_EMIT yChanged(); + } + qreal magZ = m_sensor->reading()->z(); + if (m_z != magZ) { + m_z = magZ; + Q_EMIT zChanged(); + } + qreal calLevel = m_sensor->reading()->calibrationLevel(); + if (m_calibrationLevel != calLevel) { + m_calibrationLevel = calLevel; + Q_EMIT calibrationLevelChanged(); + } +} diff --git a/src/sensorsquick/qmlmagnetometer_p.h b/src/sensorsquick/qmlmagnetometer_p.h new file mode 100644 index 00000000..ef30f6ff --- /dev/null +++ b/src/sensorsquick/qmlmagnetometer_p.h @@ -0,0 +1,118 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLMAGNETOMETER_P_H +#define QMLMAGNETOMETER_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qmlsensor_p.h" + +QT_BEGIN_NAMESPACE + +class QMagnetometer; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlMagnetometer : public QmlSensor +{ + Q_OBJECT + Q_PROPERTY(bool returnGeoValues READ returnGeoValues WRITE setReturnGeoValues NOTIFY returnGeoValuesChanged) + QML_NAMED_ELEMENT(Magnetometer) + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlMagnetometer(QObject *parent = 0); + ~QmlMagnetometer(); + + bool returnGeoValues() const; + void setReturnGeoValues(bool geo); + +Q_SIGNALS: + void returnGeoValuesChanged(bool returnGeoValues); + +private: + QSensor *sensor() const override; + QMagnetometer *m_sensor; + QmlSensorReading *createReading() const override; +}; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlMagnetometerReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal x READ x NOTIFY xChanged) + Q_PROPERTY(qreal y READ y NOTIFY yChanged) + Q_PROPERTY(qreal z READ z NOTIFY zChanged) + Q_PROPERTY(qreal calibrationLevel READ calibrationLevel NOTIFY calibrationLevelChanged) + QML_NAMED_ELEMENT(MagnetometerReading) + QML_UNCREATABLE("Cannot create MagnetometerReading") + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlMagnetometerReading(QMagnetometer *sensor); + ~QmlMagnetometerReading(); + + qreal x() const; + qreal y() const; + qreal z() const; + qreal calibrationLevel() const; + +Q_SIGNALS: + void xChanged(); + void yChanged(); + void zChanged(); + void calibrationLevelChanged(); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + QMagnetometer *m_sensor; + qreal m_x; + qreal m_y; + qreal m_z; + qreal m_calibrationLevel; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qmlorientationsensor.cpp b/src/sensorsquick/qmlorientationsensor.cpp new file mode 100644 index 00000000..0cf9cc19 --- /dev/null +++ b/src/sensorsquick/qmlorientationsensor.cpp @@ -0,0 +1,141 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmlorientationsensor_p.h" +#include <QtSensors/QOrientationSensor> + +/*! + \qmltype OrientationSensor + \instantiates QmlOrientationSensor + \ingroup qml-sensors_type + \inqmlmodule QtSensors + \since QtSensors 5.0 + \inherits Sensor + \brief The OrientationSensor element reports device orientation. + + The OrientationSensor element reports device orientation. + + This element wraps the QOrientationSensor class. Please see the documentation for + QOrientationSensor for details. + + \sa OrientationReading +*/ + +QmlOrientationSensor::QmlOrientationSensor(QObject *parent) + : QmlSensor(parent) + , m_sensor(new QOrientationSensor(this)) +{ +} + +QmlOrientationSensor::~QmlOrientationSensor() +{ +} + +QmlSensorReading *QmlOrientationSensor::createReading() const +{ + return new QmlOrientationSensorReading(m_sensor); +} + +QSensor *QmlOrientationSensor::sensor() const +{ + return m_sensor; +} + +/*! + \qmltype OrientationReading + \instantiates QmlOrientationSensorReading + \ingroup qml-sensors_reading + \inqmlmodule QtSensors + \since QtSensors 5.0 + \inherits SensorReading + \brief The OrientationReading element holds the most recent OrientationSensor reading. + + The OrientationReading element holds the most recent OrientationSensor reading. + + This element wraps the QOrientationReading class. Please see the documentation for + QOrientationReading for details. + + This element cannot be directly created. +*/ + +QmlOrientationSensorReading::QmlOrientationSensorReading(QOrientationSensor *sensor) + : QmlSensorReading(sensor) + , m_sensor(sensor) +{ +} + +QmlOrientationSensorReading::~QmlOrientationSensorReading() +{ +} + +/*! + \qmlproperty Orientation OrientationReading::orientation + This property holds the orientation of the device. + + Please see QOrientationReading::orientation for information about this property. + + Note that Orientation constants are exposed through the OrientationReading class. + \code + OrientationSensor { + onReadingChanged: { + if (reading.orientation == OrientationReading.TopUp) + // do something + } + } + \endcode +*/ + +QOrientationReading::Orientation QmlOrientationSensorReading::orientation() const +{ + return m_orientation; +} + +QSensorReading *QmlOrientationSensorReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlOrientationSensorReading::readingUpdate() +{ + QOrientationReading::Orientation o = m_sensor->reading()->orientation(); + if (m_orientation != o) { + m_orientation = o; + Q_EMIT orientationChanged(); + } +} diff --git a/src/sensorsquick/qmlorientationsensor_p.h b/src/sensorsquick/qmlorientationsensor_p.h new file mode 100644 index 00000000..4b04b3e8 --- /dev/null +++ b/src/sensorsquick/qmlorientationsensor_p.h @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLORIENTATIONSENSOR_P_H +#define QMLORIENTATIONSENSOR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qmlsensor_p.h" +#include <QtSensors/QOrientationSensor> + +QT_BEGIN_NAMESPACE + +class QOrientationSensor; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlOrientationSensor : public QmlSensor +{ + Q_OBJECT + QML_NAMED_ELEMENT(OrientationSensor) + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlOrientationSensor(QObject *parent = 0); + ~QmlOrientationSensor(); + + +private: + QSensor *sensor() const override; + QOrientationSensor *m_sensor; + QmlSensorReading *createReading() const override; +}; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlOrientationSensorReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(QOrientationReading::Orientation orientation READ orientation NOTIFY orientationChanged) + QML_NAMED_ELEMENT(OrientationReading) + QML_UNCREATABLE("Cannot create OrientationReading") + QML_ADDED_IN_VERSION(5,0) +public: + + explicit QmlOrientationSensorReading(QOrientationSensor *sensor); + ~QmlOrientationSensorReading(); + + QOrientationReading::Orientation orientation() const; + +Q_SIGNALS: + void orientationChanged(); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + QOrientationSensor *m_sensor; + QOrientationReading::Orientation m_orientation; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qmlpressuresensor.cpp b/src/sensorsquick/qmlpressuresensor.cpp new file mode 100644 index 00000000..08a434b0 --- /dev/null +++ b/src/sensorsquick/qmlpressuresensor.cpp @@ -0,0 +1,151 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Research In Motion +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qmlpressuresensor_p.h" +#include <QtSensors/QPressureSensor> + +/*! + \qmltype PressureSensor + \instantiates QmlPressureSensor + \ingroup qml-sensors_type + \inqmlmodule QtSensors + \since QtSensors 5.1 + \inherits Sensor + \brief The PressureSensor element reports on atmospheric pressure values. + + The PressureSensor element reports on atmospheric pressure values. + + This element wraps the QPressureSensor class. Please see the documentation for + QPressureSensor for details. + + \sa PressureReading +*/ + +QmlPressureSensor::QmlPressureSensor(QObject *parent) + : QmlSensor(parent) + , m_sensor(new QPressureSensor(this)) +{ +} + +QmlPressureSensor::~QmlPressureSensor() +{ +} + +QmlSensorReading *QmlPressureSensor::createReading() const +{ + return new QmlPressureReading(m_sensor); +} + +QSensor *QmlPressureSensor::sensor() const +{ + return m_sensor; +} + +/*! + \qmltype PressureReading + \instantiates QmlPressureReading + \ingroup qml-sensors_reading + \inqmlmodule QtSensors + \since QtSensors 5.1 + \inherits SensorReading + \brief The PressureReading element holds the most recent PressureSensor reading. + + The PressureReading element holds the most recent PressureSensor reading. + + This element wraps the QPressureReading class. Please see the documentation for + QPressureReading for details. + + This element cannot be directly created. +*/ + +QmlPressureReading::QmlPressureReading(QPressureSensor *sensor) + : QmlSensorReading(sensor) + , m_sensor(sensor) + , m_pressure(0) + , m_temperature(0) +{ +} + +QmlPressureReading::~QmlPressureReading() +{ +} + +/*! + \qmlproperty qreal PressureReading::pressure + This property holds the atmospheric pressure value in Pascals. + + Please see QPressureReading::pressure for information about this property. +*/ + +qreal QmlPressureReading::pressure() const +{ + return m_pressure; +} + +/*! + \qmlproperty qreal PressureReading::temperature + This property holds the pressure sensor's temperature value in degrees Celsius. + + Please see QPressureReading::temperature for information about this property. + \since QtSensors 5.2 +*/ + +qreal QmlPressureReading::temperature() const +{ + return m_temperature; +} + +QSensorReading *QmlPressureReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlPressureReading::readingUpdate() +{ + qreal pressure = m_sensor->reading()->pressure(); + if (m_pressure != pressure) { + m_pressure = pressure; + Q_EMIT pressureChanged(); + } + + qreal temperature = m_sensor->reading()->temperature(); + if (m_temperature != temperature) { + m_temperature = temperature; + Q_EMIT temperatureChanged(); + } +} diff --git a/src/sensorsquick/qmlpressuresensor_p.h b/src/sensorsquick/qmlpressuresensor_p.h new file mode 100644 index 00000000..b4b353d1 --- /dev/null +++ b/src/sensorsquick/qmlpressuresensor_p.h @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Research In Motion +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QMLPRESSURESENSOR_P_H +#define QMLPRESSURESENSOR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qmlsensor_p.h" + +QT_BEGIN_NAMESPACE + +class QPressureSensor; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlPressureSensor : public QmlSensor +{ + Q_OBJECT + QML_NAMED_ELEMENT(PressureSensor) + QML_ADDED_IN_VERSION(5,1) +public: + explicit QmlPressureSensor(QObject *parent = 0); + ~QmlPressureSensor(); + +private: + QSensor *sensor() const override; + QmlSensorReading *createReading() const override; + + QPressureSensor *m_sensor; +}; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlPressureReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal pressure READ pressure NOTIFY pressureChanged) + Q_PROPERTY(qreal temperature READ temperature NOTIFY temperatureChanged REVISION 1) + QML_NAMED_ELEMENT(PressureReading) + QML_UNCREATABLE("Cannot create PressureReading") + QML_ADDED_IN_VERSION(5,1) +public: + explicit QmlPressureReading(QPressureSensor *sensor); + ~QmlPressureReading(); + + qreal pressure() const; + qreal temperature() const; + +Q_SIGNALS: + void pressureChanged(); + Q_REVISION(1) void temperatureChanged(); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + + QPressureSensor *m_sensor; + qreal m_pressure; + qreal m_temperature; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qmlproximitysensor.cpp b/src/sensorsquick/qmlproximitysensor.cpp new file mode 100644 index 00000000..73767f64 --- /dev/null +++ b/src/sensorsquick/qmlproximitysensor.cpp @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmlproximitysensor_p.h" +#include <QtSensors/QProximitySensor> + +/*! + \qmltype ProximitySensor + \instantiates QmlProximitySensor + \ingroup qml-sensors_type + \inqmlmodule QtSensors + \since QtSensors 5.0 + \inherits Sensor + \brief The ProximitySensor element reports on object proximity. + + The ProximitySensor element reports on object proximity. + + This element wraps the QProximitySensor class. Please see the documentation for + QProximitySensor for details. + + \sa ProximityReading +*/ + +QmlProximitySensor::QmlProximitySensor(QObject *parent) + : QmlSensor(parent) + , m_sensor(new QProximitySensor(this)) +{ +} + +QmlProximitySensor::~QmlProximitySensor() +{ +} + +QmlSensorReading *QmlProximitySensor::createReading() const +{ + return new QmlProximitySensorReading(m_sensor); +} + +QSensor *QmlProximitySensor::sensor() const +{ + return m_sensor; +} + +/*! + \qmltype ProximityReading + \instantiates QmlProximitySensorReading + \ingroup qml-sensors_reading + \inqmlmodule QtSensors + \since QtSensors 5.0 + \inherits SensorReading + \brief The ProximityReading element holds the most recent ProximitySensor reading. + + The ProximityReading element holds the most recent ProximitySensor reading. + + This element wraps the QProximityReading class. Please see the documentation for + QProximityReading for details. + + This element cannot be directly created. +*/ + +QmlProximitySensorReading::QmlProximitySensorReading(QProximitySensor *sensor) + : QmlSensorReading(sensor) + , m_sensor(sensor) +{ +} + +QmlProximitySensorReading::~QmlProximitySensorReading() +{ +} + +/*! + \qmlproperty bool ProximityReading::near + This property holds a value indicating if something is near. + + Please see QProximityReading::near for information about this property. +*/ + +bool QmlProximitySensorReading::near() const +{ + return m_near; +} + +QSensorReading *QmlProximitySensorReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlProximitySensorReading::readingUpdate() +{ + bool pNear = m_sensor->reading()->close(); + if (m_near != pNear) { + m_near = pNear; + Q_EMIT nearChanged(); + } +} diff --git a/src/sensorsquick/qmlproximitysensor_p.h b/src/sensorsquick/qmlproximitysensor_p.h new file mode 100644 index 00000000..9d28dfcf --- /dev/null +++ b/src/sensorsquick/qmlproximitysensor_p.h @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLPROXIMITYSENSOR_P_H +#define QMLPROXIMITYSENSOR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qmlsensor_p.h" +#ifdef near +#undef near +#endif +QT_BEGIN_NAMESPACE + +class QProximitySensor; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlProximitySensor : public QmlSensor +{ + Q_OBJECT + QML_NAMED_ELEMENT(ProximitySensor) + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlProximitySensor(QObject *parent = 0); + ~QmlProximitySensor(); + + +private: + QSensor *sensor() const override; + QProximitySensor *m_sensor; + QmlSensorReading *createReading() const override; +}; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlProximitySensorReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(bool near READ near NOTIFY nearChanged) + QML_NAMED_ELEMENT(ProximityReading) + QML_UNCREATABLE("Cannot create ProximityReading") + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlProximitySensorReading(QProximitySensor *sensor); + ~QmlProximitySensorReading(); + + bool near() const; + +Q_SIGNALS: + void nearChanged(); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + QProximitySensor *m_sensor; + bool m_near; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qmlrotationsensor.cpp b/src/sensorsquick/qmlrotationsensor.cpp new file mode 100644 index 00000000..ef04c6bb --- /dev/null +++ b/src/sensorsquick/qmlrotationsensor.cpp @@ -0,0 +1,184 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmlrotationsensor_p.h" +#include <QtSensors/QRotationSensor> + +/*! + \qmltype RotationSensor + \instantiates QmlRotationSensor + \ingroup qml-sensors_type + \inqmlmodule QtSensors + \since QtSensors 5.0 + \inherits Sensor + \brief The RotationSensor element reports on device rotation + around the X, Y and Z axes. + + The RotationSensor element reports on device rotation + around the X, Y and Z axes. + + This element wraps the QRotationSensor class. Please see the documentation for + QRotationSensor for details. + + \sa RotationReading +*/ + +QmlRotationSensor::QmlRotationSensor(QObject *parent) + : QmlSensor(parent) + , m_sensor(new QRotationSensor(this)) +{ + connect(m_sensor, SIGNAL(hasZChanged(bool)), this, SIGNAL(hasZChanged(bool))); +} + +QmlRotationSensor::~QmlRotationSensor() +{ +} + +QmlSensorReading *QmlRotationSensor::createReading() const +{ + return new QmlRotationSensorReading(m_sensor); +} + +QSensor *QmlRotationSensor::sensor() const +{ + return m_sensor; +} + +/*! + \qmlproperty qreal RotationSensor::hasZ + This property holds a value indicating if the z angle is available. + + Please see QRotationSensor::hasZ for information about this property. +*/ + +bool QmlRotationSensor::hasZ() const +{ + return m_sensor->hasZ(); +} + +void QmlRotationSensor::_update() +{ +} + +/*! + \qmltype RotationReading + \instantiates QmlRotationSensorReading + \ingroup qml-sensors_reading + \inqmlmodule QtSensors + \since QtSensors 5.0 + \inherits SensorReading + \brief The RotationReading element holds the most recent RotationSensor reading. + + The RotationReading element holds the most recent RotationSensor reading. + + This element wraps the QRotationReading class. Please see the documentation for + QRotationReading for details. + + This element cannot be directly created. +*/ + +QmlRotationSensorReading::QmlRotationSensorReading(QRotationSensor *sensor) + : QmlSensorReading(sensor) + , m_sensor(sensor) +{ +} + +QmlRotationSensorReading::~QmlRotationSensorReading() +{ +} + +/*! + \qmlproperty qreal RotationReading::x + This property holds the rotation around the x axis. + + Please see QRotationReading::x for information about this property. +*/ + +qreal QmlRotationSensorReading::x() const +{ + return m_x; +} + +/*! + \qmlproperty qreal RotationReading::y + This property holds the rotation around the y axis. + + Please see QRotationReading::y for information about this property. +*/ + +qreal QmlRotationSensorReading::y() const +{ + return m_y; +} + +/*! + \qmlproperty qreal RotationReading::z + This property holds the rotation around the z axis. + + Please see QRotationReading::z for information about this property. +*/ + +qreal QmlRotationSensorReading::z() const +{ + return m_z; +} + +QSensorReading *QmlRotationSensorReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlRotationSensorReading::readingUpdate() +{ + qreal rX = m_sensor->reading()->x(); + if (m_x != rX) { + m_x = rX; + Q_EMIT xChanged(); + } + qreal rY = m_sensor->reading()->y(); + if (m_y != rY) { + m_y = rY; + Q_EMIT yChanged(); + } + qreal rZ = m_sensor->reading()->z(); + if (m_z != rZ) { + m_z = rZ; + Q_EMIT zChanged(); + } +} diff --git a/src/sensorsquick/qmlrotationsensor_p.h b/src/sensorsquick/qmlrotationsensor_p.h new file mode 100644 index 00000000..f14ad791 --- /dev/null +++ b/src/sensorsquick/qmlrotationsensor_p.h @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLROTATIONSENSOR_P_H +#define QMLROTATIONSENSOR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qmlsensor_p.h" + +QT_BEGIN_NAMESPACE + +class QRotationSensor; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlRotationSensor : public QmlSensor +{ + Q_OBJECT + Q_PROPERTY(bool hasZ READ hasZ NOTIFY hasZChanged) + QML_NAMED_ELEMENT(RotationSensor) + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlRotationSensor(QObject *parent = 0); + ~QmlRotationSensor(); + + bool hasZ() const; + +Q_SIGNALS: + void hasZChanged(bool hasZ); + +private: + QSensor *sensor() const override; + void _update() override; + QRotationSensor *m_sensor; + QmlSensorReading *createReading() const override; +}; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlRotationSensorReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal x READ x NOTIFY xChanged) + Q_PROPERTY(qreal y READ y NOTIFY yChanged) + Q_PROPERTY(qreal z READ z NOTIFY zChanged) + QML_NAMED_ELEMENT(RotationReading) + QML_UNCREATABLE("Cannot create RotationReading") + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlRotationSensorReading(QRotationSensor *sensor); + ~QmlRotationSensorReading(); + + qreal x() const; + qreal y() const; + qreal z() const; + +Q_SIGNALS: + void xChanged(); + void yChanged(); + void zChanged(); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + QRotationSensor *m_sensor; + qreal m_x; + qreal m_y; + qreal m_z; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qmlsensor.cpp b/src/sensorsquick/qmlsensor.cpp new file mode 100644 index 00000000..0afa91ea --- /dev/null +++ b/src/sensorsquick/qmlsensor.cpp @@ -0,0 +1,577 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmlsensor_p.h" +#include <QtSensors/QSensor> +#include <QDebug> +#include <QtCore/private/qobject_p.h> + +QT_BEGIN_NAMESPACE + +class QmlSensorPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QmlSensor) +public: + + QList<QmlSensorRange *> availableRanges; + QList<QmlSensorOutputRange *> outputRanges; +}; + +template<typename Item> +qsizetype readonlyListCount(QQmlListProperty<Item> *p) +{ + return static_cast<const QList<Item *> *>(p->data)->count(); +} + +template<typename Item> +Item *readonlyListAt(QQmlListProperty<Item> *p, qsizetype idx) +{ + return static_cast<const QList<Item *> *>(p->data)->at(idx); +}; + +template<typename Item> +QQmlListProperty<Item> readonlyListProperty(const QObject *o, const QList<Item *> *list) +{ + // Unfortunately QQmlListProperty won't accept a const object, even on the readonly ctor. + return QQmlListProperty<Item>(const_cast<QObject *>(o), const_cast<QList<Item *> *>(list), + readonlyListCount<Item>, readonlyListAt<Item>); +} + +/*! + \qmltype Sensor + \instantiates QmlSensor + \inqmlmodule QtSensors + \since QtSensors 5.0 + \brief The Sensor element serves as a base type for sensors. + + The Sensor element serves as a base type for sensors. + + This element wraps the QSensor class. Please see the documentation for + QSensor for details. + + This element cannot be directly created. Please use one of the sub-classes instead. +*/ + +QmlSensor::QmlSensor(QObject *parent) + : QObject(*(new QmlSensorPrivate), parent) + , m_parsed(false) + , m_active(false) + , m_reading(0) +{ +} + +QmlSensor::~QmlSensor() +{ +} + +/*! + \qmlproperty string Sensor::identifier + This property holds the backend identifier for the sensor. + + Please see QSensor::identifier for information about this property. +*/ + +QString QmlSensor::identifier() const +{ + return m_identifier; +} + +void QmlSensor::setIdentifier(const QString &identifier) +{ + if (m_parsed) return; + m_identifier = identifier; + Q_EMIT identifierChanged(); +} + +/*! + \qmlproperty string Sensor::type + This property holds the type of the sensor. +*/ + +QString QmlSensor::type() const +{ + return QString::fromLatin1(sensor()->type()); +} + +/*! + \qmlproperty bool Sensor::connectedToBackend + This property holds a value indicating if the sensor has connected to a backend. + + Please see QSensor::connectedToBackend for information about this property. +*/ + +bool QmlSensor::isConnectedToBackend() const +{ + return sensor()->isConnectedToBackend(); +} + +/*! + \qmlproperty bool Sensor::busy + This property holds a value to indicate if the sensor is busy. + + Please see QSensor::busy for information about this property. +*/ + +bool QmlSensor::isBusy() const +{ + return sensor()->isBusy(); +} + +/*! + \qmlproperty bool Sensor::active + This property holds a value to indicate if the sensor is active. + + Please see QSensor::active for information about this property. +*/ + +void QmlSensor::setActive(bool active) +{ + m_active = active; + if (!m_parsed) return; // delay (it'll get called again later)! + bool wasActive = sensor()->isActive(); + if (wasActive == active) return; + if (active) { + sensor()->start(); + m_active = sensor()->isActive(); + } else { + sensor()->stop(); + } + if (m_active != wasActive) + emit activeChanged(); +} + +bool QmlSensor::isActive() const +{ + return m_active; +} + +/*! + \qmlproperty bool Sensor::alwaysOn + This property holds a value to indicate if the sensor should remain running when the screen is off. + + Please see QSensor::alwaysOn for information about this property. +*/ + +bool QmlSensor::isAlwaysOn() const +{ + return sensor()->isAlwaysOn(); +} + +void QmlSensor::setAlwaysOn(bool alwaysOn) +{ + sensor()->setAlwaysOn(alwaysOn); +} + +/*! + \qmlproperty bool Sensor::skipDuplicates + \since QtSensors 5.1 + + This property indicates whether duplicate reading values should be omitted. + + Please see QSensor::skipDuplicates for information about this property. +*/ + +bool QmlSensor::skipDuplicates() const +{ + return sensor()->skipDuplicates(); +} + +void QmlSensor::setSkipDuplicates(bool skipDuplicates) +{ + sensor()->setSkipDuplicates(skipDuplicates); +} + +/*! + \qmlproperty list<Range> Sensor::availableDataRates + This property holds the data rates that the sensor supports. + + Please see QSensor::availableDataRates for information about this property. +*/ +QQmlListProperty<QmlSensorRange> QmlSensor::availableDataRates() const +{ + Q_D(const QmlSensor); + return readonlyListProperty<QmlSensorRange>(this, &d->availableRanges); +} + +/*! + \qmlproperty int Sensor::dataRate + This property holds the data rate that the sensor should be run at. + + Please see QSensor::dataRate for information about this property. +*/ + +int QmlSensor::dataRate() const +{ + return sensor()->dataRate(); +} + +void QmlSensor::setDataRate(int rate) +{ + if (rate != dataRate()) { + sensor()->setDataRate(rate); + Q_EMIT dataRateChanged(); + } +} + +/*! + \qmlproperty list<OutputRange> Sensor::outputRanges + This property holds a list of output ranges the sensor supports. + + Please see QSensor::outputRanges for information about this property. +*/ + +QQmlListProperty<QmlSensorOutputRange> QmlSensor::outputRanges() const +{ + Q_D(const QmlSensor); + return readonlyListProperty<QmlSensorOutputRange>(this, &d->outputRanges); +} + +/*! + \qmlproperty int Sensor::outputRange + This property holds the output range in use by the sensor. + + Please see QSensor::outputRange for information about this property. +*/ + +int QmlSensor::outputRange() const +{ + return sensor()->outputRange(); +} + +void QmlSensor::setOutputRange(int index) +{ + int oldRange = outputRange(); + if (oldRange == index) return; + sensor()->setOutputRange(index); + if (sensor()->outputRange() == index) + Q_EMIT outputRangeChanged(); +} + +/*! + \qmlproperty string Sensor::description + This property holds a descriptive string for the sensor. +*/ + +QString QmlSensor::description() const +{ + return sensor()->description(); +} + +/*! + \qmlproperty int Sensor::error + This property holds the last error code set on the sensor. +*/ + +int QmlSensor::error() const +{ + return sensor()->error(); +} + +/*! + \qmlproperty SensorReading Sensor::reading + This property holds the reading class. + + Please see QSensor::reading for information about this property. + \sa {QML Reading types} +*/ + +QmlSensorReading *QmlSensor::reading() const +{ + return m_reading; +} + +/*! + \qmlproperty Sensor::AxesOrientationMode Sensor::axesOrientationMode + \since QtSensors 5.1 + This property holds the mode that affects how the screen orientation changes reading values. + + Please see QSensor::axesOrientationMode for information about this property. +*/ + +QmlSensor::AxesOrientationMode QmlSensor::axesOrientationMode() const +{ + return static_cast<QmlSensor::AxesOrientationMode>(sensor()->axesOrientationMode()); +} + +void QmlSensor::setAxesOrientationMode(QmlSensor::AxesOrientationMode axesOrientationMode) +{ + sensor()->setAxesOrientationMode(static_cast<QSensor::AxesOrientationMode>(axesOrientationMode)); +} + +/*! + \qmlproperty int Sensor::currentOrientation + \since QtSensors 5.1 + This property holds the current orientation that is used for rotating the reading values. + + Please see QSensor::currentOrientation for information about this property. +*/ + +int QmlSensor::currentOrientation() const +{ + return sensor()->currentOrientation(); +} + +/*! + \qmlproperty int Sensor::userOrientation + \since QtSensors 5.1 + This property holds the angle used for rotating the reading values in the UserOrientation mode. + + Please see QSensor::userOrientation for information about this property. +*/ + +int QmlSensor::userOrientation() const +{ + return sensor()->userOrientation(); +} + +void QmlSensor::setUserOrientation(int userOrientation) +{ + sensor()->setUserOrientation(userOrientation); +} + +/*! + \qmlproperty int Sensor::maxBufferSize + \since QtSensors 5.1 + This property holds the maximum buffer size. + + Please see QSensor::maxBufferSize for information about this property. +*/ + +int QmlSensor::maxBufferSize() const +{ + return sensor()->maxBufferSize(); +} + +/*! + \qmlproperty int Sensor::efficientBufferSize + \since QtSensors 5.1 + The property holds the most efficient buffer size. + + Please see QSensor::efficientBufferSize for information about this property. +*/ + +int QmlSensor::efficientBufferSize() const +{ + return sensor()->efficientBufferSize(); +} + +/*! + \qmlproperty int Sensor::bufferSize + \since QtSensors 5.1 + This property holds the size of the buffer. + + Please see QSensor::bufferSize for information about this property. +*/ + +int QmlSensor::bufferSize() const +{ + return sensor()->bufferSize(); +} + +void QmlSensor::setBufferSize(int bufferSize) +{ + sensor()->setBufferSize(bufferSize); +} + +/*! + \qmlmethod bool Sensor::start() + Start retrieving values from the sensor. Returns true if the sensor + was started, false otherwise. + + Please see QSensor::start() for information. +*/ + +bool QmlSensor::start() +{ + setActive(true); + return isActive(); +} + +/*! + \qmlmethod bool Sensor::stop() + Stop retrieving values from the sensor. + Returns true if the sensor was stopped, false otherwise. + + Please see QSensor::stop() for information. +*/ + +void QmlSensor::stop() +{ + setActive(false); +} + +void QmlSensor::classBegin() +{ +} + +void QmlSensor::componentComplete() +{ + m_parsed = true; + + connect(sensor(), SIGNAL(sensorError(int)), this, SIGNAL(errorChanged())); + connect(sensor(), SIGNAL(activeChanged()), this, SIGNAL(activeChanged())); + connect(sensor(), SIGNAL(alwaysOnChanged()), this, SIGNAL(alwaysOnChanged())); + connect(sensor(), SIGNAL(skipDuplicatesChanged(bool)), this, SIGNAL(skipDuplicatesChanged(bool))); + connect(sensor(), SIGNAL(axesOrientationModeChanged(AxesOrientationMode)), + this, SIGNAL(axesOrientationModeChanged(AxesOrientationMode))); + connect(sensor(), SIGNAL(userOrientationChanged(int)), this, SIGNAL(userOrientationChanged(int))); + connect(sensor(), SIGNAL(currentOrientationChanged(int)), this, SIGNAL(currentOrientationChanged(int))); + connect(sensor(), SIGNAL(bufferSizeChanged(int)), this, SIGNAL(bufferSizeChanged(int))); + connect(sensor(), SIGNAL(maxBufferSizeChanged(int)), this, SIGNAL(maxBufferSizeChanged(int))); + connect(sensor(), SIGNAL(efficientBufferSizeChanged(int)), this, SIGNAL(efficientBufferSizeChanged(int))); + + // We need to set this on the sensor object now + sensor()->setIdentifier(m_identifier.toLocal8Bit()); + + // These can change! + QByteArray oldIdentifier = sensor()->identifier(); + int oldDataRate = dataRate(); + int oldOutputRange = outputRange(); + + bool ok = sensor()->connectToBackend(); + if (ok) { + Q_EMIT connectedToBackendChanged(); + m_reading = createReading(); + m_reading->setParent(this); + } + + if (oldIdentifier != sensor()->identifier()) { + m_identifier = QString::fromLatin1(sensor()->identifier()); + Q_EMIT identifierChanged(); + } + if (oldDataRate != dataRate()) + Q_EMIT dataRateChanged(); + if (oldOutputRange != outputRange()) + Q_EMIT outputRangeChanged(); + + Q_D(QmlSensor); + const auto available = sensor()->availableDataRates(); + d->availableRanges.reserve(available.size()); + for (const qrange &r : available) { + auto *range = new QmlSensorRange(this); + range->setMinumum(r.first); + range->setMaximum(r.second); + d->availableRanges.append(range); + } + const auto output = sensor()->outputRanges(); + d->outputRanges.reserve(output.size()); + for (const qoutputrange &r : output) { + auto *range = new QmlSensorOutputRange(this); + range->setMinimum(r.minimum); + range->setMaximum(r.maximum); + range->setAccuracy(r.accuracy); + d->outputRanges.append(range); + } + + // meta-data should become non-empty + if (!description().isEmpty()) + Q_EMIT descriptionChanged(); + if (available.count()) + Q_EMIT availableDataRatesChanged(); + if (output.count()) + Q_EMIT outputRangesChanged(); + + _update(); + + connect(sensor(), SIGNAL(readingChanged()), this, SLOT(updateReading())); + if (m_active) { + m_active = false; + start(); + } +} + +void QmlSensor::_update() +{ +} + +void QmlSensor::updateReading() +{ + if (m_reading) { + m_reading->update(); + Q_EMIT readingChanged(); + } +} + +/*! + \qmltype SensorReading + \instantiates QmlSensorReading + \inqmlmodule QtSensors + \since QtSensors 5.0 + \brief The SensorReading element serves as a base type for sensor readings. + + The SensorReading element serves as a base type for sensor readings. + + This element wraps the QSensorReading class. Please see the documentation for + QSensorReading for details. + + This element cannot be directly created. +*/ + +QmlSensorReading::QmlSensorReading(QSensor *) + : QObject(0) +{ +} + +QmlSensorReading::~QmlSensorReading() +{ +} + +/*! + \qmlproperty quint64 SensorReading::timestamp + A timestamp for the reading. + + Please see QSensorReading::timestamp for information about this property. +*/ + +quint64 QmlSensorReading::timestamp() const +{ + return m_timestamp; +} + +void QmlSensorReading::update() +{ + quint64 ts = reading()->timestamp(); + if (m_timestamp != ts) { + m_timestamp = ts; + Q_EMIT timestampChanged(); + } + readingUpdate(); +} + +QT_END_NAMESPACE diff --git a/src/sensorsquick/qmlsensor_p.h b/src/sensorsquick/qmlsensor_p.h new file mode 100644 index 00000000..f31ee1bf --- /dev/null +++ b/src/sensorsquick/qmlsensor_p.h @@ -0,0 +1,226 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLSENSOR_P_H +#define QMLSENSOR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qsensorsquickglobal_p.h" + +#include <QObject> +#include <QQmlParserStatus> +#include <QtQml/qqml.h> +#include <QQmlListProperty> +#include "qmlsensorrange_p.h" + +QT_BEGIN_NAMESPACE + +class QSensor; +class QSensorReading; + +class QmlSensorReading; + +class QmlSensorPrivate; +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlSensor : public QObject, public QQmlParserStatus +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlSensor) + Q_ENUMS(AxesOrientationMode) + Q_INTERFACES(QQmlParserStatus) + Q_PROPERTY(QString identifier READ identifier WRITE setIdentifier NOTIFY identifierChanged) + Q_PROPERTY(QString type READ type NOTIFY typeChanged) + Q_PROPERTY(bool connectedToBackend READ isConnectedToBackend NOTIFY connectedToBackendChanged) + Q_PROPERTY(QQmlListProperty<QmlSensorRange> availableDataRates READ availableDataRates NOTIFY availableDataRatesChanged) + Q_PROPERTY(int dataRate READ dataRate WRITE setDataRate NOTIFY dataRateChanged) + Q_PROPERTY(QmlSensorReading* reading READ reading NOTIFY readingChanged) + Q_PROPERTY(bool busy READ isBusy) + Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged) + Q_PROPERTY(QQmlListProperty<QmlSensorOutputRange> outputRanges READ outputRanges NOTIFY outputRangesChanged) + Q_PROPERTY(int outputRange READ outputRange WRITE setOutputRange NOTIFY outputRangeChanged) + Q_PROPERTY(QString description READ description NOTIFY descriptionChanged) + Q_PROPERTY(int error READ error NOTIFY errorChanged) + Q_PROPERTY(bool alwaysOn READ isAlwaysOn WRITE setAlwaysOn NOTIFY alwaysOnChanged) + Q_PROPERTY(bool skipDuplicates READ skipDuplicates WRITE setSkipDuplicates NOTIFY skipDuplicatesChanged REVISION 1) + Q_PROPERTY(AxesOrientationMode axesOrientationMode READ axesOrientationMode WRITE setAxesOrientationMode NOTIFY axesOrientationModeChanged REVISION 1) + Q_PROPERTY(int currentOrientation READ currentOrientation NOTIFY currentOrientationChanged REVISION 1) + Q_PROPERTY(int userOrientation READ userOrientation WRITE setUserOrientation NOTIFY userOrientationChanged REVISION 1) + Q_PROPERTY(int maxBufferSize READ maxBufferSize NOTIFY maxBufferSizeChanged REVISION 1) + Q_PROPERTY(int efficientBufferSize READ efficientBufferSize NOTIFY efficientBufferSizeChanged REVISION 1) + Q_PROPERTY(int bufferSize READ bufferSize WRITE setBufferSize NOTIFY bufferSizeChanged REVISION 1) + + QML_NAMED_ELEMENT(Sensor) + QML_UNCREATABLE("Cannot create Sensor") + QML_ADDED_IN_VERSION(5,0) +public: + // Keep in sync with QSensor::AxesOrientationMode + enum AxesOrientationMode { + FixedOrientation, + AutomaticOrientation, + UserOrientation + }; + + explicit QmlSensor(QObject *parent = 0); + ~QmlSensor(); + + QString identifier() const; + void setIdentifier(const QString &identifier); + + QString type() const; + + bool isConnectedToBackend() const; + + bool isBusy() const; + + void setActive(bool active); + bool isActive() const; + + bool isAlwaysOn() const; + void setAlwaysOn(bool alwaysOn); + + bool skipDuplicates() const; + void setSkipDuplicates(bool skipDuplicates); + + QQmlListProperty<QmlSensorRange> availableDataRates() const; + int dataRate() const; + void setDataRate(int rate); + + QQmlListProperty<QmlSensorOutputRange> outputRanges() const; + int outputRange() const; + void setOutputRange(int index); + + QString description() const; + int error() const; + + QmlSensorReading *reading() const; + + AxesOrientationMode axesOrientationMode() const; + void setAxesOrientationMode(AxesOrientationMode axesOrientationMode); + + int currentOrientation() const; + + int userOrientation() const; + void setUserOrientation(int userOrientation); + + int maxBufferSize() const; + + int efficientBufferSize() const; + + int bufferSize() const; + void setBufferSize(int bufferSize); + +public Q_SLOTS: + bool start(); + void stop(); + +Q_SIGNALS: + void identifierChanged(); + void typeChanged(); + void connectedToBackendChanged(); + void availableDataRatesChanged(); + void dataRateChanged(); + void readingChanged(); + void activeChanged(); + void outputRangesChanged(); + void outputRangeChanged(); + void descriptionChanged(); + void errorChanged(); + void alwaysOnChanged(); + Q_REVISION(1) void skipDuplicatesChanged(bool skipDuplicates); + Q_REVISION(1) void axesOrientationModeChanged(AxesOrientationMode axesOrientationMode); + Q_REVISION(1) void currentOrientationChanged(int currentOrientation); + Q_REVISION(1) void userOrientationChanged(int userOrientation); + Q_REVISION(1) void maxBufferSizeChanged(int maxBufferSize); + Q_REVISION(1) void efficientBufferSizeChanged(int efficientBufferSize); + Q_REVISION(1) void bufferSizeChanged(int bufferSize); + +protected: + virtual QSensor *sensor() const = 0; + virtual QmlSensorReading *createReading() const = 0; + +private Q_SLOTS: + void updateReading(); + +protected Q_SLOTS: + void componentComplete() override; + +private: + void classBegin() override; + virtual void _update(); + bool m_parsed; + bool m_active; + QString m_identifier; + QmlSensorReading *m_reading; +}; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlSensorReading : public QObject +{ + Q_OBJECT + Q_PROPERTY(quint64 timestamp READ timestamp NOTIFY timestampChanged) + QML_NAMED_ELEMENT(SensorReading) + QML_UNCREATABLE("Cannot create SensorReading") + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlSensorReading(QSensor *sensor); + ~QmlSensorReading(); + + quint64 timestamp() const; + void update(); + +Q_SIGNALS: + void timestampChanged(); + +private: + virtual QSensorReading *reading() const = 0; + virtual void readingUpdate() = 0; + quint64 m_timestamp; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/sensorsquick/qmlsensorgesture.cpp b/src/sensorsquick/qmlsensorgesture.cpp new file mode 100644 index 00000000..2879995c --- /dev/null +++ b/src/sensorsquick/qmlsensorgesture.cpp @@ -0,0 +1,262 @@ + /**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmlsensorgesture_p.h" +#include <QtSensors/qsensorgesture.h> +#include <QtSensors/qsensorgesturemanager.h> + +QT_BEGIN_NAMESPACE + +/*! + \qmltype SensorGesture + \instantiates QmlSensorGesture + \inqmlmodule QtSensors + \since QtSensors 5.0 + \brief Provides notifications when sensor-based gestures are detected. + + This type provides notification when sensor gestures are triggered. + + The following QML code creates a "shake" and "SecondCounter" SensorGesture QML type, and + displays the detected gesture in a text type. + + QtSensors.shake gesture is available with the Qt Sensors API, but the QtSensors.SecondCounter + sensor gesture is provided as example code for the \l {Qt Sensors - SensorGesture QML Type example} + + \qml + Item { + SensorGesture { + id: sensorGesture + enabled: false + gestures : ["QtSensors.shake", "QtSensors.SecondCounter"] + onDetected:{ + detectedText.text = gesture + } + } + Text { + id: detectedText + x:5 + y:160 + } + } + \endqml + + \l {Qt Sensor Gestures} contains a list of currently supported sensor gestures and their + descriptions. + + +*/ +QmlSensorGesture::QmlSensorGesture(QObject* parent) + : QObject(parent) + , isEnabled(false) + , initDone(false) + , sensorGesture(0) + , sensorGestureManager(new QSensorGestureManager(this)) +{ + connect(sensorGestureManager, SIGNAL(newSensorGestureAvailable()), SIGNAL(availableGesturesChanged())); +} + +QmlSensorGesture::~QmlSensorGesture() +{ +} + +/* + QQmlParserStatus interface implementation +*/ +void QmlSensorGesture::classBegin() +{ +} + +void QmlSensorGesture::componentComplete() +{ + /* + this is needed in the case the customer defines the type(s) and set it enabled = true + */ + initDone = true; + setEnabled(isEnabled); +} +/* + End of QQmlParserStatus interface implementation +*/ + +/*! + \qmlproperty stringlist SensorGesture::availableGestures + This property can be used to determine all available gestures on the system. +*/ +QStringList QmlSensorGesture::availableGestures() +{ + return sensorGestureManager->gestureIds(); +} + +/*! + \qmlproperty stringlist SensorGesture::gestures + Set this property to a list of the gestures that the application is interested in detecting. + This property cannot be changed while the type is enabled. + + The properties validGestures and invalidGestures will be set as appropriate immediately. + To determine all available getures on the system please use the + \l {SensorGesture::availableGestures} {availableGestures} property. + + \sa {QtSensorGestures Plugins} +*/ +QStringList QmlSensorGesture::gestures() const +{ + return gestureList; +} + +void QmlSensorGesture::setGestures(const QStringList& value) +{ + if (gestureList == value) + return; + + if (initDone && enabled()) { + qWarning() << "Cannot change gestures while running."; + return; + } + gestureList = value; + createGesture(); + Q_EMIT gesturesChanged(); +} + + +/*! + \qmlproperty stringlist SensorGesture::validGestures + This property holds the requested gestures that were found on the system. +*/ +QStringList QmlSensorGesture::validGestures() const +{ + if (sensorGesture) + return sensorGesture->validIds(); + return QStringList(); +} + +/*! + \qmlproperty stringlist SensorGesture::invalidGestures + This property holds the requested gestures that were not found on the system. +*/ +QStringList QmlSensorGesture::invalidGestures() const +{ + if (sensorGesture) + return sensorGesture->invalidIds(); + return QStringList(); +} + +/*! + \qmlproperty bool SensorGesture::enabled + This property can be used to activate or deactivate the sensor gesture. + Default value is false; + \sa {SensorGesture::detected}, {detected} +*/ +bool QmlSensorGesture::enabled() const +{ + return isEnabled; +} + +void QmlSensorGesture::setEnabled(bool value) +{ + bool hasChanged = false; + if (isEnabled != value) { + isEnabled = value; + hasChanged = true; + } + if (!initDone) + return; + + if (sensorGesture) { + if (value) { + sensorGesture->startDetection(); + } else { + sensorGesture->stopDetection(); + } + } + if (hasChanged) + Q_EMIT enabledChanged(); +} + +/*! + \qmlsignal SensorGesture::detected(string gesture) + This signal is emitted whenever a gesture is detected. + The \a gesture parameter contains the gesture that was detected. + + The corresponding handler is \c onDetected. +*/ + +/* + private function implementation +*/ +void QmlSensorGesture::deleteGesture() +{ + if (sensorGesture) { + bool emitInvalidChange = !invalidGestures().isEmpty(); + bool emitValidChange = !validGestures().isEmpty(); + + if (sensorGesture->isActive()) { + sensorGesture->stopDetection(); + } + delete sensorGesture; + sensorGesture = 0; + + if (emitInvalidChange) { + Q_EMIT invalidGesturesChanged(); + } + if (emitValidChange) { + Q_EMIT validGesturesChanged(); + } + } +} + +void QmlSensorGesture::createGesture() +{ + deleteGesture(); + sensorGesture = new QSensorGesture(gestureList, this); + if (!validGestures().isEmpty()) { + QObject::connect(sensorGesture + , SIGNAL(detected(QString)) + , this + , SIGNAL(detected(QString))); + Q_EMIT validGesturesChanged(); + } + if (!invalidGestures().isEmpty()) + Q_EMIT invalidGesturesChanged(); +} + +/* + End of private function implementation +*/ + +QT_END_NAMESPACE diff --git a/src/sensorsquick/qmlsensorgesture_p.h b/src/sensorsquick/qmlsensorgesture_p.h new file mode 100644 index 00000000..75f3e19a --- /dev/null +++ b/src/sensorsquick/qmlsensorgesture_p.h @@ -0,0 +1,116 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLSENSORGESTURE_P_H +#define QMLSENSORGESTURE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QQmlParserStatus> +#include <QtQml/qqml.h> +#include <QStringList> + +#include "qsensorsquickglobal_p.h" + +QT_BEGIN_NAMESPACE + +class QSensorGesture; +class QSensorGestureManager; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlSensorGesture : public QObject, public QQmlParserStatus +{ + Q_OBJECT + Q_PROPERTY(QStringList availableGestures READ availableGestures NOTIFY availableGesturesChanged) + Q_PROPERTY(QStringList gestures READ gestures WRITE setGestures NOTIFY gesturesChanged) + Q_PROPERTY(QStringList validGestures READ validGestures NOTIFY validGesturesChanged) + Q_PROPERTY(QStringList invalidGestures READ invalidGestures NOTIFY invalidGesturesChanged) + Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) + Q_INTERFACES(QQmlParserStatus) + QML_NAMED_ELEMENT(SensorGesture) + QML_ADDED_IN_VERSION(5,0) + +public: + explicit QmlSensorGesture(QObject* parent = 0); + ~QmlSensorGesture(); + void classBegin() override; + void componentComplete() override; + +Q_SIGNALS: + void detected(const QString &gesture); + void availableGesturesChanged(); + void gesturesChanged(); + void validGesturesChanged(); + void invalidGesturesChanged(); + void enabledChanged(); + +public: + QStringList availableGestures(); + QStringList gestures() const; + void setGestures(const QStringList& value); + bool enabled() const; + void setEnabled(bool value); + QStringList validGestures() const; + QStringList invalidGestures() const; + +private: + void deleteGesture(); + void createGesture(); + +private: + QStringList gestureIds; + bool isEnabled; + bool initDone; + QStringList gestureList; + + QSensorGesture* sensorGesture; + QSensorGestureManager* sensorGestureManager; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/sensorsquick/qmlsensorglobal.cpp b/src/sensorsquick/qmlsensorglobal.cpp new file mode 100644 index 00000000..4699a33d --- /dev/null +++ b/src/sensorsquick/qmlsensorglobal.cpp @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmlsensorglobal_p.h" +#include <QtSensors/QSensor> + +QT_BEGIN_NAMESPACE + +/*! + \qmltype QmlSensors + \instantiates QmlSensorGlobal + \inqmlmodule QtSensors + \since QtSensors 5.0 + \brief The QmlSensors singleton provides the module API. + + The QmlSensors singleton provides the module API. + + This element cannot be directly created. It can only be accessed via a namespace import. + + \code + import QtSensors 5.11 + import QtSensors 5.11 as Sensors + ... + Component.onCompleted: { + var types = Sensors.QmlSensors.sensorTypes(); + console.log(types.join(", ")); + } + \endcode +*/ + +QmlSensorGlobal::QmlSensorGlobal(QObject *parent) + : QObject(parent) + , m_sensor(new QSensor(QByteArray(), this)) +{ + connect(m_sensor, SIGNAL(availableSensorsChanged()), this, SIGNAL(availableSensorsChanged())); +} + +QmlSensorGlobal::~QmlSensorGlobal() +{ +} + +/*! + \qmlmethod list<string> QmlSensors::sensorTypes() + Returns a list of the sensor types that have been registered. + + Please see QSensor::sensorTypes() for information. +*/ +QStringList QmlSensorGlobal::sensorTypes() const +{ + QStringList ret; + const QList<QByteArray> sensorTypes = QSensor::sensorTypes(); + ret.reserve(sensorTypes.count()); + foreach (const QByteArray &type, sensorTypes) + ret << QString::fromLocal8Bit(type); + return ret; +} + +/*! + \qmlmethod list<string> QmlSensors::sensorsForType(type) + Returns a list of the sensor identifiers that have been registered for \a type. + + Please see QSensor::sensorsForType() for information. +*/ +QStringList QmlSensorGlobal::sensorsForType(const QString &type) const +{ + QStringList ret; + const QList<QByteArray> sensors = QSensor::sensorsForType(type.toLocal8Bit()); + ret.reserve(sensors.count()); + foreach (const QByteArray &identifier, sensors) + ret << QString::fromLocal8Bit(identifier); + return ret; +} + +/*! + \qmlmethod string QmlSensors::defaultSensorForType(type) + Returns the default sensor identifier that has been registered for \a type. + + Please see QSensor::defaultSensorForType() for information. +*/ +QString QmlSensorGlobal::defaultSensorForType(const QString &type) const +{ + return QString::fromLocal8Bit(QSensor::defaultSensorForType(type.toLocal8Bit())); +} + +QT_END_NAMESPACE diff --git a/src/sensorsquick/qmlsensorglobal_p.h b/src/sensorsquick/qmlsensorglobal_p.h new file mode 100644 index 00000000..cf570d90 --- /dev/null +++ b/src/sensorsquick/qmlsensorglobal_p.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLSENSORGLOBAL_P_H +#define QMLSENSORGLOBAL_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qsensorsquickglobal_p.h" +#include <QtQml/qqml.h> +#include <QObject> +#include <QStringList> + +QT_BEGIN_NAMESPACE + +class QSensor; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlSensorGlobal : public QObject +{ + Q_OBJECT +public: + explicit QmlSensorGlobal(QObject *parent = 0); + ~QmlSensorGlobal(); + + Q_INVOKABLE QStringList sensorTypes() const; + Q_INVOKABLE QStringList sensorsForType(const QString &type) const; + Q_INVOKABLE QString defaultSensorForType(const QString &type) const; + QML_NAMED_ELEMENT(QmlSensors) + QML_SINGLETON + QML_ADDED_IN_VERSION(5,0) + +Q_SIGNALS: + void availableSensorsChanged(); + +private: + QSensor *m_sensor; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/sensorsquick/qmlsensorrange.cpp b/src/sensorsquick/qmlsensorrange.cpp new file mode 100644 index 00000000..3e9a56b2 --- /dev/null +++ b/src/sensorsquick/qmlsensorrange.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmlsensorrange_p.h" + +QmlSensorRange::QmlSensorRange(QObject *parent) + : QObject(parent), + min(0), + max(0) +{ +} + +QmlSensorRange::~QmlSensorRange() +{ +} + +int QmlSensorRange::minimum() const +{ + return min; +} + +int QmlSensorRange::maximum() const +{ + return max; +} + +QmlSensorOutputRange::QmlSensorOutputRange(QObject *parent) + : QObject(parent), + min(0), + max(0), + acc(0) +{ +} + +QmlSensorOutputRange::~QmlSensorOutputRange() +{ +} + +qreal QmlSensorOutputRange::minimum() const +{ + return min; +} + +qreal QmlSensorOutputRange::maximum() const +{ + return max; +} + +qreal QmlSensorOutputRange::accuracy() const +{ + return acc; +} diff --git a/src/sensorsquick/qmlsensorrange_p.h b/src/sensorsquick/qmlsensorrange_p.h new file mode 100644 index 00000000..7e32ede2 --- /dev/null +++ b/src/sensorsquick/qmlsensorrange_p.h @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLSENSORRANGE_P_H +#define QMLSENSORRANGE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtQml/qqml.h> +#include <QObject> +#include "qsensorsquickglobal_p.h" + +QT_BEGIN_NAMESPACE + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlSensorRange : public QObject +{ + Q_OBJECT + Q_PROPERTY(int minimum READ minimum) + Q_PROPERTY(int maximum READ maximum) + QML_NAMED_ELEMENT(Range) + QML_UNCREATABLE("Cannot create Range") + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlSensorRange(QObject *parent = 0); + ~QmlSensorRange(); + + int minimum() const; + void setMinumum(int mini) { min = mini; } + + int maximum() const; + void setMaximum(int maxi) { max = maxi; } + +private: + + int min; + int max; +}; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlSensorOutputRange : public QObject +{ + Q_OBJECT + Q_PROPERTY(qreal minimum READ minimum) + Q_PROPERTY(qreal maximum READ maximum) + Q_PROPERTY(qreal accuracy READ accuracy) + QML_NAMED_ELEMENT(OutputRange) + QML_UNCREATABLE("Cannot create OutputRange") + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlSensorOutputRange(QObject *parent = 0); + ~QmlSensorOutputRange(); + + qreal minimum() const; + void setMinimum(int mini) { min = mini; } + + qreal maximum() const; + void setMaximum(int maxi) { max = maxi; } + + qreal accuracy() const; + void setAccuracy(int accu) { acc = accu; } + +private: + qreal min; + qreal max; + qreal acc; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qmltapsensor.cpp b/src/sensorsquick/qmltapsensor.cpp new file mode 100644 index 00000000..faeba623 --- /dev/null +++ b/src/sensorsquick/qmltapsensor.cpp @@ -0,0 +1,179 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmltapsensor_p.h" +#include <QtSensors/QTapSensor> + +/*! + \qmltype TapSensor + \instantiates QmlTapSensor + \ingroup qml-sensors_type + \inqmlmodule QtSensors + \since QtSensors 5.0 + \inherits Sensor + \brief The TapSensor element reports tap and double tap events + along the X, Y and Z axes. + + The TapSensor element reports tap and double tap events + along the X, Y and Z axes. + + This element wraps the QTapSensor class. Please see the documentation for + QTapSensor for details. + + \sa TapReading +*/ + +QmlTapSensor::QmlTapSensor(QObject *parent) + : QmlSensor(parent) + , m_sensor(new QTapSensor(this)) +{ + connect(m_sensor, SIGNAL(returnDoubleTapEventsChanged(bool)), + this, SIGNAL(returnDoubleTapEventsChanged(bool))); +} + +QmlTapSensor::~QmlTapSensor() +{ +} + +QmlSensorReading *QmlTapSensor::createReading() const +{ + return new QmlTapSensorReading(m_sensor); +} + +QSensor *QmlTapSensor::sensor() const +{ + return m_sensor; +} + +/*! + \qmlproperty bool TapSensor::returnDoubleTapEvents + This property holds a value indicating if double tap events should be reported. + + Please see QTapSensor::returnDoubleTapEvents for information about this property. +*/ + +bool QmlTapSensor::returnDoubleTapEvents() const +{ + return m_sensor->returnDoubleTapEvents(); +} + +void QmlTapSensor::setReturnDoubleTapEvents(bool ret) +{ + m_sensor->setReturnDoubleTapEvents(ret); +} + +/*! + \qmltype TapReading + \instantiates QmlTapSensorReading + \ingroup qml-sensors_reading + \inqmlmodule QtSensors + \since QtSensors 5.0 + \inherits SensorReading + \brief The TapReading element holds the most recent TapSensor reading. + + The TapReading element holds the most recent TapSensor reading. + + This element wraps the QTapReading class. Please see the documentation for + QTapReading for details. + + This element cannot be directly created. +*/ + +QmlTapSensorReading::QmlTapSensorReading(QTapSensor *sensor) + : QmlSensorReading(sensor) + , m_sensor(sensor) +{ +} + +QmlTapSensorReading::~QmlTapSensorReading() +{ +} + +/*! + \qmlproperty TapDirection TapReading::tapDirection + This property holds the direction of the tap. + + Please see QTapReading::tapDirection for information about this property. + + Note that TapDirection constants are exposed through the TapReading class. + \code + TapSensor { + onReadingChanged: { + if ((reading.tapDirection & TapReading.X_Both)) + // do something + } + } + \endcode +*/ + +QTapReading::TapDirection QmlTapSensorReading::tapDirection() const +{ + return m_tapDirection; +} + +/*! + \qmlproperty bool TapReading::doubleTap + This property holds a value indicating if there was a single or double tap. + + Please see QTapReading::doubleTap for information about this property. +*/ + +bool QmlTapSensorReading::isDoubleTap() const +{ + return m_isDoubleTap; +} + +QSensorReading *QmlTapSensorReading::reading() const +{ + return const_cast<QTapSensor*>(m_sensor)->reading(); +} + +void QmlTapSensorReading::readingUpdate() +{ + QTapReading::TapDirection td = m_sensor->reading()->tapDirection(); + if (m_tapDirection != td) { + m_tapDirection = td; + Q_EMIT tapDirectionChanged(); + } + bool dTap = m_sensor->reading()->isDoubleTap(); + if (m_isDoubleTap != dTap) { + m_isDoubleTap = dTap; + Q_EMIT isDoubleTapChanged(); + } +} diff --git a/src/sensorsquick/qmltapsensor_p.h b/src/sensorsquick/qmltapsensor_p.h new file mode 100644 index 00000000..7d8800c0 --- /dev/null +++ b/src/sensorsquick/qmltapsensor_p.h @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLTAPSENSOR_P_H +#define QMLTAPSENSOR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qmlsensor_p.h" +#include <QtSensors/QTapSensor> + +QT_BEGIN_NAMESPACE + +class QTapSensor; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlTapSensor : public QmlSensor +{ + Q_OBJECT + Q_PROPERTY(bool returnDoubleTapEvents READ returnDoubleTapEvents WRITE setReturnDoubleTapEvents NOTIFY returnDoubleTapEventsChanged) + QML_NAMED_ELEMENT(TapSensor) + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlTapSensor(QObject *parent = 0); + ~QmlTapSensor(); + + bool returnDoubleTapEvents() const; + void setReturnDoubleTapEvents(bool ret); + +Q_SIGNALS: + void returnDoubleTapEventsChanged(bool returnDoubleTapEvents); + +private: + QSensor *sensor() const override; + QTapSensor *m_sensor; + QmlSensorReading *createReading() const override; +}; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlTapSensorReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(QTapReading::TapDirection tapDirection READ tapDirection NOTIFY tapDirectionChanged) + Q_PROPERTY(bool doubleTap READ isDoubleTap NOTIFY isDoubleTapChanged) + QML_NAMED_ELEMENT(TapReading) + QML_UNCREATABLE("Cannot create TapReading") + QML_ADDED_IN_VERSION(5,0) +public: + + explicit QmlTapSensorReading(QTapSensor *sensor); + ~QmlTapSensorReading(); + + QTapReading::TapDirection tapDirection() const; + bool isDoubleTap() const; + +Q_SIGNALS: + void tapDirectionChanged(); + void isDoubleTapChanged(); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + QTapSensor *m_sensor; + QTapReading::TapDirection m_tapDirection; + bool m_isDoubleTap; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qmltiltsensor.cpp b/src/sensorsquick/qmltiltsensor.cpp new file mode 100644 index 00000000..81b4e696 --- /dev/null +++ b/src/sensorsquick/qmltiltsensor.cpp @@ -0,0 +1,163 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmltiltsensor_p.h" +#include <QtSensors/qtiltsensor.h> + +QT_BEGIN_NAMESPACE +QT_END_NAMESPACE + +/*! + \qmltype TiltSensor + \instantiates QmlTiltSensor + \ingroup qml-sensors_type + \inqmlmodule QtSensors + \since QtSensors 5.0 + \inherits Sensor + \brief The TiltSensor element reports tilt events + along the X and Y axes. + + The TiltSensor element reports tilt events along the X and Y axes. + + This element wraps the QTiltSensor class. Please see the documentation for + QTiltSensor for details. + + \sa TiltReading +*/ + +QmlTiltSensor::QmlTiltSensor(QObject *parent) + : QmlSensor(parent) + , m_sensor(new QTiltSensor(this)) +{ +} + +QmlTiltSensor::~QmlTiltSensor() +{ +} + +QmlSensorReading *QmlTiltSensor::createReading() const +{ + return new QmlTiltSensorReading(m_sensor); +} + +QSensor *QmlTiltSensor::sensor() const +{ + return m_sensor; +} + +/*! + \qmlmethod TiltSensor::calibrate() + Calibrate the tilt sensor. + + Please see QTiltSensor::calibrate() for information about this property. +*/ +void QmlTiltSensor::calibrate() +{ + m_sensor->calibrate(); +} + +/*! + \qmltype TiltReading + \instantiates QmlTiltSensorReading + \ingroup qml-sensors_reading + \inqmlmodule QtSensors + \since QtSensors 5.0 + \inherits SensorReading + \brief The TiltReading element holds the most recent TiltSensor reading. + + The TiltReading element holds the most recent TiltSensor reading. + + This element wraps the QTiltReading class. Please see the documentation for + QTiltReading for details. + + This element cannot be directly created. +*/ + +QmlTiltSensorReading::QmlTiltSensorReading(QTiltSensor *sensor) + : QmlSensorReading(sensor) + , m_sensor(sensor) +{ +} + +QmlTiltSensorReading::~QmlTiltSensorReading() +{ +} + +/*! + \qmlproperty qreal TiltReading::yRotation + This property holds the amount of tilt on the Y axis. + + Please see QTiltReading::yRotation for information about this property. +*/ + +qreal QmlTiltSensorReading::yRotation() const +{ + return m_yRotation; +} + +/*! + \qmlproperty qreal TiltReading::xRotation + This property holds the amount of tilt on the X axis. + + Please see QTiltReading::xRotation for information about this property. +*/ + +qreal QmlTiltSensorReading::xRotation() const +{ + return m_xRotation; +} + +QSensorReading *QmlTiltSensorReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlTiltSensorReading::readingUpdate() +{ + qreal tiltY = m_sensor->reading()->yRotation(); + if (m_yRotation != tiltY) { + m_yRotation = tiltY; + Q_EMIT yRotationChanged(); + } + qreal tiltX = m_sensor->reading()->xRotation(); + if (m_xRotation != tiltX) { + m_xRotation = tiltX; + Q_EMIT xRotationChanged(); + } +} diff --git a/src/sensorsquick/qmltiltsensor_p.h b/src/sensorsquick/qmltiltsensor_p.h new file mode 100644 index 00000000..f41757b3 --- /dev/null +++ b/src/sensorsquick/qmltiltsensor_p.h @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLTILTSENSOR_P_H +#define QMLTILTSENSOR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qmlsensor_p.h" +#include <QtSensors/QTiltSensor> + +QT_BEGIN_NAMESPACE + +class QTiltSensor; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlTiltSensor : public QmlSensor +{ + Q_OBJECT + QML_NAMED_ELEMENT(TiltSensor) + QML_ADDED_IN_VERSION(5,0) +public: + + explicit QmlTiltSensor(QObject *parent = 0); + ~QmlTiltSensor(); + Q_INVOKABLE void calibrate(); + +private: + QSensor *sensor() const override; + QTiltSensor *m_sensor; + QmlSensorReading *createReading() const override; +}; + +class Q_SENSORSQUICK_PRIVATE_EXPORT QmlTiltSensorReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal yRotation READ yRotation NOTIFY yRotationChanged) + Q_PROPERTY(qreal xRotation READ xRotation NOTIFY xRotationChanged) + QML_NAMED_ELEMENT(TiltReading) + QML_UNCREATABLE("Cannot create TiltReading") + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlTiltSensorReading(QTiltSensor *sensor); + ~QmlTiltSensorReading(); + + qreal yRotation() const; + qreal xRotation() const; + +Q_SIGNALS: + void yRotationChanged(); + void xRotationChanged(); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + QTiltSensor *m_sensor; + qreal m_yRotation; + qreal m_xRotation; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qsensorsquickglobal_p.h b/src/sensorsquick/qsensorsquickglobal_p.h new file mode 100644 index 00000000..4f6034f6 --- /dev/null +++ b/src/sensorsquick/qsensorsquickglobal_p.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSENSORSQUICKGLOBALS_P_H +#define QSENSORSQUICKGLOBALS_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtCore/qglobal.h> + +QT_BEGIN_NAMESPACE + +#if !defined(QT_STATIC) +# if defined(QT_BUILD_SENSORSQUICK_LIB) +# define Q_SENSORSQUICK_EXPORT Q_DECL_EXPORT +# else +# define Q_SENSORSQUICK_EXPORT Q_DECL_IMPORT +# endif +#else +# define Q_SENSORSQUICK_EXPORT +#endif + +#define Q_SENSORSQUICK_PRIVATE_EXPORT Q_SENSORSQUICK_EXPORT + +QT_END_NAMESPACE + +void Q_SENSORSQUICK_PRIVATE_EXPORT qml_register_types_QtSensors(); + +#endif // QSENSORSQUICKGLOBALS_P_H |