From a840cbffba476205eba81f56f40ec32cea6097cc Mon Sep 17 00:00:00 2001 From: Topi Reinio Date: Wed, 28 Aug 2013 11:26:38 +0200 Subject: Doc: Update Sensor Explorer example Following changes are made to the example - Use of Qt Quick Controls / TableView to present the sensor information, reducing the example to a single QML file - Updated launcher main.cpp for the QML example - Remove separate example doc for the import subproject - Various fixes to example doc, add a screenshot - Ensure import module + qmldir are built/deployed to correct location Task-number: QTBUG-32881 Task-number: QTBUG-33875 Change-Id: I0ed7c7ebc916fcad6da5e3c66d81be8f348a93e1 Reviewed-by: Jerome Pasion --- examples/sensors/sensor_explorer/PropertyList.qml | 127 ---------- examples/sensors/sensor_explorer/SensorList.qml | 146 ----------- .../components/ApplicationWindow.qml | 51 ---- .../sensors/sensor_explorer/components/Button.qml | 75 ------ .../sensor_explorer/components/TextField.qml | 109 -------- .../images/button_background_disabled.png | Bin 579 -> 0 bytes .../components/images/button_background_normal.png | Bin 901 -> 0 bytes .../images/button_background_pressed.png | Bin 334 -> 0 bytes .../images/textfield_background_disabled.png | Bin 936 -> 0 bytes .../images/textfield_background_normal.png | Bin 767 -> 0 bytes .../sensor_explorer/content/listitem_select.png | Bin 156 -> 0 bytes .../doc/images/qtsensors-examples-explorer.png | Bin 0 -> 39873 bytes .../sensor_explorer/doc/src/sensor_explorer.qdoc | 71 +++--- examples/sensors/sensor_explorer/import/import.pro | 32 ++- examples/sensors/sensor_explorer/import/main.cpp | 3 +- examples/sensors/sensor_explorer/main.cpp | 26 +- examples/sensors/sensor_explorer/qml.pro | 16 +- examples/sensors/sensor_explorer/qml.qrc | 11 - .../sensors/sensor_explorer/sensor_explorer.qml | 282 +++++++++++---------- 19 files changed, 251 insertions(+), 698 deletions(-) delete mode 100644 examples/sensors/sensor_explorer/PropertyList.qml delete mode 100644 examples/sensors/sensor_explorer/SensorList.qml delete mode 100644 examples/sensors/sensor_explorer/components/ApplicationWindow.qml delete mode 100644 examples/sensors/sensor_explorer/components/Button.qml delete mode 100644 examples/sensors/sensor_explorer/components/TextField.qml delete mode 100644 examples/sensors/sensor_explorer/components/images/button_background_disabled.png delete mode 100644 examples/sensors/sensor_explorer/components/images/button_background_normal.png delete mode 100644 examples/sensors/sensor_explorer/components/images/button_background_pressed.png delete mode 100644 examples/sensors/sensor_explorer/components/images/textfield_background_disabled.png delete mode 100644 examples/sensors/sensor_explorer/components/images/textfield_background_normal.png delete mode 100644 examples/sensors/sensor_explorer/content/listitem_select.png create mode 100644 examples/sensors/sensor_explorer/doc/images/qtsensors-examples-explorer.png (limited to 'examples') diff --git a/examples/sensors/sensor_explorer/PropertyList.qml b/examples/sensors/sensor_explorer/PropertyList.qml deleted file mode 100644 index 639acf19..00000000 --- a/examples/sensors/sensor_explorer/PropertyList.qml +++ /dev/null @@ -1,127 +0,0 @@ -/**************************************************************************** -** -** 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 the declarative plugins -import QtQuick 2.0 -import Explorer 1.0 - -Rectangle { - id: controlrect - anchors.margins: 5 - color: "transparent" - - property PropertyInfo selectedItem: null; - property alias listmodel: itemList.model - - onListmodelChanged: { - itemList.currentIndex = -1; - selectedItem = null; - } - - 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: "content/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; - } - } - } - } - } -} diff --git a/examples/sensors/sensor_explorer/SensorList.qml b/examples/sensors/sensor_explorer/SensorList.qml deleted file mode 100644 index 9152e42a..00000000 --- a/examples/sensors/sensor_explorer/SensorList.qml +++ /dev/null @@ -1,146 +0,0 @@ -/**************************************************************************** -** -** 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 the declarative plugins -import QtQuick 2.0 -import Explorer 1.0 - -Rectangle { - id: controlrect - anchors.margins: 5 - color: "transparent" - - property SensorItem selectedItem: null; - property alias title: labelTitle.text - property alias listmodel: itemList.model - - onListmodelChanged: { - itemList.currentIndex = -1; - selectedItem = null; - } - - 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: "content/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; - } - } - } - } - } -} diff --git a/examples/sensors/sensor_explorer/components/ApplicationWindow.qml b/examples/sensors/sensor_explorer/components/ApplicationWindow.qml deleted file mode 100644 index 06654e41..00000000 --- a/examples/sensors/sensor_explorer/components/ApplicationWindow.qml +++ /dev/null @@ -1,51 +0,0 @@ -/**************************************************************************** -** -** 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 the declarative plugins -import QtQuick 2.0 - -Rectangle { - id: appWnd - x: 0 - y: 0 - width: 320 - height: 480 - color: "#ececec" -} diff --git a/examples/sensors/sensor_explorer/components/Button.qml b/examples/sensors/sensor_explorer/components/Button.qml deleted file mode 100644 index 7c1d4986..00000000 --- a/examples/sensors/sensor_explorer/components/Button.qml +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** -** -** 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 the declarative plugins -import QtQuick 2.0 - -//Implementation of the Button control. -Item { - id: button - width: 30 - height: 100 - property alias text: innerText.text - signal clicked - - Image { - id: backgroundImage - anchors.fill: parent - source: (button.enabled ? "images/button_background_normal.png" : "images/button_background_disabled.png") - } - - 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/components/TextField.qml b/examples/sensors/sensor_explorer/components/TextField.qml deleted file mode 100644 index 43cf9530..00000000 --- a/examples/sensors/sensor_explorer/components/TextField.qml +++ /dev/null @@ -1,109 +0,0 @@ -/**************************************************************************** -** -** 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 the declarative plugins -import QtQuick 2.0 - -Item { - id: textInputFrame - property alias text: textInput.text - signal accepted - - 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; - } - - onAccepted: { - textInputFrame.accepted(); - } - - 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/components/images/button_background_disabled.png b/examples/sensors/sensor_explorer/components/images/button_background_disabled.png deleted file mode 100644 index 62a00b9a..00000000 Binary files a/examples/sensors/sensor_explorer/components/images/button_background_disabled.png and /dev/null differ diff --git a/examples/sensors/sensor_explorer/components/images/button_background_normal.png b/examples/sensors/sensor_explorer/components/images/button_background_normal.png deleted file mode 100644 index 1fecad5b..00000000 Binary files a/examples/sensors/sensor_explorer/components/images/button_background_normal.png and /dev/null differ diff --git a/examples/sensors/sensor_explorer/components/images/button_background_pressed.png b/examples/sensors/sensor_explorer/components/images/button_background_pressed.png deleted file mode 100644 index 149529e1..00000000 Binary files a/examples/sensors/sensor_explorer/components/images/button_background_pressed.png and /dev/null differ diff --git a/examples/sensors/sensor_explorer/components/images/textfield_background_disabled.png b/examples/sensors/sensor_explorer/components/images/textfield_background_disabled.png deleted file mode 100644 index 98bc601f..00000000 Binary files a/examples/sensors/sensor_explorer/components/images/textfield_background_disabled.png and /dev/null differ diff --git a/examples/sensors/sensor_explorer/components/images/textfield_background_normal.png b/examples/sensors/sensor_explorer/components/images/textfield_background_normal.png deleted file mode 100644 index b90b50cd..00000000 Binary files a/examples/sensors/sensor_explorer/components/images/textfield_background_normal.png and /dev/null differ diff --git a/examples/sensors/sensor_explorer/content/listitem_select.png b/examples/sensors/sensor_explorer/content/listitem_select.png deleted file mode 100644 index def234f1..00000000 Binary files a/examples/sensors/sensor_explorer/content/listitem_select.png and /dev/null differ diff --git a/examples/sensors/sensor_explorer/doc/images/qtsensors-examples-explorer.png b/examples/sensors/sensor_explorer/doc/images/qtsensors-examples-explorer.png new file mode 100644 index 00000000..0976b9f9 Binary files /dev/null and b/examples/sensors/sensor_explorer/doc/images/qtsensors-examples-explorer.png differ diff --git a/examples/sensors/sensor_explorer/doc/src/sensor_explorer.qdoc b/examples/sensors/sensor_explorer/doc/src/sensor_explorer.qdoc index be042156..b40bf39f 100644 --- a/examples/sensors/sensor_explorer/doc/src/sensor_explorer.qdoc +++ b/examples/sensors/sensor_explorer/doc/src/sensor_explorer.qdoc @@ -27,30 +27,45 @@ /*! \example sensor_explorer - \title Qt Sensors - Explorer QML example + \title Qt Sensors - Explorer QML Example \ingroup qtsensors-examples + \brief Demonstrates how to read the meta-data of available sensors. - \section2 Sensor Explorer in QML - \brief The Sensor Explorer example demonstrates how to read the meta-data of available sensors. - + \image qtsensors-examples-explorer.png 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. + \li A \l{Sensor Explorer QML Import}{C++ plugin} that provides QML + alternatives for \c QSensorExplorer, \c QPropertyInfo and + \c QSensorItem C++ classes. + \li A \l{Sensor Explorer QML Application}{QML Application} that uses + the QML types to read the sensor 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. + This example is built as an executable with C++ code that runs the QML, + but it can also be launched directly using the \c qmlscene tool. You + should build the top-level \e sensor_explorer project before trying to + run this example or it will not be able to find its dependencies. \code - qmlscene main.qml + qmlscene -I . sensor_explorer.qml \endcode - To write a QML application that will use the Explorer QML type you need to do the following steps: + Above, the -I . parameter adds the current directory as a module import + path to locate the Explorer QML module. + + \section1 Sensor Explorer QML Import + + The Sensor Explorer QML import defines the \e Explorer QML module, + exporting \c QSensorExplorer, \c QPropertyInfo and \c QSensorItem C++ + classes as QML types. The source code is available in the + \c sensor_explorer/import subdirectory. + + \section1 Sensor Explorer QML Application + + To write a QML application that will use the QML types exposed by the + Explorer module, following steps are needed: Import the Explorer 1.0 declarative plugin: @@ -60,32 +75,30 @@ \snippet sensor_explorer/sensor_explorer.qml 1 - You can retrieve a list of all available sensors using the SensorExplorer: + You can retrieve a list of all available sensors using + \c SensorExplorer.availableSensors: \snippet sensor_explorer/sensor_explorer.qml 2 - To retrieve the properties of a SensorItem use: + The example uses the returned list as a model to populate a view of + available sensors. + + To retrieve the properties of a sensor, use \c SensorItem.properties: \snippet sensor_explorer/sensor_explorer.qml 3 - Changing a property value can be done like: + The property list is used as a model for another view that displays the + property names and values. + + It is possible to edit the values of certain sensor properties. Selecting + a writable property value will open an editor. \c SensorExplorer QML + type allows you to pass a new value for a sensor property value as + follows: \snippet sensor_explorer/sensor_explorer.qml 4 - Starting and stopping a sensor can be done like: + Starting and stopping a sensor can be done by setting the + \c SensorItem.start property: \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/examples/sensors/sensor_explorer/import/import.pro b/examples/sensors/sensor_explorer/import/import.pro index 85f471c6..196c373c 100644 --- a/examples/sensors/sensor_explorer/import/import.pro +++ b/examples/sensors/sensor_explorer/import/import.pro @@ -2,21 +2,39 @@ TEMPLATE = lib CONFIG += plugin TARGET = $$qtLibraryTarget(declarative_explorer) -TARGETPATH = Explorer +DESTDIR = ../Explorer QT += qml sensors -SOURCES = main.cpp explorer.cpp sensoritem.cpp propertyinfo.cpp -HEADERS = explorer.h sensoritem.h propertyinfo.h +SOURCES = \ + main.cpp \ + explorer.cpp \ + sensoritem.cpp \ + propertyinfo.cpp -DESTPATH=$$[QT_INSTALL_EXAMPLES]/qtsensors/sensor_explorer/Explorer +HEADERS = \ + explorer.h \ + sensoritem.h \ + propertyinfo.h -target.path=$$DESTPATH -INSTALLS += target +DESTPATH=$$[QT_INSTALL_EXAMPLES]/sensors/sensor_explorer/Explorer +target.path=$$DESTPATH qmldir.files=$$PWD/qmldir qmldir.path=$$DESTPATH -INSTALLS += qmldir +INSTALLS += target qmldir OTHER_FILES += \ plugin.json qmldir + +copyfile = $$PWD/qmldir +copydest = $$DESTDIR + +# On Windows, use backslashes as directory separators +win32: { + copyfile ~= s,/,\\,g + copydest ~= s,/,\\,g +} + +# Copy the qmldir file to the same folder as the plugin binary +QMAKE_POST_LINK += $$QMAKE_COPY $$quote($$copyfile) $$quote($$copydest) $$escape_expand(\\n\\t) diff --git a/examples/sensors/sensor_explorer/import/main.cpp b/examples/sensors/sensor_explorer/import/main.cpp index f040fa16..36025e09 100644 --- a/examples/sensors/sensor_explorer/import/main.cpp +++ b/examples/sensors/sensor_explorer/import/main.cpp @@ -52,9 +52,8 @@ class SensorExplorerDeclarativeModule : public QQmlExtensionPlugin public: virtual void registerTypes(const char *uri) { - qDebug() << "SensorExplorerDeclarativeModule::registerTypes(const char *uri)"; - Q_ASSERT(QLatin1String(uri) == QLatin1String("Explorer")); + // @uri Explorer qmlRegisterType(uri, 1, 0, "SensorExplorer"); qmlRegisterType(uri, 1, 0, "SensorItem"); qmlRegisterType(uri, 1, 0, "PropertyInfo"); diff --git a/examples/sensors/sensor_explorer/main.cpp b/examples/sensors/sensor_explorer/main.cpp index 34f5ba3c..066f559c 100644 --- a/examples/sensors/sensor_explorer/main.cpp +++ b/examples/sensors/sensor_explorer/main.cpp @@ -38,5 +38,27 @@ ** ****************************************************************************/ -#include "../stub.h" -SENSORS_EXAMPLE_MAIN(sensor_explorer) +#include +#include + +#ifndef QT_NO_WIDGETS +#include +#define Application QApplication +#else +#include +#define Application QGuiApplication +#endif + +int main(int argc, char *argv[]) +{ + Application app(argc, argv); + QQmlApplicationEngine engine(QUrl("qrc:///sensor_explorer.qml")); + QObject *topLevel = engine.rootObjects().value(0); + QQuickWindow *window = qobject_cast(topLevel); + if (!window) { + qWarning("Error: Your root item has to be a Window."); + return -1; + } + window->show(); + return app.exec(); +} diff --git a/examples/sensors/sensor_explorer/qml.pro b/examples/sensors/sensor_explorer/qml.pro index e9fe0bf5..e018830d 100644 --- a/examples/sensors/sensor_explorer/qml.pro +++ b/examples/sensors/sensor_explorer/qml.pro @@ -1,16 +1,18 @@ TEMPLATE = app TARGET = sensor_explorer -QT += quick +QT += qml quick + +qtHaveModule(widgets) { + QT += widgets +} SOURCES = main.cpp app.files = \ - $$files(*.qml) \ - icon.png \ - components \ - content + sensor_explorer.qml \ + icon.png -target.path = $$[QT_INSTALL_EXAMPLES]/qtsensors/sensor_explorer -app.path = $$[QT_INSTALL_EXAMPLES]/qtsensors/sensor_explorer +target.path = $$[QT_INSTALL_EXAMPLES]/sensors/sensor_explorer +app.path = $$[QT_INSTALL_EXAMPLES]/sensors/sensor_explorer INSTALLS += target app RESOURCES += \ diff --git a/examples/sensors/sensor_explorer/qml.qrc b/examples/sensors/sensor_explorer/qml.qrc index 3f11f3e9..df6160ae 100644 --- a/examples/sensors/sensor_explorer/qml.qrc +++ b/examples/sensors/sensor_explorer/qml.qrc @@ -1,16 +1,5 @@ - PropertyList.qml - SensorList.qml sensor_explorer.qml - components/ApplicationWindow.qml - components/TextField.qml - components/Button.qml - components/images/button_background_disabled.png - components/images/textfield_background_normal.png - components/images/textfield_background_disabled.png - components/images/button_background_pressed.png - components/images/button_background_normal.png - content/listitem_select.png diff --git a/examples/sensors/sensor_explorer/sensor_explorer.qml b/examples/sensors/sensor_explorer/sensor_explorer.qml index d396d980..d7f8b8e3 100644 --- a/examples/sensors/sensor_explorer/sensor_explorer.qml +++ b/examples/sensors/sensor_explorer/sensor_explorer.qml @@ -38,159 +38,177 @@ ** ****************************************************************************/ -//Import the declarative plugins -import QtQuick 2.0 -import "components" +import QtQuick 2.1 +import QtQuick.Window 2.1 +import QtQuick.Controls 1.0 //! [0] import Explorer 1.0 //! [0] -ApplicationWindow { - id: mainWnd +Window { + id: window + width: 320 + height: 480 + minimumWidth: 320 + minimumHeight: 480 -//! [1] + //! [1] SensorExplorer { id: explorer } -//! [1] - - SensorList { - id: sensorList - anchors.top: parent.top - anchors.topMargin: 0 - anchors.left: parent.left - anchors.right: parent.right - height: 170 - 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] - } - } + //! [1] + + Column { + anchors.fill: parent + anchors.margins: 8 + spacing: 8 + + GroupBox { + title: qsTr("Available Sensors") + width: parent.width + height: window.height * 0.4 + + TableView { + id: sensorList + anchors.fill: parent + //! [2] + model: explorer.availableSensors + //! [2] + + TableViewColumn { role: "id"; title: qsTr("ID"); width: sensorList.width * 0.7 } + TableViewColumn { role: "start"; title: qsTr("Running"); width: sensorList.width * 0.3 - 5 } + + onClicked: { + explorer.selectedSensorItem = explorer.availableSensors[row] + //! [3] + propertyList.model = explorer.selectedSensorItem.properties + //! [3] + button.update() + } + } - 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" - } + Button { + id: button + anchors.margins: 4 + anchors.horizontalCenter: parent.horizontalCenter + anchors.top: sensorList.bottom + 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] + } + } + } - PropertyList { - id: propertyList - anchors.top: listSplitLine.bottom - anchors.left: parent.left - anchors.right: parent.right - anchors.bottom: listPropertyEndLine.top - anchors.bottomMargin: 5 - - onSelectedItemChanged: { - textfield.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" - } + GroupBox { + title: qsTr("Properties") + width: parent.width + height: window.height * 0.55 + enabled: explorer.selectedSensorItem != null - 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] - } + TableView { + id: propertyList + property PropertyInfo selectedItem: null - textfield.text = ""; - } - } + anchors.fill: parent + TableViewColumn { role: "name"; title: qsTr("Name"); width: propertyList.width * 0.5 } + TableViewColumn { role: "value"; title: qsTr("Value"); width: propertyList.width * 0.5 - 5 } - TextField { - id: textfield - anchors.top: parent.bottom - anchors.topMargin: -35 - anchors.left: startstopButton.right - anchors.right: parent.right - anchors.margins: 5 - height: 30 - enabled: false - - onEnabledChanged: { - if (!textfield.enabled) { - textfield.closeSoftwareInputPanel(); - textfield.anchors.top= parent.bottom; - textfield.anchors.topMargin= -35; - textfield.text = ""; - } - } + onClicked: { + selectedItem = model[row] + } - onFocusChanged: { - if (textfield.focus) { - textfield.anchors.top= sensorList.bottom - textfield.anchors.topMargin= -15 - } - else { - textfield.closeSoftwareInputPanel(); - textfield.anchors.top= parent.bottom; - textfield.anchors.topMargin= -35; - } - } + itemDelegate: { + if (selectedItem && selectedItem.isWriteable) + return editableDelegate; + return readOnlyDelegate; + } - onAccepted: { + 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) + } + } + } - if (explorer.selectedSensorItem !== null - && propertyList.selectedItem !== null) { -//! [4] - explorer.selectedSensorItem.changePropertyValue(propertyList.selectedItem, textfield.text); -//! [4] - propertyList.focus=true; + 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 { + id: textinput + color: styleData.textColor + text: styleData.value + MouseArea { + id: mouseArea + anchors.fill: parent + hoverEnabled: true + onClicked: textinput.forceActiveFocus() + } + } + } + } + } + } } - textfield.text = ""; } } } - -- cgit v1.2.3