From 270e896a26713cb4d7e7c5703a03413bce76e581 Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Fri, 1 Feb 2013 11:49:18 +0100 Subject: Add a QAltimeter class. Port the Blackberry backend to use it. Change-Id: I3d3bc1d6fa8b42d3d0d64bcd3245050b67a37dc7 Reviewed-by: Thomas McGuire --- src/imports/sensors/plugins.qmltypes | 11 +++ src/imports/sensors/qmlaltimeter.cpp | 133 +++++++++++++++++++++++++++++++++++ src/imports/sensors/qmlaltimeter.h | 86 ++++++++++++++++++++++ src/imports/sensors/sensors.cpp | 4 ++ src/imports/sensors/sensors.pro | 2 + 5 files changed, 236 insertions(+) create mode 100644 src/imports/sensors/qmlaltimeter.cpp create mode 100644 src/imports/sensors/qmlaltimeter.h (limited to 'src/imports/sensors') diff --git a/src/imports/sensors/plugins.qmltypes b/src/imports/sensors/plugins.qmltypes index 78011ee2..b6f724a0 100644 --- a/src/imports/sensors/plugins.qmltypes +++ b/src/imports/sensors/plugins.qmltypes @@ -33,6 +33,17 @@ Module { Property { name: "y"; type: "double"; isReadonly: true } 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" diff --git a/src/imports/sensors/qmlaltimeter.cpp b/src/imports/sensors/qmlaltimeter.cpp new file mode 100644 index 00000000..abe3f922 --- /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 + +/*! + \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 00000000..4568baaa --- /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 52b436d6..725776e1 100644 --- a/src/imports/sensors/sensors.cpp +++ b/src/imports/sensors/sensors.cpp @@ -44,6 +44,7 @@ #include #include +#include #include #include #include @@ -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(package, major, minor, "SensorReading", QLatin1String("Cannot create SensorReading")); qmlRegisterType (package, major, minor, "Accelerometer"); qmlRegisterUncreatableType(package, major, minor, "AccelerometerReading", QLatin1String("Cannot create AccelerometerReading")); + qmlRegisterType (package, major, minor, "Altimeter"); + qmlRegisterUncreatableType(package, major, minor, "AltimeterReading", QLatin1String("Cannot create AltimeterReading")); qmlRegisterType (package, major, minor, "AmbientLightSensor"); qmlRegisterUncreatableType(package, major, minor, "AmbientLightReading", QLatin1String("Cannot create AmbientLightReading")); qmlRegisterType (package, major, minor, "Compass"); diff --git a/src/imports/sensors/sensors.pro b/src/imports/sensors/sensors.pro index 102dd30f..61994b0a 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 \ -- cgit v1.2.3