diff options
author | Thomas McGuire <thomas.mcguire.qnx@kdab.com> | 2013-02-01 11:49:18 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-02-08 11:17:38 +0100 |
commit | 270e896a26713cb4d7e7c5703a03413bce76e581 (patch) | |
tree | b805f467bb5c3d57fd5fd1b912ec69b6ab9ba986 /src/imports | |
parent | e2bee30ba347f781c9fd635375040604c7270621 (diff) | |
download | qtsensors-270e896a26713cb4d7e7c5703a03413bce76e581.tar.gz |
Add a QAltimeter class.
Port the Blackberry backend to use it.
Change-Id: I3d3bc1d6fa8b42d3d0d64bcd3245050b67a37dc7
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/qmlaltimeter.cpp | 133 | ||||
-rw-r--r-- | src/imports/sensors/qmlaltimeter.h | 86 | ||||
-rw-r--r-- | src/imports/sensors/sensors.cpp | 4 | ||||
-rw-r--r-- | src/imports/sensors/sensors.pro | 2 |
5 files changed, 236 insertions, 0 deletions
diff --git a/src/imports/sensors/plugins.qmltypes b/src/imports/sensors/plugins.qmltypes index 78011ee..b6f724a 100644 --- a/src/imports/sensors/plugins.qmltypes +++ b/src/imports/sensors/plugins.qmltypes @@ -34,6 +34,17 @@ Module { Property { name: "z"; type: "double"; isReadonly: true } } Component { + name: "QmlAltimeter" + prototype: "QmlSensor" + exports: ["Altimeter 5.1"] + } + Component { + name: "QmlAltimeterReading" + prototype: "QmlSensorReading" + exports: ["AltimeterReading 5.1"] + Property { name: "altitude"; type: "double"; isReadonly: true } + } + Component { name: "QmlAmbientLightSensor" prototype: "QmlSensor" exports: ["AmbientLightSensor 5.0", "AmbientLightSensor 5.1"] diff --git a/src/imports/sensors/qmlaltimeter.cpp b/src/imports/sensors/qmlaltimeter.cpp new file mode 100644 index 0000000..abe3f92 --- /dev/null +++ b/src/imports/sensors/qmlaltimeter.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 "qmlaltimeter.h" +#include <QAltimeter> + +/*! + \qmltype Altimeter + \instantiates QmlAltimeter + \ingroup qml-sensors_type + \inqmlmodule QtSensors 5.0 + \since QtSensors 5.1 + \inherits Sensor + \brief The Altimeter element reports on altitude. + + The Altimeter element reports on altitude. + + This element wraps the QAltimeter class. Please see the documentation for + QAltimeter for details. + + \sa AltimeterReading +*/ + +QmlAltimeter::QmlAltimeter(QObject *parent) + : QmlSensor(parent) + , m_sensor(new QAltimeter(this)) +{ +} + +QmlAltimeter::~QmlAltimeter() +{ +} + +QmlSensorReading *QmlAltimeter::createReading() const +{ + return new QmlAltimeterReading(m_sensor); +} + +QSensor *QmlAltimeter::sensor() const +{ + return m_sensor; +} + +/*! + \qmltype AltimeterReading + \instantiates QmlAltimeterReading + \ingroup qml-sensors_reading + \inqmlmodule QtSensors 5.0 + \since QtSensors 5.1 + \inherits SensorReading + \brief The AltimeterReading element holds the most recent Altimeter reading. + + The AltimeterReading element holds the most recent Altimeter reading. + + This element wraps the QAltimeterReading class. Please see the documentation for + QAltimeterReading for details. + + This element cannot be directly created. +*/ + +QmlAltimeterReading::QmlAltimeterReading(QAltimeter *sensor) + : QmlSensorReading(sensor) + , m_sensor(sensor) + , m_altitude(0) +{ +} + +QmlAltimeterReading::~QmlAltimeterReading() +{ +} + +/*! + \qmlproperty qreal AltimeterReading::altitude + This property holds the altitude of the device. + + Please see QAltimeterReading::altitude for information about this property. +*/ + +qreal QmlAltimeterReading::altitude() const +{ + return m_altitude; +} + +QSensorReading *QmlAltimeterReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlAltimeterReading::readingUpdate() +{ + qreal altitude = m_sensor->reading()->altitude(); + if (m_altitude != altitude) { + m_altitude = altitude; + Q_EMIT altitudeChanged(); + } +} diff --git a/src/imports/sensors/qmlaltimeter.h b/src/imports/sensors/qmlaltimeter.h new file mode 100644 index 0000000..4568baa --- /dev/null +++ b/src/imports/sensors/qmlaltimeter.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** 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 QMLALTIMETER_H +#define QMLALTIMETER_H + +#include "qmlsensor.h" + +QT_BEGIN_NAMESPACE + +class QAltimeter; + +class QmlAltimeter : public QmlSensor +{ + Q_OBJECT +public: + explicit QmlAltimeter(QObject *parent = 0); + ~QmlAltimeter(); + +private: + QSensor *sensor() const Q_DECL_OVERRIDE; + QmlSensorReading *createReading() const Q_DECL_OVERRIDE; + + QAltimeter *m_sensor; +}; + +class QmlAltimeterReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal altitude READ altitude NOTIFY altitudeChanged) +public: + explicit QmlAltimeterReading(QAltimeter *sensor); + ~QmlAltimeterReading(); + + qreal altitude() const; + +Q_SIGNALS: + void altitudeChanged(); + +private: + QSensorReading *reading() const Q_DECL_OVERRIDE; + void readingUpdate() Q_DECL_OVERRIDE; + + QAltimeter *m_sensor; + qreal m_altitude; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/imports/sensors/sensors.cpp b/src/imports/sensors/sensors.cpp index 52b436d..725776e 100644 --- a/src/imports/sensors/sensors.cpp +++ b/src/imports/sensors/sensors.cpp @@ -44,6 +44,7 @@ #include <QtSensors/QSensorManager> #include <QtSensors/qaccelerometer.h> +#include <QtSensors/qaltimeter.h> #include <QtSensors/qambientlightsensor.h> #include <QtSensors/qcompass.h> #include <QtSensors/qmagnetometer.h> @@ -59,6 +60,7 @@ #include "qmlsensorglobal.h" #include "qmlsensor.h" #include "qmlaccelerometer.h" +#include "qmlaltimeter.h" #include "qmlambientlightsensor.h" #include "qmlcompass.h" #include "qmlgyroscope.h" @@ -138,6 +140,8 @@ public: qmlRegisterUncreatableType<QmlSensorReading >(package, major, minor, "SensorReading", QLatin1String("Cannot create SensorReading")); qmlRegisterType <QmlAccelerometer,1 >(package, major, minor, "Accelerometer"); qmlRegisterUncreatableType<QmlAccelerometerReading >(package, major, minor, "AccelerometerReading", QLatin1String("Cannot create AccelerometerReading")); + qmlRegisterType <QmlAltimeter >(package, major, minor, "Altimeter"); + qmlRegisterUncreatableType<QmlAltimeterReading >(package, major, minor, "AltimeterReading", QLatin1String("Cannot create AltimeterReading")); qmlRegisterType <QmlAmbientLightSensor >(package, major, minor, "AmbientLightSensor"); qmlRegisterUncreatableType<QmlAmbientLightSensorReading>(package, major, minor, "AmbientLightReading", QLatin1String("Cannot create AmbientLightReading")); qmlRegisterType <QmlCompass >(package, major, minor, "Compass"); diff --git a/src/imports/sensors/sensors.pro b/src/imports/sensors/sensors.pro index 102dd30..61994b0 100644 --- a/src/imports/sensors/sensors.pro +++ b/src/imports/sensors/sensors.pro @@ -9,6 +9,7 @@ HEADERS += \ qmlsensor.h \ qmlsensorrange.h \ qmlaccelerometer.h \ + qmlaltimeter.h \ qmlambientlightsensor.h \ qmlcompass.h \ qmlgyroscope.h \ @@ -29,6 +30,7 @@ SOURCES += sensors.cpp \ qmlsensor.cpp \ qmlsensorrange.cpp \ qmlaccelerometer.cpp \ + qmlaltimeter.cpp \ qmlambientlightsensor.cpp \ qmlcompass.cpp \ qmlgyroscope.cpp \ |