diff options
-rw-r--r-- | .qmake.conf | 2 | ||||
-rw-r--r-- | dist/changes-5.12.10 | 28 | ||||
-rw-r--r-- | dist/changes-5.12.6 | 20 | ||||
-rw-r--r-- | dist/changes-5.12.7 | 20 | ||||
-rw-r--r-- | dist/changes-5.12.8 | 20 | ||||
-rw-r--r-- | dist/changes-5.12.9 | 20 | ||||
-rw-r--r-- | src/imports/sensors/qmlsensor.cpp | 81 | ||||
-rw-r--r-- | src/imports/sensors/qmlsensor.h | 3 | ||||
-rw-r--r-- | src/imports/sensors/sensors.pro | 2 | ||||
-rw-r--r-- | tests/auto/sensors2qmlapi/sensors2qmlapi.pro | 4 | ||||
-rw-r--r-- | tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp | 113 |
11 files changed, 286 insertions, 27 deletions
diff --git a/.qmake.conf b/.qmake.conf index 2e1d6b7f..912747cb 100644 --- a/.qmake.conf +++ b/.qmake.conf @@ -1,3 +1,3 @@ load(qt_build_config) -MODULE_VERSION = 5.12.6 +MODULE_VERSION = 5.12.12 diff --git a/dist/changes-5.12.10 b/dist/changes-5.12.10 new file mode 100644 index 00000000..c9b97b2a --- /dev/null +++ b/dist/changes-5.12.10 @@ -0,0 +1,28 @@ +Qt 5.12.10 is a bug-fix release. It maintains both forward and backward +compatibility (source and binary) with Qt 5.12.9. + +For more details, refer to the online documentation included in this +distribution. The documentation is also available online: + + https://doc.qt.io/qt-5.12/index.html + +The Qt version 5.12 series is binary compatible with the 5.11.x series. +Applications compiled for 5.11 will continue to run with 5.12. + +Some of the changes listed in this file include issue tracking numbers +corresponding to tasks in the Qt Bug Tracker: + + https://bugreports.qt.io/ + +Each of these identifiers can be entered in the bug tracker to obtain more +information about a particular change. + +**************************************************************************** +* Important Behavior Changes * +**************************************************************************** + +**************************************************************************** +* Library * +**************************************************************************** + + diff --git a/dist/changes-5.12.6 b/dist/changes-5.12.6 new file mode 100644 index 00000000..ad5098e3 --- /dev/null +++ b/dist/changes-5.12.6 @@ -0,0 +1,20 @@ +Qt 5.12.6 is a bug-fix release. It maintains both forward and backward +compatibility (source and binary) with Qt 5.12.0 through 5.12.5. + +For more details, refer to the online documentation included in this +distribution. The documentation is also available online: + +https://doc.qt.io/qt-5/index.html + +The Qt version 5.12 series is binary compatible with the 5.11.x series. +Applications compiled for 5.11 will continue to run with 5.12. + +Some of the changes listed in this file include issue tracking numbers +corresponding to tasks in the Qt Bug Tracker: + +https://bugreports.qt.io/ + +Each of these identifiers can be entered in the bug tracker to obtain more +information about a particular change. + + - This release contains only minor code improvements. diff --git a/dist/changes-5.12.7 b/dist/changes-5.12.7 new file mode 100644 index 00000000..c9716139 --- /dev/null +++ b/dist/changes-5.12.7 @@ -0,0 +1,20 @@ +Qt 5.12.7 is a bug-fix release. It maintains both forward and backward +compatibility (source and binary) with Qt 5.12.0 through 5.12.6. + +For more details, refer to the online documentation included in this +distribution. The documentation is also available online: + +https://doc.qt.io/qt-5/index.html + +The Qt version 5.12 series is binary compatible with the 5.11.x series. +Applications compiled for 5.11 will continue to run with 5.12. + +Some of the changes listed in this file include issue tracking numbers +corresponding to tasks in the Qt Bug Tracker: + +https://bugreports.qt.io/ + +Each of these identifiers can be entered in the bug tracker to obtain more +information about a particular change. + + - This release contains only minor code improvements. diff --git a/dist/changes-5.12.8 b/dist/changes-5.12.8 new file mode 100644 index 00000000..729d7404 --- /dev/null +++ b/dist/changes-5.12.8 @@ -0,0 +1,20 @@ +Qt 5.12.8 is a bug-fix release. It maintains both forward and backward +compatibility (source and binary) with Qt 5.12.0 through 5.12.7. + +For more details, refer to the online documentation included in this +distribution. The documentation is also available online: + +https://doc.qt.io/qt-5/index.html + +The Qt version 5.12 series is binary compatible with the 5.11.x series. +Applications compiled for 5.11 will continue to run with 5.12. + +Some of the changes listed in this file include issue tracking numbers +corresponding to tasks in the Qt Bug Tracker: + +https://bugreports.qt.io/ + +Each of these identifiers can be entered in the bug tracker to obtain more +information about a particular change. + + - This release contains only minor code improvements. diff --git a/dist/changes-5.12.9 b/dist/changes-5.12.9 new file mode 100644 index 00000000..d3d50ba6 --- /dev/null +++ b/dist/changes-5.12.9 @@ -0,0 +1,20 @@ +Qt 5.12.9 is a bug-fix release. It maintains both forward and backward +compatibility (source and binary) with Qt 5.12.0 through 5.12.8. + +For more details, refer to the online documentation included in this +distribution. The documentation is also available online: + +https://doc.qt.io/qt-5/index.html + +The Qt version 5.12 series is binary compatible with the 5.11.x series. +Applications compiled for 5.11 will continue to run with 5.12. + +Some of the changes listed in this file include issue tracking numbers +corresponding to tasks in the Qt Bug Tracker: + +https://bugreports.qt.io/ + +Each of these identifiers can be entered in the bug tracker to obtain more +information about a particular change. + + - This release contains only minor code improvements. diff --git a/src/imports/sensors/qmlsensor.cpp b/src/imports/sensors/qmlsensor.cpp index 84eea6f7..e0a6958d 100644 --- a/src/imports/sensors/qmlsensor.cpp +++ b/src/imports/sensors/qmlsensor.cpp @@ -40,9 +40,39 @@ #include "qmlsensor.h" #include <QtSensors/QSensor> #include <QDebug> +#include <QtCore/private/qobject_p.h> QT_BEGIN_NAMESPACE +class QmlSensorPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QmlSensor) +public: + + QList<QmlSensorRange *> availableRanges; + QList<QmlSensorOutputRange *> outputRanges; +}; + +template<typename Item> +int readonlyListCount(QQmlListProperty<Item> *p) +{ + return static_cast<const QList<Item *> *>(p->data)->count(); +} + +template<typename Item> +Item *readonlyListAt(QQmlListProperty<Item> *p, int idx) +{ + return static_cast<const QList<Item *> *>(p->data)->at(idx); +}; + +template<typename Item> +QQmlListProperty<Item> readonlyListProperty(const QObject *o, const QList<Item *> *list) +{ + // Unfortunately QQmlListProperty won't accept a const object, even on the readonly ctor. + return QQmlListProperty<Item>(const_cast<QObject *>(o), const_cast<QList<Item *> *>(list), + readonlyListCount<Item>, readonlyListAt<Item>); +} + /*! \qmltype Sensor \instantiates QmlSensor @@ -59,7 +89,7 @@ QT_BEGIN_NAMESPACE */ QmlSensor::QmlSensor(QObject *parent) - : QObject(parent) + : QObject(*(new QmlSensorPrivate), parent) , m_parsed(false) , m_active(false) , m_reading(0) @@ -193,19 +223,10 @@ void QmlSensor::setSkipDuplicates(bool skipDuplicates) Please see QSensor::availableDataRates for information about this property. */ - QQmlListProperty<QmlSensorRange> QmlSensor::availableDataRates() const { - QList<QmlSensorRange*> ret; - ret.reserve(sensor()->availableDataRates().size()); - foreach (const qrange &r, sensor()->availableDataRates()) { - QmlSensorRange *range = new QmlSensorRange; - //QQmlEngine::setObjectOwnership(range, QQmlEngine::JavaScriptOwnership); - range->setMinumum(r.first); - range->setMaximum(r.second); - ret << range; - } - return QQmlListProperty<QmlSensorRange>(const_cast<QmlSensor*>(this), ret); + Q_D(const QmlSensor); + return readonlyListProperty<QmlSensorRange>(this, &d->availableRanges); } /*! @@ -237,17 +258,8 @@ void QmlSensor::setDataRate(int rate) QQmlListProperty<QmlSensorOutputRange> QmlSensor::outputRanges() const { - QList<QmlSensorOutputRange*> ret; - ret.reserve(sensor()->outputRanges().size()); - foreach (const qoutputrange &r, sensor()->outputRanges()) { - QmlSensorOutputRange *range = new QmlSensorOutputRange; - //QQmlEngine::setObjectOwnership(range, QQmlEngine::JavaScriptOwnership); - range->setMinimum(r.minimum); - range->setMaximum(r.maximum); - range->setAccuracy(r.accuracy); - ret << range; - } - return QQmlListProperty<QmlSensorOutputRange>(const_cast<QmlSensor*>(this), ret); + Q_D(const QmlSensor); + return readonlyListProperty<QmlSensorOutputRange>(this, &d->outputRanges); } /*! @@ -466,12 +478,31 @@ void QmlSensor::componentComplete() if (oldOutputRange != outputRange()) Q_EMIT outputRangeChanged(); + Q_D(QmlSensor); + const auto available = sensor()->availableDataRates(); + d->availableRanges.reserve(available.size()); + for (const qrange &r : available) { + auto *range = new QmlSensorRange(this); + range->setMinumum(r.first); + range->setMaximum(r.second); + d->availableRanges.append(range); + } + const auto output = sensor()->outputRanges(); + d->outputRanges.reserve(output.size()); + for (const qoutputrange &r : output) { + auto *range = new QmlSensorOutputRange(this); + range->setMinimum(r.minimum); + range->setMaximum(r.maximum); + range->setAccuracy(r.accuracy); + d->outputRanges.append(range); + } + // meta-data should become non-empty if (!description().isEmpty()) Q_EMIT descriptionChanged(); - if (sensor()->availableDataRates().count()) + if (available.count()) Q_EMIT availableDataRatesChanged(); - if (sensor()->outputRanges().count()) + if (output.count()) Q_EMIT outputRangesChanged(); _update(); diff --git a/src/imports/sensors/qmlsensor.h b/src/imports/sensors/qmlsensor.h index e46278b2..3ac82699 100644 --- a/src/imports/sensors/qmlsensor.h +++ b/src/imports/sensors/qmlsensor.h @@ -40,6 +40,7 @@ #ifndef QMLSENSOR_H #define QMLSENSOR_H +#include <QObject> #include <QQmlParserStatus> #include <QQmlListProperty> #include "qmlsensorrange.h" @@ -51,9 +52,11 @@ class QSensorReading; class QmlSensorReading; +class QmlSensorPrivate; class QmlSensor : public QObject, public QQmlParserStatus { Q_OBJECT + Q_DECLARE_PRIVATE(QmlSensor) Q_ENUMS(AxesOrientationMode) Q_INTERFACES(QQmlParserStatus) Q_PROPERTY(QString identifier READ identifier WRITE setIdentifier NOTIFY identifierChanged) diff --git a/src/imports/sensors/sensors.pro b/src/imports/sensors/sensors.pro index d6279168..7d15ec9f 100644 --- a/src/imports/sensors/sensors.pro +++ b/src/imports/sensors/sensors.pro @@ -1,4 +1,4 @@ -QT += qml sensors sensors-private +QT += core-private qml sensors sensors-private HEADERS += \ qmlsensor.h \ diff --git a/tests/auto/sensors2qmlapi/sensors2qmlapi.pro b/tests/auto/sensors2qmlapi/sensors2qmlapi.pro index 3d5e2377..74388660 100644 --- a/tests/auto/sensors2qmlapi/sensors2qmlapi.pro +++ b/tests/auto/sensors2qmlapi/sensors2qmlapi.pro @@ -5,12 +5,16 @@ CONFIG += testcase QT = core testlib sensors-private qml SOURCES += tst_sensors2qmlapi.cpp \ + ./../../../src/imports/sensors/qmlsensor.cpp \ ./../../../src/imports/sensors/qmlsensorgesture.cpp \ + ./../../../src/imports/sensors/qmlsensorrange.cpp \ qtemplategestureplugin.cpp \ qtemplaterecognizer.cpp HEADERS += \ + ./../../../src/imports/sensors/qmlsensor.h \ ./../../../src/imports/sensors/qmlsensorgesture.h \ + ./../../../src/imports/sensors/qmlsensorrange.h \ qtemplategestureplugin.h \ qtemplaterecognizer.h diff --git a/tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp b/tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp index d0074146..51007fcb 100644 --- a/tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp +++ b/tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp @@ -29,10 +29,14 @@ #include <QtTest/QtTest> #include <QtTest/QSignalSpy> #include <QtCore/QDebug> + +#include "../../../src/imports/sensors/qmlsensor.h" #include "../../../src/imports/sensors/qmlsensorgesture.h" + #include "qtemplategestureplugin.h" #include "qtemplaterecognizer.h" #include <qsensorgesturemanager.h> +#include <qsensorbackend.h> #include "qsensormanager.h" QT_USE_NAMESPACE @@ -46,6 +50,7 @@ class tst_Sensors2QMLAPI : public QObject private slots: void initTestCase(); void testGesture(); + void testSensorRanges(); }; void tst_Sensors2QMLAPI::initTestCase() @@ -169,6 +174,114 @@ void tst_Sensors2QMLAPI::testGesture() QCOMPARE(spy2_detected.count(), 1); } +class QDummySensorBackend : public QSensorBackend +{ + Q_OBJECT +public: + QDummySensorBackend(QSensor *sensor) : QSensorBackend(sensor) + { + addDataRate(2, 3); + addDataRate(5, 7); + addOutputRange(100, 200, 1); + addOutputRange(600, 700, 10); + addOutputRange(0, 1, 2); + } + + void start() override {} + void stop() override {} +}; + +class QDummySensorReading : public QSensorReading +{ + Q_OBJECT +public: + QDummySensorReading(QObject *parent) : QSensorReading(parent, nullptr) {} +}; + +class QmlDummySensorReading : public QmlSensorReading +{ + Q_OBJECT +public: + QmlDummySensorReading(QSensor *sensor) : + QmlSensorReading(sensor), + m_reading(new QDummySensorReading(this)) + {} + + QSensorReading *reading() const override { return m_reading; } + void readingUpdate() override {} + +private: + QSensorReading *m_reading = nullptr; +}; + +class QmlDummySensor : public QmlSensor +{ + Q_OBJECT +public: + QmlDummySensor(QObject *parent = nullptr) : + QmlSensor(parent), + m_sensor(new QSensor("dummy", this)) + { + QDummySensorBackend b(m_sensor); + Q_UNUSED(b); + } + + QSensor *sensor() const override { return m_sensor; } + QmlSensorReading *createReading() const override { return new QmlDummySensorReading(m_sensor); } + + void componentComplete() override { QmlSensor::componentComplete(); } + +private: + QSensor *m_sensor = nullptr; +}; + +void tst_Sensors2QMLAPI::testSensorRanges() +{ + QScopedPointer<QmlDummySensor> qmlSensor(new QmlDummySensor); + qmlSensor->componentComplete(); + + auto ranges = qmlSensor->availableDataRates(); + QCOMPARE(ranges.count(&ranges), 2); + + const auto range0 = ranges.at(&ranges, 0); + QCOMPARE(range0->minimum(), 2); + QCOMPARE(range0->maximum(), 3); + QSignalSpy range0Spy(range0, SIGNAL(destroyed())); + + const auto range1 = ranges.at(&ranges, 1); + QCOMPARE(range1->minimum(), 5); + QCOMPARE(range1->maximum(), 7); + QSignalSpy range1Spy(range1, SIGNAL(destroyed())); + + auto outputs = qmlSensor->outputRanges(); + QCOMPARE(outputs.count(&outputs), 3); + + const auto output0 = outputs.at(&outputs, 0); + QCOMPARE(output0->minimum(), 100); + QCOMPARE(output0->maximum(), 200); + QCOMPARE(output0->accuracy(), 1); + QSignalSpy output0Spy(output0, SIGNAL(destroyed())); + + const auto output1 = outputs.at(&outputs, 1); + QCOMPARE(output1->minimum(), 600); + QCOMPARE(output1->maximum(), 700); + QCOMPARE(output1->accuracy(), 10); + QSignalSpy output1Spy(output1, SIGNAL(destroyed())); + + const auto output2 = outputs.at(&outputs, 2); + QCOMPARE(output2->minimum(), 0); + QCOMPARE(output2->maximum(), 1); + QCOMPARE(output2->accuracy(), 2); + QSignalSpy output2Spy(output2, SIGNAL(destroyed())); + + qmlSensor.reset(); + QCOMPARE(range0Spy.count(), 1); + QCOMPARE(range1Spy.count(), 1); + QCOMPARE(output0Spy.count(), 1); + QCOMPARE(output1Spy.count(), 1); + QCOMPARE(output2Spy.count(), 1); +} + QT_END_NAMESPACE QTEST_MAIN(tst_Sensors2QMLAPI) |