summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThomas McGuire <thomas.mcguire@kdab.com>2013-02-18 17:30:49 +0100
committerThomas McGuire <thomas.mcguire@kdab.com>2013-02-21 09:04:49 +0100
commite0d7cc1c701397ceba111be2c1155b846554eae8 (patch)
tree04844c3defb7741b89bb10bf306dd3a0c8c08e69 /src
parent536219c6066aec1ff34e5fb4976f72e39ebcfb10 (diff)
Use real properties for QSensor::bufferSize & co
The #ifdef Q_DOC hack is not really needed and was confusing. In addition, expose those properties to the QML API. As a result, the backends can now listen to the bufferSizeChanged() signal to update the buffering while the sensor is running. This has been implemented for the BlackBerry platform. This is a backport of QtSensors commit 4d9edb754b3dff3331c8d8790a04548f0981f315 Change-Id: Ia34fc1ad2e59552355f1e7d27a67000c29a9900f Reviewed-by: Bernd Weimer <bweimer@rim.com> Reviewed-by: Lorn Potter <lorn.potter@jollamobile.com>
Diffstat (limited to 'src')
-rw-r--r--src/sensors/qsensor.cpp59
-rw-r--r--src/sensors/qsensor.h20
-rw-r--r--src/sensors/qsensor_p.h8
3 files changed, 74 insertions, 13 deletions
diff --git a/src/sensors/qsensor.cpp b/src/sensors/qsensor.cpp
index 4ae9bb7ec1..fdbe9d4f61 100644
--- a/src/sensors/qsensor.cpp
+++ b/src/sensors/qsensor.cpp
@@ -796,11 +796,28 @@ int QSensor::error() const
The property holds the maximum buffer size.
- Note that this may be undefined, in which case the sensor does not support any form of buffering.
+ Note that this may be 1, in which case the sensor does not support any form of buffering.
\sa QSensor::bufferSize, QSensor::efficientBufferSize
*/
+int QSensor::maxBufferSize() const
+{
+ return d->maxBufferSize;
+}
+
+/*!
+ Sets the maximum buffer size to \a maxBufferSize. This is to be called from the
+ backend.
+*/
+void QSensor::setMaxBufferSize(int maxBufferSize)
+{
+ if (d->maxBufferSize != maxBufferSize) {
+ d->maxBufferSize = maxBufferSize;
+ emit maxBufferSizeChanged(maxBufferSize);
+ }
+}
+
/*!
\property QSensor::efficientBufferSize
@@ -808,17 +825,32 @@ int QSensor::error() const
no particular size is most efficient). Some sensor drivers have a FIFO buffer which
makes it more efficient to deliver the FIFO's size worth of readings at one time.
- Note that this may be undefined, in which case the sensor does not support any form of buffering.
-
\sa QSensor::bufferSize, QSensor::maxBufferSize
*/
+int QSensor::efficientBufferSize() const
+{
+ return d->efficientBufferSize;
+}
+
+/*!
+ Sets the efficient buffer size to \a efficientBufferSize. This is to be called from the
+ backend.
+*/
+void QSensor::setEfficientBufferSize(int efficientBufferSize)
+{
+ if (d->efficientBufferSize != efficientBufferSize) {
+ d->efficientBufferSize = efficientBufferSize;
+ emit efficientBufferSizeChanged(efficientBufferSize);
+ }
+}
+
/*!
\property QSensor::bufferSize
- This property holds the size of the buffer. By default (and if the property
- is left undefined), the buffer size is 1, which means no buffering.
- If the maximum buffer size is 1 (or undefined), then buffering is not supported
+ This property holds the size of the buffer. By default, the buffer size is 1,
+ which means no buffering.
+ If the maximum buffer size is 1, then buffering is not supported
by the sensor.
Setting bufferSize greater than maxBufferSize will cause maxBufferSize to be used.
@@ -845,11 +877,22 @@ int QSensor::error() const
in time, for example when the event loop is blocked for too long. Without a buffer, these readings
would simply be dropped.
- The buffer size can only be changed while the sensor is not active.
-
\sa QSensor::maxBufferSize, QSensor::efficientBufferSize
*/
+int QSensor::bufferSize() const
+{
+ return d->bufferSize;
+}
+
+void QSensor::setBufferSize(int bufferSize)
+{
+ if (d->bufferSize != bufferSize) {
+ d->bufferSize = bufferSize;
+ emit bufferSizeChanged(bufferSize);
+ }
+}
+
// =====================================================================
/*!
diff --git a/src/sensors/qsensor.h b/src/sensors/qsensor.h
index 1a221c55d9..8b4fe0b413 100644
--- a/src/sensors/qsensor.h
+++ b/src/sensors/qsensor.h
@@ -100,11 +100,9 @@ class Q_SENSORS_EXPORT QSensor : public QObject
Q_PROPERTY(int error READ error NOTIFY sensorError)
Q_PROPERTY(bool alwaysOn READ isAlwaysOn WRITE setAlwaysOn NOTIFY alwaysOnChanged)
Q_PROPERTY(bool skipDuplicates READ skipDuplicates WRITE setSkipDuplicates NOTIFY skipDuplicatesChanged)
-#ifdef Q_QDOC
- Q_PROPERTY(int maxBufferSize)
- Q_PROPERTY(int efficientBufferSize)
- Q_PROPERTY(int bufferSize)
-#endif
+ Q_PROPERTY(int maxBufferSize READ maxBufferSize NOTIFY maxBufferSizeChanged)
+ Q_PROPERTY(int efficientBufferSize READ efficientBufferSize NOTIFY efficientBufferSizeChanged)
+ Q_PROPERTY(int bufferSize READ bufferSize WRITE setBufferSize NOTIFY bufferSizeChanged)
public:
explicit QSensor(const QByteArray &type, QObject *parent = 0);
virtual ~QSensor();
@@ -153,6 +151,15 @@ public:
static QList<QByteArray> sensorsForType(const QByteArray &type);
static QByteArray defaultSensorForType(const QByteArray &type);
+ int maxBufferSize() const;
+ void setMaxBufferSize(int maxBufferSize);
+
+ int efficientBufferSize() const;
+ void setEfficientBufferSize(int efficientBufferSize);
+
+ int bufferSize() const;
+ void setBufferSize(int bufferSize);
+
public Q_SLOTS:
// Start receiving values from the sensor
bool start();
@@ -169,6 +176,9 @@ Q_SIGNALS:
void alwaysOnChanged();
void skipDuplicatesChanged(bool skipDuplicates);
void dataRateChanged();
+ void maxBufferSizeChanged(int maxBufferSize);
+ void efficientBufferSizeChanged(int efficientBufferSize);
+ void bufferSizeChanged(int bufferSize);
protected:
QSensor(const QByteArray &type, QSensorPrivate *dd, QObject* parent = 0);
diff --git a/src/sensors/qsensor_p.h b/src/sensors/qsensor_p.h
index 650612c15d..ca8dc0a4a8 100644
--- a/src/sensors/qsensor_p.h
+++ b/src/sensors/qsensor_p.h
@@ -76,6 +76,9 @@ public:
, error(0)
, alwaysOn(false)
, skipDuplicates(false)
+ , bufferSize(1)
+ , maxBufferSize(1)
+ , efficientBufferSize(1)
, q(sensor)
{
}
@@ -107,6 +110,11 @@ public:
bool alwaysOn;
bool skipDuplicates;
+
+ int bufferSize;
+ int maxBufferSize;
+ int efficientBufferSize;
+
QSensor *q;
};