| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #include "qmlrotationsensor_p.h" |
| 5 | #include <QtSensors/QRotationSensor> |
| 6 | |
| 7 | /*! |
| 8 | \qmltype RotationSensor |
| 9 | //! \nativetype QmlRotationSensor |
| 10 | \ingroup qml-sensors_type |
| 11 | \inqmlmodule QtSensors |
| 12 | \since QtSensors 5.0 |
| 13 | \inherits Sensor |
| 14 | \brief The RotationSensor element reports on device rotation |
| 15 | around the X, Y and Z axes. |
| 16 | |
| 17 | The RotationSensor element reports on device rotation |
| 18 | around the X, Y and Z axes. |
| 19 | |
| 20 | This element wraps the QRotationSensor class. Please see the documentation for |
| 21 | QRotationSensor for details. |
| 22 | |
| 23 | \sa RotationReading |
| 24 | */ |
| 25 | |
| 26 | QmlRotationSensor::QmlRotationSensor(QObject *parent) |
| 27 | : QmlSensor(parent) |
| 28 | , m_sensor(new QRotationSensor(this)) |
| 29 | { |
| 30 | connect(sender: m_sensor, SIGNAL(hasZChanged(bool)), receiver: this, SIGNAL(hasZChanged(bool))); |
| 31 | } |
| 32 | |
| 33 | QmlRotationSensor::~QmlRotationSensor() |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | QmlSensorReading *QmlRotationSensor::createReading() const |
| 38 | { |
| 39 | return new QmlRotationSensorReading(m_sensor); |
| 40 | } |
| 41 | |
| 42 | QSensor *QmlRotationSensor::sensor() const |
| 43 | { |
| 44 | return m_sensor; |
| 45 | } |
| 46 | |
| 47 | /*! |
| 48 | \qmlproperty bool RotationSensor::hasZ |
| 49 | This property holds a value indicating if the z angle is available. |
| 50 | |
| 51 | Please see QRotationSensor::hasZ for information about this property. |
| 52 | */ |
| 53 | |
| 54 | bool QmlRotationSensor::hasZ() const |
| 55 | { |
| 56 | return m_sensor->hasZ(); |
| 57 | } |
| 58 | |
| 59 | /*! |
| 60 | \qmltype RotationReading |
| 61 | //! \nativetype QmlRotationSensorReading |
| 62 | \ingroup qml-sensors_reading |
| 63 | \inqmlmodule QtSensors |
| 64 | \since QtSensors 5.0 |
| 65 | \inherits SensorReading |
| 66 | \brief The RotationReading element holds the most recent RotationSensor reading. |
| 67 | |
| 68 | The RotationReading element holds the most recent RotationSensor reading. |
| 69 | |
| 70 | This element wraps the QRotationReading class. Please see the documentation for |
| 71 | QRotationReading for details. |
| 72 | |
| 73 | This element cannot be directly created. |
| 74 | */ |
| 75 | |
| 76 | QmlRotationSensorReading::QmlRotationSensorReading(QRotationSensor *sensor) |
| 77 | : m_sensor(sensor) |
| 78 | { |
| 79 | } |
| 80 | |
| 81 | QmlRotationSensorReading::~QmlRotationSensorReading() |
| 82 | { |
| 83 | } |
| 84 | |
| 85 | /*! |
| 86 | \qmlproperty real RotationReading::x |
| 87 | This property holds the rotation around the x axis. |
| 88 | |
| 89 | Please see QRotationReading::x for information about this property. |
| 90 | */ |
| 91 | |
| 92 | qreal QmlRotationSensorReading::x() const |
| 93 | { |
| 94 | return m_x; |
| 95 | } |
| 96 | |
| 97 | QBindable<qreal> QmlRotationSensorReading::bindableX() const |
| 98 | { |
| 99 | return &m_x; |
| 100 | } |
| 101 | |
| 102 | /*! |
| 103 | \qmlproperty real RotationReading::y |
| 104 | This property holds the rotation around the y axis. |
| 105 | |
| 106 | Please see QRotationReading::y for information about this property. |
| 107 | */ |
| 108 | |
| 109 | qreal QmlRotationSensorReading::y() const |
| 110 | { |
| 111 | return m_y; |
| 112 | } |
| 113 | |
| 114 | QBindable<qreal> QmlRotationSensorReading::bindableY() const |
| 115 | { |
| 116 | return &m_y; |
| 117 | } |
| 118 | |
| 119 | /*! |
| 120 | \qmlproperty real RotationReading::z |
| 121 | This property holds the rotation around the z axis. |
| 122 | |
| 123 | Please see QRotationReading::z for information about this property. |
| 124 | */ |
| 125 | |
| 126 | qreal QmlRotationSensorReading::z() const |
| 127 | { |
| 128 | return m_z; |
| 129 | } |
| 130 | |
| 131 | QBindable<qreal> QmlRotationSensorReading::bindableZ() const |
| 132 | { |
| 133 | return &m_z; |
| 134 | } |
| 135 | |
| 136 | QSensorReading *QmlRotationSensorReading::reading() const |
| 137 | { |
| 138 | return m_sensor->reading(); |
| 139 | } |
| 140 | |
| 141 | void QmlRotationSensorReading::readingUpdate() |
| 142 | { |
| 143 | m_x = m_sensor->reading()->x(); |
| 144 | m_y = m_sensor->reading()->y(); |
| 145 | m_z = m_sensor->reading()->z(); |
| 146 | } |
| 147 | |