summaryrefslogtreecommitdiffstats
path: root/examples/sensors/sensorsshowcase/sensorsupport.h
blob: 915157f852ef5fa73d30b022b10c28102cc9a054 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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