diff options
Diffstat (limited to 'src/sensorsquick')
40 files changed, 4224 insertions, 0 deletions
diff --git a/src/sensorsquick/CMakeLists.txt b/src/sensorsquick/CMakeLists.txt new file mode 100644 index 00000000..5ae32088 --- /dev/null +++ b/src/sensorsquick/CMakeLists.txt @@ -0,0 +1,38 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +qt_internal_add_qml_module(SensorsQuick + URI "QtSensors" + VERSION "${PROJECT_VERSION}" + SOURCES + qmlaccelerometer.cpp qmlaccelerometer_p.h + qmlambientlightsensor.cpp qmlambientlightsensor_p.h + qmlambienttemperaturesensor.cpp qmlambienttemperaturesensor_p.h + qmlcompass.cpp qmlcompass_p.h + qmlgyroscope.cpp qmlgyroscope_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 + 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 + DEPENDENCIES + QtQml + PUBLIC_LIBRARIES + Qt::Core + Qt::Qml + Qt::Sensors + LIBRARIES + Qt::CorePrivate +) diff --git a/src/sensorsquick/qmlaccelerometer.cpp b/src/sensorsquick/qmlaccelerometer.cpp new file mode 100644 index 00000000..70394043 --- /dev/null +++ b/src/sensorsquick/qmlaccelerometer.cpp @@ -0,0 +1,154 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#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) + : 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; +} + +QBindable<qreal> QmlAccelerometerReading::bindableX() 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; +} + +QBindable<qreal> QmlAccelerometerReading::bindableY() 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; +} + +QBindable<qreal> QmlAccelerometerReading::bindableZ() const +{ + return &m_z; +} + +QSensorReading *QmlAccelerometerReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlAccelerometerReading::readingUpdate() +{ + m_x = m_sensor->reading()->x(); + m_y = m_sensor->reading()->y(); + m_z = m_sensor->reading()->z(); +} diff --git a/src/sensorsquick/qmlaccelerometer_p.h b/src/sensorsquick/qmlaccelerometer_p.h new file mode 100644 index 00000000..aae90879 --- /dev/null +++ b/src/sensorsquick/qmlaccelerometer_p.h @@ -0,0 +1,94 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#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_EXPORT QmlAccelerometer : public QmlSensor +{ + Q_OBJECT + 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 + }; + Q_ENUM(AccelerationMode) + + AccelerationMode accelerationMode() const; + void setAccelerationMode(AccelerationMode accelerationMode); + + QSensor *sensor() const override; + +signals: + Q_REVISION(1) void accelerationModeChanged(AccelerationMode accelerationMode); + +private: + QAccelerometer *m_sensor; + QmlSensorReading *createReading() const override; +}; + +class Q_SENSORSQUICK_EXPORT QmlAccelerometerReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal x READ x NOTIFY xChanged BINDABLE bindableX) + Q_PROPERTY(qreal y READ y NOTIFY yChanged BINDABLE bindableY) + Q_PROPERTY(qreal z READ z NOTIFY zChanged BINDABLE bindableZ) + QML_NAMED_ELEMENT(AccelerometerReading) + QML_UNCREATABLE("Cannot create AccelerometerReading") + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlAccelerometerReading(QAccelerometer *sensor); + ~QmlAccelerometerReading(); + + qreal x() const; + QBindable<qreal> bindableX() const; + qreal y() const; + QBindable<qreal> bindableY() const; + qreal z() const; + QBindable<qreal> bindableZ() const; + +Q_SIGNALS: + void xChanged(); + void yChanged(); + void zChanged(); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + QAccelerometer *m_sensor; + Q_OBJECT_BINDABLE_PROPERTY(QmlAccelerometerReading, qreal, + m_x, &QmlAccelerometerReading::xChanged) + Q_OBJECT_BINDABLE_PROPERTY(QmlAccelerometerReading, qreal, + m_y, &QmlAccelerometerReading::yChanged) + Q_OBJECT_BINDABLE_PROPERTY(QmlAccelerometerReading, qreal, + m_z, &QmlAccelerometerReading::zChanged) +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qmlambientlightsensor.cpp b/src/sensorsquick/qmlambientlightsensor.cpp new file mode 100644 index 00000000..475ec98d --- /dev/null +++ b/src/sensorsquick/qmlambientlightsensor.cpp @@ -0,0 +1,105 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#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) + : 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; +} + +QBindable<QAmbientLightReading::LightLevel> QmlAmbientLightSensorReading::bindableLightLevel() const +{ + return &m_lightLevel; +} + +QSensorReading *QmlAmbientLightSensorReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlAmbientLightSensorReading::readingUpdate() +{ + m_lightLevel = m_sensor->reading()->lightLevel(); +} diff --git a/src/sensorsquick/qmlambientlightsensor_p.h b/src/sensorsquick/qmlambientlightsensor_p.h new file mode 100644 index 00000000..83bcd60c --- /dev/null +++ b/src/sensorsquick/qmlambientlightsensor_p.h @@ -0,0 +1,70 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#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_EXPORT QmlAmbientLightSensor : public QmlSensor +{ + Q_OBJECT + QML_NAMED_ELEMENT(AmbientLightSensor) + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlAmbientLightSensor(QObject *parent = 0); + ~QmlAmbientLightSensor(); + + QSensor *sensor() const override; + +private: + QAmbientLightSensor *m_sensor; + QmlSensorReading *createReading() const override; + +}; + +class Q_SENSORSQUICK_EXPORT QmlAmbientLightSensorReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(QAmbientLightReading::LightLevel lightLevel READ lightLevel + NOTIFY lightLevelChanged BINDABLE bindableLightLevel) + 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; + QBindable<QAmbientLightReading::LightLevel> bindableLightLevel() const; + +Q_SIGNALS: + void lightLevelChanged(); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + QAmbientLightSensor *m_sensor; + Q_OBJECT_BINDABLE_PROPERTY(QmlAmbientLightSensorReading, QAmbientLightReading::LightLevel, + m_lightLevel, &QmlAmbientLightSensorReading::lightLevelChanged) +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qmlambienttemperaturesensor.cpp b/src/sensorsquick/qmlambienttemperaturesensor.cpp new file mode 100644 index 00000000..876cda63 --- /dev/null +++ b/src/sensorsquick/qmlambienttemperaturesensor.cpp @@ -0,0 +1,95 @@ +// Copyright (C) 2016 Research In Motion +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +#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) + : 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; +} + +QBindable<qreal> QmlAmbientTemperatureReading::bindableTemperature() const +{ + return &m_temperature; +} + +QSensorReading *QmlAmbientTemperatureReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlAmbientTemperatureReading::readingUpdate() +{ + m_temperature = m_sensor->reading()->temperature(); +} diff --git a/src/sensorsquick/qmlambienttemperaturesensor_p.h b/src/sensorsquick/qmlambienttemperaturesensor_p.h new file mode 100644 index 00000000..898c0617 --- /dev/null +++ b/src/sensorsquick/qmlambienttemperaturesensor_p.h @@ -0,0 +1,68 @@ +// Copyright (C) 2016 Research In Motion +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +#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_EXPORT QmlAmbientTemperatureSensor : public QmlSensor +{ + Q_OBJECT + QML_NAMED_ELEMENT(AmbientTemperatureSensor) + QML_ADDED_IN_VERSION(5,1) +public: + explicit QmlAmbientTemperatureSensor(QObject *parent = 0); + ~QmlAmbientTemperatureSensor(); + + QSensor *sensor() const override; + +private: + QmlSensorReading *createReading() const override; + + QAmbientTemperatureSensor *m_sensor; +}; + +class Q_SENSORSQUICK_EXPORT QmlAmbientTemperatureReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal temperature READ temperature + NOTIFY temperatureChanged BINDABLE bindableTemperature) + QML_NAMED_ELEMENT(AmbientTemperatureReading) + QML_UNCREATABLE("Cannot create AmbientTemperatureReading") + QML_ADDED_IN_VERSION(5,1) +public: + explicit QmlAmbientTemperatureReading(QAmbientTemperatureSensor *sensor); + ~QmlAmbientTemperatureReading(); + + qreal temperature() const; + QBindable<qreal> bindableTemperature() const; + +Q_SIGNALS: + void temperatureChanged(); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + + QAmbientTemperatureSensor *m_sensor; + Q_OBJECT_BINDABLE_PROPERTY(QmlAmbientTemperatureReading, qreal, + m_temperature, &QmlAmbientTemperatureReading::temperatureChanged) +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qmlcompass.cpp b/src/sensorsquick/qmlcompass.cpp new file mode 100644 index 00000000..c7088d33 --- /dev/null +++ b/src/sensorsquick/qmlcompass.cpp @@ -0,0 +1,113 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#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) + : 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; +} + +QBindable<qreal> QmlCompassReading::bindableAzimuth() 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; +} + +QBindable<qreal> QmlCompassReading::bindableCalibrationLevel() const +{ + return &m_calibrationLevel; +} + +QSensorReading *QmlCompassReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlCompassReading::readingUpdate() +{ + m_azimuth = m_sensor->reading()->azimuth(); + m_calibrationLevel = m_sensor->reading()->calibrationLevel(); +} diff --git a/src/sensorsquick/qmlcompass_p.h b/src/sensorsquick/qmlcompass_p.h new file mode 100644 index 00000000..312bf13c --- /dev/null +++ b/src/sensorsquick/qmlcompass_p.h @@ -0,0 +1,73 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#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_EXPORT QmlCompass : public QmlSensor +{ + Q_OBJECT + QML_NAMED_ELEMENT(Compass) + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlCompass(QObject *parent = 0); + ~QmlCompass(); + + QSensor *sensor() const override; + +private: + QCompass *m_sensor; + QmlSensorReading *createReading() const override; +}; + +class Q_SENSORSQUICK_EXPORT QmlCompassReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal azimuth READ azimuth NOTIFY azimuthChanged BINDABLE bindableAzimuth) + Q_PROPERTY(qreal calibrationLevel READ calibrationLevel + NOTIFY calibrationLevelChanged BINDABLE bindableCalibrationLevel) + QML_NAMED_ELEMENT(CompassReading) + QML_UNCREATABLE("Cannot create CompassReading") + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlCompassReading(QCompass *sensor); + ~QmlCompassReading(); + + qreal azimuth() const; + QBindable<qreal> bindableAzimuth() const; + qreal calibrationLevel() const; + QBindable<qreal> bindableCalibrationLevel() const; + +Q_SIGNALS: + void azimuthChanged(); + void calibrationLevelChanged(); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + QCompass *m_sensor; + Q_OBJECT_BINDABLE_PROPERTY(QmlCompassReading, qreal, + m_azimuth, &QmlCompassReading::azimuthChanged) + Q_OBJECT_BINDABLE_PROPERTY(QmlCompassReading, qreal, + m_calibrationLevel, &QmlCompassReading::calibrationLevelChanged) +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qmlgyroscope.cpp b/src/sensorsquick/qmlgyroscope.cpp new file mode 100644 index 00000000..bb4458f7 --- /dev/null +++ b/src/sensorsquick/qmlgyroscope.cpp @@ -0,0 +1,130 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#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) + : 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; +} + +QBindable<qreal> QmlGyroscopeReading::bindableX() 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; +} + +QBindable<qreal> QmlGyroscopeReading::bindableY() 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; +} + +QBindable<qreal> QmlGyroscopeReading::bindableZ() const +{ + return &m_z; +} + +QSensorReading *QmlGyroscopeReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlGyroscopeReading::readingUpdate() +{ + m_x = m_sensor->reading()->x(); + m_y = m_sensor->reading()->y(); + m_z = m_sensor->reading()->z(); +} diff --git a/src/sensorsquick/qmlgyroscope_p.h b/src/sensorsquick/qmlgyroscope_p.h new file mode 100644 index 00000000..02697718 --- /dev/null +++ b/src/sensorsquick/qmlgyroscope_p.h @@ -0,0 +1,78 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#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_EXPORT QmlGyroscope : public QmlSensor +{ + Q_OBJECT + QML_NAMED_ELEMENT(Gyroscope) + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlGyroscope(QObject *parent = 0); + ~QmlGyroscope(); + + QSensor *sensor() const override; + +private: + QGyroscope *m_sensor; + QmlSensorReading *createReading() const override; +}; + +class Q_SENSORSQUICK_EXPORT QmlGyroscopeReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal x READ x NOTIFY xChanged BINDABLE bindableX) + Q_PROPERTY(qreal y READ y NOTIFY yChanged BINDABLE bindableY) + Q_PROPERTY(qreal z READ z NOTIFY zChanged BINDABLE bindableZ) + QML_NAMED_ELEMENT(GyroscopeReading) + QML_UNCREATABLE("Cannot create GyroscopeReading") + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlGyroscopeReading(QGyroscope *sensor); + ~QmlGyroscopeReading(); + + qreal x() const; + QBindable<qreal> bindableX() const; + qreal y() const; + QBindable<qreal> bindableY() const; + qreal z() const; + QBindable<qreal> bindableZ() const; + +Q_SIGNALS: + void xChanged(); + void yChanged(); + void zChanged(); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + QGyroscope *m_sensor; + Q_OBJECT_BINDABLE_PROPERTY(QmlGyroscopeReading, qreal, + m_x, &QmlGyroscopeReading::xChanged) + Q_OBJECT_BINDABLE_PROPERTY(QmlGyroscopeReading, qreal, + m_y, &QmlGyroscopeReading::yChanged) + Q_OBJECT_BINDABLE_PROPERTY(QmlGyroscopeReading, qreal, + m_z, &QmlGyroscopeReading::zChanged) +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qmlhumiditysensor.cpp b/src/sensorsquick/qmlhumiditysensor.cpp new file mode 100644 index 00000000..915e81b6 --- /dev/null +++ b/src/sensorsquick/qmlhumiditysensor.cpp @@ -0,0 +1,115 @@ +// Copyright (C) 2016 Canonical Ltd +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#include "qmlhumiditysensor_p.h" +#include <QtSensors/QHumiditySensor> + +/*! + \qmltype HumiditySensor +//! \instantiates QmlHumiditySensor + \ingroup qml-sensors_type + \inqmlmodule QtSensors + \since QtSensors 5.9 + \inherits Sensor + \brief The HumiditySensor element reports on humidity. + + The HumiditySensor element reports on humidity. + + This element wraps the QHumiditySensor class. Please see the documentation for + QHumiditySensor for details. + + \sa HumidityReading +*/ + +QmlHumiditySensor::QmlHumiditySensor(QObject *parent) + : QmlSensor(parent) + , m_sensor(new QHumiditySensor(this)) +{ +} + +QmlHumiditySensor::~QmlHumiditySensor() +{ +} + +QmlSensorReading *QmlHumiditySensor::createReading() const +{ + return new QmlHumidityReading(m_sensor); +} + +QSensor *QmlHumiditySensor::sensor() const +{ + return m_sensor; +} + +/*! + \qmltype HumidityReading +//! \instantiates QmlHumidityReading + \ingroup qml-sensors_reading + \inqmlmodule QtSensors + \since QtSensors 5.9 + \inherits SensorReading + \brief The HumidityReading element holds the most recent HumiditySensor reading. + + The HumidityReading element holds the most recent HumiditySensor reading. + + This element wraps the QHumidityReading class. Please see the documentation for + QHumidityReading for details. + + This element cannot be directly created. +*/ + +QmlHumidityReading::QmlHumidityReading(QHumiditySensor *sensor) + : m_sensor(sensor) + , m_relativeHumidity(0) + , m_absoluteHumidity(0) +{ +} + +QmlHumidityReading::~QmlHumidityReading() +{ +} + +/*! + \qmlproperty qreal HumidityReading::relativeHumidity + This property holds the relative humidity as a percentage. + + Please see QHumidityReading::relativeHumidity for information about this property. +*/ + +qreal QmlHumidityReading::relativeHumidity() const +{ + return m_relativeHumidity; +} + +QBindable<qreal> QmlHumidityReading::bindableRelativeHumidity() const +{ + return &m_relativeHumidity; +} + +/*! + \qmlproperty qreal HumidityReading::absoluteHumidity + This property holds the absolute humidity in grams per cubic meter (g/m3). + + Please see QHumidityReading::absoluteHumidity for information about this property. +*/ + +qreal QmlHumidityReading::absoluteHumidity() const +{ + return m_absoluteHumidity; +} + +QBindable<qreal> QmlHumidityReading::bindableAbsoluteHumidity() const +{ + return &m_absoluteHumidity; +} + +QSensorReading *QmlHumidityReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlHumidityReading::readingUpdate() +{ + m_relativeHumidity = m_sensor->reading()->relativeHumidity(); + m_absoluteHumidity = m_sensor->reading()->absoluteHumidity(); +} diff --git a/src/sensorsquick/qmlhumiditysensor_p.h b/src/sensorsquick/qmlhumiditysensor_p.h new file mode 100644 index 00000000..e01b0dc3 --- /dev/null +++ b/src/sensorsquick/qmlhumiditysensor_p.h @@ -0,0 +1,77 @@ +// Copyright (C) 2016 Canonical Ltd +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#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_EXPORT QmlHumiditySensor : public QmlSensor +{ + Q_OBJECT + + QML_NAMED_ELEMENT(HumiditySensor) + QML_ADDED_IN_VERSION(5,9) +public: + explicit QmlHumiditySensor(QObject *parent = nullptr); + ~QmlHumiditySensor(); + + QSensor *sensor() const override; + +private: + QmlSensorReading *createReading() const override; + + QHumiditySensor *m_sensor; +}; + +class Q_SENSORSQUICK_EXPORT QmlHumidityReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal relativeHumidity READ relativeHumidity + NOTIFY relativeHumidityChanged BINDABLE bindableRelativeHumidity) + Q_PROPERTY(qreal absoluteHumidity READ absoluteHumidity + NOTIFY absoluteHumidityChanged BINDABLE bindableAbsoluteHumidity) + QML_NAMED_ELEMENT(HumidityReading) + QML_UNCREATABLE("Cannot create HumidityReading") + QML_ADDED_IN_VERSION(5,9) +public: + explicit QmlHumidityReading(QHumiditySensor *sensor); + ~QmlHumidityReading(); + + qreal relativeHumidity() const; + QBindable<qreal> bindableRelativeHumidity() const; + qreal absoluteHumidity() const; + QBindable<qreal> bindableAbsoluteHumidity() const; + +Q_SIGNALS: + void relativeHumidityChanged(); + void absoluteHumidityChanged(); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + + QHumiditySensor *m_sensor; + Q_OBJECT_BINDABLE_PROPERTY(QmlHumidityReading, qreal, + m_relativeHumidity, &QmlHumidityReading::relativeHumidityChanged) + Q_OBJECT_BINDABLE_PROPERTY(QmlHumidityReading, qreal, + m_absoluteHumidity, &QmlHumidityReading::absoluteHumidityChanged) +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qmlirproximitysensor.cpp b/src/sensorsquick/qmlirproximitysensor.cpp new file mode 100644 index 00000000..84ccc455 --- /dev/null +++ b/src/sensorsquick/qmlirproximitysensor.cpp @@ -0,0 +1,96 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#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. + \internal + + 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. + \internal + + 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) + : 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; +} + +QBindable<qreal> QmlIRProximitySensorReading::bindableReflectance() const +{ + return &m_reflectance; +} + + +QSensorReading *QmlIRProximitySensorReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlIRProximitySensorReading::readingUpdate() +{ + m_reflectance = m_sensor->reading()->reflectance(); +} diff --git a/src/sensorsquick/qmlirproximitysensor_p.h b/src/sensorsquick/qmlirproximitysensor_p.h new file mode 100644 index 00000000..b1f97d5d --- /dev/null +++ b/src/sensorsquick/qmlirproximitysensor_p.h @@ -0,0 +1,67 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#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_EXPORT QmlIRProximitySensor : public QmlSensor +{ + Q_OBJECT + QML_NAMED_ELEMENT(IRProximitySensor) + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlIRProximitySensor(QObject *parent = 0); + ~QmlIRProximitySensor(); + + QSensor *sensor() const override; + +private: + QIRProximitySensor *m_sensor; + QmlSensorReading *createReading() const override; +}; + +class Q_SENSORSQUICK_EXPORT QmlIRProximitySensorReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal reflectance READ reflectance + NOTIFY reflectanceChanged BINDABLE bindableReflectance) + QML_NAMED_ELEMENT(IRProximityReading) + QML_UNCREATABLE("Cannot create IRProximityReading") + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlIRProximitySensorReading(QIRProximitySensor *sensor); + ~QmlIRProximitySensorReading(); + + qreal reflectance() const; + QBindable<qreal> bindableReflectance() const; + +Q_SIGNALS: + void reflectanceChanged(); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + QIRProximitySensor *m_sensor; + Q_OBJECT_BINDABLE_PROPERTY(QmlIRProximitySensorReading, qreal, + m_reflectance, &QmlIRProximitySensorReading::reflectanceChanged) +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qmllidsensor.cpp b/src/sensorsquick/qmllidsensor.cpp new file mode 100644 index 00000000..be1f600b --- /dev/null +++ b/src/sensorsquick/qmllidsensor.cpp @@ -0,0 +1,116 @@ +// Copyright (C) 2016 Canonical, Ltd +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +#include "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. + \internal + + 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. + \internal + + 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) + : 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::backLidClosed() const +{ + return m_backClosed; +} + +QBindable<bool> QmlLidReading::bindableBackLidClosed() 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; +} + +QBindable<bool> QmlLidReading::bindableFrontLidClosed() const +{ + return &m_frontClosed; +} + +QSensorReading *QmlLidReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlLidReading::readingUpdate() +{ + m_backClosed = m_sensor->reading()->backLidClosed(); + m_frontClosed = m_sensor->reading()->frontLidClosed(); +} diff --git a/src/sensorsquick/qmllidsensor_p.h b/src/sensorsquick/qmllidsensor_p.h new file mode 100644 index 00000000..1ddf60a9 --- /dev/null +++ b/src/sensorsquick/qmllidsensor_p.h @@ -0,0 +1,75 @@ +// Copyright (C) 2016 Canonical, Ltd +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +#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_EXPORT QmlLidSensor : public QmlSensor +{ + Q_OBJECT + QML_NAMED_ELEMENT(LidSensor) + QML_ADDED_IN_VERSION(5,9) +public: + explicit QmlLidSensor(QObject *parent = 0); + ~QmlLidSensor(); + + QSensor *sensor() const override; + +private: + QmlSensorReading *createReading() const override; + + QLidSensor *m_sensor; +}; + +class Q_SENSORSQUICK_EXPORT QmlLidReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(bool backLidClosed READ backLidClosed + NOTIFY backLidChanged BINDABLE bindableBackLidClosed) + Q_PROPERTY(bool frontLidClosed READ frontLidClosed + NOTIFY frontLidChanged BINDABLE bindableFrontLidClosed) + QML_NAMED_ELEMENT(LidReading) + QML_UNCREATABLE("Cannot create LidReading") + QML_ADDED_IN_VERSION(5,9) +public: + explicit QmlLidReading(QLidSensor *sensor); + ~QmlLidReading(); + + bool backLidClosed() const; + QBindable<bool> bindableBackLidClosed() const; + bool frontLidClosed() const; + QBindable<bool> bindableFrontLidClosed() const; + +Q_SIGNALS: + void backLidChanged(bool closed); + bool frontLidChanged(bool closed); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + + QLidSensor *m_sensor; + Q_OBJECT_BINDABLE_PROPERTY(QmlLidReading, bool, + m_backClosed, &QmlLidReading::backLidChanged) + Q_OBJECT_BINDABLE_PROPERTY(QmlLidReading, bool, + m_frontClosed, &QmlLidReading::frontLidChanged) +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qmllightsensor.cpp b/src/sensorsquick/qmllightsensor.cpp new file mode 100644 index 00000000..f80dd630 --- /dev/null +++ b/src/sensorsquick/qmllightsensor.cpp @@ -0,0 +1,109 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#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) + : 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; +} + +QBindable<qreal> QmlLightSensorReading::bindableIlluminance() const +{ + return &m_illuminance; +} + +QSensorReading *QmlLightSensorReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlLightSensorReading::readingUpdate() +{ + m_illuminance = m_sensor->reading()->lux(); +} diff --git a/src/sensorsquick/qmllightsensor_p.h b/src/sensorsquick/qmllightsensor_p.h new file mode 100644 index 00000000..6758ffba --- /dev/null +++ b/src/sensorsquick/qmllightsensor_p.h @@ -0,0 +1,72 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#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_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; + QSensor *sensor() const override; + +Q_SIGNALS: + void fieldOfViewChanged(qreal fieldOfView); + +private: + QLightSensor *m_sensor; + QmlSensorReading *createReading() const override; +}; + +class Q_SENSORSQUICK_EXPORT QmlLightSensorReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal illuminance READ illuminance + NOTIFY illuminanceChanged BINDABLE bindableIlluminance) + QML_NAMED_ELEMENT(LightReading) + QML_UNCREATABLE("Cannot create LightReading") + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlLightSensorReading(QLightSensor *sensor); + ~QmlLightSensorReading(); + + qreal illuminance() const; + QBindable<qreal> bindableIlluminance() const; + +Q_SIGNALS: + void illuminanceChanged(); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + QLightSensor *m_sensor; + Q_OBJECT_BINDABLE_PROPERTY(QmlLightSensorReading, qreal, + m_illuminance, &QmlLightSensorReading::illuminanceChanged) +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qmlmagnetometer.cpp b/src/sensorsquick/qmlmagnetometer.cpp new file mode 100644 index 00000000..1bbaa0eb --- /dev/null +++ b/src/sensorsquick/qmlmagnetometer.cpp @@ -0,0 +1,170 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#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) + : 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; +} + +QBindable<qreal> QmlMagnetometerReading::bindableX() 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; +} + +QBindable<qreal> QmlMagnetometerReading::bindableY() 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; +} + +QBindable<qreal> QmlMagnetometerReading::bindableZ() 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; +} + +QBindable<qreal> QmlMagnetometerReading::bindableCalibrationLevel() const +{ + return &m_calibrationLevel; +} + +QSensorReading *QmlMagnetometerReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlMagnetometerReading::readingUpdate() +{ + m_x = m_sensor->reading()->x(); + m_y = m_sensor->reading()->y(); + m_z = m_sensor->reading()->z(); + m_calibrationLevel= m_sensor->reading()->calibrationLevel(); +} diff --git a/src/sensorsquick/qmlmagnetometer_p.h b/src/sensorsquick/qmlmagnetometer_p.h new file mode 100644 index 00000000..9080f3e7 --- /dev/null +++ b/src/sensorsquick/qmlmagnetometer_p.h @@ -0,0 +1,93 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#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_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); + + QSensor *sensor() const override; + +Q_SIGNALS: + void returnGeoValuesChanged(bool returnGeoValues); + +private: + QMagnetometer *m_sensor; + QmlSensorReading *createReading() const override; +}; + +class Q_SENSORSQUICK_EXPORT QmlMagnetometerReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal x READ x NOTIFY xChanged BINDABLE bindableX) + Q_PROPERTY(qreal y READ y NOTIFY yChanged BINDABLE bindableY) + Q_PROPERTY(qreal z READ z NOTIFY zChanged BINDABLE bindableZ) + Q_PROPERTY(qreal calibrationLevel READ calibrationLevel + NOTIFY calibrationLevelChanged BINDABLE bindableCalibrationLevel) + QML_NAMED_ELEMENT(MagnetometerReading) + QML_UNCREATABLE("Cannot create MagnetometerReading") + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlMagnetometerReading(QMagnetometer *sensor); + ~QmlMagnetometerReading(); + + qreal x() const; + QBindable<qreal> bindableX() const; + qreal y() const; + QBindable<qreal> bindableY() const; + qreal z() const; + QBindable<qreal> bindableZ() const; + qreal calibrationLevel() const; + QBindable<qreal> bindableCalibrationLevel() const; + + +Q_SIGNALS: + void xChanged(); + void yChanged(); + void zChanged(); + void calibrationLevelChanged(); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + QMagnetometer *m_sensor; + Q_OBJECT_BINDABLE_PROPERTY(QmlMagnetometerReading, qreal, + m_x, &QmlMagnetometerReading::xChanged) + Q_OBJECT_BINDABLE_PROPERTY(QmlMagnetometerReading, qreal, + m_y, &QmlMagnetometerReading::yChanged) + Q_OBJECT_BINDABLE_PROPERTY(QmlMagnetometerReading, qreal, + m_z, &QmlMagnetometerReading::zChanged) + Q_OBJECT_BINDABLE_PROPERTY(QmlMagnetometerReading, qreal, + m_calibrationLevel, &QmlMagnetometerReading::calibrationLevelChanged) +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qmlorientationsensor.cpp b/src/sensorsquick/qmlorientationsensor.cpp new file mode 100644 index 00000000..c40bd474 --- /dev/null +++ b/src/sensorsquick/qmlorientationsensor.cpp @@ -0,0 +1,105 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#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) + : 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; +} + +QBindable<QOrientationReading::Orientation> QmlOrientationSensorReading::bindableOrientation() const +{ + return &m_orientation; +} + +QSensorReading *QmlOrientationSensorReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlOrientationSensorReading::readingUpdate() +{ + m_orientation = m_sensor->reading()->orientation(); +} diff --git a/src/sensorsquick/qmlorientationsensor_p.h b/src/sensorsquick/qmlorientationsensor_p.h new file mode 100644 index 00000000..9be7b7e5 --- /dev/null +++ b/src/sensorsquick/qmlorientationsensor_p.h @@ -0,0 +1,69 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#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_EXPORT QmlOrientationSensor : public QmlSensor +{ + Q_OBJECT + QML_NAMED_ELEMENT(OrientationSensor) + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlOrientationSensor(QObject *parent = 0); + ~QmlOrientationSensor(); + + QSensor *sensor() const override; + +private: + QOrientationSensor *m_sensor; + QmlSensorReading *createReading() const override; +}; + +class Q_SENSORSQUICK_EXPORT QmlOrientationSensorReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(QOrientationReading::Orientation orientation READ orientation + NOTIFY orientationChanged BINDABLE bindableOrientation) + 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; + QBindable<QOrientationReading::Orientation> bindableOrientation() const; + +Q_SIGNALS: + void orientationChanged(); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + QOrientationSensor *m_sensor; + Q_OBJECT_BINDABLE_PROPERTY(QmlOrientationSensorReading, QOrientationReading::Orientation, + m_orientation, &QmlOrientationSensorReading::orientationChanged) +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qmlpressuresensor.cpp b/src/sensorsquick/qmlpressuresensor.cpp new file mode 100644 index 00000000..d2e38a33 --- /dev/null +++ b/src/sensorsquick/qmlpressuresensor.cpp @@ -0,0 +1,115 @@ +// Copyright (C) 2016 Research In Motion +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +#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) + : 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; +} + +QBindable<qreal> QmlPressureReading::bindablePressure() 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; +} + +QBindable<qreal> QmlPressureReading::bindableTemperature() const +{ + return &m_temperature; +} + +QSensorReading *QmlPressureReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlPressureReading::readingUpdate() +{ + m_pressure = m_sensor->reading()->pressure(); + m_temperature = m_sensor->reading()->temperature(); +} diff --git a/src/sensorsquick/qmlpressuresensor_p.h b/src/sensorsquick/qmlpressuresensor_p.h new file mode 100644 index 00000000..8b531fba --- /dev/null +++ b/src/sensorsquick/qmlpressuresensor_p.h @@ -0,0 +1,74 @@ +// Copyright (C) 2016 Research In Motion +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +#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_EXPORT QmlPressureSensor : public QmlSensor +{ + Q_OBJECT + QML_NAMED_ELEMENT(PressureSensor) + QML_ADDED_IN_VERSION(5,1) +public: + explicit QmlPressureSensor(QObject *parent = 0); + ~QmlPressureSensor(); + + QSensor *sensor() const override; + +private: + QmlSensorReading *createReading() const override; + + QPressureSensor *m_sensor; +}; + +class Q_SENSORSQUICK_EXPORT QmlPressureReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal pressure READ pressure NOTIFY pressureChanged BINDABLE bindablePressure) + Q_PROPERTY(qreal temperature READ temperature + NOTIFY temperatureChanged REVISION 1 BINDABLE bindableTemperature) + QML_NAMED_ELEMENT(PressureReading) + QML_UNCREATABLE("Cannot create PressureReading") + QML_ADDED_IN_VERSION(5,1) +public: + explicit QmlPressureReading(QPressureSensor *sensor); + ~QmlPressureReading(); + + qreal pressure() const; + QBindable<qreal> bindablePressure() const; + qreal temperature() const; + QBindable<qreal> bindableTemperature() const; + +Q_SIGNALS: + void pressureChanged(); + Q_REVISION(1) void temperatureChanged(); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + + QPressureSensor *m_sensor; + Q_OBJECT_BINDABLE_PROPERTY(QmlPressureReading, qreal, + m_pressure, &QmlPressureReading::pressureChanged) + Q_OBJECT_BINDABLE_PROPERTY(QmlPressureReading, qreal, + m_temperature, &QmlPressureReading::temperatureChanged) +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qmlproximitysensor.cpp b/src/sensorsquick/qmlproximitysensor.cpp new file mode 100644 index 00000000..6019a15a --- /dev/null +++ b/src/sensorsquick/qmlproximitysensor.cpp @@ -0,0 +1,95 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#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) + : 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; +} + +QBindable<bool> QmlProximitySensorReading::bindableNear() const +{ + return &m_near; +} + +QSensorReading *QmlProximitySensorReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlProximitySensorReading::readingUpdate() +{ + m_near = m_sensor->reading()->close(); +} diff --git a/src/sensorsquick/qmlproximitysensor_p.h b/src/sensorsquick/qmlproximitysensor_p.h new file mode 100644 index 00000000..8ce4fdb8 --- /dev/null +++ b/src/sensorsquick/qmlproximitysensor_p.h @@ -0,0 +1,68 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#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_EXPORT QmlProximitySensor : public QmlSensor +{ + Q_OBJECT + QML_NAMED_ELEMENT(ProximitySensor) + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlProximitySensor(QObject *parent = 0); + ~QmlProximitySensor(); + + QSensor *sensor() const override; + +private: + QProximitySensor *m_sensor; + QmlSensorReading *createReading() const override; +}; + +class Q_SENSORSQUICK_EXPORT QmlProximitySensorReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(bool near READ near NOTIFY nearChanged BINDABLE bindableNear) + QML_NAMED_ELEMENT(ProximityReading) + QML_UNCREATABLE("Cannot create ProximityReading") + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlProximitySensorReading(QProximitySensor *sensor); + ~QmlProximitySensorReading(); + + bool near() const; + QBindable<bool> bindableNear() const; + +Q_SIGNALS: + void nearChanged(); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + QProximitySensor *m_sensor; + Q_OBJECT_BINDABLE_PROPERTY(QmlProximitySensorReading, bool, + m_near, &QmlProximitySensorReading::nearChanged) +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qmlrotationsensor.cpp b/src/sensorsquick/qmlrotationsensor.cpp new file mode 100644 index 00000000..d21b062f --- /dev/null +++ b/src/sensorsquick/qmlrotationsensor.cpp @@ -0,0 +1,146 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#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 bool 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(); +} + +/*! + \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) + : 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; +} + +QBindable<qreal> QmlRotationSensorReading::bindableX() 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; +} + +QBindable<qreal> QmlRotationSensorReading::bindableY() 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; +} + +QBindable<qreal> QmlRotationSensorReading::bindableZ() const +{ + return &m_z; +} + +QSensorReading *QmlRotationSensorReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlRotationSensorReading::readingUpdate() +{ + m_x = m_sensor->reading()->x(); + m_y = m_sensor->reading()->y(); + m_z = m_sensor->reading()->z(); +} diff --git a/src/sensorsquick/qmlrotationsensor_p.h b/src/sensorsquick/qmlrotationsensor_p.h new file mode 100644 index 00000000..1ef008b8 --- /dev/null +++ b/src/sensorsquick/qmlrotationsensor_p.h @@ -0,0 +1,83 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#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_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; + QSensor *sensor() const override; + +Q_SIGNALS: + void hasZChanged(bool hasZ); + +private: + QRotationSensor *m_sensor; + QmlSensorReading *createReading() const override; +}; + +class Q_SENSORSQUICK_EXPORT QmlRotationSensorReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal x READ x NOTIFY xChanged BINDABLE bindableX) + Q_PROPERTY(qreal y READ y NOTIFY yChanged BINDABLE bindableY) + Q_PROPERTY(qreal z READ z NOTIFY zChanged BINDABLE bindableZ) + QML_NAMED_ELEMENT(RotationReading) + QML_UNCREATABLE("Cannot create RotationReading") + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlRotationSensorReading(QRotationSensor *sensor); + ~QmlRotationSensorReading(); + + qreal x() const; + QBindable<qreal> bindableX() const; + qreal y() const; + QBindable<qreal> bindableY() const; + qreal z() const; + QBindable<qreal> bindableZ() const; + +Q_SIGNALS: + void xChanged(); + void yChanged(); + void zChanged(); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + QRotationSensor *m_sensor; + Q_OBJECT_BINDABLE_PROPERTY(QmlRotationSensorReading, qreal, + m_x, &QmlRotationSensorReading::xChanged) + Q_OBJECT_BINDABLE_PROPERTY(QmlRotationSensorReading, qreal, + m_y, &QmlRotationSensorReading::yChanged) + Q_OBJECT_BINDABLE_PROPERTY(QmlRotationSensorReading, qreal, + m_z, &QmlRotationSensorReading::zChanged) +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qmlsensor.cpp b/src/sensorsquick/qmlsensor.cpp new file mode 100644 index 00000000..d507e919 --- /dev/null +++ b/src/sensorsquick/qmlsensor.cpp @@ -0,0 +1,529 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#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)->size(); +} + +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) +{ +} + +QmlSensor::~QmlSensor() +{ +} + +/*! + \qmlproperty string Sensor::identifier + This property holds the backend identifier for the sensor. + + Please see QSensor::identifier for information about this property. +*/ + +QByteArray QmlSensor::identifier() const +{ + return sensor()->identifier(); +} + +void QmlSensor::setIdentifier(const QByteArray &identifier) +{ + sensor()->setIdentifier(identifier); +} + +/*! + \qmlproperty string Sensor::type + This property holds the type of the sensor. +*/ + +QByteArray QmlSensor::type() const +{ + return 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) +{ + if (!m_componentComplete) { + m_activateOnComplete = active; + return; + } + if (active) + sensor()->start(); + else + sensor()->stop(); +} + +bool QmlSensor::isActive() const +{ + return sensor()->isActive(); +} + +/*! + \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; +} + +QBindable<QmlSensorReading*> QmlSensor::bindableReading() const +{ + return &m_reading; +} + +/*! + \qmlmethod bool Sensor::isFeatureSupported(feature) + \since QtSensors 6.7 + Checks if a specific feature is supported by the backend. + Returns \c true if the \a feature is supported, and \c false otherwise. + For feature descriptions see \l {QSensor::Feature}. + + Please see QSensor::isFeatureSupported for information. +*/ + +bool QmlSensor::isFeatureSupported(Feature feature) const +{ + return sensor()->isFeatureSupported(static_cast<QSensor::Feature>(feature)); +} + +/*! + \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() +{ + return sensor()->start(); +} + +/*! + \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_componentComplete = 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))); + connect(sensor(), &QSensor::busyChanged, this, &QmlSensor::busyChanged); + connect(sensor(), &QSensor::identifierChanged, this, &QmlSensor::identifierChanged); + + // These can change! + int oldDataRate = dataRate(); + int oldOutputRange = outputRange(); + + if (sensor()->connectToBackend()) + Q_EMIT connectedToBackendChanged(); + + m_reading.setValueBypassingBindings(createReading()); + m_reading->setParent(this); + 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.size()) + Q_EMIT availableDataRatesChanged(); + if (output.size()) + Q_EMIT outputRangesChanged(); + + connect(sensor(), SIGNAL(readingChanged()), this, SLOT(updateReading())); + if (m_activateOnComplete) + start(); +} + +void QmlSensor::updateReading() +{ + if (m_reading) { + m_reading->update(); + m_reading.notify(); + 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. +*/ + +/*! + \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; +} + +QBindable<quint64> QmlSensorReading::bindableTimestamp() const +{ + return &m_timestamp; +} + + +void QmlSensorReading::update() +{ + m_timestamp = reading()->timestamp(); + readingUpdate(); +} + +QT_END_NAMESPACE diff --git a/src/sensorsquick/qmlsensor_p.h b/src/sensorsquick/qmlsensor_p.h new file mode 100644 index 00000000..d08d797f --- /dev/null +++ b/src/sensorsquick/qmlsensor_p.h @@ -0,0 +1,211 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#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 <QProperty> +#include <QQmlParserStatus> +#include <QtQml/qqml.h> +#include <QQmlListProperty> +#include <QtSensors/QSensor> + +#include "qmlsensorrange_p.h" + +QT_BEGIN_NAMESPACE + +class QSensor; +class QSensorReading; + +class QmlSensorReading; + +class QmlSensorPrivate; +class Q_SENSORSQUICK_EXPORT QmlSensor : public QObject, public QQmlParserStatus +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlSensor) + Q_INTERFACES(QQmlParserStatus) + Q_PROPERTY(QByteArray identifier READ identifier WRITE setIdentifier NOTIFY identifierChanged) + Q_PROPERTY(QByteArray type READ type CONSTANT) + 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 BINDABLE bindableReading) + Q_PROPERTY(bool busy READ isBusy NOTIFY busyChanged) + 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::Feature + enum Feature : int { + Buffering = QSensor::Buffering, + AlwaysOn = QSensor::AlwaysOn, + GeoValues = QSensor::GeoValues, + FieldOfView = QSensor::FieldOfView, + AccelerationMode = QSensor::AccelerationMode, + SkipDuplicates = QSensor::SkipDuplicates, + AxesOrientation = QSensor::AxesOrientation, + PressureSensorTemperature = QSensor::PressureSensorTemperature + }; + Q_ENUM(Feature) + + // Keep in sync with QSensor::AxesOrientationMode + enum AxesOrientationMode { + FixedOrientation, + AutomaticOrientation, + UserOrientation + }; + Q_ENUM(AxesOrientationMode) + + explicit QmlSensor(QObject *parent = 0); + ~QmlSensor(); + + QByteArray identifier() const; + void setIdentifier(const QByteArray &identifier); + + QByteArray 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; + QBindable<QmlSensorReading*> bindableReading() const; + + Q_INVOKABLE Q_REVISION(6, 7) bool isFeatureSupported(Feature feature) 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); + + virtual QSensor *sensor() const = 0; + + void componentComplete() override; + +public Q_SLOTS: + bool start(); + void stop(); + +Q_SIGNALS: + void identifierChanged(); + void connectedToBackendChanged(); + void availableDataRatesChanged(); + void dataRateChanged(); + void readingChanged(); + void activeChanged(); + void outputRangesChanged(); + void outputRangeChanged(); + void descriptionChanged(); + void errorChanged(); + void alwaysOnChanged(); + void busyChanged(); + 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 QmlSensorReading *createReading() const = 0; + +private Q_SLOTS: + void updateReading(); + +private: + void classBegin() override; + bool m_componentComplete = false; + bool m_activateOnComplete = false; + Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(QmlSensor, QmlSensorReading*, + m_reading, nullptr) +}; + +class Q_SENSORSQUICK_EXPORT QmlSensorReading : public QObject +{ + Q_OBJECT + Q_PROPERTY(quint64 timestamp READ timestamp NOTIFY timestampChanged BINDABLE bindableTimestamp) + QML_NAMED_ELEMENT(SensorReading) + QML_UNCREATABLE("Cannot create SensorReading") + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlSensorReading() = default; + ~QmlSensorReading() = default; + + quint64 timestamp() const; + QBindable<quint64> bindableTimestamp() const; + + void update(); + +Q_SIGNALS: + void timestampChanged(); + +private: + virtual QSensorReading *reading() const = 0; + virtual void readingUpdate() = 0; + Q_OBJECT_BINDABLE_PROPERTY(QmlSensorReading, quint64, + m_timestamp, &QmlSensorReading::timestampChanged) +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/sensorsquick/qmlsensorglobal.cpp b/src/sensorsquick/qmlsensorglobal.cpp new file mode 100644 index 00000000..73f865c4 --- /dev/null +++ b/src/sensorsquick/qmlsensorglobal.cpp @@ -0,0 +1,86 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#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, but its functionality + can be accessed as a QML singleton as illustrated below: + + \code + import QtSensors + import QtSensors 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.size()); + for (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.size()); + for (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..8b5214a2 --- /dev/null +++ b/src/sensorsquick/qmlsensorglobal_p.h @@ -0,0 +1,50 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#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_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..2a1d4ae9 --- /dev/null +++ b/src/sensorsquick/qmlsensorrange.cpp @@ -0,0 +1,52 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#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..324c24db --- /dev/null +++ b/src/sensorsquick/qmlsensorrange_p.h @@ -0,0 +1,77 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#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_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_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..2fa75f00 --- /dev/null +++ b/src/sensorsquick/qmltapsensor.cpp @@ -0,0 +1,147 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#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. + \internal + + 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. + \internal + + 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) + : 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; +} + +QBindable<QTapReading::TapDirection> QmlTapSensorReading::bindableTapDirection() 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; +} + +QBindable<bool> QmlTapSensorReading::bindableDoubleTap() const +{ + return &m_isDoubleTap; +} + +QSensorReading *QmlTapSensorReading::reading() const +{ + return const_cast<QTapSensor*>(m_sensor)->reading(); +} + +void QmlTapSensorReading::readingUpdate() +{ + m_tapDirection = m_sensor->reading()->tapDirection(); + m_isDoubleTap = m_sensor->reading()->isDoubleTap(); +} diff --git a/src/sensorsquick/qmltapsensor_p.h b/src/sensorsquick/qmltapsensor_p.h new file mode 100644 index 00000000..7537c5db --- /dev/null +++ b/src/sensorsquick/qmltapsensor_p.h @@ -0,0 +1,83 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#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_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); + + QSensor *sensor() const override; + +Q_SIGNALS: + void returnDoubleTapEventsChanged(bool returnDoubleTapEvents); + +private: + QTapSensor *m_sensor; + QmlSensorReading *createReading() const override; +}; + +class Q_SENSORSQUICK_EXPORT QmlTapSensorReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(QTapReading::TapDirection tapDirection READ tapDirection + NOTIFY tapDirectionChanged BINDABLE bindableTapDirection) + Q_PROPERTY(bool doubleTap READ isDoubleTap + NOTIFY isDoubleTapChanged BINDABLE bindableDoubleTap) + 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; + QBindable<QTapReading::TapDirection> bindableTapDirection() const; + bool isDoubleTap() const; + QBindable<bool> bindableDoubleTap() const; + +Q_SIGNALS: + void tapDirectionChanged(); + void isDoubleTapChanged(); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + QTapSensor *m_sensor; + Q_OBJECT_BINDABLE_PROPERTY(QmlTapSensorReading, QTapReading::TapDirection, + m_tapDirection, &QmlTapSensorReading::tapDirectionChanged) + Q_OBJECT_BINDABLE_PROPERTY(QmlTapSensorReading, bool, + m_isDoubleTap, &QmlTapSensorReading::isDoubleTapChanged) +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qmltiltsensor.cpp b/src/sensorsquick/qmltiltsensor.cpp new file mode 100644 index 00000000..9f8e0335 --- /dev/null +++ b/src/sensorsquick/qmltiltsensor.cpp @@ -0,0 +1,128 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#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) + : 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; +} + +QBindable<qreal> QmlTiltSensorReading::bindableYRotation() 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; +} + +QBindable<qreal> QmlTiltSensorReading::bindableXRotation() const +{ + return &m_xRotation; +} + +QSensorReading *QmlTiltSensorReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlTiltSensorReading::readingUpdate() +{ + m_yRotation = m_sensor->reading()->yRotation(); + m_xRotation = m_sensor->reading()->xRotation(); +} diff --git a/src/sensorsquick/qmltiltsensor_p.h b/src/sensorsquick/qmltiltsensor_p.h new file mode 100644 index 00000000..d660229d --- /dev/null +++ b/src/sensorsquick/qmltiltsensor_p.h @@ -0,0 +1,75 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#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_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(); + + QSensor *sensor() const override; + +private: + QTiltSensor *m_sensor; + QmlSensorReading *createReading() const override; +}; + +class Q_SENSORSQUICK_EXPORT QmlTiltSensorReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal yRotation READ yRotation NOTIFY yRotationChanged BINDABLE bindableYRotation) + Q_PROPERTY(qreal xRotation READ xRotation NOTIFY xRotationChanged BINDABLE bindableXRotation) + QML_NAMED_ELEMENT(TiltReading) + QML_UNCREATABLE("Cannot create TiltReading") + QML_ADDED_IN_VERSION(5,0) +public: + explicit QmlTiltSensorReading(QTiltSensor *sensor); + ~QmlTiltSensorReading(); + + qreal yRotation() const; + QBindable<qreal> bindableYRotation() const; + qreal xRotation() const; + QBindable<qreal> bindableXRotation() const; + +Q_SIGNALS: + void yRotationChanged(); + void xRotationChanged(); + +private: + QSensorReading *reading() const override; + void readingUpdate() override; + QTiltSensor *m_sensor; + Q_OBJECT_BINDABLE_PROPERTY(QmlTiltSensorReading, qreal, + m_yRotation, &QmlTiltSensorReading::yRotationChanged) + Q_OBJECT_BINDABLE_PROPERTY(QmlTiltSensorReading, qreal, + m_xRotation, &QmlTiltSensorReading::xRotationChanged) +}; + +QT_END_NAMESPACE +#endif diff --git a/src/sensorsquick/qsensorsquickglobal_p.h b/src/sensorsquick/qsensorsquickglobal_p.h new file mode 100644 index 00000000..4826ed82 --- /dev/null +++ b/src/sensorsquick/qsensorsquickglobal_p.h @@ -0,0 +1,23 @@ +// Copyright (C) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#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> +#include <QtSensorsQuick/qtsensorsquickexports.h> + +void Q_SENSORSQUICK_EXPORT qml_register_types_QtSensors(); + +#endif // QSENSORSQUICKGLOBALS_P_H |