summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGatis Paeglis <gatis.paeglis@digia.com>2013-10-10 08:40:39 +0200
committerEirik Aavitsland <eirik.aavitsland@digia.com>2013-10-10 15:39:12 +0300
commit926985dea77120cc901a595bc53d4701b668a1d9 (patch)
treecf11e5f6549ac57d4cbb0ffc0a83f9b7aed88123
parent56cd7ece3a17c0b119bb05f405fcb18896f8fa72 (diff)
[Sensor example] Check for the required sensor types on starup
If the requited sensor dependencies are not met, output an informative message. Change-Id: I1ed73729a100cf9e91a2c8a3aded2a13c09b0bb1 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@digia.com>
-rw-r--r--basicsuite/Sensors/main.qml67
1 files changed, 52 insertions, 15 deletions
diff --git a/basicsuite/Sensors/main.qml b/basicsuite/Sensors/main.qml
index 2e1b820..90d1dcd 100644
--- a/basicsuite/Sensors/main.qml
+++ b/basicsuite/Sensors/main.qml
@@ -1,28 +1,65 @@
import QtQuick 2.0
import QtSensors 5.0
+import QtSensors 5.0 as Sensors
Item {
id: root
width: 800
height: 1280
- Rectangle {
- id: main
- width: root.height
- height: root.width
- anchors.centerIn: parent
- rotation: 90
- border.width: 1
- Light {
- id: lys
- width: main.width
- height: main.height / 2
+ Component {
+ id: sensorExample
+ Rectangle {
+ id: main
+ width: root.height
+ height: root.width
+ rotation: 90
+ border.width: 1
+ Light {
+ id: lys
+ width: main.width
+ height: main.height / 2
+ }
+
+ Accelbubble {
+ width: main.width
+ height: main.height / 2
+ anchors.top: lys.bottom
+ }
+ }
+ }
+
+ Component {
+ id: message
+ Rectangle {
+ width: root.width
+ height: root.height
+ Text {
+ font.pixelSize: 22
+ anchors.centerIn: parent
+ text: "It appears that this device doesn't provide the required sensors!"
+ }
}
+ }
- Accelbubble {
- width: main.width
- height: main.height / 2
- anchors.top: lys.bottom
+ Loader {
+ id: pageLoader
+ anchors.centerIn: parent
+ }
+
+ Component.onCompleted: {
+ var typesList = Sensors.QmlSensors.sensorTypes();
+ var count = 0
+ for (var i = 0; i < typesList.length; ++i) {
+ if (typesList[i] == "QAccelerometer")
+ count++
+ if (typesList[i] == "QLightSensor")
+ count++
}
+
+ if (count > 1)
+ pageLoader.sourceComponent = sensorExample
+ else
+ pageLoader.sourceComponent = message
}
}