summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJuha Vuolle <juha.vuolle@insta.fi>2021-06-10 13:27:19 +0300
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-06-15 09:39:14 +0000
commitce77413488e1da71ef286ec40f5a4afd40cab512 (patch)
tree759a95366e4e4a0667048fef84452eac0b5e13f5 /src
parent7a82ee1645ef0df9c766031edd20ea99d5ea7b6e (diff)
Sensor identifier autotest and fix related findings
This commit adds a (QML) test for sensor identifier (and activation whose logic is closely related). The related changes: * Change sensor 'identifier' and 'type' properties to QByteArray. This now matches with C++ side that uses QByteArray * Allow changing of 'identifier' after componentComplete. This is now aligned with C++ side. Changing identifier is fine as long as the backend is not connected. Task-number: QTBUG-92513 Task-number: QTBUG-92505 Change-Id: I326d840d5a4efb13a3a6578711563e8054cc9961 Reviewed-by: Alex Blasche <alexander.blasche@qt.io> (cherry picked from commit c3cc1253ba159e6f4c9bd4c92da2b8c300ee94f2) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r--src/sensors/doc/src/qt6-changes.qdoc5
-rw-r--r--src/sensorsquick/qmlsensor.cpp31
-rw-r--r--src/sensorsquick/qmlsensor_p.h12
3 files changed, 20 insertions, 28 deletions
diff --git a/src/sensors/doc/src/qt6-changes.qdoc b/src/sensors/doc/src/qt6-changes.qdoc
index f71cde15..ffde4d19 100644
--- a/src/sensors/doc/src/qt6-changes.qdoc
+++ b/src/sensors/doc/src/qt6-changes.qdoc
@@ -79,4 +79,9 @@
that in most if not all cases the changes are not mandatory. Instead it is up to the
individual sensor backend implementations to decide if the changes are useful.
+ \section2 Sensor::type and and QSensor::type properties marked as constant
+
+ The \c type property cannot change after instantiation and is marked as constant
+ in both C++ and QML.
+
*/
diff --git a/src/sensorsquick/qmlsensor.cpp b/src/sensorsquick/qmlsensor.cpp
index 14dc21c7..2ff544a5 100644
--- a/src/sensorsquick/qmlsensor.cpp
+++ b/src/sensorsquick/qmlsensor.cpp
@@ -104,16 +104,14 @@ QmlSensor::~QmlSensor()
Please see QSensor::identifier for information about this property.
*/
-QString QmlSensor::identifier() const
+QByteArray QmlSensor::identifier() const
{
- return m_identifier;
+ return sensor()->identifier();
}
-void QmlSensor::setIdentifier(const QString &identifier)
+void QmlSensor::setIdentifier(const QByteArray &identifier)
{
- if (m_componentComplete) return;
- m_identifier = identifier;
- Q_EMIT identifierChanged();
+ sensor()->setIdentifier(identifier);
}
/*!
@@ -121,9 +119,9 @@ void QmlSensor::setIdentifier(const QString &identifier)
This property holds the type of the sensor.
*/
-QString QmlSensor::type() const
+QByteArray QmlSensor::type() const
{
- return QString::fromLatin1(sensor()->type());
+ return sensor()->type();
}
/*!
@@ -448,26 +446,17 @@ void QmlSensor::componentComplete()
connect(sensor(), SIGNAL(maxBufferSizeChanged(int)), this, SIGNAL(maxBufferSizeChanged(int)));
connect(sensor(), SIGNAL(efficientBufferSizeChanged(int)), this, SIGNAL(efficientBufferSizeChanged(int)));
connect(sensor(), &QSensor::busyChanged, this, &QmlSensor::busyChanged);
-
- // We need to set this on the sensor object now
- sensor()->setIdentifier(m_identifier.toLocal8Bit());
+ connect(sensor(), &QSensor::identifierChanged, this, &QmlSensor::identifierChanged);
// These can change!
- QByteArray oldIdentifier = sensor()->identifier();
int oldDataRate = dataRate();
int oldOutputRange = outputRange();
- bool ok = sensor()->connectToBackend();
- if (ok) {
+ if (sensor()->connectToBackend())
Q_EMIT connectedToBackendChanged();
- m_reading = createReading();
- m_reading->setParent(this);
- }
- if (oldIdentifier != sensor()->identifier()) {
- m_identifier = QString::fromLatin1(sensor()->identifier());
- Q_EMIT identifierChanged();
- }
+ m_reading = createReading();
+ m_reading->setParent(this);
if (oldDataRate != dataRate())
Q_EMIT dataRateChanged();
if (oldOutputRange != outputRange())
diff --git a/src/sensorsquick/qmlsensor_p.h b/src/sensorsquick/qmlsensor_p.h
index 2b893c99..276b6e76 100644
--- a/src/sensorsquick/qmlsensor_p.h
+++ b/src/sensorsquick/qmlsensor_p.h
@@ -72,8 +72,8 @@ class Q_SENSORSQUICK_PRIVATE_EXPORT QmlSensor : public QObject, public QQmlParse
Q_OBJECT
Q_DECLARE_PRIVATE(QmlSensor)
Q_INTERFACES(QQmlParserStatus)
- Q_PROPERTY(QString identifier READ identifier WRITE setIdentifier NOTIFY identifierChanged)
- Q_PROPERTY(QString type READ type NOTIFY typeChanged)
+ Q_PROPERTY(QByteArray identifier READ identifier WRITE setIdentifier NOTIFY identifierChanged)
+ Q_PROPERTY(QByteArray type READ type CONSTANT)
Q_PROPERTY(bool connectedToBackend READ isConnectedToBackend NOTIFY connectedToBackendChanged)
Q_PROPERTY(QQmlListProperty<QmlSensorRange> availableDataRates READ availableDataRates NOTIFY availableDataRatesChanged)
Q_PROPERTY(int dataRate READ dataRate WRITE setDataRate NOTIFY dataRateChanged)
@@ -108,10 +108,10 @@ public:
explicit QmlSensor(QObject *parent = 0);
~QmlSensor();
- QString identifier() const;
- void setIdentifier(const QString &identifier);
+ QByteArray identifier() const;
+ void setIdentifier(const QByteArray &identifier);
- QString type() const;
+ QByteArray type() const;
bool isConnectedToBackend() const;
@@ -162,7 +162,6 @@ public Q_SLOTS:
Q_SIGNALS:
void identifierChanged();
- void typeChanged();
void connectedToBackendChanged();
void availableDataRatesChanged();
void dataRateChanged();
@@ -196,7 +195,6 @@ private:
virtual void _update();
bool m_componentComplete = false;
bool m_activateOnComplete = false;
- QString m_identifier;
QmlSensorReading *m_reading = nullptr;
};