summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas McGuire <thomas.mcguire.qnx@kdab.com>2013-02-01 10:31:57 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-02-08 11:17:40 +0100
commitb974efa5ca4306b1b9474207317ade4da33bdbc9 (patch)
treeb7d242eea56196b23ffebacd5191f80d809afb3c
parent270e896a26713cb4d7e7c5703a03413bce76e581 (diff)
Convert QLightSensor::fieldOfView to a proper property
Change-Id: Ic6e5388e0cbc2a0045157873c05aa241ffe5e82d Reviewed-by: Lorn Potter <lorn.potter@jollamobile.com>
-rw-r--r--src/imports/sensors/plugins.qmltypes4
-rw-r--r--src/imports/sensors/qmllightsensor.cpp10
-rw-r--r--src/imports/sensors/qmllightsensor.h4
-rw-r--r--src/sensors/qlightsensor.cpp28
-rw-r--r--src/sensors/qlightsensor.h13
-rw-r--r--src/sensors/qlightsensor_p.h11
6 files changed, 56 insertions, 14 deletions
diff --git a/src/imports/sensors/plugins.qmltypes b/src/imports/sensors/plugins.qmltypes
index b6f724a0..88f61f9e 100644
--- a/src/imports/sensors/plugins.qmltypes
+++ b/src/imports/sensors/plugins.qmltypes
@@ -107,6 +107,10 @@ Module {
prototype: "QmlSensor"
exports: ["LightSensor 5.0", "LightSensor 5.1"]
Property { name: "fieldOfView"; type: "double"; isReadonly: true }
+ Signal {
+ name: "fieldOfViewChanged"
+ Parameter { name: "fieldOfView"; type: "double" }
+ }
}
Component {
name: "QmlLightSensorReading"
diff --git a/src/imports/sensors/qmllightsensor.cpp b/src/imports/sensors/qmllightsensor.cpp
index 1c3fed2c..86126a2a 100644
--- a/src/imports/sensors/qmllightsensor.cpp
+++ b/src/imports/sensors/qmllightsensor.cpp
@@ -63,6 +63,8 @@ QmlLightSensor::QmlLightSensor(QObject *parent)
: QmlSensor(parent)
, m_sensor(new QLightSensor(this))
{
+ connect(m_sensor, SIGNAL(fieldOfViewChanged(qreal)),
+ this, SIGNAL(fieldOfViewChanged(qreal)));
}
QmlLightSensor::~QmlLightSensor()
@@ -88,13 +90,7 @@ QSensor *QmlLightSensor::sensor() const
qreal QmlLightSensor::fieldOfView() const
{
- return m_sensor->property("fieldOfView").value<qreal>();
-}
-
-void QmlLightSensor::_update()
-{
- if (fieldOfView() != qreal())
- Q_EMIT fieldOfViewChanged();
+ return m_sensor->fieldOfView();
}
/*!
diff --git a/src/imports/sensors/qmllightsensor.h b/src/imports/sensors/qmllightsensor.h
index de7e3944..e42d7818 100644
--- a/src/imports/sensors/qmllightsensor.h
+++ b/src/imports/sensors/qmllightsensor.h
@@ -58,13 +58,11 @@ public:
qreal fieldOfView() const;
-
Q_SIGNALS:
- void fieldOfViewChanged();
+ void fieldOfViewChanged(qreal fieldOfView);
private:
QSensor *sensor() const Q_DECL_OVERRIDE;
- void _update();
QLightSensor *m_sensor;
QmlSensorReading *createReading() const Q_DECL_OVERRIDE;
};
diff --git a/src/sensors/qlightsensor.cpp b/src/sensors/qlightsensor.cpp
index b712bb6e..f02f6b10 100644
--- a/src/sensors/qlightsensor.cpp
+++ b/src/sensors/qlightsensor.cpp
@@ -120,7 +120,7 @@ char const * const QLightSensor::type("QLightSensor");
Construct the sensor as a child of \a parent.
*/
QLightSensor::QLightSensor(QObject *parent)
- : QSensor(QLightSensor::type, parent)
+ : QSensor(QLightSensor::type, *new QLightSensorPrivate, parent)
{
}
@@ -144,7 +144,33 @@ QLightSensor::~QLightSensor()
\brief a value indicating the field of view.
This is an angle that represents the field of view of the sensor.
+
+ Not all light sensor support retrieving their field of view. For sensors
+ that don't support this property, the value will be 0. Whether the field of
+ view is supported can be checked with QSensor::isFeatureSupported() and the
+ QSensor::FieldOfView flag.
+*/
+
+qreal QLightSensor::fieldOfView() const
+{
+ Q_D(const QLightSensor);
+ return d->fieldOfView;
+}
+
+/*!
+ \since 5.1
+
+ Sets the field of view. This is to be called from the
+ backend.
*/
+void QLightSensor::setFieldOfView(qreal fieldOfView)
+{
+ Q_D(QLightSensor);
+ if (d->fieldOfView != fieldOfView) {
+ d->fieldOfView = fieldOfView;
+ emit fieldOfViewChanged(fieldOfView);
+ }
+}
#include "moc_qlightsensor.cpp"
QT_END_NAMESPACE
diff --git a/src/sensors/qlightsensor.h b/src/sensors/qlightsensor.h
index ddfca171..1da84498 100644
--- a/src/sensors/qlightsensor.h
+++ b/src/sensors/qlightsensor.h
@@ -66,19 +66,26 @@ private:
bool filter(QSensorReading *reading) { return filter(static_cast<QLightReading*>(reading)); }
};
+class QLightSensorPrivate;
+
class Q_SENSORS_EXPORT QLightSensor : public QSensor
{
Q_OBJECT
-#ifdef Q_QDOC
- Q_PROPERTY(qreal fieldOfView)
-#endif
+ Q_PROPERTY(qreal fieldOfView READ fieldOfView NOTIFY fieldOfViewChanged)
public:
explicit QLightSensor(QObject *parent = 0);
virtual ~QLightSensor();
QLightReading *reading() const { return static_cast<QLightReading*>(QSensor::reading()); }
static char const * const type;
+ qreal fieldOfView() const;
+ void setFieldOfView(qreal fieldOfView);
+
+Q_SIGNALS:
+ void fieldOfViewChanged(qreal fieldOfView);
+
private:
+ Q_DECLARE_PRIVATE(QLightSensor)
Q_DISABLE_COPY(QLightSensor)
};
diff --git a/src/sensors/qlightsensor_p.h b/src/sensors/qlightsensor_p.h
index bd0edfc5..a9df63e4 100644
--- a/src/sensors/qlightsensor_p.h
+++ b/src/sensors/qlightsensor_p.h
@@ -68,6 +68,17 @@ public:
qreal lux;
};
+class QLightSensorPrivate : public QSensorPrivate
+{
+public:
+ QLightSensorPrivate()
+ : fieldOfView(0)
+ {
+ }
+
+ qreal fieldOfView;
+};
+
QT_END_NAMESPACE
#endif