diff options
20 files changed, 217 insertions, 192 deletions
diff --git a/examples/sensors/accelbubble/accelbubble.qml b/examples/sensors/accelbubble/accelbubble.qml index 8bd036ff..a980033f 100644 --- a/examples/sensors/accelbubble/accelbubble.qml +++ b/examples/sensors/accelbubble/accelbubble.qml @@ -50,7 +50,7 @@ import QtQuick 2.1 -import QtQuick.Controls 1.0 +import QtQuick.Controls 2.0 //! [0] import QtSensors 5.0 diff --git a/examples/sensors/sensor_explorer/import/sensoritem.cpp b/examples/sensors/sensor_explorer/import/sensoritem.cpp index f268db3a..40fb847e 100644 --- a/examples/sensors/sensor_explorer/import/sensoritem.cpp +++ b/examples/sensors/sensor_explorer/import/sensoritem.cpp @@ -110,7 +110,7 @@ void QSensorItem::setStart(bool run) */ QString QSensorItem::id() { - return (_qsensor ? _qsensor->identifier() : ""); + return (_qsensor ? _qsensor->identifier() : QStringLiteral("")); } /* diff --git a/examples/sensors/sensor_explorer/sensor_explorer.qml b/examples/sensors/sensor_explorer/sensor_explorer.qml index 365842d9..24e22133 100644 --- a/examples/sensors/sensor_explorer/sensor_explorer.qml +++ b/examples/sensors/sensor_explorer/sensor_explorer.qml @@ -50,7 +50,7 @@ import QtQuick 2.1 import QtQuick.Window 2.1 -import QtQuick.Controls 1.0 +import QtQuick.Controls 2.0 //! [0] import Explorer 1.0 diff --git a/src/plugins/sensors/generic/generictiltsensor.cpp b/src/plugins/sensors/generic/generictiltsensor.cpp index bb418893..ddb6bde3 100644 --- a/src/plugins/sensors/generic/generictiltsensor.cpp +++ b/src/plugins/sensors/generic/generictiltsensor.cpp @@ -161,5 +161,5 @@ bool GenericTiltSensor::filter(QAccelerometerReading *reading) bool GenericTiltSensor::isFeatureSupported(QSensor::Feature feature) const { - return (feature == QSensor::SkipDuplicates); + return (feature == QSensor::Feature::SkipDuplicates); } diff --git a/src/plugins/sensors/sensors.pro b/src/plugins/sensors/sensors.pro index 7fce2071..c637e6ac 100644 --- a/src/plugins/sensors/sensors.pro +++ b/src/plugins/sensors/sensors.pro @@ -13,7 +13,7 @@ darwin { isEmpty(SENSORS_PLUGINS): SENSORS_PLUGINS = ios generic } -winrt { +win32 { isEmpty(SENSORS_PLUGINS): SENSORS_PLUGINS = winrt generic } @@ -42,4 +42,4 @@ isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, android):android:SUBDIRS += a isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, sensorfw):sensorfw:SUBDIRS += sensorfw isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, sensortag):linux:SUBDIRS += sensortag isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, ios):darwin:SUBDIRS += ios -isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, winrt):winrt:SUBDIRS += winrt +isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, winrt):SUBDIRS += winrt diff --git a/src/plugins/sensors/winrt/main.cpp b/src/plugins/sensors/winrt/main.cpp index ecf2a41b..cae34037 100644 --- a/src/plugins/sensors/winrt/main.cpp +++ b/src/plugins/sensors/winrt/main.cpp @@ -59,6 +59,7 @@ class WinRtSensorPlugin : public QObject, public QSensorPluginInterface, public Q_PLUGIN_METADATA(IID "com.qt-project.Qt.QSensorPluginInterface/1.0" FILE "plugin.json") Q_INTERFACES(QSensorPluginInterface) public: + void registerSensors() override { QSensorManager::registerBackend(QAccelerometer::type, QByteArrayLiteral("WinRtAccelerometer"), this); diff --git a/src/plugins/sensors/winrt/winrt.pro b/src/plugins/sensors/winrt/winrt.pro index 21996fdd..0de6293b 100644 --- a/src/plugins/sensors/winrt/winrt.pro +++ b/src/plugins/sensors/winrt/winrt.pro @@ -22,6 +22,8 @@ SOURCES += \ OTHER_FILES = plugin.json +LIBS += runtimeobject.lib + PLUGIN_TYPE = sensors PLUGIN_CLASS_NAME = WinRtSensorPlugin load(qt_plugin) diff --git a/src/plugins/sensors/winrt/winrtaccelerometer.cpp b/src/plugins/sensors/winrt/winrtaccelerometer.cpp index 3570a47d..e2bc0613 100644 --- a/src/plugins/sensors/winrt/winrtaccelerometer.cpp +++ b/src/plugins/sensors/winrt/winrtaccelerometer.cpp @@ -41,11 +41,11 @@ #include "winrtcommon.h" #include <QtSensors/QAccelerometerReading> -#include <private/qeventdispatcher_winrt_p.h> #include <functional> #include <wrl.h> #include <windows.devices.sensors.h> + using namespace Microsoft::WRL; using namespace Microsoft::WRL::Wrappers; using namespace ABI::Windows::Foundation; @@ -119,28 +119,30 @@ WinRtAccelerometer::WinRtAccelerometer(QSensor *sensor) : QSensorBackend(sensor), d_ptr(new WinRtAccelerometerPrivate(this)) { Q_D(WinRtAccelerometer); - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - HStringReference classId(RuntimeClass_Windows_Devices_Sensors_Accelerometer); - ComPtr<IAccelerometerStatics> factory; - HRESULT hr = RoGetActivationFactory(classId.Get(), IID_PPV_ARGS(&factory)); - if (FAILED(hr)) { - qCWarning(lcWinRtSensors) << "Unable to initialize accelerometer factory." + + HStringReference classId(RuntimeClass_Windows_Devices_Sensors_Accelerometer); + ComPtr<IAccelerometerStatics> factory; + HRESULT hr = RoGetActivationFactory(classId.Get(), IID_PPV_ARGS(&factory)); + if (FAILED(hr)) { + qCWarning(lcWinRtSensors) << "Unable to initialize accelerometer factory." << qt_error_string(hr); - return hr; - } + sensorError(hr); + return; + } + hr = factory->GetDefault(&d->sensor); - hr = factory->GetDefault(&d->sensor); - if (FAILED(hr)) { - qCWarning(lcWinRtSensors) << "Unable to get default accelerometer." + if (FAILED(hr)) { + qCWarning(lcWinRtSensors) << "Unable to get default accelerometer." << qt_error_string(hr); - } - return hr; - }); - if (FAILED(hr) || !d->sensor) { sensorError(hr); return; } + if (!d->sensor) { + qCWarning(lcWinRtSensors) << "Default accelerometer was not found on the system."; + return; + } + hr = d->sensor->get_MinimumReportInterval(&d->minimumReportInterval); if (FAILED(hr)) { qCWarning(lcWinRtSensors) << "Unable to get the minimum report interval." @@ -167,11 +169,10 @@ void WinRtAccelerometer::start() if (d->token.value) return; - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - ComPtr<AccelerometerReadingHandler> callback = - Callback<AccelerometerReadingHandler>(d, &WinRtAccelerometerPrivate::readingChanged); - return d->sensor->add_ReadingChanged(callback.Get(), &d->token); - }); + ComPtr<AccelerometerReadingHandler> callback = + Callback<AccelerometerReadingHandler>(d, &WinRtAccelerometerPrivate::readingChanged); + HRESULT hr = d->sensor->add_ReadingChanged(callback.Get(), &d->token); + if (FAILED(hr)) { qCWarning(lcWinRtSensors) << "Unable to attach to reading changed event." << qt_error_string(hr); @@ -200,9 +201,7 @@ void WinRtAccelerometer::stop() if (!d->token.value) return; - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - return d->sensor->remove_ReadingChanged(d->token); - }); + HRESULT hr = d->sensor->remove_ReadingChanged(d->token); if (FAILED(hr)) { qCWarning(lcWinRtSensors) << "Unable to detach from reading changed event." << qt_error_string(hr); diff --git a/src/plugins/sensors/winrt/winrtambientlightsensor.cpp b/src/plugins/sensors/winrt/winrtambientlightsensor.cpp index 426d61bf..7832eb1c 100644 --- a/src/plugins/sensors/winrt/winrtambientlightsensor.cpp +++ b/src/plugins/sensors/winrt/winrtambientlightsensor.cpp @@ -41,7 +41,6 @@ #include "winrtcommon.h" #include <QtSensors/QAmbientLightSensor> -#include <private/qeventdispatcher_winrt_p.h> #include <functional> #include <wrl.h> @@ -118,27 +117,27 @@ WinRtAmbientLightSensor::WinRtAmbientLightSensor(QSensor *sensor) : QSensorBackend(sensor), d_ptr(new WinRtAmbientLightSensorPrivate(this)) { Q_D(WinRtAmbientLightSensor); - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - HStringReference classId(RuntimeClass_Windows_Devices_Sensors_LightSensor); - ComPtr<ILightSensorStatics> factory; - HRESULT hr = RoGetActivationFactory(classId.Get(), IID_PPV_ARGS(&factory)); - if (FAILED(hr)) { - qCWarning(lcWinRtSensors) << "Unable to initialize light sensor factory." - << qt_error_string(hr); - return hr; - } - hr = factory->GetDefault(&d->sensor); - if (FAILED(hr)) { - qCWarning(lcWinRtSensors) << "Unable to get default light sensor." + HStringReference classId(RuntimeClass_Windows_Devices_Sensors_LightSensor); + ComPtr<ILightSensorStatics> factory; + HRESULT hr = RoGetActivationFactory(classId.Get(), IID_PPV_ARGS(&factory)); + if (FAILED(hr)) { + qCWarning(lcWinRtSensors) << "Unable to initialize light sensor factory." << qt_error_string(hr); - } - return hr; - }); - if (FAILED(hr) || !d->sensor) { sensorError(hr); return; } + hr = factory->GetDefault(&d->sensor); + if (FAILED(hr)) { + qCWarning(lcWinRtSensors) << "Unable to get default light sensor." + << qt_error_string(hr); + sensorError(hr); + return; + } + if (!d->sensor) { + qCWarning(lcWinRtSensors) << "Default lightsensor was not found on the system."; + return; + } hr = d->sensor->get_MinimumReportInterval(&d->minimumReportInterval); if (FAILED(hr)) { @@ -166,11 +165,10 @@ void WinRtAmbientLightSensor::start() if (d->token.value) return; - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - ComPtr<LightSensorReadingHandler> callback = + ComPtr<LightSensorReadingHandler> callback = Callback<LightSensorReadingHandler>(d, &WinRtAmbientLightSensorPrivate::readingChanged); - return d->sensor->add_ReadingChanged(callback.Get(), &d->token); - }); + HRESULT hr = d->sensor->add_ReadingChanged(callback.Get(), &d->token); + if (FAILED(hr)) { qCWarning(lcWinRtSensors) << "Unable to attach to reading changed event." << qt_error_string(hr); @@ -199,9 +197,7 @@ void WinRtAmbientLightSensor::stop() if (!d->token.value) return; - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - return d->sensor->remove_ReadingChanged(d->token); - }); + HRESULT hr = d->sensor->remove_ReadingChanged(d->token); if (FAILED(hr)) { qCWarning(lcWinRtSensors) << "Unable to detach from reading changed event." << qt_error_string(hr); diff --git a/src/plugins/sensors/winrt/winrtcompass.cpp b/src/plugins/sensors/winrt/winrtcompass.cpp index 5ef730d0..bfe70d77 100644 --- a/src/plugins/sensors/winrt/winrtcompass.cpp +++ b/src/plugins/sensors/winrt/winrtcompass.cpp @@ -41,7 +41,6 @@ #include "winrtcommon.h" #include <QtSensors/QCompass> -#include <private/qeventdispatcher_winrt_p.h> #include <functional> #include <wrl.h> @@ -136,28 +135,30 @@ WinRtCompass::WinRtCompass(QSensor *sensor) : QSensorBackend(sensor), d_ptr(new WinRtCompassPrivate(this)) { Q_D(WinRtCompass); - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - HStringReference classId(RuntimeClass_Windows_Devices_Sensors_Compass); - ComPtr<ICompassStatics> factory; - HRESULT hr = RoGetActivationFactory(classId.Get(), IID_PPV_ARGS(&factory)); - if (FAILED(hr)) { - qCWarning(lcWinRtSensors) << "Unable to initialize light sensor factory." + + HStringReference classId(RuntimeClass_Windows_Devices_Sensors_Compass); + ComPtr<ICompassStatics> factory; + HRESULT hr = RoGetActivationFactory(classId.Get(), IID_PPV_ARGS(&factory)); + if (FAILED(hr)) { + qCWarning(lcWinRtSensors) << "Unable to initialize light sensor factory." << qt_error_string(hr); - return hr; - } + sensorError(hr); + return; + } - hr = factory->GetDefault(&d->sensor); - if (FAILED(hr)) { - qCWarning(lcWinRtSensors) << "Unable to get default compass." + hr = factory->GetDefault(&d->sensor); + if (FAILED(hr)) { + qCWarning(lcWinRtSensors) << "Unable to get default compass." << qt_error_string(hr); - } - return hr; - }); - if (FAILED(hr) || !d->sensor) { sensorError(hr); return; } + if (!d->sensor) { + qCWarning(lcWinRtSensors) << "Default compass was not found on the system."; + return; + } + hr = d->sensor->get_MinimumReportInterval(&d->minimumReportInterval); if (FAILED(hr)) { qCWarning(lcWinRtSensors) << "Unable to get the minimum report interval." @@ -183,12 +184,10 @@ void WinRtCompass::start() return; if (d->token.value) return; - - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - ComPtr<CompassReadingHandler> callback = + ComPtr<CompassReadingHandler> callback = Callback<CompassReadingHandler>(d, &WinRtCompassPrivate::readingChanged); - return d->sensor->add_ReadingChanged(callback.Get(), &d->token); - }); + HRESULT hr = d->sensor->add_ReadingChanged(callback.Get(), &d->token); + if (FAILED(hr)) { qCWarning(lcWinRtSensors) << "Unable to attach to reading changed event." << qt_error_string(hr); @@ -216,9 +215,8 @@ void WinRtCompass::stop() return; if (!d->token.value) return; - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - return d->sensor->remove_ReadingChanged(d->token); - }); + HRESULT hr = d->sensor->remove_ReadingChanged(d->token); + if (FAILED(hr)) { qCWarning(lcWinRtSensors) << "Unable to detach from reading changed event." << qt_error_string(hr); diff --git a/src/plugins/sensors/winrt/winrtgyroscope.cpp b/src/plugins/sensors/winrt/winrtgyroscope.cpp index 45b544c7..3de73247 100644 --- a/src/plugins/sensors/winrt/winrtgyroscope.cpp +++ b/src/plugins/sensors/winrt/winrtgyroscope.cpp @@ -41,7 +41,6 @@ #include "winrtcommon.h" #include <QtSensors/QGyroscope> -#include <private/qeventdispatcher_winrt_p.h> #include <functional> #include <wrl.h> @@ -116,28 +115,30 @@ WinRtGyroscope::WinRtGyroscope(QSensor *sensor) : QSensorBackend(sensor), d_ptr(new WinRtGyroscopePrivate(this)) { Q_D(WinRtGyroscope); - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - HStringReference classId(RuntimeClass_Windows_Devices_Sensors_Gyrometer); - ComPtr<IGyrometerStatics> factory; - HRESULT hr = RoGetActivationFactory(classId.Get(), IID_PPV_ARGS(&factory)); - if (FAILED(hr)) { - qCWarning(lcWinRtSensors) << "Unable to initialize gyroscope sensor factory." + + HStringReference classId(RuntimeClass_Windows_Devices_Sensors_Gyrometer); + ComPtr<IGyrometerStatics> factory; + HRESULT hr = RoGetActivationFactory(classId.Get(), IID_PPV_ARGS(&factory)); + if (FAILED(hr)) { + qCWarning(lcWinRtSensors) << "Unable to initialize gyroscope sensor factory." << qt_error_string(hr); - return hr; - } + sensorError(hr); + return; + } - hr = factory->GetDefault(&d->sensor); - if (FAILED(hr)) { - qCWarning(lcWinRtSensors) << "Unable to get default gyroscope sensor." + hr = factory->GetDefault(&d->sensor); + if (FAILED(hr)) { + qCWarning(lcWinRtSensors) << "Unable to get default gyroscope sensor." << qt_error_string(hr); - } - return hr; - }); - if (FAILED(hr) || !d->sensor) { sensorError(hr); return; } + if (!d->sensor) { + qCWarning(lcWinRtSensors) << "Default gyroscope was not found on the system."; + return; + } + hr = d->sensor->get_MinimumReportInterval(&d->minimumReportInterval); if (FAILED(hr)) { qCWarning(lcWinRtSensors) << "Unable to get the minimum report interval." @@ -164,11 +165,10 @@ void WinRtGyroscope::start() if (d->token.value) return; - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - ComPtr<InclinometerReadingHandler> callback = + ComPtr<InclinometerReadingHandler> callback = Callback<InclinometerReadingHandler>(d, &WinRtGyroscopePrivate::readingChanged); - return d->sensor->add_ReadingChanged(callback.Get(), &d->token); - }); + HRESULT hr = d->sensor->add_ReadingChanged(callback.Get(), &d->token); + if (FAILED(hr)) { qCWarning(lcWinRtSensors) << "Unable to attach to reading changed event." << qt_error_string(hr); @@ -197,9 +197,7 @@ void WinRtGyroscope::stop() if (!d->token.value) return; - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - return d->sensor->remove_ReadingChanged(d->token); - }); + HRESULT hr = d->sensor->remove_ReadingChanged(d->token); if (FAILED(hr)) { qCWarning(lcWinRtSensors) << "Unable to detach from reading changed event." << qt_error_string(hr); diff --git a/src/plugins/sensors/winrt/winrtgyroscope.h b/src/plugins/sensors/winrt/winrtgyroscope.h index 7bd85332..308b769e 100644 --- a/src/plugins/sensors/winrt/winrtgyroscope.h +++ b/src/plugins/sensors/winrt/winrtgyroscope.h @@ -55,7 +55,7 @@ public: bool isFeatureSupported(QSensor::Feature feature) const override { - if (feature == QSensor::AxesOrientation || feature == QSensor::AccelerationMode) + if (feature == QSensor::Feature::AxesOrientation || feature == QSensor::Feature::AccelerationMode) return true; return false; } diff --git a/src/plugins/sensors/winrt/winrtorientationsensor.cpp b/src/plugins/sensors/winrt/winrtorientationsensor.cpp index e24ff954..1511a308 100644 --- a/src/plugins/sensors/winrt/winrtorientationsensor.cpp +++ b/src/plugins/sensors/winrt/winrtorientationsensor.cpp @@ -41,7 +41,6 @@ #include "winrtcommon.h" #include <QtSensors/QOrientationSensor> -#include <private/qeventdispatcher_winrt_p.h> #include <functional> #include <wrl.h> @@ -122,27 +121,26 @@ WinRtOrientationSensor::WinRtOrientationSensor(QSensor *sensor) : QSensorBackend(sensor), d_ptr(new WinRtOrientationSensorPrivate(this)) { Q_D(WinRtOrientationSensor); - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - HStringReference classId(RuntimeClass_Windows_Devices_Sensors_SimpleOrientationSensor); - ComPtr<ISimpleOrientationSensorStatics> factory; - HRESULT hr = RoGetActivationFactory(classId.Get(), IID_PPV_ARGS(&factory)); - if (FAILED(hr)) { - qCWarning(lcWinRtSensors) << "Unable to initialize orientation sensor factory." + HStringReference classId(RuntimeClass_Windows_Devices_Sensors_SimpleOrientationSensor); + ComPtr<ISimpleOrientationSensorStatics> factory; + HRESULT hr = RoGetActivationFactory(classId.Get(), IID_PPV_ARGS(&factory)); + if (FAILED(hr)) { + qCWarning(lcWinRtSensors) << "Unable to initialize orientation sensor factory." << qt_error_string(hr); - return hr; - } - - hr = factory->GetDefault(&d->sensor); - if (FAILED(hr)) { - qCWarning(lcWinRtSensors) << "Unable to get default orientation sensor." + sensorError(hr); + return; + } + hr = factory->GetDefault(&d->sensor); + if (FAILED(hr)) { + qCWarning(lcWinRtSensors) << "Unable to get default orientation sensor." << qt_error_string(hr); - } - return hr; - }); - if (FAILED(hr) || !d->sensor) { sensorError(hr); return; } + if (!d->sensor) { + qCWarning(lcWinRtSensors) << "Default orientationsensor was not found on the system."; + return; + } setReading<QOrientationReading>(&d->reading); } @@ -159,11 +157,10 @@ void WinRtOrientationSensor::start() if (d->token.value) return; - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - ComPtr<SimpleOrientationReadingHandler> callback = + ComPtr<SimpleOrientationReadingHandler> callback = Callback<SimpleOrientationReadingHandler>(d, &WinRtOrientationSensorPrivate::readingChanged); - return d->sensor->add_OrientationChanged(callback.Get(), &d->token); - }); + HRESULT hr = d->sensor->add_OrientationChanged(callback.Get(), &d->token); + if (FAILED(hr)) { qCWarning(lcWinRtSensors) << "Unable to attach to reading changed event." << qt_error_string(hr); @@ -180,9 +177,7 @@ void WinRtOrientationSensor::stop() if (!d->token.value) return; - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - return d->sensor->remove_OrientationChanged(d->token); - }); + HRESULT hr = d->sensor->remove_OrientationChanged(d->token); if (FAILED(hr)) { qCWarning(lcWinRtSensors) << "Unable to detach from reading changed event." << qt_error_string(hr); diff --git a/src/plugins/sensors/winrt/winrtrotationsensor.cpp b/src/plugins/sensors/winrt/winrtrotationsensor.cpp index 5dd4eae5..4f37ea15 100644 --- a/src/plugins/sensors/winrt/winrtrotationsensor.cpp +++ b/src/plugins/sensors/winrt/winrtrotationsensor.cpp @@ -41,7 +41,6 @@ #include "winrtcommon.h" #include <QtSensors/QRotationSensor> -#include <private/qeventdispatcher_winrt_p.h> #include <functional> #include <wrl.h> @@ -114,28 +113,29 @@ WinRtRotationSensor::WinRtRotationSensor(QSensor *sensor) : QSensorBackend(sensor), d_ptr(new WinRtRotationSensorPrivate(this)) { Q_D(WinRtRotationSensor); - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - HStringReference classId(RuntimeClass_Windows_Devices_Sensors_Inclinometer); - ComPtr<IInclinometerStatics> factory; - HRESULT hr = RoGetActivationFactory(classId.Get(), IID_PPV_ARGS(&factory)); - if (FAILED(hr)) { - qCWarning(lcWinRtSensors) << "Unable to initialize rotation sensor factory." - << qt_error_string(hr); - return hr; - } - hr = factory->GetDefault(&d->sensor); - if (FAILED(hr)) { - qCWarning(lcWinRtSensors) << "Unable to get default rotation sensor." + HStringReference classId(RuntimeClass_Windows_Devices_Sensors_Inclinometer); + ComPtr<IInclinometerStatics> factory; + HRESULT hr = RoGetActivationFactory(classId.Get(), IID_PPV_ARGS(&factory)); + if (FAILED(hr)) { + qCWarning(lcWinRtSensors) << "Unable to initialize rotation sensor factory." + << qt_error_string(hr); + sensorError(hr); + return; + } + hr = factory->GetDefault(&d->sensor); + if (FAILED(hr)) { + qCWarning(lcWinRtSensors) << "Unable to get default rotation sensor." << qt_error_string(hr); - } - return hr; - }); - if (FAILED(hr) || !d->sensor) { sensorError(hr); return; } + if (!d->sensor) { + qCWarning(lcWinRtSensors) << "Default rotationsensor was not found on the system."; + return; + } + hr = d->sensor->get_MinimumReportInterval(&d->minimumReportInterval); if (FAILED(hr)) { qCWarning(lcWinRtSensors) << "Unable to get the minimum report interval." @@ -162,11 +162,10 @@ void WinRtRotationSensor::start() if (d->token.value) return; - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - ComPtr<InclinometerReadingHandler> callback = + ComPtr<InclinometerReadingHandler> callback = Callback<InclinometerReadingHandler>(d, &WinRtRotationSensorPrivate::readingChanged); - return d->sensor->add_ReadingChanged(callback.Get(), &d->token); - }); + HRESULT hr = d->sensor->add_ReadingChanged(callback.Get(), &d->token); + if (FAILED(hr)) { qCWarning(lcWinRtSensors) << "Unable to attach to reading changed event." << qt_error_string(hr); @@ -195,9 +194,7 @@ void WinRtRotationSensor::stop() if (!d->token.value) return; - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - return d->sensor->remove_ReadingChanged(d->token); - }); + HRESULT hr = d->sensor->remove_ReadingChanged(d->token); if (FAILED(hr)) { qCWarning(lcWinRtSensors) << "Unable to detach from reading changed event." << qt_error_string(hr); diff --git a/src/plugins/sensors/winrt/winrtrotationsensor.h b/src/plugins/sensors/winrt/winrtrotationsensor.h index 4b3e6faf..39fa4551 100644 --- a/src/plugins/sensors/winrt/winrtrotationsensor.h +++ b/src/plugins/sensors/winrt/winrtrotationsensor.h @@ -55,7 +55,7 @@ public: bool isFeatureSupported(QSensor::Feature feature) const override { - if (feature == QSensor::AxesOrientation || feature == QSensor::AccelerationMode) + if (feature == QSensor::Feature::AxesOrientation || feature == QSensor::Feature::AccelerationMode) return true; return false; } diff --git a/src/sensors/doc/src/qt6-changes.qdoc b/src/sensors/doc/src/qt6-changes.qdoc new file mode 100644 index 00000000..e4447a2f --- /dev/null +++ b/src/sensors/doc/src/qt6-changes.qdoc @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \page qtsensors-changes-qt6.html + \title Changes to Qt Sensors + \ingroup changes-qt-5-to-6 + \brief Migrate Qt Sensors to Qt 6. + + Qt 6 is a result of the conscious effort to make the framework more + efficient and easy to use. + + We try to maintain binary and source compatibility for all the public + APIs in each release. But some changes were inevitable in an effort to + make Qt a better framework. + + In this topic we summarize those changes in Qt Sensors, and provide + guidance to handle them. + + \section1 Platform notes + + On Windows the Qt6 does not support the UWP (Universal Windows Platform) + any longer. As such the QtSensors now builds on the Win32 + + \section1 API changes + + \section2 Deleted typedef for qtimestamp + + The typedef for the historical, QtMobility-era, 'qtimestamp' has been + removed. Use the actual type 'quint64' directly. +*/ diff --git a/src/sensors/qsensor.h b/src/sensors/qsensor.h index 7dd7ea19..c988a661 100644 --- a/src/sensors/qsensor.h +++ b/src/sensors/qsensor.h @@ -56,26 +56,22 @@ class QSensorReading; class QSensorReadingPrivate; class QSensorFilter; -// This type is no longer used in the API but third party apps may be using it -typedef quint64 qtimestamp; +using qrange = QPair<int,int>; +using qrangelist = QList<qrange>; -typedef QPair<int,int> qrange; -typedef QList<qrange> qrangelist; struct qoutputrange { qreal minimum; qreal maximum; qreal accuracy; }; -typedef QList<qoutputrange> qoutputrangelist; + +using qoutputrangelist = QList<qoutputrange>; class Q_SENSORS_EXPORT QSensor : public QObject { friend class QSensorBackend; - Q_OBJECT - Q_ENUMS(Feature) - Q_ENUMS(AxesOrientationMode) Q_PROPERTY(QByteArray identifier READ identifier WRITE setIdentifier) Q_PROPERTY(QByteArray type READ type) Q_PROPERTY(bool connectedToBackend READ isConnectedToBackend) @@ -108,6 +104,7 @@ public: PressureSensorTemperature, Reserved = 257 // Make sure at least 2 bytes are used for the enum to avoid breaking BC later }; + Q_ENUM(Feature) // Keep in sync with QmlSensor::AxesOrientationMode enum AxesOrientationMode { @@ -115,6 +112,7 @@ public: AutomaticOrientation, UserOrientation }; + Q_ENUM(AxesOrientationMode) explicit QSensor(const QByteArray &type, QObject *parent = Q_NULLPTR); virtual ~QSensor(); diff --git a/src/sensors/qsensor_p.h b/src/sensors/qsensor_p.h index f3e41e4d..5d4fff0f 100644 --- a/src/sensors/qsensor_p.h +++ b/src/sensors/qsensor_p.h @@ -77,7 +77,7 @@ public: , error(0) , alwaysOn(false) , skipDuplicates(false) - , axesOrientationMode(QSensor::FixedOrientation) + , axesOrientationMode(QSensor::AxesOrientationMode::FixedOrientation) , currentOrientation(0) , userOrientation(0) , bufferSize(1) diff --git a/tests/auto/qsensor/test_sensorimpl.cpp b/tests/auto/qsensor/test_sensorimpl.cpp index c9a1fe63..bbf4e59d 100644 --- a/tests/auto/qsensor/test_sensorimpl.cpp +++ b/tests/auto/qsensor/test_sensorimpl.cpp @@ -106,6 +106,6 @@ void testsensorimpl::stop() bool testsensorimpl::isFeatureSupported(QSensor::Feature feature) const { - return (feature == QSensor::AlwaysOn || feature == QSensor::GeoValues); + return (feature == QSensor::Feature::AlwaysOn || feature == QSensor::Feature::GeoValues); } diff --git a/tests/auto/qsensor/tst_qsensor.cpp b/tests/auto/qsensor/tst_qsensor.cpp index 8e027971..b12b1a73 100644 --- a/tests/auto/qsensor/tst_qsensor.cpp +++ b/tests/auto/qsensor/tst_qsensor.cpp @@ -43,9 +43,6 @@ QT_BEGIN_NAMESPACE -// The unit test needs to change the behaviour of the library. It does this -// through an exported but undocumented function. -Q_SENSORS_EXPORT void sensors_unit_test_hook(int index); bool operator==(const qoutputrange &orl1, const qoutputrange &orl2) { return (orl1.minimum == orl2.minimum && @@ -54,27 +51,16 @@ bool operator==(const qoutputrange &orl1, const qoutputrange &orl2) } namespace QTest { - template<> char *toString(const qoutputrangelist &orl) + // QCOMPARE calls this upon failure (and if a list of these elements is compared, + // it will call this individually for each element) + template<> char* toString(const qoutputrange& range) { - QStringList list; - foreach (const qoutputrange &item, orl) { - list << QString("%1-%2%3%4").arg(item.minimum).arg(item.maximum).arg(QString::fromWCharArray(L"\u00B1")).arg(item.accuracy); - } - QString ret = QString("qoutputrangelist: (%1)").arg(list.join("), (")); - return qstrdup(ret.toLatin1().data()); - } - template<> char *toString(const QList<QByteArray> &data) - { - QStringList list; - foreach (const QByteArray &str, data) { - list << QString::fromLatin1(str); - } - QString ret = QString("QList<QByteArray>: (%1)").arg(list.join("), (")); + QString ret = QString("%1-%2%3%4").arg(range.minimum).arg(range.maximum) + .arg(QString::fromWCharArray(L"\u00B1")).arg(range.accuracy); return qstrdup(ret.toLatin1().data()); } } - class MyFilter : public TestSensorFilter { bool filter(TestSensorReading *) override { return false; } }; class ModFilter : public TestSensorFilter @@ -241,9 +227,9 @@ private slots: sensor.connectToBackend(); QVERIFY(sensor.reading() != 0); quint64 timestamp = sensor.reading()->timestamp(); - qtimestamp timestamp2 = sensor.reading()->timestamp(); + quint64 timestamp2 = sensor.reading()->timestamp(); QVERIFY(timestamp == quint64()); - QVERIFY(timestamp2 == qtimestamp()); + QVERIFY(timestamp2 == quint64()); sensor.setProperty("doThis", "setOne"); sensor.start(); timestamp = sensor.reading()->timestamp(); @@ -959,21 +945,21 @@ private slots: // Not connected to backend - should report false for any feature QVERIFY(!sensor.isConnectedToBackend()); - QVERIFY(!sensor.isFeatureSupported(QSensor::AlwaysOn)); - QVERIFY(!sensor.isFeatureSupported(QSensor::Buffering)); - QVERIFY(!sensor.isFeatureSupported(QSensor::GeoValues)); - QVERIFY(!sensor.isFeatureSupported(QSensor::FieldOfView)); - QVERIFY(!sensor.isFeatureSupported(QSensor::AccelerationMode)); + QVERIFY(!sensor.isFeatureSupported(QSensor::Feature::AlwaysOn)); + QVERIFY(!sensor.isFeatureSupported(QSensor::Feature::Buffering)); + QVERIFY(!sensor.isFeatureSupported(QSensor::Feature::GeoValues)); + QVERIFY(!sensor.isFeatureSupported(QSensor::Feature::FieldOfView)); + QVERIFY(!sensor.isFeatureSupported(QSensor::Feature::AccelerationMode)); // Connect to backend - according to the testsensorimpl implementation, AlwaysOn and // GeoValues should be supported afterwards QVERIFY(sensor.connectToBackend()); - QVERIFY(sensor.isFeatureSupported(QSensor::AlwaysOn)); - QVERIFY(!sensor.isFeatureSupported(QSensor::Buffering)); - QVERIFY(sensor.isFeatureSupported(QSensor::GeoValues)); - QVERIFY(!sensor.isFeatureSupported(QSensor::FieldOfView)); - QVERIFY(!sensor.isFeatureSupported(QSensor::AccelerationMode)); + QVERIFY(sensor.isFeatureSupported(QSensor::Feature::AlwaysOn)); + QVERIFY(!sensor.isFeatureSupported(QSensor::Feature::Buffering)); + QVERIFY(sensor.isFeatureSupported(QSensor::Feature::GeoValues)); + QVERIFY(!sensor.isFeatureSupported(QSensor::Feature::FieldOfView)); + QVERIFY(!sensor.isFeatureSupported(QSensor::Feature::AccelerationMode)); } }; |