From 4e857032c66ffd92c5660cbc2cb9eced3ba82320 Mon Sep 17 00:00:00 2001 From: Gatis Paeglis Date: Fri, 20 Sep 2013 13:44:31 +0200 Subject: Add sensor explorer demo to basicsuite Change-Id: Ifb2ea5b161d09ea500f7b51c8b0ffc422ab62073 Reviewed-by: Eirik Aavitsland --- basicsuite/SensorExplorer/SensorExplorer.pro | 4 + basicsuite/SensorExplorer/description.txt | 1 + .../SensorExplorer/doc/src/sensor_explorer.qdoc | 91 ++++++ basicsuite/SensorExplorer/imports/explorer.cpp | 136 +++++++++ basicsuite/SensorExplorer/imports/explorer.h | 79 +++++ basicsuite/SensorExplorer/imports/imports.pro | 17 ++ basicsuite/SensorExplorer/imports/main.cpp | 63 ++++ basicsuite/SensorExplorer/imports/plugin.json | 1 + basicsuite/SensorExplorer/imports/propertyinfo.cpp | 140 +++++++++ basicsuite/SensorExplorer/imports/propertyinfo.h | 83 ++++++ basicsuite/SensorExplorer/imports/qmldir | 2 + basicsuite/SensorExplorer/imports/sensoritem.cpp | 322 +++++++++++++++++++++ basicsuite/SensorExplorer/imports/sensoritem.h | 96 ++++++ basicsuite/SensorExplorer/main.qml | 224 ++++++++++++++ basicsuite/SensorExplorer/preview_l.jpg | Bin 0 -> 21818 bytes basicsuite/SensorExplorer/title.txt | 1 + basicsuite/basicsuite.pro | 3 +- 17 files changed, 1262 insertions(+), 1 deletion(-) create mode 100644 basicsuite/SensorExplorer/SensorExplorer.pro create mode 100644 basicsuite/SensorExplorer/description.txt create mode 100644 basicsuite/SensorExplorer/doc/src/sensor_explorer.qdoc create mode 100644 basicsuite/SensorExplorer/imports/explorer.cpp create mode 100644 basicsuite/SensorExplorer/imports/explorer.h create mode 100644 basicsuite/SensorExplorer/imports/imports.pro create mode 100644 basicsuite/SensorExplorer/imports/main.cpp create mode 100644 basicsuite/SensorExplorer/imports/plugin.json create mode 100644 basicsuite/SensorExplorer/imports/propertyinfo.cpp create mode 100644 basicsuite/SensorExplorer/imports/propertyinfo.h create mode 100644 basicsuite/SensorExplorer/imports/qmldir create mode 100644 basicsuite/SensorExplorer/imports/sensoritem.cpp create mode 100644 basicsuite/SensorExplorer/imports/sensoritem.h create mode 100644 basicsuite/SensorExplorer/main.qml create mode 100644 basicsuite/SensorExplorer/preview_l.jpg create mode 100644 basicsuite/SensorExplorer/title.txt (limited to 'basicsuite') diff --git a/basicsuite/SensorExplorer/SensorExplorer.pro b/basicsuite/SensorExplorer/SensorExplorer.pro new file mode 100644 index 0000000..175b966 --- /dev/null +++ b/basicsuite/SensorExplorer/SensorExplorer.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs +SUBDIRS += \ + imports + diff --git a/basicsuite/SensorExplorer/description.txt b/basicsuite/SensorExplorer/description.txt new file mode 100644 index 0000000..9724112 --- /dev/null +++ b/basicsuite/SensorExplorer/description.txt @@ -0,0 +1 @@ +This example provides a list of all available sensors installed on the system for which Qt has a backend. Start a sensor to see how values changes depending from environment and user-device interaction. diff --git a/basicsuite/SensorExplorer/doc/src/sensor_explorer.qdoc b/basicsuite/SensorExplorer/doc/src/sensor_explorer.qdoc new file mode 100644 index 0000000..be04215 --- /dev/null +++ b/basicsuite/SensorExplorer/doc/src/sensor_explorer.qdoc @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example sensor_explorer + \title Qt Sensors - Explorer QML example + \ingroup qtsensors-examples + + \section2 Sensor Explorer in QML + \brief The Sensor Explorer example demonstrates how to read the meta-data of available sensors. + + + This example is divided into two parts: + + \list + \li A \l{Sensor Explorer QML Import}{C++ plug-in} that provides QML alternatives for QSensorExplorer, QPropertyInfo and the QSensorItem classes. + \li A QML Application that uses the QML alternatives to read the sensors meta-data and present it. + \endlist + + + This is a pure QML application that can be run from Qt Creator or directly using the + \c qmlscene binary. You should install the other C++ plug-in before trying to run + this example, otherwise it will not find its dependencies. + + \code + qmlscene main.qml + \endcode + + To write a QML application that will use the Explorer QML type you need to do the following steps: + + Import the Explorer 1.0 declarative plugin: + + \snippet sensor_explorer/sensor_explorer.qml 0 + + Create a SensorExplorer QML item: + + \snippet sensor_explorer/sensor_explorer.qml 1 + + You can retrieve a list of all available sensors using the SensorExplorer: + + \snippet sensor_explorer/sensor_explorer.qml 2 + + To retrieve the properties of a SensorItem use: + + \snippet sensor_explorer/sensor_explorer.qml 3 + + Changing a property value can be done like: + + \snippet sensor_explorer/sensor_explorer.qml 4 + + Starting and stopping a sensor can be done like: + + \snippet sensor_explorer/sensor_explorer.qml 5 +*/ + +/*! + \example sensor_explorer/import + \title Sensor Explorer QML Import + + \section2 Sensor Explorer Declarative Plugin + \brief The Sensor Explorer QML import exports the QSensorExplorer, QPropertyInfo and the QSensorItem class as a QML type. + + This example creates the \e {Explorer 1.0} import. + + \sa {Qt Sensors - Explorer QML example} +*/ + diff --git a/basicsuite/SensorExplorer/imports/explorer.cpp b/basicsuite/SensorExplorer/imports/explorer.cpp new file mode 100644 index 0000000..f9edc90 --- /dev/null +++ b/basicsuite/SensorExplorer/imports/explorer.cpp @@ -0,0 +1,136 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "explorer.h" +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +/* + \class QSensorExplorer + \brief The QSensorExplorer type provides an easy access for reading all avalaible sensors installed on the system. +*/ + +/* + Construct a QSensorExplorer object with parent \a parent +*/ +QSensorExplorer::QSensorExplorer(QObject* parent) + : QObject(parent) + , _selectedSensorItem(0) +{ + loadSensors(); +} + +/* + Destructor of a QSensorExplorer +*/ +QSensorExplorer::~QSensorExplorer() +{ +} + +/* + Load all available sensors and store it in a list. +*/ +void QSensorExplorer::loadSensors() +{ + _availableSensors.clear(); + foreach (const QByteArray &type, QSensor::sensorTypes()) { + foreach (const QByteArray &identifier, QSensor::sensorsForType(type)) { + // Don't put in sensors we can't connect to + QSensor* sensor = new QSensor(type, this); + //sensor->setIdentifier(identifier); + if (!sensor->connectToBackend()) { + qWarning() << "Couldn't connect to" << sensor->description(); + continue; + } + _availableSensors.append(new QSensorItem(sensor, this)); + } + } + emit availableSensorsChanged(); +} + +/* + \fn QSensorExplorer::availableSensorsChanged() + Notifies the client if the list of the available sensors was changed +*/ + +/* + \property QSensorExplorer::availableSensors + Returns a list of all available sensor. +*/ +QQmlListProperty QSensorExplorer::availableSensors() +{ + return QQmlListProperty(this,_availableSensors); +} + +/* + \fn QSensorExplorer::selectedSensorItemChanged() + Notifies the client if the selected sensor has been changed +*/ + +/* + \property QSensorExplorer::selectedSensorItem + Returns the current selected sensor item. +*/ +QSensorItem* QSensorExplorer::selectedSensorItem() +{ + return _selectedSensorItem; +} + +/* + \fn QSensorExplorer::setSelectedSensorItem(QSensorItem* selitem) + Sets the QSensorItem \a selitem as the current selected QSensorItem. +*/ +void QSensorExplorer::setSelectedSensorItem(QSensorItem* selitem) +{ + if (selitem && _selectedSensorItem != selitem) { + if (_selectedSensorItem) + _selectedSensorItem->unSelect(); + _selectedSensorItem = selitem; + _selectedSensorItem->select(); + emit selectedSensorItemChanged(); + } +} + +QT_END_NAMESPACE diff --git a/basicsuite/SensorExplorer/imports/explorer.h b/basicsuite/SensorExplorer/imports/explorer.h new file mode 100644 index 0000000..d9d9546 --- /dev/null +++ b/basicsuite/SensorExplorer/imports/explorer.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSEONSOREXPLORER_H +#define QSEONSOREXPLORER_H + +#include +#include +#include "sensoritem.h" + +QT_BEGIN_NAMESPACE + +class QSensorExplorer : public QObject +{ + Q_OBJECT + Q_PROPERTY(QQmlListProperty availableSensors READ availableSensors NOTIFY availableSensorsChanged) + Q_PROPERTY(QSensorItem* selectedSensorItem READ selectedSensorItem WRITE setSelectedSensorItem NOTIFY selectedSensorItemChanged) +public: + QSensorExplorer(QObject* parent = 0); + virtual ~QSensorExplorer(); + +private: + QQmlListProperty availableSensors(); + void loadSensors(); + void setSelectedSensorItem(QSensorItem* selitem); + QSensorItem* selectedSensorItem(); + +Q_SIGNALS: + void availableSensorsChanged(); + void selectedSensorItemChanged(); + +private: + QList _availableSensors; + QSensorItem* _selectedSensorItem; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QSensorExplorer) + +#endif // QSEONSOREXPLORER_H diff --git a/basicsuite/SensorExplorer/imports/imports.pro b/basicsuite/SensorExplorer/imports/imports.pro new file mode 100644 index 0000000..c596185 --- /dev/null +++ b/basicsuite/SensorExplorer/imports/imports.pro @@ -0,0 +1,17 @@ +CXX_MODULE = qml +TARGET = sensorexplorer +TARGETPATH = Explorer +IMPORT_VERSION = 1.0 + +QT += qml sensors + +SOURCES = main.cpp \ + explorer.cpp \ + sensoritem.cpp \ + propertyinfo.cpp \ + +HEADERS = explorer.h \ + sensoritem.h \ + propertyinfo.h \ + +load(qml_plugin) diff --git a/basicsuite/SensorExplorer/imports/main.cpp b/basicsuite/SensorExplorer/imports/main.cpp new file mode 100644 index 0000000..3a8f506 --- /dev/null +++ b/basicsuite/SensorExplorer/imports/main.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include "explorer.h" + +QT_BEGIN_NAMESPACE + +class SensorExplorerDeclarativeModule : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface" FILE "plugin.json") +public: + virtual void registerTypes(const char *uri) + { + Q_ASSERT(QLatin1String(uri) == QLatin1String("Explorer")); + qmlRegisterType(uri, 1, 0, "SensorExplorer"); + qmlRegisterType(uri, 1, 0, "SensorItem"); + qmlRegisterType(uri, 1, 0, "PropertyInfo"); + } +}; + +QT_END_NAMESPACE + +#include "main.moc" diff --git a/basicsuite/SensorExplorer/imports/plugin.json b/basicsuite/SensorExplorer/imports/plugin.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/basicsuite/SensorExplorer/imports/plugin.json @@ -0,0 +1 @@ +{} diff --git a/basicsuite/SensorExplorer/imports/propertyinfo.cpp b/basicsuite/SensorExplorer/imports/propertyinfo.cpp new file mode 100644 index 0000000..0481d4d --- /dev/null +++ b/basicsuite/SensorExplorer/imports/propertyinfo.cpp @@ -0,0 +1,140 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sensoritem.h" +#include +#include + +QT_BEGIN_NAMESPACE + +/* + \class QPropertyInfo + \brief The QPropertyInfo type provides an easy access for reading and writing the property values. +*/ + +/* + Construct a QPropertyInfo object with parent \a parent +*/ +QPropertyInfo::QPropertyInfo(QObject* parent) + : QObject(parent) + , _index(0) + , _isWriteable(false) + , _name("") + , _typeName("") + , _value("") +{} + +/* + Construct a QPropertyInfo object with parent \a parent, property name \a name, property index \a index, + property write access \a writeable, property type \a typeName and property value \a value +*/ +QPropertyInfo::QPropertyInfo(const QString& name, int index, bool writeable, const QString& typeName, const QString& value, QObject* parent) + : QObject(parent) + , _index(index) + , _isWriteable(writeable) + , _name(name) + , _typeName(typeName) + , _value(value) +{} + +/* + \property QPropertyInfo::name + Returns the name of the property +*/ +QString QPropertyInfo::name() +{ + return _name; +} + +/* + \property QPropertyInfo::typeName + Returns the type of the property +*/ +QString QPropertyInfo::typeName() +{ + return _typeName; +} + +/* + \property QPropertyInfo::value + Returns the current value of the property +*/ +QString QPropertyInfo::value() +{ + return _value; +} + +/* + \fn void QPropertyInfo::valueChanged() + Signal that notifies the client if the property value was changed. +*/ + +/* + \fn QPropertyInfo::setValue(const QString& value) + Sets the value \a value of the property +*/ +void QPropertyInfo::setValue(const QString& value) +{ + if (value != _value){ + _value = value; + emit valueChanged(); + } +} + +/* + \fn QPropertyInfo::index() + Returns the meta-data index of the property +*/ +int QPropertyInfo::index() +{ + return _index; +} + +/* + \property QPropertyInfo::isWriteable + Returns true if the property is writeable false if property is read only +*/ +bool QPropertyInfo::isWriteable() +{ + return _isWriteable; +} + +QT_END_NAMESPACE diff --git a/basicsuite/SensorExplorer/imports/propertyinfo.h b/basicsuite/SensorExplorer/imports/propertyinfo.h new file mode 100644 index 0000000..72ce640 --- /dev/null +++ b/basicsuite/SensorExplorer/imports/propertyinfo.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QPROPERTYINFO_H +#define QPROPERTYINFO_H + +#include +#include + +QT_BEGIN_NAMESPACE + +class QPropertyInfo : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString name READ name CONSTANT) + Q_PROPERTY(QString typeName READ typeName CONSTANT) + Q_PROPERTY(QString value READ value NOTIFY valueChanged) + Q_PROPERTY(bool isWriteable READ isWriteable CONSTANT) + +public: + QPropertyInfo(QObject* parent = 0); + QPropertyInfo(const QString& name, int index, bool writeable, const QString& typeName, const QString& value, QObject* parent=0); + QString name(); + QString typeName(); + QString value(); + void setValue(const QString& value); + int index(); + bool isWriteable(); + +Q_SIGNALS: + void valueChanged(); + +private: + int _index; + bool _isWriteable; + QString _name; + QString _typeName; + QString _value; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QPropertyInfo) + +#endif // QPROPERTYINFO_H diff --git a/basicsuite/SensorExplorer/imports/qmldir b/basicsuite/SensorExplorer/imports/qmldir new file mode 100644 index 0000000..ad67d81 --- /dev/null +++ b/basicsuite/SensorExplorer/imports/qmldir @@ -0,0 +1,2 @@ +module Explorer +plugin sensorexplorer diff --git a/basicsuite/SensorExplorer/imports/sensoritem.cpp b/basicsuite/SensorExplorer/imports/sensoritem.cpp new file mode 100644 index 0000000..cd33549 --- /dev/null +++ b/basicsuite/SensorExplorer/imports/sensoritem.cpp @@ -0,0 +1,322 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sensoritem.h" +#include +#include + +QT_BEGIN_NAMESPACE + +/* + \class QSensorItem + \brief The QSensorItem type provides information about the meta-data from a sensors installed on the system. +*/ + +/* + Construct a QSensorItem object with parent \a parent +*/ +QSensorItem::QSensorItem(QObject* parent) + : QObject(parent) + , _qsensor(0) +{ +} + +/* + Construct a QSensorItem object with QSensor \a sensor and parent \a parent +*/ +QSensorItem::QSensorItem(QSensor* sensor, QObject* parent) + : QObject(parent) + , _qsensor(sensor) +{ +} + +/* + Destructor of a QSensorItem +*/ +QSensorItem::~QSensorItem() +{ +} + +/* + \fn QSensorItem::startChanged() + Notifies the client if the sensors has changed its start active status +*/ + +/* + \property QSensorItem::start + This property starts or stops the sensor +*/ +bool QSensorItem::start() +{ + return (_qsensor ? _qsensor->isActive() : false); +} + +void QSensorItem::setStart(bool run) +{ + if (_qsensor) + _qsensor->setActive(run); +} + +/* + \property QSensorItem::id + Returns the sensor id of the sensor item +*/ +QString QSensorItem::id() +{ + return (_qsensor ? _qsensor->description() : ""); +} + +/* + Set the new value \a val to the QPropertyInfo object \a property +*/ +void QSensorItem::changePropertyValue(QPropertyInfo* property, const QString& val) +{ + if (_qsensor && _sensorProperties.contains(property)){ + if ( _qsensor->setProperty(property->name().toLatin1().constData(), QVariant(val))) + updateSensorPropertyValues(); + else + qWarning() << "new property value couldn't be set"; + } +} + +/* + Reading the meta-data and activates the sensor. +*/ +void QSensorItem::select() +{ + if (_sensorProperties.isEmpty()) { + // Probe the reading using Qt's meta-object facilities + //Read properties from reader + QSensorReading *reading = _qsensor->reading(); + const QMetaObject *mo = reading->metaObject(); + int firstProperty = QSensorReading::staticMetaObject.propertyOffset(); + + for (int i = firstProperty; i < mo->propertyCount(); ++i) { + QString typeName = QLatin1String(mo->property(i).typeName()); + int crap = typeName.lastIndexOf("::"); + if (crap != -1) + typeName = typeName.mid(crap + 2); + + QPropertyInfo* pi = new QPropertyInfo(mo->property(i).name() + , i + , isWriteable(mo->property(i).name()) + , typeName + , "-" + , this); + _readerProperties.append(pi); + } + + //Read properties from sensor + const QMetaObject *mo1 = _qsensor->metaObject(); + firstProperty = QSensorReading::staticMetaObject.propertyOffset(); + + for (int i = firstProperty; i < mo1->propertyCount(); ++i) { + QString propertyname = mo1->property(i).name(); + if (ignoreProperty(propertyname)) + continue; + + QString typeName = QLatin1String(mo1->property(i).typeName()); + int crap = typeName.lastIndexOf("::"); + if (crap != -1) + typeName = typeName.mid(crap + 2); + + QPropertyInfo* pi = new QPropertyInfo(propertyname + , i + , isWriteable(propertyname) + , typeName + , "-" + , this); + _sensorProperties.append(pi); + } + updateSensorPropertyValues(); + connect(_qsensor, SIGNAL(readingChanged()), this, SLOT(sensorReadingChanged())); + } + connect(_qsensor, SIGNAL(activeChanged()), SIGNAL(startChanged())); +} + +/* + Unselect the sensor by stopping the sensor. +*/ +void QSensorItem::unSelect() +{ + _qsensor->stop(); + disconnect(_qsensor, SIGNAL(activeChanged()), this , SIGNAL(startChanged())); +} + +/* + Updates the property values from QSensor +*/ +void QSensorItem::updateSensorPropertyValues() +{ + if (_qsensor){ + const QMetaObject *mo = _qsensor->metaObject(); + for (int i = 0; i < _sensorProperties.count(); i++){ + QVariant val = mo->property(_sensorProperties[i]->index()).read(_qsensor); + _sensorProperties[i]->setValue(convertValue(_sensorProperties[i]->typeName(), val)); + } + } +} + +/* + \fn QSensorItem::propertiesChanged() + Notifies the client if the list of the properties was changed +*/ + +/* + Updates the property values from the QSensorReader +*/ +void QSensorItem::sensorReadingChanged() +{ + QSensorReading *reading = _qsensor->reading(); + const QMetaObject *mo = reading->metaObject(); + for (int i = 0; i < _readerProperties.count(); i++){ + QVariant val = mo->property(_readerProperties[i]->index()).read(reading); + _readerProperties[i]->setValue(convertValue(_readerProperties[i]->typeName(), val)); + } +} + +/* + Returns true if the property with the name \a propertyname should be ignored +*/ +bool QSensorItem::ignoreProperty(const QString& propertyname) +{ + if (propertyname == "reading" || + propertyname == "active" || + propertyname == "identifier" || + propertyname == "connectedToBackend" || + propertyname == "busy") + return true; + + return false; +} + +/* + Returns true if the property with the name \a propertyname is writeable +*/ +bool QSensorItem::isWriteable(const QString& propertyname) +{ + if (_qsensor){ + const QMetaObject *mo = _qsensor->metaObject(); + int propertyindex = mo->indexOfProperty(propertyname.toLocal8Bit().constData()); + if (propertyindex >= 0){ + QMetaProperty prop = mo->property(propertyindex); + return prop.isWritable(); + } + else { + QSensorReading *reading = _qsensor->reading(); + const QMetaObject *moreader = reading->metaObject(); + propertyindex = moreader->indexOfProperty(propertyname.toLocal8Bit().constData()); + if (propertyindex >= 0){ + QMetaProperty prop = mo->property(propertyindex); + return prop.isWritable(); + } + } + } + + return false; +} + +/* + Convert the variant \a val dependent on the type \a type and returns the converted value as a QString +*/ +QString QSensorItem::convertValue(const QString& type, const QVariant& val) +{ + if (type == "LightLevel"){ + switch (val.toInt()) { + case 1: return "Dark"; + case 2: return "Twilight"; + case 3: return "Light"; + case 4: return "Bright"; + case 5: return "Sunny"; + default: return "Undefined"; + } + } + else if (type == "Orientation"){ + switch (val.toInt()) { + case 1: return "TopUp"; + case 2: return "TopDown"; + case 3: return "LeftUp"; + case 4: return "RightUp"; + case 5: return "FaceUp"; + case 6: return "FaceDown"; + default: return "Undefined"; + } + } + else if (type == "qrangelist"){ + qrangelist rangelist = val.value(); + QStringList ranges; + foreach (const qrange &r, rangelist) { + if (r.first == r.second) + ranges << QString("%1 Hz").arg(r.first); + else + ranges << QString("%1-%2 Hz").arg(r.first).arg(r.second); + } + if (ranges.count() > 0) + return ranges.join(", "); + return "-"; + } + else if (type == "qoutputrangelist") { + qoutputrangelist rangelist = val.value(); + QStringList ranges; + foreach (const qoutputrange &r, rangelist) { + ranges << QString("(%1, %2) += %3").arg(r.minimum).arg(r.maximum).arg(r.accuracy); + } + if (ranges.count() > 0) + return ranges.join(", "); + return "-"; + } + + return val.toString(); +} + +/* + \property QSensorItem::properties + Returns a list of all properties from the sensor +*/ +QQmlListProperty QSensorItem::properties() +{ + _properties.clear(); + _properties.append(_sensorProperties); + _properties.append(_readerProperties); + return QQmlListProperty (this, _properties); +} + +QT_END_NAMESPACE diff --git a/basicsuite/SensorExplorer/imports/sensoritem.h b/basicsuite/SensorExplorer/imports/sensoritem.h new file mode 100644 index 0000000..b17d8ed --- /dev/null +++ b/basicsuite/SensorExplorer/imports/sensoritem.h @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSENSORITEM_H +#define QSENSORITEM_H + +#include +#include +#include "propertyinfo.h" + +QT_BEGIN_NAMESPACE + +class QSensor; +class QSensorItem : public QObject +{ + Q_OBJECT + Q_PROPERTY(bool start READ start WRITE setStart NOTIFY startChanged) + Q_PROPERTY(QString id READ id CONSTANT) + Q_PROPERTY(QQmlListProperty properties READ properties NOTIFY propertiesChanged) +public: + QSensorItem(QObject* parent = 0); + QSensorItem(QSensor* sensor, QObject* parent = 0); + virtual ~QSensorItem(); + +public slots: + void select(); + void unSelect(); + void changePropertyValue(QPropertyInfo* property, const QString& val); + +private slots: + void sensorReadingChanged(); + +private: + QString id(); + bool start(); + void setStart(bool run); + QQmlListProperty properties(); + QString convertValue(const QString& type, const QVariant& val); + bool isWriteable(const QString& propertyname); + bool ignoreProperty(const QString& propertyname); + void updateSensorPropertyValues(); + +Q_SIGNALS: + void propertiesChanged(); + void startChanged(); + +private: + QSensor* _qsensor; + QList _properties; + QList _readerProperties; + QList _sensorProperties; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QSensorItem) + +#endif // QSENSORITEM_H diff --git a/basicsuite/SensorExplorer/main.qml b/basicsuite/SensorExplorer/main.qml new file mode 100644 index 0000000..7b71250 --- /dev/null +++ b/basicsuite/SensorExplorer/main.qml @@ -0,0 +1,224 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Controls 1.0 +import QtSensors 5.0 + +//! [0] +import Explorer 1.0 +//! [0] + +Item { + id: root + width: 800 + height: 1280 + Rectangle { + id: main + width: root.height + height: root.width + anchors.centerIn: parent + rotation: -90 + + //! [1] + SensorExplorer { + id: explorer + } + //! [1] + + Column { + anchors.fill: parent + anchors.margins: 8 + spacing: 8 + + GroupBox { + id: topBox + title: qsTr("Available Sensors") + width: parent.width + height: main.height * 0.4 + + TableView { + id: sensorList + width: parent.width + height: parent.height * 0.80 + anchors.top: parent.top + anchors.topMargin: 22 + //! [2] + model: explorer.availableSensors + //! [2] + + TableViewColumn { role: "id"; title: qsTr("ID"); width: main.width * 0.7 } + TableViewColumn { role: "start"; title: qsTr("Running"); width: main.width * 0.15 } + + onClicked: { + explorer.selectedSensorItem = explorer.availableSensors[row] + //! [3] + propertyList.model = explorer.selectedSensorItem.properties + //! [3] + button.update() + } + } + + Button { + id: button + anchors.top: sensorList.bottom + anchors.right: parent.right + anchors.topMargin: 8 + text: qsTr("Start") + enabled: explorer.selectedSensorItem !== null + + function update() { + text = (explorer.selectedSensorItem !== null ? + (explorer.selectedSensorItem.start === true ? + qsTr("Stop") : qsTr("Start")) : qsTr("Start")) + } + + onClicked: { + if (explorer.selectedSensorItem !== null) { + //! [5] + if (text === "Start") { + explorer.selectedSensorItem.start = true; + text = "Stop"; + } + else { + explorer.selectedSensorItem.start = false; + text = "Start"; + } + //! [5] + } + } + } + + } + + GroupBox { + title: qsTr("Properties") + width: parent.width + height: main.height - topBox.height - 30 + enabled: explorer.selectedSensorItem != null + + TableView { + id: propertyList + property PropertyInfo selectedItem: null + + anchors.fill: parent + anchors.topMargin: 22 + + TableViewColumn { role: "name"; title: qsTr("Name"); width: 140 } + TableViewColumn { role: "value"; title: qsTr("Value"); width: 140 } + + onClicked: { + selectedItem = model[row] + } + + itemDelegate: { + if (selectedItem && selectedItem.isWriteable) + return editableDelegate; + return readOnlyDelegate; + } + + Component { + id: readOnlyDelegate + Item { + Text { + width: parent.width + anchors.margins: 4 + anchors.left: parent.left + anchors.verticalCenter: parent.verticalCenter + elide: styleData.elideMode + text: styleData.value + color: propertyList.model[styleData.row].isWriteable ? + styleData.textColor : Qt.lighter(styleData.textColor) + } + } + } + + Component { + id: editableDelegate + Item { + Text { + width: parent.width + anchors.margins: 4 + anchors.left: parent.left + anchors.verticalCenter: parent.verticalCenter + elide: styleData.elideMode + text: styleData.value + color: styleData.textColor + visible: !styleData.selected || styleData.column === 0 + } + Loader { // Initialize text editor lazily to improve performance + id: loaderEditor + anchors.margins: 4 + anchors.left: parent.left + anchors.verticalCenter: parent.verticalCenter + Connections { + target: loaderEditor.item + onAccepted: { + //! [4] + explorer.selectedSensorItem.changePropertyValue(propertyList.selectedItem, loaderEditor.item.text); + //! [4] + } + } + + // Load the editor for selected 'Value' cell + sourceComponent: (styleData.selected && styleData.column === 1) ? editor : null + + Component { + id: editor + TextInput { // ### TODO - this needs to utilize a virtual keyboard + id: textinput + color: styleData.textColor + text: styleData.value + MouseArea { + id: mouseArea + anchors.fill: parent + hoverEnabled: true + onClicked: textinput.forceActiveFocus() + } + } + } + } + } + } + } + } + } + } +} diff --git a/basicsuite/SensorExplorer/preview_l.jpg b/basicsuite/SensorExplorer/preview_l.jpg new file mode 100644 index 0000000..eeb2282 Binary files /dev/null and b/basicsuite/SensorExplorer/preview_l.jpg differ diff --git a/basicsuite/SensorExplorer/title.txt b/basicsuite/SensorExplorer/title.txt new file mode 100644 index 0000000..c56fed8 --- /dev/null +++ b/basicsuite/SensorExplorer/title.txt @@ -0,0 +1 @@ +Sensor Explorer diff --git a/basicsuite/basicsuite.pro b/basicsuite/basicsuite.pro index 2729de4..672cb4c 100644 --- a/basicsuite/basicsuite.pro +++ b/basicsuite/basicsuite.pro @@ -1,4 +1,5 @@ TEMPLATE = subdirs SUBDIRS += \ Qt5Everywhere \ - Camera + Camera \ + SensorExplorer -- cgit v1.2.3