From b64e52acb421dceae303124f63059c658090bd5d Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Fri, 29 Jun 2012 13:18:47 +0200 Subject: Add QPressureSensor and QHolsterSensor Change-Id: I650e31887d8e8651058e6d30417e8c64a4ed8645 Reviewed-by: Thomas McGuire Reviewed-by: Lorn Potter --- src/sensors/qholstersensor.cpp | 145 +++++++++++++++++++++++++++++++++++++++ src/sensors/qholstersensor.h | 84 +++++++++++++++++++++++ src/sensors/qholstersensor_p.h | 70 +++++++++++++++++++ src/sensors/qpressuresensor.cpp | 148 ++++++++++++++++++++++++++++++++++++++++ src/sensors/qpressuresensor.h | 81 ++++++++++++++++++++++ src/sensors/qpressuresensor_p.h | 70 +++++++++++++++++++ src/sensors/sensors.pro | 2 + 7 files changed, 600 insertions(+) create mode 100644 src/sensors/qholstersensor.cpp create mode 100644 src/sensors/qholstersensor.h create mode 100644 src/sensors/qholstersensor_p.h create mode 100644 src/sensors/qpressuresensor.cpp create mode 100644 src/sensors/qpressuresensor.h create mode 100644 src/sensors/qpressuresensor_p.h (limited to 'src') diff --git a/src/sensors/qholstersensor.cpp b/src/sensors/qholstersensor.cpp new file mode 100644 index 0000000000..7c1a2197fb --- /dev/null +++ b/src/sensors/qholstersensor.cpp @@ -0,0 +1,145 @@ +/**************************************************************************** +** +** Copyright (C) 2012 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 +#include "qholstersensor_p.h" + +QTM_BEGIN_NAMESPACE + +IMPLEMENT_READING(QHolsterReading) + +/*! + \class QHolsterReading + \ingroup sensors_reading + \inmodule QtSensors + + \brief The QHolsterReading class holds readings from the holster sensor. + + \section2 QHolsterReading Units + The holster sensor can detect if a device is holstered or not. A holster is a pocket, + similar to a gun holster, specifically made for the device. If the device is inside of this + pocket, it is holstered. The holster supports the device in detecting whether the device is + holstered or not. +*/ + +/*! + \property QHolsterReading::holstered + \brief A value indicating whether the device is holstered. + + \sa {QHolsterReading Units} +*/ + +bool QHolsterReading::holstered() const +{ + return d->holstered; +} + +/*! + Sets the holstered value to \a holstered. +*/ +void QHolsterReading::setHolstered(bool holstered) +{ + d->holstered = holstered; +} + +// ===================================================================== + +/*! + \class QHolsterFilter + \ingroup sensors_filter + \inmodule QtSensors + + \brief The QHolsterFilter class is a convenience wrapper around QSensorFilter. + + The only difference is that the filter() method features a pointer to QHolsterReading + instead of QSensorReading. +*/ + +/*! + \fn QHolsterFilter::filter(QHolsterReading *reading) + + Called when \a reading changes. Returns false to prevent the reading from propagating. + + \sa QSensorFilter::filter() +*/ + +char const * const QHolsterSensor::type("QHolsterSensor"); + +/*! + \class QHolsterSensor + \ingroup sensors_type + \inmodule QtSensors + + \brief The QHolsterSensor 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 QHolsterReading instead of a QSensorReading. + + For details about how the sensor works, see \l QHolsterReading. + + \sa QHolsterReading +*/ + +/*! + Construct the sensor as a child of \a parent. +*/ +QHolsterSensor::QHolsterSensor(QObject *parent) + : QSensor(QHolsterSensor::type, parent) +{ +} + +/*! + Destroy the sensor. Stops the sensor if it has not already been stopped. +*/ +QHolsterSensor::~QHolsterSensor() +{ +} + +/*! + \fn QHolsterSensor::reading() const + + Returns the reading class for this sensor. + + \sa QSensor::reading() +*/ + +#include "moc_qholstersensor.cpp" +QTM_END_NAMESPACE diff --git a/src/sensors/qholstersensor.h b/src/sensors/qholstersensor.h new file mode 100644 index 0000000000..ea9acb6cea --- /dev/null +++ b/src/sensors/qholstersensor.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2012 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 QHOLSTERSENSOR_H +#define QHOLSTERSENSOR_H + +#include + +QTM_BEGIN_NAMESPACE + +class QHolsterReadingPrivate; + +class Q_SENSORS_EXPORT QHolsterReading : public QSensorReading +{ + Q_OBJECT + Q_PROPERTY(bool holstered READ holstered) + DECLARE_READING(QHolsterReading) +public: + bool holstered() const; + void setHolstered(bool holstered); +}; + +class Q_SENSORS_EXPORT QHolsterFilter : public QSensorFilter +{ +public: + virtual bool filter(QHolsterReading *reading) = 0; +private: + bool filter(QSensorReading *reading) + { return filter(static_cast(reading)); } +}; + +class Q_SENSORS_EXPORT QHolsterSensor : public QSensor +{ + Q_OBJECT +public: + explicit QHolsterSensor(QObject *parent = 0); + ~QHolsterSensor(); + QHolsterReading *reading() const { return static_cast(QSensor::reading()); } + static char const * const type; + +private: + Q_DISABLE_COPY(QHolsterSensor) +}; + +QTM_END_NAMESPACE + +#endif diff --git a/src/sensors/qholstersensor_p.h b/src/sensors/qholstersensor_p.h new file mode 100644 index 0000000000..c8a4cc4088 --- /dev/null +++ b/src/sensors/qholstersensor_p.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2012 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 QHOLSTERSENSOR_P_H +#define QHOLSTERSENSOR_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 QHolsterReadingPrivate +{ +public: + QHolsterReadingPrivate() + : holstered(false) + { + } + + bool holstered; +}; + +QTM_END_NAMESPACE + +#endif diff --git a/src/sensors/qpressuresensor.cpp b/src/sensors/qpressuresensor.cpp new file mode 100644 index 0000000000..6eb889fc36 --- /dev/null +++ b/src/sensors/qpressuresensor.cpp @@ -0,0 +1,148 @@ +/**************************************************************************** +** +** Copyright (C) 2012 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 +#include "qpressuresensor_p.h" + +QTM_BEGIN_NAMESPACE + +IMPLEMENT_READING(QPressureReading) + +/*! + \class QPressureReading + \ingroup sensors_reading + \inmodule QtSensors + + \brief The QPressureReading class holds readings from the pressure sensor. + + \section2 QPressureReading Units + + The pressure sensor returns atmospheric pressure values in Pascals. +*/ + +/*! + \property QPressureReading::pressure + \brief The measured atmospheric pressure. + + Returned as Pascals. + \sa {QPressureReading Units} +*/ + +qreal QPressureReading::pressure() const +{ + return d->pressure; +} + +/*! + Sets the pressure to \a pressure. +*/ +void QPressureReading::setPressure(qreal pressure) +{ + d->pressure = pressure; +} + +// ===================================================================== + +/*! + \class QPressureFilter + \ingroup sensors_filter + \inmodule QtSensors + + \brief The QPressureFilter class is a convenience wrapper around QSensorFilter. + + The only difference is that the filter() method features a pointer to QPressureReading + instead of QSensorReading. +*/ + +/*! + \fn QPressureFilter::filter(QPressureReading *reading) + + Called when \a reading changes. Returns false to prevent the reading from propagating. + + \sa QSensorFilter::filter() +*/ + +char const * const QPressureSensor::type("QPressureSensor"); + +/*! + \class QPressureSensor + \ingroup sensors_type + \inmodule QtSensors + + \brief The QPressureSensor 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 QPressureReading instead of a QSensorReading. + + For details about how the sensor works, see \l QPressureReading. + + \sa QPressureReading +*/ + +/*! + \fn QPressureSensor::QPressureSensor(QObject *parent) + + Construct the sensor as a child of \a parent. +*/ +QPressureSensor::QPressureSensor(QObject *parent) + : QSensor(QPressureSensor::type, parent) +{ +} + +/*! + \fn QPressureSensor::~QPressureSensor() + + Destroy the sensor. Stops the sensor if it has not already been stopped. +*/ +QPressureSensor::~QPressureSensor() +{ +} + +/*! + \fn QPressureSensor::reading() const + + Returns the reading class for this sensor. + + \sa QSensor::reading() +*/ + +#include "moc_qpressuresensor.cpp" +QTM_END_NAMESPACE diff --git a/src/sensors/qpressuresensor.h b/src/sensors/qpressuresensor.h new file mode 100644 index 0000000000..8c917f9370 --- /dev/null +++ b/src/sensors/qpressuresensor.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2012 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 QPRESSURESENSOR_H +#define QPRESSURESENSOR_H + +#include + +QTM_BEGIN_NAMESPACE + +class QPressureReadingPrivate; + +class Q_SENSORS_EXPORT QPressureReading : public QSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal pressure READ pressure) + DECLARE_READING(QPressureReading) +public: + qreal pressure() const; + void setPressure(qreal pressure); +}; + +class Q_SENSORS_EXPORT QPressureFilter : public QSensorFilter +{ +public: + virtual bool filter(QPressureReading *reading) = 0; +private: + bool filter(QSensorReading *reading) + { return filter(static_cast(reading)); } +}; + +class Q_SENSORS_EXPORT QPressureSensor : public QSensor +{ + Q_OBJECT +public: + explicit QPressureSensor(QObject *parent = 0); + virtual ~QPressureSensor(); + QPressureReading *reading() const { return static_cast(QSensor::reading()); } + static char const * const type; +}; + +QTM_END_NAMESPACE + +#endif diff --git a/src/sensors/qpressuresensor_p.h b/src/sensors/qpressuresensor_p.h new file mode 100644 index 0000000000..790e0d53dd --- /dev/null +++ b/src/sensors/qpressuresensor_p.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2012 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 QPRESSURESENSOR_P_H +#define QPRESSURESENSOR_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 QPressureReadingPrivate +{ +public: + QPressureReadingPrivate() + : pressure(0) + { + } + + qreal pressure; +}; + +QTM_END_NAMESPACE + +#endif diff --git a/src/sensors/sensors.pro b/src/sensors/sensors.pro index 3c16db72bf..f9f587991b 100644 --- a/src/sensors/sensors.pro +++ b/src/sensors/sensors.pro @@ -52,9 +52,11 @@ SENSORS=\ qaccelerometer\ qambientlightsensor\ qcompass\ + qholstersensor\ qlightsensor\ qmagnetometer\ qorientationsensor\ + qpressuresensor\ qproximitysensor\ qrotationsensor\ qtapsensor\ -- cgit v1.2.3