summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTamas Martinec <tamas.martinec@symbio.com>2021-10-08 12:25:13 +0300
committerRym Bouabid <rym.bouabid@qt.io>2023-10-31 11:02:07 +0100
commitf5eae761742c9099b9a8226c11559e61fc63de15 (patch)
tree8e883edbc271d8c7a446309e4a0c6a513e23bf17
parent81cd71ffe6d7ecf832376006aee8eb72d83cfa69 (diff)
QtSensors: Expose QSensor::isFeatureSupported to QML
Checking if a specific feature is supported by the backend is now available from QML. [ChangeLog][QmlSensor] Add QmlSensor::isFeatureSupported(). Fixes: QTBUG-97273 Change-Id: I0ec71fa51c792afc4b6b6191b85910095d2b87a2 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
-rw-r--r--src/sensorsquick/qmlsensor.cpp15
-rw-r--r--src/sensorsquick/qmlsensor_p.h17
-rw-r--r--tests/auto/common/test_backends.h6
-rw-r--r--tests/auto/qml/qml_quick/tst_sensors_basic.qml22
4 files changed, 60 insertions, 0 deletions
diff --git a/src/sensorsquick/qmlsensor.cpp b/src/sensorsquick/qmlsensor.cpp
index 1e375415..d507e919 100644
--- a/src/sensorsquick/qmlsensor.cpp
+++ b/src/sensorsquick/qmlsensor.cpp
@@ -277,6 +277,21 @@ QBindable<QmlSensorReading*> QmlSensor::bindableReading() const
}
/*!
+ \qmlmethod bool Sensor::isFeatureSupported(feature)
+ \since QtSensors 6.7
+ Checks if a specific feature is supported by the backend.
+ Returns \c true if the \a feature is supported, and \c false otherwise.
+ For feature descriptions see \l {QSensor::Feature}.
+
+ Please see QSensor::isFeatureSupported for information.
+*/
+
+bool QmlSensor::isFeatureSupported(Feature feature) const
+{
+ return sensor()->isFeatureSupported(static_cast<QSensor::Feature>(feature));
+}
+
+/*!
\qmlproperty Sensor::AxesOrientationMode Sensor::axesOrientationMode
\since QtSensors 5.1
This property holds the mode that affects how the screen orientation changes reading values.
diff --git a/src/sensorsquick/qmlsensor_p.h b/src/sensorsquick/qmlsensor_p.h
index 6e1460a4..0c0a9527 100644
--- a/src/sensorsquick/qmlsensor_p.h
+++ b/src/sensorsquick/qmlsensor_p.h
@@ -22,6 +22,8 @@
#include <QQmlParserStatus>
#include <QtQml/qqml.h>
#include <QQmlListProperty>
+#include <QtSensors/QSensor>
+
#include "qmlsensorrange_p.h"
QT_BEGIN_NAMESPACE
@@ -62,6 +64,19 @@ class Q_SENSORSQUICK_PRIVATE_EXPORT QmlSensor : public QObject, public QQmlParse
QML_UNCREATABLE("Cannot create Sensor")
QML_ADDED_IN_VERSION(5,0)
public:
+ // Keep in sync with QSensor::Feature
+ enum Feature {
+ Buffering = QSensor::Buffering,
+ AlwaysOn = QSensor::AlwaysOn,
+ GeoValues = QSensor::GeoValues,
+ FieldOfView = QSensor::FieldOfView,
+ AccelerationMode = QSensor::AccelerationMode,
+ SkipDuplicates = QSensor::SkipDuplicates,
+ AxesOrientation = QSensor::AxesOrientation,
+ PressureSensorTemperature = QSensor::PressureSensorTemperature
+ };
+ Q_ENUM(Feature)
+
// Keep in sync with QSensor::AxesOrientationMode
enum AxesOrientationMode {
FixedOrientation,
@@ -105,6 +120,8 @@ public:
QmlSensorReading *reading() const;
QBindable<QmlSensorReading*> bindableReading() const;
+ Q_INVOKABLE bool isFeatureSupported(Feature feature) const;
+
AxesOrientationMode axesOrientationMode() const;
void setAxesOrientationMode(AxesOrientationMode axesOrientationMode);
diff --git a/tests/auto/common/test_backends.h b/tests/auto/common/test_backends.h
index 1aff64e5..95d93e6c 100644
--- a/tests/auto/common/test_backends.h
+++ b/tests/auto/common/test_backends.h
@@ -36,6 +36,7 @@ void set_test_backend_busy(QSensor* sensor, bool busy);
SensorClass ## _impl(QSensor *sensor);\
void start() override;\
void stop() override;\
+ bool isFeatureSupported(QSensor::Feature feature) const override;\
};\
class SensorClass ## _testfilter : public FilterClass { bool filter(ReadingClass *) override; };
@@ -47,6 +48,11 @@ void set_test_backend_busy(QSensor* sensor, bool busy);
newReadingAvailable();\
}\
void SensorClass ##_impl::stop() {}\
+ bool SensorClass ##_impl::isFeatureSupported(QSensor::Feature feature) const { \
+ if (feature == QSensor::Feature::SkipDuplicates) \
+ return true; \
+ return false; \
+ } \
bool SensorClass ## _testfilter::filter(ReadingClass *) { return true; }\
static QSensorBackend *create_ ## SensorClass ## _impl(QSensor *sensor) { return new SensorClass ## _impl(sensor); }\
static bool registered_ ## SensorClass = registerTestBackend(#SensorClass, create_ ## SensorClass ## _impl);
diff --git a/tests/auto/qml/qml_quick/tst_sensors_basic.qml b/tests/auto/qml/qml_quick/tst_sensors_basic.qml
index 687382ee..38bde570 100644
--- a/tests/auto/qml/qml_quick/tst_sensors_basic.qml
+++ b/tests/auto/qml/qml_quick/tst_sensors_basic.qml
@@ -201,4 +201,26 @@ TestCase {
{tag: "IRProximitySensor", initialReading: {reflectance: 0.5}, newReading: {reflectance: 0.6}}
];
}
+
+ function test_SupportedFeatures()
+ {
+ var sensor = Qt.createQmlObject("import QtSensors; Accelerometer \
+ {identifier: \"QAccelerometer\"}",
+ testCase);
+ verify(sensor.start())
+ verify(sensor.connectedToBackend)
+
+ // According to isFeatureSupported() override implementation in test_backends.h,
+ // only SkipDuplicates should be supported afterwards
+ verify(!sensor.isFeatureSupported(Sensor.Buffering))
+ verify(!sensor.isFeatureSupported(Sensor.AlwaysOn))
+ verify(!sensor.isFeatureSupported(Sensor.GeoValues))
+ verify(!sensor.isFeatureSupported(Sensor.FieldOfView))
+ verify(!sensor.isFeatureSupported(Sensor.AccelerationMode))
+ verify(sensor.isFeatureSupported(Sensor.SkipDuplicates))
+ verify(!sensor.isFeatureSupported(Sensor.AxesOrientation))
+ verify(!sensor.isFeatureSupported(Sensor.PressureSensorTemperature))
+
+ sensor.destroy()
+ }
}