summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWolfgang Beck <wolfgang.beck@nokia.com>2011-09-28 13:55:12 +1000
committerLincoln Ramsay <lincoln.ramsay@nokia.com>2011-10-10 09:25:31 +1000
commitc25e4e542fd846facb1ca250d44829c0121abdd2 (patch)
treed9133e16dd718488d3d8e22216747b0c9cc6430c
parent4e04cda0e600f4e3bb148956ba631647a5c1fa4c (diff)
MTMW356 Coderevew changes for the AmbientLightSensor QML Element
Change-Id: Ic5ceb21897fdf65ca611ad5ff4c7ac397b44547c Reviewed-on: http://codereview.qt-project.org/5664 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Wolfgang Beck <wolfgang.beck@nokia.com>
-rw-r--r--examples/sensors/qmlqtsensors5/main.qml46
-rw-r--r--src/imports/sensors2/qsensor2ambientlight.cpp76
-rw-r--r--src/imports/sensors2/qsensor2ambientlight.h13
-rw-r--r--tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp8
4 files changed, 63 insertions, 80 deletions
diff --git a/examples/sensors/qmlqtsensors5/main.qml b/examples/sensors/qmlqtsensors5/main.qml
index b0f213ca..e1de1048 100644
--- a/examples/sensors/qmlqtsensors5/main.qml
+++ b/examples/sensors/qmlqtsensors5/main.qml
@@ -238,7 +238,7 @@ Rectangle {
}
Rectangle {
- id: ablrect
+ id: ambientlightrect
x: 2
y: tiltrect.y + tiltrect.height + 10
width: 315
@@ -246,45 +246,45 @@ Rectangle {
border.width: 1
AmbientLightSensor {
- id: abl
- running: false
+ id: ambientlight
+ enabled: false
onLightLevelChanged:{
- if (abl.lightLevel == AmbientLightSensor.Undefined)
- abltext.text = "Ambient light: Undefined";
- else if (abl.lightLevel == AmbientLightSensor.Dark)
- abltext.text = "Ambient light: Dark";
- else if (abl.lightLevel == AmbientLightSensor.Twilight)
- abltext.text = "Ambient light: Twilight";
- else if (abl.lightLevel == AmbientLightSensor.Light)
- abltext.text = "Ambient light: Light";
- else if (abl.lightLevel == AmbientLightSensor.Bright)
- abltext.text = "Ambient light: Bright";
- else if (abl.lightLevel == AmbientLightSensor.Sunny)
- abltext.text = "Ambient light: Sunny";
+ if (ambientlight.lightLevel == AmbientLightSensor.Unknown)
+ ambientlighttext.text = "Ambient light: Unknown";
+ else if (ambientlight.lightLevel == AmbientLightSensor.Dark)
+ ambientlighttext.text = "Ambient light: Dark";
+ else if (ambientlight.lightLevel == AmbientLightSensor.Twilight)
+ ambientlighttext.text = "Ambient light: Twilight";
+ else if (ambientlight.lightLevel == AmbientLightSensor.Light)
+ ambientlighttext.text = "Ambient light: Light";
+ else if (ambientlight.lightLevel == AmbientLightSensor.Bright)
+ ambientlighttext.text = "Ambient light: Bright";
+ else if (ambientlight.lightLevel == AmbientLightSensor.Sunny)
+ ambientlighttext.text = "Ambient light: Sunny";
}
}
Text {
- id: abltext
+ id: ambientlighttext
x: 5
y: 10
text: "Ambient light: -"
}
Button{
- id: ablStart
+ id: ambientlightStart
x: 5
y: 35
text: "start"
checkColor: "lightblue"
unCheckColor: "lightyellow"
- checked: abl.running
+ checked: ambientlight.enabled
color: "lightyellow"
onClicked:{
- abl.running = ablStart.checked;
- if (ablStart.checked)
- ablStart.text = "running";
+ ambientlight.enabled = ambientlightStart.checked;
+ if (ambientlightStart.checked)
+ ambientlightStart.text = "running";
else
- ablStart.text = "stopped";
+ ambientlightStart.text = "stopped";
}
}
}
@@ -292,7 +292,7 @@ Rectangle {
Rectangle {
id: proxirect
x: 2
- y: ablrect.y + ablrect.height + 10
+ y: ambientlightrect.y + ambientlightrect.height + 10
width: 315
height: 70
border.width: 1
diff --git a/src/imports/sensors2/qsensor2ambientlight.cpp b/src/imports/sensors2/qsensor2ambientlight.cpp
index e2a99510..376b8919 100644
--- a/src/imports/sensors2/qsensor2ambientlight.cpp
+++ b/src/imports/sensors2/qsensor2ambientlight.cpp
@@ -52,37 +52,10 @@ QT_BEGIN_NAMESPACE
\brief The AmbientLightSensor element provide an easy access to determine the ambient light by using the ambient light sensor.
This element is part of the \bold{QtSensors 5} module.
-
- \target lightLevelenum
- \section1 Enums
- \section2 AmbientLightSensor::LighLevel
-
- This enum describes the ambient light levels.
-
- \table
- \row
- \o AmbientLightSensor::Undefined
- \o Ambient light not defined.
- \row
- \o AmbientLightSensor::Dark
- \o Ambient light is dark.
- \row
- \o AmbientLightSensor::Twilight
- \o Ambient light is twilight.
- \row
- \o AmbientLightSensor::Light
- \o Ambient light is light.
- \row
- \o AmbientLightSensor::Bright
- \o Ambient light is bright.
- \row
- \o AmbientLightSensor::Sunny
- \o Ambient light is sunny.
- \endtable
*/
QSensor2AmbientLight::QSensor2AmbientLight(QObject* parent)
: QObject(parent)
- , _lightLevel(QSensor2AmbientLight::Undefined)
+ , _lightLevel(QSensor2AmbientLight::Unknown)
{
_ambientLight = new QAmbientLightSensor(this);
_ambientLight->addFilter(this);
@@ -94,21 +67,17 @@ QSensor2AmbientLight::~QSensor2AmbientLight()
}
/*!
- \qmlproperty bool QtSensors5::AmbientLightSensor::running
- Holds the identication if the sensor runs or not.
-*/
-/*!
- \qmlsignal QtSensors5::AmbientLightSensor::onRunningChanged()
- This signal is emitted whenever the value of the property running has been changed.
+ \qmlproperty bool QtSensors5::QSensor2AmbientLight::enabled
+ This property can be used to activate or deactivate the sensor.
*/
-bool QSensor2AmbientLight::running()
+bool QSensor2AmbientLight::enabled()
{
return _ambientLight->isActive();
}
-void QSensor2AmbientLight::setRunning(bool val)
+void QSensor2AmbientLight::setEnabled(bool val)
{
- bool active = running();
+ bool active = enabled();
if (active != val){
if (val){
bool ret = _ambientLight->start();
@@ -117,20 +86,35 @@ void QSensor2AmbientLight::setRunning(bool val)
}
else
_ambientLight->stop();
- emit runningChanged();
+ emit enabledChanged();
}
}
/*!
- \qmlproperty AmbientLightSensor::LightLevel QtSensors5::AmbientLightSensor::lightLevel
- Holds the ambient light level.
- \sa {lightLevelenum} {AmbientLightSensor::LighLevel}
-*/
-/*!
- \qmlsignal QtSensors5::AmbientLightSensor::onLightLevelChanged()
- This signal is emitted whenever the value of the property lightLevel has been changed.
-*/
+ \qmlproperty enumeration QtSensors5::AmbientLightSensor::lightLevel
+ Holds the ambient light level in the form of the LightLevel enum:
+ \table
+ \row
+ \o AmbientLightSensor.Unknown
+ \o Ambient light value is not set yet.
+ \row
+ \o AmbientLightSensor.Dark
+ \o It is dark.
+ \row
+ \o AmbientLightSensor.Twilight
+ \o It is moderately dark.
+ \row
+ \o AmbientLightSensor.Light
+ \o It is light (eg. internal lights).
+ \row
+ \o AmbientLightSensor.Bright
+ \o It is bright (eg. shade).
+ \row
+ \o AmbientLightSensor.Sunny
+ \o It is very bright (eg. direct sunlight).
+ \endtable
+*/
QSensor2AmbientLight::LightLevel QSensor2AmbientLight::lightLevel()
{
return _lightLevel;
diff --git a/src/imports/sensors2/qsensor2ambientlight.h b/src/imports/sensors2/qsensor2ambientlight.h
index 5b9a516a..e111508a 100644
--- a/src/imports/sensors2/qsensor2ambientlight.h
+++ b/src/imports/sensors2/qsensor2ambientlight.h
@@ -52,14 +52,14 @@ class QSensor2AmbientLight : public QObject, public QAmbientLightFilter
Q_OBJECT
Q_ENUMS(LightLevel)
Q_PROPERTY(LightLevel lightLevel READ lightLevel NOTIFY lightLevelChanged)
- Q_PROPERTY(bool running READ running WRITE setRunning NOTIFY runningChanged)
+ Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
public:
QSensor2AmbientLight(QObject* parent = 0);
virtual ~QSensor2AmbientLight();
enum LightLevel {
- Undefined = 0,
+ Unknown = 0,
Dark,
Twilight,
Light,
@@ -69,22 +69,21 @@ public:
Q_SIGNALS:
void lightLevelChanged();
- void runningChanged();
+ void enabledChanged();
private:
// Override of QAmbientLightFilter::filter(QAmbientLightReading*)
bool filter(QAmbientLightReading *reading);
LightLevel lightLevel();
- bool running();
- void setRunning(bool val);
+ bool enabled();
+ void setEnabled(bool val);
QAmbientLightSensor* _ambientLight;
LightLevel _lightLevel;
};
-QML_DECLARE_TYPE(QT_PREPEND_NAMESPACE(QSensor2AmbientLight))
-
QT_END_NAMESPACE
+QML_DECLARE_TYPE(QSensor2AmbientLight)
#endif // QSENSOR2AMBIENTLIGHT_H
diff --git a/tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp b/tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp
index 33de1e70..9ffafb94 100644
--- a/tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp
+++ b/tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp
@@ -114,12 +114,12 @@ void tst_Sensors2QMLAPI::testProximity()
void tst_Sensors2QMLAPI::testAmbientLight()
{
QSensor2AmbientLight als;
- QSignalSpy spy(&als, SIGNAL(runningChanged()));
- als.setProperty("running", QVariant(true));
+ QSignalSpy spy(&als, SIGNAL(enabledChanged()));
+ als.setProperty("enabled", QVariant(true));
QCOMPARE(spy.count() , 1);
spy.clear();
- als.setProperty("running", QVariant(true));
+ als.setProperty("enabled", QVariant(true));
QCOMPARE(spy.count() , 0);
TestSensorPlugin plugin;
@@ -138,7 +138,7 @@ void tst_Sensors2QMLAPI::testAmbientLight()
abl->test((QSensor2AmbientLight::LightLevel)en);
QCOMPARE(spy1.count() , 0);
}
- als.setProperty("running", QVariant(false));
+ als.setProperty("enabled", QVariant(false));
}
void tst_Sensors2QMLAPI::testTilt_data()