summaryrefslogtreecommitdiffstats
path: root/examples/sensors/sensorsshowcase/sensorsupport.h
diff options
context:
space:
mode:
Diffstat (limited to 'examples/sensors/sensorsshowcase/sensorsupport.h')
-rw-r--r--examples/sensors/sensorsshowcase/sensorsupport.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/examples/sensors/sensorsshowcase/sensorsupport.h b/examples/sensors/sensorsshowcase/sensorsupport.h
new file mode 100644
index 00000000..915157f8
--- /dev/null
+++ b/examples/sensors/sensorsshowcase/sensorsupport.h
@@ -0,0 +1,41 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#ifndef SENSORSUPPORT_H
+#define SENSORSUPPORT_H
+
+#include <QObject>
+#include <QtQmlIntegration>
+#include <QtSensors/QtSensors>
+
+class SensorSupport : public QObject
+{
+ Q_OBJECT
+ QML_ELEMENT
+ QML_SINGLETON
+ QML_UNCREATABLE("SensorSupport is a utility class")
+public:
+ explicit SensorSupport(QObject *parent = nullptr) : QObject(parent) { }
+
+ Q_INVOKABLE static bool hasAccelerometer()
+ {
+ return !QSensor::sensorsForType(QAccelerometer::sensorType).empty();
+ }
+ Q_INVOKABLE static bool hasCompass()
+ {
+ return !QSensor::sensorsForType(QCompass::sensorType).empty();
+ }
+ Q_INVOKABLE static bool hasGyroscope()
+ {
+ return !QSensor::sensorsForType(QGyroscope::sensorType).empty();
+ }
+ Q_INVOKABLE static bool hasMagnetometer()
+ {
+ return !QSensor::sensorsForType(QMagnetometer::sensorType).empty();
+ }
+ Q_INVOKABLE static bool hasProximity()
+ {
+ return !QSensor::sensorsForType(QProximitySensor::sensorType).empty();
+ }
+};
+
+#endif // SENSORSUPPORT_H