diff options
author | Wolfgang Beck <wolfgang.beck@nokia.com> | 2011-12-30 12:53:45 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-01-11 23:48:22 +0100 |
commit | 1a2c653e3ef82de04906e88bdf2ec5efada324f9 (patch) | |
tree | 6c08cc73ba134644fb7e0a02d918974c2d4dd2a2 /examples/sensors | |
parent | f9672df5ea9872f911eb0011012f829309e11e71 (diff) | |
download | qtsensors-1a2c653e3ef82de04906e88bdf2ec5efada324f9.tar.gz |
Convert sensor explorer example into a QML based application
Change-Id: If8628363c4998dabf85cad4277df088be23e3ff4
Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Zsolt Simon <zsolt.simon@nokia.com>
Diffstat (limited to 'examples/sensors')
28 files changed, 1571 insertions, 918 deletions
diff --git a/examples/sensors/sensor_explorer/explorer.cpp b/examples/sensors/sensor_explorer/explorer.cpp deleted file mode 100644 index e8fd3f5..0000000 --- a/examples/sensors/sensor_explorer/explorer.cpp +++ /dev/null @@ -1,450 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** 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 Nokia Corporation 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 "explorer.h" -#include <QTimer> -#include <QDebug> -#include <qsensor.h> -#include <QMetaObject> -#include <QMetaProperty> - -Explorer::Explorer(QWidget *parent) - : QMainWindow(parent) - , m_sensor(0) - , ignoreItemChanged(false) -{ - ui.setupUi(this); -#ifdef MAEMO5 - ui.label->hide(); -#endif - // Clear out example data from the .ui file - ui.sensors->clear(); - clearSensorProperties(); - clearReading(); - - // Force types to be registered - (void)QSensor::sensorTypes(); - // Listen for changes to the registered types - QSensor *sensor = new QSensor(QByteArray(), this); - connect(sensor, SIGNAL(availableSensorsChanged()), this, SLOT(loadSensors())); -} - -Explorer::~Explorer() -{ -} - -void Explorer::loadSensors() -{ - qDebug() << "Explorer::loadSensors"; - - // Clear out anything that's in there now - ui.sensors->clear(); - - foreach (const QByteArray &type, QSensor::sensorTypes()) { - qDebug() << "Found type" << type; - foreach (const QByteArray &identifier, QSensor::sensorsForType(type)) { - qDebug() << "Found identifier" << identifier; - // Don't put in sensors we can't connect to - QSensor sensor(type); - sensor.setIdentifier(identifier); - if (!sensor.connectToBackend()) { - qDebug() << "Couldn't connect to" << identifier; - continue; - } - - qDebug() << "Adding identifier" << identifier; - QTreeWidgetItem *item = new QTreeWidgetItem(QStringList() << QString::fromLatin1(identifier)); - item->setData(0, Qt::UserRole, QString::fromLatin1(type)); - ui.sensors->addTopLevelItem(item); - } - } - - if (ui.sensors->topLevelItemCount() == 0) { - QTreeWidgetItem *item = new QTreeWidgetItem(QStringList() << tr("No Sensors Found")); - item->setData(0, Qt::UserRole, QString()); - ui.sensors->addTopLevelItem(item); - } - - ui.sensors->setCurrentItem(0); - ui.scrollArea->hide(); - - resizeSensors(); -} - -void Explorer::resizeSensors() -{ - ui.sensors->resizeColumnToContents(0); - int length = ui.sensors->header()->length() + 4; - ui.sensors->setFixedWidth(length); -} - -void Explorer::on_sensors_currentItemChanged() -{ - qDebug() << "Explorer::sensorSelected"; - - // Clear out anything that's in there now - if (m_sensor) { - delete m_sensor; - m_sensor = 0; - } - clearSensorProperties(); - clearReading(); - ui.scrollArea->hide(); - - // Check that we've selected an item - QTreeWidgetItem *item = ui.sensors->currentItem(); - if (!item) { - qWarning() << "Didn't select an item!"; - return; - } - - QByteArray type = item->data(0, Qt::UserRole).toString().toLatin1(); - QByteArray identifier = item->data(0, Qt::DisplayRole).toString().toLatin1(); - - if (type.isEmpty()) { - // Uh oh, there aren't any sensors. - // The user has clicked the dummy list entry so just ignore it. - return; - } - - // Connect to the sensor so we can probe it - m_sensor = new QSensor(type, this); - connect(m_sensor, SIGNAL(readingChanged()), this, SLOT(sensor_changed())); - m_sensor->setIdentifier(identifier); - if (!m_sensor->connectToBackend()) { - delete m_sensor; - m_sensor = 0; - qWarning() << "Can't connect to the sensor!"; - return; - } - - ui.scrollArea->show(); - loadSensorProperties(); - loadReading(); - - adjustTableColumns(ui.sensorprops); - adjustTableColumns(ui.reading); - QTimer::singleShot(100, this, SLOT(adjustSizes())); -} - -void Explorer::clearReading() -{ - ui.reading->setRowCount(0); -} - -void Explorer::loadReading() -{ - // Probe the reading using Qt's meta-object facilities - QSensorReading *reading = m_sensor->reading(); - const QMetaObject *mo = reading->metaObject(); - int firstProperty = QSensorReading::staticMetaObject.propertyOffset(); - - ui.reading->setRowCount(mo->propertyCount() - firstProperty); - - for (int i = firstProperty; i < mo->propertyCount(); ++i) { - int row = i - firstProperty; - QTableWidgetItem *index; - if (row == 0) - // timestamp is not available via index - index = new QTableWidgetItem(QLatin1String("N/A")); - else - index = new QTableWidgetItem(QVariant(row - 1).toString()); - QTableWidgetItem *prop = new QTableWidgetItem(mo->property(i).name()); - QString typeName = QLatin1String(mo->property(i).typeName()); - int crap = typeName.lastIndexOf("::"); - if (crap != -1) - typeName = typeName.mid(crap + 2); - QTableWidgetItem *type = new QTableWidgetItem(typeName); - QTableWidgetItem *value = new QTableWidgetItem(); - - index->setFlags(value->flags() ^ Qt::ItemIsEditable); - prop->setFlags(value->flags() ^ Qt::ItemIsEditable); - type->setFlags(value->flags() ^ Qt::ItemIsEditable); - value->setFlags(value->flags() ^ Qt::ItemIsEditable); - - ui.reading->setItem(row, 0, index); - ui.reading->setItem(row, 1, prop); - ui.reading->setItem(row, 2, type); - ui.reading->setItem(row, 3, value); - } -} - -void Explorer::clearSensorProperties() -{ - ui.sensorprops->setRowCount(0); -} - -void Explorer::loadSensorProperties() -{ - ignoreItemChanged = true; - - // Probe the sensor using Qt's meta-object facilities - const QMetaObject *mo = m_sensor->metaObject(); - int firstProperty = QSensor::staticMetaObject.propertyOffset(); - - int rows = mo->propertyCount() - firstProperty; - ui.sensorprops->setRowCount(rows); - - int offset = 0; - for (int i = firstProperty; i < mo->propertyCount(); ++i) { - int row = i - firstProperty - offset; - QLatin1String name(mo->property(i).name()); - if (name == "sensorid" || - //name == "type" || - name == "reading" || - name == "connected" || - name == "running" || - name == "supportsPolling") { - ++offset; - continue; - } - QTableWidgetItem *prop = new QTableWidgetItem(name); - QString typeName = QLatin1String(mo->property(i).typeName()); - int crap = typeName.lastIndexOf("::"); - if (crap != -1) - typeName = typeName.mid(crap + 2); - QTableWidgetItem *type = new QTableWidgetItem(typeName); - QVariant v = mo->property(i).read(m_sensor); - QString val; - if (typeName == "qrangelist") { - qrangelist rl = v.value<qrangelist>(); - QStringList out; - foreach (const qrange &r, rl) { - if (r.first == r.second) - out << QString("%1 Hz").arg(r.first); - else - out << QString("%1-%2 Hz").arg(r.first).arg(r.second); - } - val = out.join(", "); - } else if (typeName == "qoutputrangelist") { - qoutputrangelist rl = v.value<qoutputrangelist>(); - QStringList out; - foreach (const qoutputrange &r, rl) { - out << QString("(%1, %2) += %3").arg(r.minimum).arg(r.maximum).arg(r.accuracy); - } - val = out.join(", "); - } else { - val = v.toString(); - } - QTableWidgetItem *value = new QTableWidgetItem(val); - - prop->setFlags(value->flags() ^ Qt::ItemIsEditable); - type->setFlags(value->flags() ^ Qt::ItemIsEditable); - if (!mo->property(i).isWritable()) { - // clear the editable flag - value->setFlags(value->flags() ^ Qt::ItemIsEditable); - } - - ui.sensorprops->setItem(row, 0, prop); - ui.sensorprops->setItem(row, 1, type); - ui.sensorprops->setItem(row, 2, value); - } - - // We don't add all properties - ui.sensorprops->setRowCount(rows - offset); - - ignoreItemChanged = false; -} - -void Explorer::showEvent(QShowEvent *event) -{ - // Once we're visible, load the sensors - // (don't delay showing the UI while we load plugins, connect to backends, etc.) - QTimer::singleShot(0, this, SLOT(loadSensors())); - - QMainWindow::showEvent(event); -} - -// Resize columns to fit the space. -// This shouldn't be so hard! -void Explorer::adjustTableColumns(QTableWidget *table) -{ - if (table->rowCount() == 0) { - table->setFixedHeight(0); - return; - } - - // At least this is easy to do - table->resizeColumnsToContents(); - int length = table->verticalHeader()->length(); - length += (length / static_cast<qreal>(table->verticalHeader()->count())); // Add 1 more (the header itself) -#ifdef MAEMO5 - length += 10; // required for N900 UI -#endif - table->setFixedHeight(length); - - int columns = table->columnCount(); - QList<int> width; - int suggestedWidth = 0; - for (int i = 0; i < columns; ++i) { - int cwidth = table->columnWidth(i); - width << cwidth; - suggestedWidth += cwidth; - } - - int actualWidth = table->size().width(); - //qDebug() << "suggestedWidth" << suggestedWidth << "actualWidth" << actualWidth; - - // We only scale the columns up, we don't scale down - if (actualWidth <= suggestedWidth) - return; - - qreal multiplier = actualWidth / static_cast<qreal>(suggestedWidth); - int currentSpace = 4; - for (int i = 0; i < columns; ++i) { - width[i] = multiplier * width[i]; - currentSpace += width[i]; - } - - // It ends up too big due to cell decorations or something. - // Make things smaller one pixel at a time in round robin fashion until we're good. - int i = 0; - while (currentSpace > actualWidth) { - --width[i]; - --currentSpace; - i = (i + 1) % columns; - } - - for (int i = 0; i < columns; ++i) { - table->setColumnWidth(i, width[i]); - } - - table->setMinimumWidth(suggestedWidth); -} - -void Explorer::adjustSizes() -{ - adjustTableColumns(ui.reading); - adjustTableColumns(ui.sensorprops); -} - -void Explorer::resizeEvent(QResizeEvent *event) -{ - resizeSensors(); - adjustSizes(); - - QMainWindow::resizeEvent(event); -} - -void Explorer::on_start_clicked() -{ - m_sensor->start(); - QTimer::singleShot(0, this, SLOT(loadSensorProperties())); -} - -void Explorer::on_stop_clicked() -{ - m_sensor->stop(); - QTimer::singleShot(0, this, SLOT(loadSensorProperties())); -} - -void Explorer::sensor_changed() -{ - QSensorReading *reading = m_sensor->reading(); - filter(reading); -} - -bool Explorer::filter(QSensorReading *reading) -{ - const QMetaObject *mo = reading->metaObject(); - int firstProperty = QSensorReading::staticMetaObject.propertyOffset(); - - for (int i = firstProperty; i < mo->propertyCount(); ++i) { - int row = i - firstProperty; - QString typeName = QLatin1String(mo->property(i).typeName()); - int crap = typeName.lastIndexOf("::"); - if (crap != -1) - typeName = typeName.mid(crap + 2); - QLatin1String name(mo->property(i).name()); - QTableWidgetItem *value = ui.reading->item(row, 3); - QVariant val = mo->property(i).read(reading); - if (typeName == "qtimestamp") { - value->setText(QString("%1").arg(val.value<qtimestamp>())); - } else if (typeName == "LightLevel") { - QString text; - switch (val.toInt()) { - case 1: - text = "Dark"; - break; - case 2: - text = "Twilight"; - break; - case 3: - text = "Light"; - break; - case 4: - text = "Bright"; - break; - case 5: - text = "Sunny"; - break; - default: - text = "Undefined"; - break; - } - value->setText(text); - } else { - value->setText(val.toString()); - } - } - - adjustTableColumns(ui.reading); - //QTimer::singleShot(0, this, SLOT(adjustSizes())); - - return false; -} - -void Explorer::on_sensorprops_itemChanged(QTableWidgetItem *item) -{ - if (ignoreItemChanged) - return; - if (!(item->flags() & Qt::ItemIsEditable)) - return; - - int row = item->row(); - QString name = ui.sensorprops->item(row, 0)->text(); - QVariant value = item->text(); - - qDebug() << "setProperty" << name << value; - m_sensor->setProperty(name.toLatin1().constData(), QVariant(value)); - - QTimer::singleShot(0, this, SLOT(loadSensorProperties())); -} - diff --git a/examples/sensors/sensor_explorer/explorer.ui b/examples/sensors/sensor_explorer/explorer.ui deleted file mode 100644 index 166e9c3..0000000 --- a/examples/sensors/sensor_explorer/explorer.ui +++ /dev/null @@ -1,406 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>Explorer</class> - <widget class="QMainWindow" name="Explorer"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>760</width> - <height>636</height> - </rect> - </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="Minimum" vsizetype="Minimum"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="windowTitle"> - <string>MainWindow</string> - </property> - <widget class="QWidget" name="centralwidget"> - <layout class="QVBoxLayout" name="verticalLayout_4"> - <property name="spacing"> - <number>9</number> - </property> - <item> - <widget class="QLabel" name="label"> - <property name="text"> - <string>Sensors that were detected on the device are listed in the list on the left, grouped by type. The reading properties for the sensor will be presented on the right.</string> - </property> - <property name="textFormat"> - <enum>Qt::AutoText</enum> - </property> - <property name="wordWrap"> - <bool>true</bool> - </property> - </widget> - </item> - <item> - <widget class="QWidget" name="widget" native="true"> - <layout class="QHBoxLayout" name="horizontalLayout"> - <property name="spacing"> - <number>9</number> - </property> - <property name="margin"> - <number>0</number> - </property> - <item> - <widget class="QWidget" name="widget_2" native="true"> - <layout class="QVBoxLayout" name="verticalLayout"> - <property name="spacing"> - <number>9</number> - </property> - <property name="margin"> - <number>0</number> - </property> - <item> - <widget class="QLabel" name="label_2"> - <property name="text"> - <string>Sensor</string> - </property> - <property name="buddy"> - <cstring>sensors</cstring> - </property> - </widget> - </item> - <item> - <widget class="QTreeWidget" name="sensors"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Minimum" vsizetype="Expanding"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="alternatingRowColors"> - <bool>true</bool> - </property> - <property name="selectionBehavior"> - <enum>QAbstractItemView::SelectRows</enum> - </property> - <property name="rootIsDecorated"> - <bool>false</bool> - </property> - <property name="itemsExpandable"> - <bool>false</bool> - </property> - <property name="expandsOnDoubleClick"> - <bool>false</bool> - </property> - <attribute name="headerVisible"> - <bool>false</bool> - </attribute> - <attribute name="headerVisible"> - <bool>false</bool> - </attribute> - <column> - <property name="text"> - <string notr="true">Sensor</string> - </property> - </column> - <item> - <property name="text"> - <string notr="true">dummy.accelerometer</string> - </property> - </item> - </widget> - </item> - </layout> - </widget> - </item> - <item> - <widget class="QScrollArea" name="scrollArea"> - <property name="frameShape"> - <enum>QFrame::NoFrame</enum> - </property> - <property name="widgetResizable"> - <bool>true</bool> - </property> - <widget class="QWidget" name="scrollAreaWidgetContents"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>477</width> - <height>556</height> - </rect> - </property> - <layout class="QVBoxLayout" name="verticalLayout_5"> - <property name="spacing"> - <number>9</number> - </property> - <property name="margin"> - <number>0</number> - </property> - <item> - <widget class="QWidget" name="widget_4" native="true"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Minimum"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <layout class="QVBoxLayout" name="verticalLayout_3"> - <property name="spacing"> - <number>9</number> - </property> - <property name="margin"> - <number>0</number> - </property> - <item> - <widget class="QLabel" name="label_4"> - <property name="text"> - <string>Sensor Properties</string> - </property> - </widget> - </item> - <item> - <widget class="QTableWidget" name="sensorprops"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Minimum"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="verticalScrollBarPolicy"> - <enum>Qt::ScrollBarAlwaysOff</enum> - </property> - <property name="alternatingRowColors"> - <bool>true</bool> - </property> - <property name="columnCount"> - <number>3</number> - </property> - <attribute name="verticalHeaderVisible"> - <bool>false</bool> - </attribute> - <attribute name="verticalHeaderVisible"> - <bool>false</bool> - </attribute> - <row> - <property name="text"> - <string notr="true">1</string> - </property> - </row> - <column> - <property name="text"> - <string>Name</string> - </property> - </column> - <column> - <property name="text"> - <string>Type</string> - </property> - </column> - <column> - <property name="text"> - <string>Value</string> - </property> - </column> - <item row="0" column="0"> - <property name="text"> - <string notr="true">supportedIntervals</string> - </property> - </item> - <item row="0" column="1"> - <property name="text"> - <string notr="true">qrangelist</string> - </property> - </item> - <item row="0" column="2"> - <property name="text"> - <string/> - </property> - </item> - </widget> - </item> - </layout> - </widget> - </item> - <item> - <widget class="QWidget" name="widget_3" native="true"> - <layout class="QHBoxLayout" name="horizontalLayout_2"> - <property name="spacing"> - <number>9</number> - </property> - <property name="margin"> - <number>0</number> - </property> - <item> - <widget class="QPushButton" name="start"> - <property name="text"> - <string>start</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="stop"> - <property name="text"> - <string>stop</string> - </property> - </widget> - </item> - <item> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - </layout> - </widget> - </item> - <item> - <widget class="QWidget" name="widget_5" native="true"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Minimum"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <layout class="QVBoxLayout" name="verticalLayout_2"> - <property name="spacing"> - <number>9</number> - </property> - <property name="margin"> - <number>0</number> - </property> - <item> - <widget class="QLabel" name="label_6"> - <property name="text"> - <string>Reading Properties</string> - </property> - </widget> - </item> - <item> - <widget class="QTableWidget" name="reading"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Minimum"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="verticalScrollBarPolicy"> - <enum>Qt::ScrollBarAlwaysOff</enum> - </property> - <property name="alternatingRowColors"> - <bool>true</bool> - </property> - <property name="columnCount"> - <number>4</number> - </property> - <attribute name="verticalHeaderVisible"> - <bool>false</bool> - </attribute> - <attribute name="verticalHeaderVisible"> - <bool>false</bool> - </attribute> - <row> - <property name="text"> - <string notr="true">1</string> - </property> - </row> - <row> - <property name="text"> - <string notr="true">2</string> - </property> - </row> - <column> - <property name="text"> - <string>Index</string> - </property> - </column> - <column> - <property name="text"> - <string>Value</string> - </property> - </column> - <column> - <property name="text"> - <string>Type</string> - </property> - </column> - <column> - <property name="text"> - <string>Value</string> - </property> - </column> - <item row="0" column="0"> - <property name="text"> - <string notr="true">0</string> - </property> - </item> - <item row="0" column="1"> - <property name="text"> - <string notr="true">x</string> - </property> - </item> - <item row="0" column="2"> - <property name="text"> - <string notr="true">qreal</string> - </property> - </item> - <item row="0" column="3"> - <property name="text"> - <string>9.8</string> - </property> - </item> - <item row="1" column="0"> - <property name="text"> - <string notr="true">0</string> - </property> - </item> - <item row="1" column="1"> - <property name="text"> - <string notr="true">changeOfBeingEaten</string> - </property> - </item> - <item row="1" column="2"> - <property name="text"> - <string notr="true">bool</string> - </property> - </item> - <item row="1" column="3"> - <property name="text"> - <string>true</string> - </property> - </item> - </widget> - </item> - </layout> - </widget> - </item> - <item> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>0</width> - <height>18</height> - </size> - </property> - </spacer> - </item> - </layout> - </widget> - </widget> - </item> - </layout> - </widget> - </item> - </layout> - </widget> - <widget class="QStatusBar" name="statusbar"/> - </widget> - <resources/> - <connections/> -</ui> diff --git a/examples/sensors/sensor_explorer/import/explorer.cpp b/examples/sensors/sensor_explorer/import/explorer.cpp new file mode 100644 index 0000000..65f2472 --- /dev/null +++ b/examples/sensors/sensor_explorer/import/explorer.cpp @@ -0,0 +1,138 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia 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. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "explorer.h" +#include <QtCore/QDebug> +#include <qsensor.h> +#include <QMetaObject> +#include <QMetaProperty> + +QT_BEGIN_NAMESPACE + +/*! + \class QSensorExplorer + \brief The QSensorExplorer element 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() +{ + //! [0] + _availableSensors.clear(); + + foreach (const QByteArray &type, QSensor::sensorTypes()) { + qDebug() << "Found type" << type; + foreach (const QByteArray &identifier, QSensor::sensorsForType(type)) { + qDebug() << "Found identifier" << identifier; + // Don't put in sensors we can't connect to + QSensor* sensor = new QSensor(type, this); + sensor->setIdentifier(identifier); + if (!sensor->connectToBackend()) { + qDebug() << "Couldn't connect to" << identifier; + continue; + } + + qDebug() << "Adding identifier" << identifier; + _availableSensors.append(new QSensorItem(sensor, this)); + } + } + emit availableSensorsChanged(); + //! [0] +} + +/*! + \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. +*/ +QDeclarativeListProperty<QSensorItem> QSensorExplorer::availableSensors() +{ + return QDeclarativeListProperty<QSensorItem>(this,_availableSensors); +} + +/*! + \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/examples/sensors/sensor_explorer/import/explorer.h b/examples/sensors/sensor_explorer/import/explorer.h new file mode 100644 index 0000000..b32e6bd --- /dev/null +++ b/examples/sensors/sensor_explorer/import/explorer.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia 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. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSEONSOREXPLORER_H +#define QSEONSOREXPLORER_H + +#include <QtDeclarative/qdeclarative.h> +#include <QtDeclarative/QDeclarativeListProperty> +#include "sensoritem.h" + +QT_BEGIN_NAMESPACE + +class QSensorExplorer : public QObject +{ + Q_OBJECT + Q_PROPERTY(QDeclarativeListProperty<QSensorItem> availableSensors READ availableSensors NOTIFY availableSensorsChanged) + Q_PROPERTY(QSensorItem* selectedSensorItem READ selectedSensorItem WRITE setSelectedSensorItem NOTIFY selectedSensorItemChanged) +public: + QSensorExplorer(QObject* parent = 0); + virtual ~QSensorExplorer(); + +private: + QDeclarativeListProperty<QSensorItem> availableSensors(); + void loadSensors(); + void setSelectedSensorItem(QSensorItem* selitem); + QSensorItem* selectedSensorItem(); + +Q_SIGNALS: + void availableSensorsChanged(); + void selectedSensorItemChanged(); + +private: + QList<QSensorItem*> _availableSensors; + QSensorItem* _selectedSensorItem; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QSensorExplorer) + +#endif // QSEONSOREXPLORER_H diff --git a/examples/sensors/sensor_explorer/import/import.pro b/examples/sensors/sensor_explorer/import/import.pro new file mode 100644 index 0000000..7baec42 --- /dev/null +++ b/examples/sensors/sensor_explorer/import/import.pro @@ -0,0 +1,24 @@ +TARGET = declarative_explorer +TARGETPATH = Explorer + +include(qsensorsimport.pri) + +QT += declarative sensors + +SOURCES = main.cpp explorer.cpp sensoritem.cpp propertyinfo.cpp +HEADERS = explorer.h sensoritem.h propertyinfo.h + +symbian { + TARGET.EPOCALLOWDLLDATA = 1 + TARGET.CAPABILITY = ALL -TCB +} + +!isEmpty(EXAMPLES_PREFIX):DESTPATH=$$EXAMPLES_PREFIX/sensor_explorer/imports/Explorer +else:DESTPATH=$$[QT_INSTALL_IMPORTS]/Explorer + +target.path=$$DESTPATH +INSTALLS += target + +qmldir.files=$$PWD/qmldir +qmldir.path=$$DESTPATH +INSTALLS += qmldir diff --git a/examples/sensors/sensor_explorer/main.cpp b/examples/sensors/sensor_explorer/import/main.cpp index 624f7b6..df4db20 100644 --- a/examples/sensors/sensor_explorer/main.cpp +++ b/examples/sensors/sensor_explorer/import/main.cpp @@ -38,13 +38,30 @@ ** ****************************************************************************/ +#include <QtDeclarative/qdeclarativeextensionplugin.h> +#include <QtDeclarative/qdeclarative.h> #include "explorer.h" +#include <QtCore/QDebug> -int main(int argc, char **argv) +QT_BEGIN_NAMESPACE + +class SensorExplorerDeclarativeModule : public QDeclarativeExtensionPlugin { - QApplication app(argc, argv); - Explorer explorer; - explorer.show(); - return app.exec(); -} + Q_OBJECT +public: + virtual void registerTypes(const char *uri) + { + qDebug() << "SensorExplorerDeclarativeModule::registerTypes(const char *uri)"; + + Q_ASSERT(QLatin1String(uri) == QLatin1String("Explorer")); + qmlRegisterType<QSensorExplorer>(uri, 1, 0, "SensorExplorer"); + qmlRegisterType<QSensorItem>(uri, 1, 0, "SensorItem"); + qmlRegisterType<QPropertyInfo>(uri, 1, 0, "PropertyInfo"); + } +}; + +QT_END_NAMESPACE + +#include "main.moc" +Q_EXPORT_PLUGIN2(sensorexplorerdeclarativemodule, QT_PREPEND_NAMESPACE(SensorExplorerDeclarativeModule)) diff --git a/examples/sensors/sensor_explorer/import/propertyinfo.cpp b/examples/sensors/sensor_explorer/import/propertyinfo.cpp new file mode 100644 index 0000000..6ddcd3f --- /dev/null +++ b/examples/sensors/sensor_explorer/import/propertyinfo.cpp @@ -0,0 +1,140 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia 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. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sensoritem.h" +#include <QtCore/QDebug> +#include <QtSensors> + +QT_BEGIN_NAMESPACE + +/*! + \class QPropertyInfo + \brief The QPropertyInfo element 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/examples/sensors/sensor_explorer/import/propertyinfo.h b/examples/sensors/sensor_explorer/import/propertyinfo.h new file mode 100644 index 0000000..4f693e8 --- /dev/null +++ b/examples/sensors/sensor_explorer/import/propertyinfo.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia 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. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QPROPERTYINFO_H +#define QPROPERTYINFO_H + +#include <QtDeclarative/qdeclarative.h> +#include <QtCore/QString> + +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/examples/sensors/sensor_explorer/import/qmldir b/examples/sensors/sensor_explorer/import/qmldir new file mode 100644 index 0000000..60d8f88 --- /dev/null +++ b/examples/sensors/sensor_explorer/import/qmldir @@ -0,0 +1 @@ +plugin declarative_explorer diff --git a/examples/sensors/sensor_explorer/import/qsensorsimport.pri b/examples/sensors/sensor_explorer/import/qsensorsimport.pri new file mode 100644 index 0000000..b8af2b7 --- /dev/null +++ b/examples/sensors/sensor_explorer/import/qsensorsimport.pri @@ -0,0 +1,27 @@ +load(qt_module) + +symbian:load(qt_plugin) +TEMPLATE = lib +CONFIG += qt plugin + +win32|mac:!wince*:!win32-msvc:!macx-xcode:CONFIG += debug_and_release + +isEmpty(TARGETPATH) { + error("qimportbase.pri: You must provide a TARGETPATH!") +} +isEmpty(TARGET) { + error("qimportbase.pri: You must provide a TARGET!") +} + +TARGET = $$qtLibraryTarget($$TARGET) +contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols + +load(qt_targets) + +wince*:LIBS += $$QMAKE_LIBS_GUI + +symbian: { + TARGET.EPOCALLOWDLLDATA=1 + TARGET.CAPABILITY = All -Tcb + load(armcc_warnings) +} diff --git a/examples/sensors/sensor_explorer/import/sensoritem.cpp b/examples/sensors/sensor_explorer/import/sensoritem.cpp new file mode 100644 index 0000000..21fc776 --- /dev/null +++ b/examples/sensors/sensor_explorer/import/sensoritem.cpp @@ -0,0 +1,317 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia 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. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sensoritem.h" +#include <QtCore/QDebug> +#include <QtSensors> + +QT_BEGIN_NAMESPACE + +/*! + \class QSensorItem + \brief The QSensorItem element provides information about the meta-datas 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() +{ +} + +/*! + \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->identifier() : ""); +} + +/*! + 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-datas 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 == "sensorid" || + 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 dependend 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<qrangelist>(); + 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<qoutputrangelist>(); + 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 +*/ +QDeclarativeListProperty<QPropertyInfo> QSensorItem::properties() +{ + _properties.clear(); + _properties.append(_sensorProperties); + _properties.append(_readerProperties); + return QDeclarativeListProperty<QPropertyInfo> (this, _properties); +} + +QT_END_NAMESPACE diff --git a/examples/sensors/sensor_explorer/import/sensoritem.h b/examples/sensors/sensor_explorer/import/sensoritem.h new file mode 100644 index 0000000..9e9ab94 --- /dev/null +++ b/examples/sensors/sensor_explorer/import/sensoritem.h @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia 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. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSENSORITEM_H +#define QSENSORITEM_H + +#include <QtDeclarative/qdeclarative.h> +#include <QtCore/QString> +#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(QDeclarativeListProperty<QPropertyInfo> 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); + QDeclarativeListProperty<QPropertyInfo> 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<QPropertyInfo*> _properties; + QList<QPropertyInfo*> _readerProperties; + QList<QPropertyInfo*> _sensorProperties; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QSensorItem) + +#endif // QSENSORITEM_H diff --git a/examples/sensors/sensor_explorer/explorer.h b/examples/sensors/sensor_explorer/qml_app/Button.qml index 18887fe..ce8feb3 100644 --- a/examples/sensors/sensor_explorer/explorer.h +++ b/examples/sensors/sensor_explorer/qml_app/Button.qml @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -38,46 +38,38 @@ ** ****************************************************************************/ -#ifndef EXPLORER_H -#define EXPLORER_H +//Import the declarative plugins +import QtQuick 2.0 -#include <QMainWindow> -#include <ui_explorer.h> -#include <qsensor.h> +//Implementation of the Button control. +Item { + id: button + width: 30 + height: 100 + property alias text: innerText.text + signal clicked -class Explorer : public QMainWindow, public QSensorFilter -{ - Q_OBJECT -public: - Explorer(QWidget *parent = 0); - ~Explorer(); + Image { + id: backgroundImage + anchors.fill: parent + source: (button.enabled ? "images/button_background_normal.png" : "images/button_background_disabled.png") + } - bool filter(QSensorReading *reading); - -private slots: - void loadSensors(); - void on_sensors_currentItemChanged(); - void on_sensorprops_itemChanged(QTableWidgetItem *item); - void on_start_clicked(); - void on_stop_clicked(); - void sensor_changed(); - void adjustSizes(); - void loadSensorProperties(); - -private: - void showEvent(QShowEvent *event); - void resizeEvent(QResizeEvent *event); - - void clearReading(); - void loadReading(); - void clearSensorProperties(); - void adjustTableColumns(QTableWidget *table); - void resizeSensors(); - - Ui::Explorer ui; - QSensor *m_sensor; - bool ignoreItemChanged; -}; - -#endif + Text { + id: innerText + anchors.centerIn: parent + color: "white" + font.bold: true + } + //Mouse area to react on click events + MouseArea { + anchors.fill: button + onClicked: { button.clicked();} + onPressed: { + backgroundImage.source = "images/button_background_pressed.png" } + onReleased: { + backgroundImage.source = (button.enabled ? "images/button_background_normal.png" : "images/button_background_disabled.png") + } + } +} diff --git a/examples/sensors/sensor_explorer/qml_app/PropertyList.qml b/examples/sensors/sensor_explorer/qml_app/PropertyList.qml new file mode 100644 index 0000000..1e55b48 --- /dev/null +++ b/examples/sensors/sensor_explorer/qml_app/PropertyList.qml @@ -0,0 +1,130 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 Nokia Corporation 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 the declarative plugins +import QtQuick 2.0 +import Explorer 1.0 + +Rectangle { + id: controlrect + anchors.margins: 5 + color: "transparent" + + property PropertyInfo selectedItem: null; + signal selectedItemChanged(); + property alias listmodel: itemList.model + + onListmodelChanged: { + itemList.currentIndex = -1; + selectedItem = null; + selectedItemChanged(); + } + + Rectangle { + id: itemListRect + anchors.fill: parent + color: "transparent" + + ListView { + id: itemList + anchors.fill: itemListRect + anchors.leftMargin: 5 + anchors.rightMargin: 5 + focus: true + currentIndex: -1 + delegate: itemListDelegate + clip: true + + Rectangle { + id: scrollbar + anchors.right: itemList.right + y: itemList.visibleArea.yPosition * itemList.height + width: 2 + height: itemList.visibleArea.heightRatio * itemList.height + color: "black" + } + } + + Component { + id: itemListDelegate + + Rectangle { + width: itemList.width + height: itemNameText.font.pixelSize + 3 + color: "transparent" + + Image { + id: backgroundImage + anchors.fill: parent + source: "images/listitem_select.png" + visible: itemList.currentIndex === index + } + + Text { + id: itemNameText + text: model.modelData.name + font.pixelSize: 15 + color: (itemList.currentIndex === index ? "#1c94ff" : "black") + } + + Text { + id: itemValueText + anchors.left: parent.left + anchors.right: parent.right + anchors.rightMargin: 5 + font.pixelSize: 15 + horizontalAlignment: Text.AlignRight + text: model.modelData.value + color: (itemList.currentIndex === index ? "#1c94ff" : "black") + } + + MouseArea { + anchors.fill: parent + + onClicked: { + itemList.currentIndex = index; + selectedItem = model.modelData; + selectedItemChanged(); + } + } + } + } + } +} diff --git a/examples/sensors/sensor_explorer/qml_app/SensorList.qml b/examples/sensors/sensor_explorer/qml_app/SensorList.qml new file mode 100644 index 0000000..a9f40ce --- /dev/null +++ b/examples/sensors/sensor_explorer/qml_app/SensorList.qml @@ -0,0 +1,149 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 Nokia Corporation 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 the declarative plugins +import QtQuick 2.0 +import Explorer 1.0 + +Rectangle { + id: controlrect + anchors.margins: 5 + color: "transparent" + + property SensorItem selectedItem: null; + signal selectedItemChanged(); + property alias title: labelTitle.text + property alias listmodel: itemList.model + + onListmodelChanged: { + itemList.currentIndex = -1; + selectedItem = null; + selectedItemChanged(); + } + + Text { + id: labelTitle + anchors.top: controlrect.top + anchors.left: controlrect.left + anchors.right: controlrect.right + horizontalAlignment: Text.AlignHCenter + font.pixelSize: 30 + font.bold: true + text: "" + } + + Rectangle { + id: titleLine + anchors.top: labelTitle.bottom + anchors.left: controlrect.left + anchors.right: controlrect.right + height: 1 + border.width: 1 + border.color: "#999999" + } + + Rectangle { + id: itemListRect + anchors.top: titleLine.bottom + anchors.left: controlrect.left + anchors.right: controlrect.right + anchors.bottom: controlrect.bottom + color: "transparent" + + ListView { + id: itemList + anchors.fill: itemListRect + anchors.leftMargin: 5 + anchors.rightMargin: 5 + focus: true + currentIndex: -1 + delegate: itemListDelegate + clip: true + + Rectangle { + id: scrollbar + anchors.right: itemList.right + y: itemList.visibleArea.yPosition * itemList.height + width: 2 + height: itemList.visibleArea.heightRatio * itemList.height + color: "black" + } + } + + Component { + id: itemListDelegate + + Rectangle { + width: itemList.width + height: 30 + color: "transparent" + + Image { + id: backgroundImage + anchors.fill: parent + source: "images/listitem_select.png" + visible: itemList.currentIndex === index + } + + Text { + id: itemText + height: 30 + anchors.top: parent.top + anchors.left: parent.left + anchors.leftMargin: 5 + text: model.modelData.id + color: (itemList.currentIndex === index ? "#1c94ff" : "black") + verticalAlignment: Text.AlignVCenter + font.pixelSize: 15 + } + + MouseArea { + anchors.fill: parent + + onClicked: { + itemList.currentIndex = index; + selectedItem = model.modelData; + selectedItemChanged(); + } + } + } + } + } +} diff --git a/examples/sensors/sensor_explorer/qml_app/TextField.qml b/examples/sensors/sensor_explorer/qml_app/TextField.qml new file mode 100644 index 0000000..681b712 --- /dev/null +++ b/examples/sensors/sensor_explorer/qml_app/TextField.qml @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 Nokia Corporation 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 the declarative plugins +import QtQuick 2.0 + +Item { + id: textInputFrame + property alias text: textInput.text + resources: [ + Component{ + id: cursorA + Rectangle { + id: cursor_rect + width: 2 + height: 20 + color: "#1c94ff" + visible: textInput.cursorVisible + + PropertyAnimation on opacity { + easing.type: Easing.OutSine + loops: Animation.Infinite + from: 0 + to: 1.0 + duration: 750 + } + } + } + ] + + Image { + id: backgroundImage + anchors.fill: parent + source: (textInputFrame.enabled ? "images/textfield_background_normal.png" : "images/textfield_background_disabled.png") + } + + TextInput { + id: textInput + anchors.fill: parent + anchors.topMargin: 5 + anchors.leftMargin: 5 + anchors.rightMargin: 5 + activeFocusOnPress: false + + cursorDelegate: cursorA + + onEnabledChanged: { + textInput.focus = false; + } + + MouseArea { + anchors.fill: parent + + onClicked: { + if (!textInput.activeFocus) { + textInput.forceActiveFocus() + textInput.openSoftwareInputPanel(); + } else { + textInput.focus = false; + } + } + + onPressAndHold: textInput.closeSoftwareInputPanel(); + } + } +} diff --git a/examples/sensors/sensor_explorer/qml_app/icon.png b/examples/sensors/sensor_explorer/qml_app/icon.png Binary files differnew file mode 100755 index 0000000..c48b609 --- /dev/null +++ b/examples/sensors/sensor_explorer/qml_app/icon.png diff --git a/examples/sensors/sensor_explorer/qml_app/images/button_background_disabled.png b/examples/sensors/sensor_explorer/qml_app/images/button_background_disabled.png Binary files differnew file mode 100644 index 0000000..62a00b9 --- /dev/null +++ b/examples/sensors/sensor_explorer/qml_app/images/button_background_disabled.png diff --git a/examples/sensors/sensor_explorer/qml_app/images/button_background_normal.png b/examples/sensors/sensor_explorer/qml_app/images/button_background_normal.png Binary files differnew file mode 100644 index 0000000..1fecad5 --- /dev/null +++ b/examples/sensors/sensor_explorer/qml_app/images/button_background_normal.png diff --git a/examples/sensors/sensor_explorer/qml_app/images/button_background_pressed.png b/examples/sensors/sensor_explorer/qml_app/images/button_background_pressed.png Binary files differnew file mode 100644 index 0000000..149529e --- /dev/null +++ b/examples/sensors/sensor_explorer/qml_app/images/button_background_pressed.png diff --git a/examples/sensors/sensor_explorer/qml_app/images/listitem_select.png b/examples/sensors/sensor_explorer/qml_app/images/listitem_select.png Binary files differnew file mode 100644 index 0000000..def234f --- /dev/null +++ b/examples/sensors/sensor_explorer/qml_app/images/listitem_select.png diff --git a/examples/sensors/sensor_explorer/qml_app/images/textfield_background_disabled.png b/examples/sensors/sensor_explorer/qml_app/images/textfield_background_disabled.png Binary files differnew file mode 100644 index 0000000..98bc601 --- /dev/null +++ b/examples/sensors/sensor_explorer/qml_app/images/textfield_background_disabled.png diff --git a/examples/sensors/sensor_explorer/qml_app/images/textfield_background_normal.png b/examples/sensors/sensor_explorer/qml_app/images/textfield_background_normal.png Binary files differnew file mode 100644 index 0000000..b90b50c --- /dev/null +++ b/examples/sensors/sensor_explorer/qml_app/images/textfield_background_normal.png diff --git a/examples/sensors/sensor_explorer/qml_app/info.json b/examples/sensors/sensor_explorer/qml_app/info.json new file mode 100644 index 0000000..3f1feb4 --- /dev/null +++ b/examples/sensors/sensor_explorer/qml_app/info.json @@ -0,0 +1,15 @@ +{ + "info-version": "1.0", + "dict": { + "Category": "application", + "Runtime": "qml", + "DisplayName": "Sensor Explorer", + "Subcategory": "utility", + "MainQML": "main.qml", + "Version": "1.0", + "Identifier": "com.nokia.mt.sensorexplorer.demo", + "Summary": "QML Sensor Explorer demo", + "Author": "Qt" + } +} + diff --git a/examples/sensors/sensor_explorer/qml_app/main.qml b/examples/sensors/sensor_explorer/qml_app/main.qml new file mode 100644 index 0000000..7796b8a --- /dev/null +++ b/examples/sensors/sensor_explorer/qml_app/main.qml @@ -0,0 +1,192 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 Nokia Corporation 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 the declarative plugins +import QtQuick 2.0 + +//! [0] +import Explorer 1.0 +//! [0] + +Rectangle { + id: mainWnd + x: 0 + y: 0 + width: 320 + height: 480 + color: "#ececec" + +//! [1] + SensorExplorer { + id: explorer + } +//! [1] + + SensorList { + id: sensorList + anchors.top: parent.top + anchors.topMargin: 20 + anchors.left: parent.left + anchors.right: parent.right + height: 200 + title: "sensor explorer" + +//! [2] + listmodel: explorer.availableSensors +//! [2] + + onSelectedItemChanged: { + explorer.selectedSensorItem = sensorList.selectedItem; + startstopButton.text=(explorer.selectedSensorItem !== null ? + (explorer.selectedSensorItem.start === true ? "Stop" : "Start") : "Start") + if (sensorList.selectedItem !== null) + +//! [3] + propertyList.listmodel = sensorList.selectedItem.properties; +//! [3] + } + } + + Rectangle { + id: listSplitLine + anchors.top: sensorList.bottom + anchors.left: parent.left + anchors.right: parent.right + anchors.leftMargin: 5 + anchors.rightMargin: 5 + height: 1 + border.width: 1 + border.color: "#999999" + } + + PropertyList { + id: propertyList + anchors.top: listSplitLine.bottom + anchors.left: parent.left + anchors.right: parent.right + anchors.bottom: listPropertyEndLine.top + anchors.bottomMargin: 5 + + onSelectedItemChanged: { + changePropertyButton.enabled = (propertyList.selectedItem === null ? + false : propertyList.selectedItem.isWriteable); + } + } + + Rectangle { + id: listPropertyEndLine + anchors.bottom: startstopButton.top + anchors.bottomMargin: 5 + anchors.left: parent.left + anchors.right: parent.right + anchors.leftMargin: 5 + anchors.rightMargin: 5 + height: 1 + border.width: 1 + border.color: "#999999" + } + + + Button { + id: startstopButton + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.margins: 5 + text: (explorer.selectedSensorItem !== null ? + (explorer.selectedSensorItem.start === true ? "Stop" : "Start") : "Start") + enabled: true + height: 30 + width: 80 + + onClicked: { + if (explorer.selectedSensorItem !== null) { +//! [5] + if (text === "Start") { + explorer.selectedSensorItem.start = true; + text = "Stop"; + } + else { + explorer.selectedSensorItem.start = false; + text = "Start"; + } +//! [5] + } + + textfield.text = ""; + } + } + + Button { + id: changePropertyButton + anchors.bottom: parent.bottom + anchors.left: startstopButton.right + anchors.margins: 5 + text: "Set" + enabled: false + height: 30 + width: 60 + + onEnabledChanged: { + textfield.visible = changePropertyButton.enabled; + } + + onClicked: { + if (explorer.selectedSensorItem !== null + && propertyList.selectedItem !== null) { +//! [4] + explorer.selectedSensorItem.changePropertyValue(propertyList.selectedItem, textfield.text); +//! [4] + } + + textfield.text = ""; + } + } + + TextField { + id: textfield + anchors.bottom: parent.bottom + anchors.left: changePropertyButton.right + anchors.right: parent.right + anchors.margins: 5 + height: 30 + enabled: true + } +} + diff --git a/examples/sensors/sensor_explorer/qml_app/qml_app.qmlproject b/examples/sensors/sensor_explorer/qml_app/qml_app.qmlproject new file mode 100644 index 0000000..4d32f75 --- /dev/null +++ b/examples/sensors/sensor_explorer/qml_app/qml_app.qmlproject @@ -0,0 +1,18 @@ +import QmlProject 1.1 + +Project { + mainFile: "main.qml" + + /* Include .qml, .js, and image files from current directory and subdirectories */ + QmlFiles { + directory: "." + } + JavaScriptFiles { + directory: "." + } + ImageFiles { + directory: "." + } + /* List of plugin directories passed to QML runtime */ + // importPaths: [ "../exampleplugin" ] +} diff --git a/examples/sensors/sensor_explorer/sensor_explorer.pro b/examples/sensors/sensor_explorer/sensor_explorer.pro index 311ae0b..caa6680 100644 --- a/examples/sensors/sensor_explorer/sensor_explorer.pro +++ b/examples/sensors/sensor_explorer/sensor_explorer.pro @@ -1,16 +1,4 @@ -TEMPLATE=app -TARGET=sensor_explorer -QT=core gui widgets sensors +TEMPLATE = subdirs -FORMS=\ - explorer.ui - -HEADERS=\ - explorer.h - -SOURCES=\ - explorer.cpp\ - main.cpp - -maemo5:DEFINES+=MAEMO5 +SUBDIRS += import #qml_app diff --git a/examples/sensors/sensors.pro b/examples/sensors/sensors.pro index 7a79b5f..f09991c 100644 --- a/examples/sensors/sensors.pro +++ b/examples/sensors/sensors.pro @@ -3,9 +3,9 @@ TEMPLATE = subdirs SUBDIRS += \ accel \ grue \ - qmlsensorgestures + qmlsensorgestures \ + sensor_explorer contains(QT_CONFIG,widgets):SUBDIRS += \ - sensor_explorer \ sensorgestures |