diff options
author | Thomas McGuire <thomas.mcguire.qnx@kdab.com> | 2013-01-29 15:01:40 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-02-08 11:18:01 +0100 |
commit | 4d9edb754b3dff3331c8d8790a04548f0981f315 (patch) | |
tree | c5d96c9f8136c16b05323fb4e0841201af1c4ea4 /src/sensors | |
parent | 62ce0b92ee34a1ae6b2f4e81bb0efbaa2a7d53c9 (diff) | |
download | qtsensors-4d9edb754b3dff3331c8d8790a04548f0981f315.tar.gz |
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.
Change-Id: I5239ba2a4b791cfc9f684b44ff2bc103a7b5b0da
Reviewed-by: Lorn Potter <lorn.potter@jollamobile.com>
Diffstat (limited to 'src/sensors')
-rw-r--r-- | src/sensors/qsensor.cpp | 72 | ||||
-rw-r--r-- | src/sensors/qsensor.h | 20 | ||||
-rw-r--r-- | src/sensors/qsensor_p.h | 7 |
3 files changed, 86 insertions, 13 deletions
diff --git a/src/sensors/qsensor.cpp b/src/sensors/qsensor.cpp index 125d592..01a4f7b 100644 --- a/src/sensors/qsensor.cpp +++ b/src/sensors/qsensor.cpp @@ -1016,11 +1016,33 @@ void QSensor::setUserOrientation(int userOrientation) 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. + In that case, isFeatureSupported(QSensor::Buffering) will also return false. \sa QSensor::bufferSize, QSensor::efficientBufferSize */ +int QSensor::maxBufferSize() const +{ + Q_D(const QSensor); + return d->maxBufferSize; +} + +/*! + \since 5.1 + Sets the maximum buffer size to \a maxBufferSize. This is to be called from the + backend. +*/ +void QSensor::setMaxBufferSize(int maxBufferSize) +{ + // ### Qt 6: Remove the entire maxBufferSize property, no backend really uses it + Q_D(QSensor); + if (d->maxBufferSize != maxBufferSize) { + d->maxBufferSize = maxBufferSize; + emit maxBufferSizeChanged(maxBufferSize); + } +} + /*! \property QSensor::efficientBufferSize @@ -1028,17 +1050,36 @@ void QSensor::setUserOrientation(int userOrientation) 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 +{ + Q_D(const QSensor); + return d->efficientBufferSize; +} + +/*! + \since 5.1 + Sets the efficient buffer size to \a efficientBufferSize. This is to be called from the + backend. +*/ +void QSensor::setEfficientBufferSize(int efficientBufferSize) +{ + // ### Qt 6: Remove the entire efficientBufferSize property, no backend really uses it + Q_D(QSensor); + 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. @@ -1065,11 +1106,26 @@ void QSensor::setUserOrientation(int userOrientation) 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 +{ + Q_D(const QSensor); + return d->bufferSize; +} + +void QSensor::setBufferSize(int bufferSize) +{ + // ### Qt 6: Currently only the Blackberry backend supports this, but only as an on/off switch. + // We should consider changing this to a more appropriate API. + Q_D(QSensor); + if (d->bufferSize != bufferSize) { + d->bufferSize = bufferSize; + emit bufferSizeChanged(bufferSize); + } +} + // ===================================================================== /*! diff --git a/src/sensors/qsensor.h b/src/sensors/qsensor.h index 5c47df3..2314fb9 100644 --- a/src/sensors/qsensor.h +++ b/src/sensors/qsensor.h @@ -95,11 +95,9 @@ class Q_SENSORS_EXPORT QSensor : public QObject Q_PROPERTY(AxesOrientationMode axesOrientationMode READ axesOrientationMode WRITE setAxesOrientationMode NOTIFY axesOrientationModeChanged) Q_PROPERTY(int currentOrientation READ currentOrientation NOTIFY currentOrientationChanged) Q_PROPERTY(int userOrientation READ userOrientation WRITE setUserOrientation NOTIFY userOrientationChanged) -#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: enum Feature { Buffering, @@ -177,6 +175,15 @@ public: int userOrientation() const; void setUserOrientation(int userOrientation); + 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(); @@ -196,6 +203,9 @@ Q_SIGNALS: void axesOrientationModeChanged(AxesOrientationMode axesOrientationMode); void currentOrientationChanged(int currentOrientation); void userOrientationChanged(int userOrientation); + void maxBufferSizeChanged(int maxBufferSize); + void efficientBufferSizeChanged(int efficientBufferSize); + void bufferSizeChanged(int bufferSize); protected: explicit QSensor(const QByteArray &type, QSensorPrivate &dd, QObject* parent = 0); diff --git a/src/sensors/qsensor_p.h b/src/sensors/qsensor_p.h index 9b6e7e5..71a5b6e 100644 --- a/src/sensors/qsensor_p.h +++ b/src/sensors/qsensor_p.h @@ -82,6 +82,9 @@ public: , axesOrientationMode(QSensor::FixedOrientation) , currentOrientation(0) , userOrientation(0) + , bufferSize(1) + , maxBufferSize(1) + , efficientBufferSize(1) { } @@ -116,6 +119,10 @@ public: QSensor::AxesOrientationMode axesOrientationMode; int currentOrientation; int userOrientation; + + int bufferSize; + int maxBufferSize; + int efficientBufferSize; }; class QSensorReadingPrivate |