summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas McGuire <thomas.mcguire.qnx@kdab.com>2013-02-01 09:44:00 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-02-08 11:17:45 +0100
commitae6d8a286b760198705e877a5ba4c1eecc7a5e8d (patch)
treeef93fec2264376743fe0fdf8bac1cac1dfe3d13d
parenta3f4766964022ff0dc7ea0832922c2a58ab47e82 (diff)
Convert QRotationSensor::hasZ to a proper property
Change-Id: I32edf761653fbe9d08710703b02fb1c0183aba3e Reviewed-by: Lorn Potter <lorn.potter@jollamobile.com>
-rw-r--r--src/imports/sensors/plugins.qmltypes4
-rw-r--r--src/imports/sensors/qmlrotationsensor.cpp3
-rw-r--r--src/imports/sensors/qmlrotationsensor.h4
-rw-r--r--src/plugins/sensors/generic/genericrotationsensor.cpp4
-rw-r--r--src/sensors/qrotationsensor.cpp24
-rw-r--r--src/sensors/qrotationsensor.h13
-rw-r--r--src/sensors/qrotationsensor_p.h13
7 files changed, 58 insertions, 7 deletions
diff --git a/src/imports/sensors/plugins.qmltypes b/src/imports/sensors/plugins.qmltypes
index 86ba0ad0..97a2bcd1 100644
--- a/src/imports/sensors/plugins.qmltypes
+++ b/src/imports/sensors/plugins.qmltypes
@@ -170,6 +170,10 @@ Module {
prototype: "QmlSensor"
exports: ["RotationSensor 5.0", "RotationSensor 5.1"]
Property { name: "hasZ"; type: "bool"; isReadonly: true }
+ Signal {
+ name: "hasZChanged"
+ Parameter { name: "hasZ"; type: "bool" }
+ }
}
Component {
name: "QmlRotationSensorReading"
diff --git a/src/imports/sensors/qmlrotationsensor.cpp b/src/imports/sensors/qmlrotationsensor.cpp
index e58a3f8c..f1821641 100644
--- a/src/imports/sensors/qmlrotationsensor.cpp
+++ b/src/imports/sensors/qmlrotationsensor.cpp
@@ -65,6 +65,7 @@ QmlRotationSensor::QmlRotationSensor(QObject *parent)
: QmlSensor(parent)
, m_sensor(new QRotationSensor(this))
{
+ connect(m_sensor, SIGNAL(hasZChanged(bool)), this, SIGNAL(hasZChanged(bool)));
}
QmlRotationSensor::~QmlRotationSensor()
@@ -90,7 +91,7 @@ QSensor *QmlRotationSensor::sensor() const
bool QmlRotationSensor::hasZ() const
{
- return m_sensor->property("hasZ").toBool();
+ return m_sensor->hasZ();
}
void QmlRotationSensor::_update()
diff --git a/src/imports/sensors/qmlrotationsensor.h b/src/imports/sensors/qmlrotationsensor.h
index 105b0fb8..4d7b543a 100644
--- a/src/imports/sensors/qmlrotationsensor.h
+++ b/src/imports/sensors/qmlrotationsensor.h
@@ -51,13 +51,15 @@ class QRotationSensor;
class QmlRotationSensor : public QmlSensor
{
Q_OBJECT
- Q_PROPERTY(bool hasZ READ hasZ)
+ Q_PROPERTY(bool hasZ READ hasZ NOTIFY hasZChanged)
public:
explicit QmlRotationSensor(QObject *parent = 0);
~QmlRotationSensor();
bool hasZ() const;
+Q_SIGNALS:
+ void hasZChanged(bool hasZ);
private:
QSensor *sensor() const Q_DECL_OVERRIDE;
diff --git a/src/plugins/sensors/generic/genericrotationsensor.cpp b/src/plugins/sensors/generic/genericrotationsensor.cpp
index b5f80cb3..0548adc0 100644
--- a/src/plugins/sensors/generic/genericrotationsensor.cpp
+++ b/src/plugins/sensors/generic/genericrotationsensor.cpp
@@ -57,7 +57,9 @@ genericrotationsensor::genericrotationsensor(QSensor *sensor)
setReading<QRotationReading>(&m_reading);
setDataRates(accelerometer);
- sensor->setProperty("hasZ", false);
+ QRotationSensor * const rotationSensor = qobject_cast<QRotationSensor *>(sensor);
+ if (rotationSensor)
+ rotationSensor->setHasZ(false);
}
void genericrotationsensor::start()
diff --git a/src/sensors/qrotationsensor.cpp b/src/sensors/qrotationsensor.cpp
index 9acc1cd8..ea0515ca 100644
--- a/src/sensors/qrotationsensor.cpp
+++ b/src/sensors/qrotationsensor.cpp
@@ -201,7 +201,7 @@ char const * const QRotationSensor::type("QRotationSensor");
Construct the sensor as a child of \a parent.
*/
QRotationSensor::QRotationSensor(QObject *parent)
- : QSensor(QRotationSensor::type, parent)
+ : QSensor(QRotationSensor::type, *new QRotationSensorPrivate, parent)
{
}
@@ -228,6 +228,28 @@ QRotationSensor::~QRotationSensor()
Returns false if z is not available.
*/
+bool QRotationSensor::hasZ() const
+{
+ Q_D(const QRotationSensor);
+ return (d->hasZ);
+}
+
+/*!
+ \since 5.1
+
+ Sets whether the z angle is available. This is to be called from the
+ backend. By default the hasZ property is true, so a backend only has to
+ call this if its rotation sensor can not report z angles.
+*/
+void QRotationSensor::setHasZ(bool hasZ)
+{
+ Q_D(QRotationSensor);
+ if (d->hasZ != hasZ) {
+ d->hasZ = hasZ;
+ emit hasZChanged(hasZ);
+ }
+}
+
#include "moc_qrotationsensor.cpp"
QT_END_NAMESPACE
diff --git a/src/sensors/qrotationsensor.h b/src/sensors/qrotationsensor.h
index 77da31cd..68a0d1d3 100644
--- a/src/sensors/qrotationsensor.h
+++ b/src/sensors/qrotationsensor.h
@@ -71,19 +71,26 @@ private:
bool filter(QSensorReading *reading) { return filter(static_cast<QRotationReading*>(reading)); }
};
+class QRotationSensorPrivate;
+
class Q_SENSORS_EXPORT QRotationSensor : public QSensor
{
Q_OBJECT
-#ifdef Q_QDOC
- Q_PROPERTY(bool hasZ)
-#endif
+ Q_PROPERTY(bool hasZ READ hasZ NOTIFY hasZChanged)
public:
explicit QRotationSensor(QObject *parent = 0);
virtual ~QRotationSensor();
QRotationReading *reading() const { return static_cast<QRotationReading*>(QSensor::reading()); }
static char const * const type;
+ bool hasZ() const;
+ void setHasZ(bool hasZ);
+
+Q_SIGNALS:
+ void hasZChanged(bool hasZ);
+
private:
+ Q_DECLARE_PRIVATE(QRotationSensor)
Q_DISABLE_COPY(QRotationSensor)
};
diff --git a/src/sensors/qrotationsensor_p.h b/src/sensors/qrotationsensor_p.h
index bf3aef7c..401c2143 100644
--- a/src/sensors/qrotationsensor_p.h
+++ b/src/sensors/qrotationsensor_p.h
@@ -53,6 +53,8 @@
// We mean it.
//
+#include "qsensor_p.h"
+
QT_BEGIN_NAMESPACE
class QRotationReadingPrivate
@@ -70,6 +72,17 @@ public:
qreal z;
};
+class QRotationSensorPrivate : public QSensorPrivate
+{
+public:
+ QRotationSensorPrivate()
+ : hasZ(true)
+ {
+ }
+
+ bool hasZ;
+};
+
QT_END_NAMESPACE
#endif