diff options
author | Thomas McGuire <thomas.mcguire.qnx@kdab.com> | 2013-01-08 16:55:38 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-01-23 18:32:35 +0100 |
commit | 02285d735e7d3bd8ddfb61b7ea5e16da4ad522d1 (patch) | |
tree | 6000899044feee17aae140df56eba1aa6126ffee /src/imports | |
parent | bbf9a9f61a18ccb478cbca414d85ed531f078966 (diff) | |
download | qtsensors-02285d735e7d3bd8ddfb61b7ea5e16da4ad522d1.tar.gz |
Add QPressureSensor
This adds a new QPressureSensor plus the assorted reading and filter
classes, as well as a QML API.
The Blackberry backend is ported to use the new reading class.
Change-Id: Ifc86a2ae955a9337a67fd9a86ceabab908917cb3
Reviewed-by: Thomas McGuire <thomas.mcguire@kdab.com>
Diffstat (limited to 'src/imports')
-rw-r--r-- | src/imports/sensors/plugins.qmltypes | 11 | ||||
-rw-r--r-- | src/imports/sensors/qmlpressuresensor.cpp | 133 | ||||
-rw-r--r-- | src/imports/sensors/qmlpressuresensor.h | 88 | ||||
-rw-r--r-- | src/imports/sensors/sensors.cpp | 3 | ||||
-rw-r--r-- | src/imports/sensors/sensors.pro | 2 |
5 files changed, 237 insertions, 0 deletions
diff --git a/src/imports/sensors/plugins.qmltypes b/src/imports/sensors/plugins.qmltypes index 00d8c36..1429ae7 100644 --- a/src/imports/sensors/plugins.qmltypes +++ b/src/imports/sensors/plugins.qmltypes @@ -118,6 +118,17 @@ Module { Property { name: "orientation"; type: "QOrientationReading::Orientation"; isReadonly: true } } Component { + name: "QmlPressureReading" + prototype: "QmlSensorReading" + exports: ["PressureReading 5.1"] + Property { name: "pressure"; type: "double"; isReadonly: true } + } + Component { + name: "QmlPressureSensor" + prototype: "QmlSensor" + exports: ["PressureSensor 5.1"] + } + Component { name: "QmlProximitySensor" prototype: "QmlSensor" exports: ["ProximitySensor 5.0", "ProximitySensor 5.1"] diff --git a/src/imports/sensors/qmlpressuresensor.cpp b/src/imports/sensors/qmlpressuresensor.cpp new file mode 100644 index 0000000..a21f7c0 --- /dev/null +++ b/src/imports/sensors/qmlpressuresensor.cpp @@ -0,0 +1,133 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qmlpressuresensor.h" +#include <QPressureSensor> + +/*! + \qmltype PressureSensor + \instantiates QmlPressureSensor + \ingroup qml-sensors_type + \inqmlmodule QtSensors 5.0 + \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 5.0 + \since QtSensors 5.1 + \inherits SensorReading + \brief The PressureReading element holds the most recent PressureSensor reading. + + The PressureReading element holds the most recent PressureSensor reading. + + This element wraps the QPressureReading class. Please see the documentation for + QPressureReading for details. + + This element cannot be directly created. +*/ + +QmlPressureReading::QmlPressureReading(QPressureSensor *sensor) + : QmlSensorReading(sensor) + , m_sensor(sensor) + , m_pressure(0) +{ +} + +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; +} + +QSensorReading *QmlPressureReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlPressureReading::readingUpdate() +{ + qreal pressure = m_sensor->reading()->pressure(); + if (m_pressure != pressure) { + m_pressure = pressure; + Q_EMIT pressureChanged(); + } +} diff --git a/src/imports/sensors/qmlpressuresensor.h b/src/imports/sensors/qmlpressuresensor.h new file mode 100644 index 0000000..e150c7d --- /dev/null +++ b/src/imports/sensors/qmlpressuresensor.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QMLPRESSURESENSOR_H +#define QMLPRESSURESENSOR_H + +#include "qmlsensor.h" + +QT_BEGIN_HEADER +QT_BEGIN_NAMESPACE + +class QPressureSensor; + +class QmlPressureSensor : public QmlSensor +{ + Q_OBJECT +public: + explicit QmlPressureSensor(QObject *parent = 0); + ~QmlPressureSensor(); + +private: + QSensor *sensor() const Q_DECL_OVERRIDE; + QmlSensorReading *createReading() const Q_DECL_OVERRIDE; + + QPressureSensor *m_sensor; +}; + +class QmlPressureReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal pressure READ pressure NOTIFY pressureChanged) +public: + explicit QmlPressureReading(QPressureSensor *sensor); + ~QmlPressureReading(); + + qreal pressure() const; + +Q_SIGNALS: + void pressureChanged(); + +private: + QSensorReading *reading() const Q_DECL_OVERRIDE; + void readingUpdate() Q_DECL_OVERRIDE; + + QPressureSensor *m_sensor; + qreal m_pressure; +}; + +QT_END_NAMESPACE +QT_END_HEADER +#endif diff --git a/src/imports/sensors/sensors.cpp b/src/imports/sensors/sensors.cpp index 95fc8cc..9392baf 100644 --- a/src/imports/sensors/sensors.cpp +++ b/src/imports/sensors/sensors.cpp @@ -66,6 +66,7 @@ #include "qmllightsensor.h" #include "qmlmagnetometer.h" #include "qmlorientationsensor.h" +#include "qmlpressuresensor.h" #include "qmlproximitysensor.h" #include "qmlrotationsensor.h" #include "qmltapsensor.h" @@ -150,6 +151,8 @@ public: qmlRegisterUncreatableType<QmlMagnetometerReading >(package, major, minor, "MagnetometerReading", QLatin1String("Cannot create MagnetometerReading")); qmlRegisterType <QmlOrientationSensor >(package, major, minor, "OrientationSensor"); qmlRegisterUncreatableType<QmlOrientationSensorReading >(package, major, minor, "OrientationReading", QLatin1String("Cannot create OrientationReading")); + qmlRegisterType <QmlPressureSensor >(package, major, minor, "PressureSensor"); + qmlRegisterUncreatableType<QmlPressureReading >(package, major, minor, "PressureReading", QLatin1String("Cannot create PressureReading")); qmlRegisterType <QmlProximitySensor >(package, major, minor, "ProximitySensor"); qmlRegisterUncreatableType<QmlProximitySensorReading >(package, major, minor, "ProximityReading", QLatin1String("Cannot create ProximityReading")); qmlRegisterType <QmlRotationSensor >(package, major, minor, "RotationSensor"); diff --git a/src/imports/sensors/sensors.pro b/src/imports/sensors/sensors.pro index 7636201..8224151 100644 --- a/src/imports/sensors/sensors.pro +++ b/src/imports/sensors/sensors.pro @@ -16,6 +16,7 @@ HEADERS += \ qmllightsensor.h \ qmlmagnetometer.h \ qmlorientationsensor.h \ + qmlpressuresensor.h\ qmlproximitysensor.h \ qmltapsensor.h \ qmlrotationsensor.h \ @@ -34,6 +35,7 @@ SOURCES += sensors.cpp \ qmllightsensor.cpp \ qmlmagnetometer.cpp \ qmlorientationsensor.cpp \ + qmlpressuresensor.cpp\ qmlproximitysensor.cpp \ qmltapsensor.cpp \ qmlrotationsensor.cpp \ |