diff options
author | Sergio Martins <sergio.martins.qnx@kdab.com> | 2013-02-27 05:22:01 +0000 |
---|---|---|
committer | Sérgio Martins <sergio.martins.qnx@kdab.com> | 2013-03-07 13:29:39 +0100 |
commit | 4d18883db196e771057e67b7deed4c2a09511a62 (patch) | |
tree | 5269642147c58ca55fffcfce7b2b73e582464cf4 | |
parent | 27e62ecfafa5e3e269eb470e591d51496c58cc1d (diff) |
Backport QAmbientTemperatureSensor from QSensors to qt-mobility.
Change-Id: Ibaf0f89cfb8e3f570980b43ff3179afe83e7cb48
Reviewed-by: Thomas McGuire <thomas.mcguire@kdab.com>
-rw-r--r-- | plugins/declarative/sensors/sensors.cpp | 41 | ||||
-rw-r--r-- | plugins/sensors/blackberry/bbtemperaturesensor.cpp | 26 | ||||
-rw-r--r-- | plugins/sensors/blackberry/bbtemperaturesensor.h | 17 | ||||
-rw-r--r-- | plugins/sensors/blackberry/main.cpp | 2 | ||||
-rw-r--r-- | src/sensors/qambienttemperaturesensor.cpp | 144 | ||||
-rw-r--r-- | src/sensors/qambienttemperaturesensor.h | 84 | ||||
-rw-r--r-- | src/sensors/qambienttemperaturesensor_p.h | 70 | ||||
-rw-r--r-- | src/sensors/sensors.pro | 1 | ||||
-rw-r--r-- | tests/auto/qsensor/test_backends.h | 4 | ||||
-rw-r--r-- | tests/auto/qsensor/tst_qsensor.cpp | 4 |
10 files changed, 354 insertions, 39 deletions
diff --git a/plugins/declarative/sensors/sensors.cpp b/plugins/declarative/sensors/sensors.cpp index c6146136fb..05239b5c01 100644 --- a/plugins/declarative/sensors/sensors.cpp +++ b/plugins/declarative/sensors/sensors.cpp @@ -45,6 +45,7 @@ #include <qaccelerometer.h> #include <qaltimeter.h> #include <qambientlightsensor.h> +#include <qambienttemperaturesensor.h> #include <qcompass.h> #include <qmagnetometer.h> #include <qorientationsensor.h> @@ -129,6 +130,8 @@ public: qmlRegisterUncreatableType<QAltimeterReading >(package, major, minor, "AltimeterReading", QLatin1String("Cannot create AltimeterReading")); qmlRegisterType <QAmbientLightSensor >(package, major, minor, "AmbientLightSensor"); qmlRegisterUncreatableType<QAmbientLightReading >(package, major, minor, "AmbientLightReading", QLatin1String("Cannot create AmbientLightReading")); + qmlRegisterType <QAmbientTemperatureSensor >(package, major, minor, "AmbientTemperatureSensor"); + qmlRegisterUncreatableType<QAmbientTemperatureReading >(package, major, minor, "AmbientTemperatureReading", QLatin1String("Cannot create AmbientTemperatureReading")); qmlRegisterType <QCompass >(package, major, minor, "Compass"); qmlRegisterUncreatableType<QCompassReading >(package, major, minor, "CompassReading", QLatin1String("Cannot create CompassReading")); qmlRegisterType <QIRProximitySensor >(package, major, minor, "IRProximitySensor"); @@ -424,6 +427,44 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara */ /*! + \qmlclass AmbientTemperatureSensor QAmbientTemperatureSensor + \ingroup qml-sensors_type + \since Mobility 1.3 + \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 +*/ + +/*! + \qmltype AmbientTemperatureReading QAmbientTemperatureReading + \ingroup qml-sensors_reading + \since Mobility 1.3 + \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. +*/ + +/*! + \qmlproperty qreal AmbientTemperatureReading::temperature + This property holds the ambient temperature in degree Celsius. + + Please see QAmbientTemperatureReading::temperature for information about this property. + \since Mobility 1.3 +*/ + +/*! \qmlclass Compass QCompass \ingroup qml-sensors_type \since Mobility 1.1 diff --git a/plugins/sensors/blackberry/bbtemperaturesensor.cpp b/plugins/sensors/blackberry/bbtemperaturesensor.cpp index b23b735e90..403bb79500 100644 --- a/plugins/sensors/blackberry/bbtemperaturesensor.cpp +++ b/plugins/sensors/blackberry/bbtemperaturesensor.cpp @@ -40,31 +40,9 @@ ****************************************************************************/ #include "bbtemperaturesensor.h" -class BbTemperatureReadingPrivate -{ -public: - BbTemperatureReadingPrivate() - : temperature(0) - { - } - - qreal temperature; -}; - -IMPLEMENT_READING(BbTemperatureReading) - -qreal BbTemperatureReading::temperature() const -{ - return d->temperature; -} - -void BbTemperatureReading::setTemperature(qreal temperature) -{ - d->temperature = temperature; -} BbTemperatureSensor::BbTemperatureSensor(QSensor *sensor) - : BbSensorBackend<BbTemperatureReading>(devicePath(), SENSOR_TYPE_TEMPERATURE, sensor) + : BbSensorBackend<QAmbientTemperatureReading>(devicePath(), SENSOR_TYPE_TEMPERATURE, sensor) { setDescription(QLatin1String("Temperature in degrees Celsius")); } @@ -74,7 +52,7 @@ QString BbTemperatureSensor::devicePath() return QLatin1String("/dev/sensor/temp"); } -bool BbTemperatureSensor::updateReadingFromEvent(const sensor_event_t &event, BbTemperatureReading *reading) +bool BbTemperatureSensor::updateReadingFromEvent(const sensor_event_t &event, QAmbientTemperatureReading *reading) { // TODO: I was unable to test this since the device I was testing this with did not have // a temperature sensor. Verify that this works and check that the units are correct. diff --git a/plugins/sensors/blackberry/bbtemperaturesensor.h b/plugins/sensors/blackberry/bbtemperaturesensor.h index eef19cbd34..f451c5188a 100644 --- a/plugins/sensors/blackberry/bbtemperaturesensor.h +++ b/plugins/sensors/blackberry/bbtemperaturesensor.h @@ -42,22 +42,11 @@ #define BBTEMPERATURESENSOR_H #include "bbsensorbackend.h" +#include "qambienttemperaturesensor.h" QTM_USE_NAMESPACE -class BbTemperatureReadingPrivate; - -class BbTemperatureReading : public QSensorReading -{ - Q_OBJECT - Q_PROPERTY(qreal temperature READ temperature) - DECLARE_READING(BbTemperatureReading) -public: - qreal temperature() const; - void setTemperature(qreal temperature); -}; - -class BbTemperatureSensor : public BbSensorBackend<BbTemperatureReading> +class BbTemperatureSensor : public BbSensorBackend<QAmbientTemperatureReading> { Q_OBJECT @@ -67,7 +56,7 @@ public: static QString devicePath(); protected: - bool updateReadingFromEvent(const sensor_event_t &event, BbTemperatureReading *reading); + bool updateReadingFromEvent(const sensor_event_t &event, QAmbientTemperatureReading *reading); }; #endif diff --git a/plugins/sensors/blackberry/main.cpp b/plugins/sensors/blackberry/main.cpp index b309d1b415..957a4066b2 100644 --- a/plugins/sensors/blackberry/main.cpp +++ b/plugins/sensors/blackberry/main.cpp @@ -114,7 +114,7 @@ public: if (sensorSupported(BbRotationSensor::devicePath())) QSensorManager::registerBackend(QRotationSensor::type, bbRotationSensorId, this); if (sensorSupported(BbTemperatureSensor::devicePath())) - QSensorManager::registerBackend("BbTemperatureSensor", bbTemperatureSensorId, this); + QSensorManager::registerBackend(QAmbientTemperatureSensor::type, bbTemperatureSensorId, this); } QSensorBackend *createBackend(QSensor *sensor) diff --git a/src/sensors/qambienttemperaturesensor.cpp b/src/sensors/qambienttemperaturesensor.cpp new file mode 100644 index 0000000000..cc43742226 --- /dev/null +++ b/src/sensors/qambienttemperaturesensor.cpp @@ -0,0 +1,144 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 <qambienttemperaturesensor.h> +#include "qambienttemperaturesensor_p.h" + +QTM_BEGIN_NAMESPACE + +IMPLEMENT_READING(QAmbientTemperatureReading) + +/*! + \class QAmbientTemperatureReading + \ingroup sensors_reading + \inmodule QtSensors + \since 1.3 + + \brief The QAmbientTemperatureReading class holds readings of the ambient temperature. + + The ambient (room) temperature is the temperature in degree Celsius. +*/ + +/*! + \property QAmbientTemperatureReading::temperature + \brief The ambient temperature + + Measured in degree Celsius. +*/ + +qreal QAmbientTemperatureReading::temperature() const +{ + return d->temperature; +} + +/*! + Sets ambient temperature to \a temperature. +*/ +void QAmbientTemperatureReading::setTemperature(qreal temperature) +{ + d->temperature = temperature; +} + +// ===================================================================== + +/*! + \class QAmbientTemperatureFilter + \ingroup sensors_filter + \inmodule QtSensors + \since 1.3 + + \brief The QAmbientTemperatureFilter class is a convenience wrapper around QSensorFilter. + + The only difference is that the filter() method features a pointer to QAmbientTemperatureReading + instead of QSensorReading. +*/ + +/*! + \fn QAmbientTemperatureFilter::filter(QAmbientTemperatureReading *reading) + + Called when \a reading changes. Returns false to prevent the reading from propagating. + + \sa QSensorFilter::filter() +*/ + +char const * const QAmbientTemperatureSensor::type("QAmbientTemperatureSensor"); + +/*! + \class QAmbientTemperatureSensor + \ingroup sensors_type + \inmodule QtSensors + \since 1.3 + + \brief The QAmbientTemperatureSensor class is a convenience wrapper around QSensor. + + The only behavioural difference is that this class sets the type properly. + + This class also features a reading() function that returns a QAmbientTemperatureReading instead of a QSensorReading. + + For details about how the sensor works, see \l QAmbientTemperatureReading. + + \sa QAmbientTemperatureReading +*/ + +/*! + Construct the sensor as a child of \a parent. +*/ +QAmbientTemperatureSensor::QAmbientTemperatureSensor(QObject *parent) + : QSensor(QAmbientTemperatureSensor::type, parent) +{ +} + +/*! + Destroy the sensor. Stops the sensor if it has not already been stopped. +*/ +QAmbientTemperatureSensor::~QAmbientTemperatureSensor() +{ +} + +/*! + \fn QAmbientTemperatureSensor::reading() const + + Returns the reading class for this sensor. + + \sa QSensor::reading() +*/ + +#include "moc_qambienttemperaturesensor.cpp" +QTM_END_NAMESPACE diff --git a/src/sensors/qambienttemperaturesensor.h b/src/sensors/qambienttemperaturesensor.h new file mode 100644 index 0000000000..0d5fc8566b --- /dev/null +++ b/src/sensors/qambienttemperaturesensor.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 QAMBIENTTEMPERATURESENSOR_H +#define QAMBIENTTEMPERATURESENSOR_H + +#include <QtSensors/qsensor.h> + +QTM_BEGIN_NAMESPACE + +class QAmbientTemperatureReadingPrivate; + +class Q_SENSORS_EXPORT QAmbientTemperatureReading : public QSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal temperature READ temperature) + DECLARE_READING(QAmbientTemperatureReading) +public: + qreal temperature() const; + void setTemperature(qreal temperature); +}; + +class Q_SENSORS_EXPORT QAmbientTemperatureFilter : public QSensorFilter +{ +public: + virtual bool filter(QAmbientTemperatureReading *reading) = 0; +private: + bool filter(QSensorReading *reading) + { return filter(static_cast<QAmbientTemperatureReading*>(reading)); } +}; + +class Q_SENSORS_EXPORT QAmbientTemperatureSensor : public QSensor +{ + Q_OBJECT +public: + explicit QAmbientTemperatureSensor(QObject *parent = 0); + ~QAmbientTemperatureSensor(); + QAmbientTemperatureReading *reading() const { return static_cast<QAmbientTemperatureReading*>(QSensor::reading()); } + static char const * const type; + +private: + Q_DISABLE_COPY(QAmbientTemperatureSensor) +}; + +QTM_END_NAMESPACE + +#endif diff --git a/src/sensors/qambienttemperaturesensor_p.h b/src/sensors/qambienttemperaturesensor_p.h new file mode 100644 index 0000000000..e5bfa47b88 --- /dev/null +++ b/src/sensors/qambienttemperaturesensor_p.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 QAMBIENTTEMPERATURESENSOR_P_H +#define QAMBIENTTEMPERATURESENSOR_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. +// + +QTM_BEGIN_NAMESPACE + +class QAmbientTemperatureReadingPrivate +{ +public: + QAmbientTemperatureReadingPrivate() + : temperature(0) + { + } + + qreal temperature; +}; + +QTM_END_NAMESPACE + +#endif diff --git a/src/sensors/sensors.pro b/src/sensors/sensors.pro index 8909969ad6..7f0259a61f 100644 --- a/src/sensors/sensors.pro +++ b/src/sensors/sensors.pro @@ -58,6 +58,7 @@ SENSORS=\ qaccelerometer\ qaltimeter\ qambientlightsensor\ + qambienttemperaturesensor\ qcompass\ qholstersensor\ qlightsensor\ diff --git a/tests/auto/qsensor/test_backends.h b/tests/auto/qsensor/test_backends.h index 49223f807d..c98e373e84 100644 --- a/tests/auto/qsensor/test_backends.h +++ b/tests/auto/qsensor/test_backends.h @@ -52,6 +52,7 @@ void unregister_test_backends(); #include <qaccelerometer.h> #include <qaltimeter.h> #include <qambientlightsensor.h> +#include <qambienttemperaturesensor.h> #include <qcompass.h> #include <qgyroscope.h> #include <qlightsensor.h> @@ -105,6 +106,9 @@ PREPARE_SENSORINTERFACE(QAccelerometer, QAccelerometerReading, QAccelerometerFil PREPARE_SENSORINTERFACE(QAmbientLightSensor, QAmbientLightReading, QAmbientLightFilter, { reading->setLightLevel(QAmbientLightReading::Twilight); }) +PREPARE_SENSORINTERFACE(QAmbientTemperatureSensor, QAmbientTemperatureReading, QAmbientTemperatureFilter, { + reading->setTemperature(30); +}) PREPARE_SENSORINTERFACE(QCompass, QCompassReading, QCompassFilter, { reading->setAzimuth(1.0); reading->setCalibrationLevel(1.0); diff --git a/tests/auto/qsensor/tst_qsensor.cpp b/tests/auto/qsensor/tst_qsensor.cpp index 8b25c32cf3..c4f42a8eee 100644 --- a/tests/auto/qsensor/tst_qsensor.cpp +++ b/tests/auto/qsensor/tst_qsensor.cpp @@ -841,6 +841,10 @@ private slots: QCOMPARE(reading->lightLevel(), QAmbientLightReading::Twilight); }) + TEST_SENSORINTERFACE(QAmbientTemperatureSensor, QAmbientTemperatureReading, { + QCOMPARE(reading->temperature(), 30); + }) + TEST_SENSORINTERFACE(QCompass, QCompassReading, { QCOMPARE(reading->azimuth(), 1.0); QCOMPARE(reading->calibrationLevel(), 1.0); |