diff options
Diffstat (limited to 'src/sensorsquick/qmlsensorglobal.cpp')
-rw-r--r-- | src/sensorsquick/qmlsensorglobal.cpp | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/sensorsquick/qmlsensorglobal.cpp b/src/sensorsquick/qmlsensorglobal.cpp new file mode 100644 index 00000000..73f865c4 --- /dev/null +++ b/src/sensorsquick/qmlsensorglobal.cpp @@ -0,0 +1,86 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#include "qmlsensorglobal_p.h" +#include <QtSensors/QSensor> + +QT_BEGIN_NAMESPACE + +/*! + \qmltype QmlSensors +//! \instantiates QmlSensorGlobal + \inqmlmodule QtSensors + \since QtSensors 5.0 + \brief The QmlSensors singleton provides the module API. + + The QmlSensors singleton provides the module API. + + This element cannot be directly created, but its functionality + can be accessed as a QML singleton as illustrated below: + + \code + import QtSensors + import QtSensors as Sensors + ... + Component.onCompleted: { + var types = Sensors.QmlSensors.sensorTypes(); + console.log(types.join(", ")); + } + \endcode +*/ + +QmlSensorGlobal::QmlSensorGlobal(QObject *parent) + : QObject(parent) + , m_sensor(new QSensor(QByteArray(), this)) +{ + connect(m_sensor, SIGNAL(availableSensorsChanged()), this, SIGNAL(availableSensorsChanged())); +} + +QmlSensorGlobal::~QmlSensorGlobal() +{ +} + +/*! + \qmlmethod list<string> QmlSensors::sensorTypes() + Returns a list of the sensor types that have been registered. + + Please see QSensor::sensorTypes() for information. +*/ +QStringList QmlSensorGlobal::sensorTypes() const +{ + QStringList ret; + const QList<QByteArray> sensorTypes = QSensor::sensorTypes(); + ret.reserve(sensorTypes.size()); + for (const QByteArray &type : sensorTypes) + ret << QString::fromLocal8Bit(type); + return ret; +} + +/*! + \qmlmethod list<string> QmlSensors::sensorsForType(type) + Returns a list of the sensor identifiers that have been registered for \a type. + + Please see QSensor::sensorsForType() for information. +*/ +QStringList QmlSensorGlobal::sensorsForType(const QString &type) const +{ + QStringList ret; + const QList<QByteArray> sensors = QSensor::sensorsForType(type.toLocal8Bit()); + ret.reserve(sensors.size()); + for (const QByteArray &identifier : sensors) + ret << QString::fromLocal8Bit(identifier); + return ret; +} + +/*! + \qmlmethod string QmlSensors::defaultSensorForType(type) + Returns the default sensor identifier that has been registered for \a type. + + Please see QSensor::defaultSensorForType() for information. +*/ +QString QmlSensorGlobal::defaultSensorForType(const QString &type) const +{ + return QString::fromLocal8Bit(QSensor::defaultSensorForType(type.toLocal8Bit())); +} + +QT_END_NAMESPACE |