From 505dbc8230414a31cd3def9f2d8b144b0e9444f4 Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Mon, 9 Jul 2012 10:54:25 +0200 Subject: Add QSensor::isFeatureSupported() Now it is possible to check if a backend supports a specific feature. During reviews of features like acceleration mode or duplicate skipping, the issue was raised how to check if these features are actually supported. The same is true for existing features like QMagnetometer::returnGeoValues. Change-Id: I47115d6c487bbcbb668a9021cdc7085e6780a67c Reviewed-by: Marc Mutz Reviewed-by: Lorn Potter --- src/sensors/qsensor.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'src/sensors/qsensor.cpp') diff --git a/src/sensors/qsensor.cpp b/src/sensors/qsensor.cpp index be0c7862..9d41dbf7 100644 --- a/src/sensors/qsensor.cpp +++ b/src/sensors/qsensor.cpp @@ -178,6 +178,33 @@ void QSensorPrivate::init(const QByteArray &sensorType) \sa QSensorReading */ +/*! + \enum QSensor::Feature + \brief Lists optional features a backend might support. + + The features common to all sensor types are: + + \value Buffering The backend supports buffering of readings, controlled by the + QSensor::bufferSize property. + \value AlwaysOn The backend supports changing the policy on whether to suspend when idle, + controlled by the QSensor::alwaysOn property. + + The features of QMagnetometer are: + + \value GeoValues The backend supports returning geo values, which can be + controlled with the QMagnetometer::returnGeoValues property. + + The features of QLightSensor are: + + \value FieldOfView The backend specifies its field of view, which can be + read from the QLightSensor::fieldOfView property. + + \omitvalue Reserved + + \sa QSensor::isFeatureSupported() + \since 5.0 +*/ + /*! Construct the \a type sensor as a child of \a parent. */ @@ -470,6 +497,28 @@ void QSensor::setDataRate(int rate) } } +/*! + Checks if a specific feature is supported by the backend. + + QtSensors supports a rich API for controlling and providing information about sensors. Naturally, + not all of this functionality can be supported by all of the backends. + + To check if the current backend supports the feature \a feature, call this function. + + The backend needs to be connected, otherwise false will be returned. Calling connectToBackend() + or start() will create a connection to the backend. + + Backends have to implement QSensorBackend::isFeatureSupported() to make this work. + + \return whether or not the feature is supported if the backend is connected, or false if the backend is not connected. + \since 5.0 + */ +bool QSensor::isFeatureSupported(Feature feature) const +{ + Q_D(const QSensor); + return d->backend && d->backend->isFeatureSupported(feature); +} + /*! Start retrieving values from the sensor. Returns true if the sensor was started, false otherwise. -- cgit v1.2.3