summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJuha Vuolle <juha.vuolle@insta.fi>2021-06-03 13:12:52 +0300
committerJuha Vuolle <juha.vuolle@insta.fi>2021-06-15 11:36:02 +0300
commit54b3ca67ad7230a21d76c581dd4287401acb230f (patch)
tree2d9b59930700cf99b7553c21a5846c4bee6f9191 /src
parentae82c50ca7fd5e356a736467e660acd976ec2e25 (diff)
Increase QtSensors QML autotest coverage
This commit introduces QML based auto tests in order to increase the autotest coverage. Additionally the QML sensor activity handling is fixed which caused the newly added tests to fail. There are also long-standing bugs about these activeChanged() double emits. Pick-to: 6.2 Task-number: QTBUG-92514 Task-number: QTBUG-70770 Task-number: QTBUG-80755 Change-Id: I98f036f665a056c441efa00aab76ec47bc628057 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/sensors/doc/src/qt6-changes.qdoc5
-rw-r--r--src/sensorsquick/qmllidsensor.cpp2
-rw-r--r--src/sensorsquick/qmllidsensor_p.h4
-rw-r--r--src/sensorsquick/qmlsensor.cpp32
-rw-r--r--src/sensorsquick/qmlsensor_p.h9
5 files changed, 24 insertions, 28 deletions
diff --git a/src/sensors/doc/src/qt6-changes.qdoc b/src/sensors/doc/src/qt6-changes.qdoc
index e68aab3e..7baad9f0 100644
--- a/src/sensors/doc/src/qt6-changes.qdoc
+++ b/src/sensors/doc/src/qt6-changes.qdoc
@@ -61,4 +61,9 @@
compilation errors and consequent workarounds. The \e type string has been
now renamed as \e sensorType.
+ \section2 Renamed LidReading::backLidChanged property to \c backLidClosed
+
+ The property name is now aligned with the \c frontLidClosed property of
+ the same QML type.
+
*/
diff --git a/src/sensorsquick/qmllidsensor.cpp b/src/sensorsquick/qmllidsensor.cpp
index 3725f0ca..698c03cc 100644
--- a/src/sensorsquick/qmllidsensor.cpp
+++ b/src/sensorsquick/qmllidsensor.cpp
@@ -112,7 +112,7 @@ QmlLidReading::~QmlLidReading()
Please see QLidReading::backLidClosed for information about this property.
*/
-bool QmlLidReading::backLidChanged() const
+bool QmlLidReading::backLidClosed() const
{
return m_backClosed;
}
diff --git a/src/sensorsquick/qmllidsensor_p.h b/src/sensorsquick/qmllidsensor_p.h
index 6a58ce53..99f6eba3 100644
--- a/src/sensorsquick/qmllidsensor_p.h
+++ b/src/sensorsquick/qmllidsensor_p.h
@@ -75,7 +75,7 @@ private:
class Q_SENSORSQUICK_PRIVATE_EXPORT QmlLidReading : public QmlSensorReading
{
Q_OBJECT
- Q_PROPERTY(bool backLidChanged READ backLidChanged NOTIFY backLidChanged)
+ Q_PROPERTY(bool backLidClosed READ backLidClosed NOTIFY backLidChanged)
Q_PROPERTY(bool frontLidClosed READ frontLidClosed NOTIFY frontLidChanged)
QML_NAMED_ELEMENT(LidReading)
QML_UNCREATABLE("Cannot create LidReading")
@@ -84,7 +84,7 @@ public:
explicit QmlLidReading(QLidSensor *sensor);
~QmlLidReading();
- bool backLidChanged() const;
+ bool backLidClosed() const;
bool frontLidClosed() const;
Q_SIGNALS:
diff --git a/src/sensorsquick/qmlsensor.cpp b/src/sensorsquick/qmlsensor.cpp
index 0afa91ea..7957a663 100644
--- a/src/sensorsquick/qmlsensor.cpp
+++ b/src/sensorsquick/qmlsensor.cpp
@@ -90,9 +90,6 @@ QQmlListProperty<Item> readonlyListProperty(const QObject *o, const QList<Item *
QmlSensor::QmlSensor(QObject *parent)
: QObject(*(new QmlSensorPrivate), parent)
- , m_parsed(false)
- , m_active(false)
- , m_reading(0)
{
}
@@ -114,7 +111,7 @@ QString QmlSensor::identifier() const
void QmlSensor::setIdentifier(const QString &identifier)
{
- if (m_parsed) return;
+ if (m_componentComplete) return;
m_identifier = identifier;
Q_EMIT identifierChanged();
}
@@ -162,23 +159,19 @@ bool QmlSensor::isBusy() const
void QmlSensor::setActive(bool active)
{
- m_active = active;
- if (!m_parsed) return; // delay (it'll get called again later)!
- bool wasActive = sensor()->isActive();
- if (wasActive == active) return;
- if (active) {
+ if (!m_componentComplete) {
+ m_activateOnComplete = active;
+ return;
+ }
+ if (active)
sensor()->start();
- m_active = sensor()->isActive();
- } else {
+ else
sensor()->stop();
- }
- if (m_active != wasActive)
- emit activeChanged();
}
bool QmlSensor::isActive() const
{
- return m_active;
+ return sensor()->isActive();
}
/*!
@@ -419,8 +412,7 @@ void QmlSensor::setBufferSize(int bufferSize)
bool QmlSensor::start()
{
- setActive(true);
- return isActive();
+ return sensor()->start();
}
/*!
@@ -442,7 +434,7 @@ void QmlSensor::classBegin()
void QmlSensor::componentComplete()
{
- m_parsed = true;
+ m_componentComplete = true;
connect(sensor(), SIGNAL(sensorError(int)), this, SIGNAL(errorChanged()));
connect(sensor(), SIGNAL(activeChanged()), this, SIGNAL(activeChanged()));
@@ -510,10 +502,8 @@ void QmlSensor::componentComplete()
_update();
connect(sensor(), SIGNAL(readingChanged()), this, SLOT(updateReading()));
- if (m_active) {
- m_active = false;
+ if (m_activateOnComplete)
start();
- }
}
void QmlSensor::_update()
diff --git a/src/sensorsquick/qmlsensor_p.h b/src/sensorsquick/qmlsensor_p.h
index 930142b1..55d4eb42 100644
--- a/src/sensorsquick/qmlsensor_p.h
+++ b/src/sensorsquick/qmlsensor_p.h
@@ -154,6 +154,8 @@ public:
int bufferSize() const;
void setBufferSize(int bufferSize);
+ virtual QSensor *sensor() const = 0;
+
public Q_SLOTS:
bool start();
void stop();
@@ -180,7 +182,6 @@ Q_SIGNALS:
Q_REVISION(1) void bufferSizeChanged(int bufferSize);
protected:
- virtual QSensor *sensor() const = 0;
virtual QmlSensorReading *createReading() const = 0;
private Q_SLOTS:
@@ -192,10 +193,10 @@ protected Q_SLOTS:
private:
void classBegin() override;
virtual void _update();
- bool m_parsed;
- bool m_active;
+ bool m_componentComplete = false;
+ bool m_activateOnComplete = false;
QString m_identifier;
- QmlSensorReading *m_reading;
+ QmlSensorReading *m_reading = nullptr;
};
class Q_SENSORSQUICK_PRIVATE_EXPORT QmlSensorReading : public QObject