From 926985dea77120cc901a595bc53d4701b668a1d9 Mon Sep 17 00:00:00 2001 From: Gatis Paeglis Date: Thu, 10 Oct 2013 08:40:39 +0200 Subject: [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 --- basicsuite/Sensors/main.qml | 67 +++++++++++++++++++++++++++++++++++---------- 1 file 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 } } -- cgit v1.2.3