summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLincoln Ramsay <lincoln.ramsay@nokia.com>2011-10-04 15:14:01 +1000
committerLincoln Ramsay <lincoln.ramsay@nokia.com>2011-10-10 09:25:31 +1000
commit4e04cda0e600f4e3bb148956ba631647a5c1fa4c (patch)
tree5dd8a0f2e2a0b2cdc8075f05a66cb1f6689e51c4 /examples
parent93be0e5c0fd1694b0868187ed3daa006dfa4bd79 (diff)
Grue Sensor example
Updated, documented as an example. Now with a QML import and a QML app. Fixes: MTMW-85 Change-Id: I06772cf4a07ea0d2ec7bfccda6e8f51b5d866c20 Reviewed-on: http://codereview.qt-project.org/6016 Reviewed-by: Lincoln Ramsay <lincoln.ramsay@nokia.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/sensors/grue/console_app/console_app.pro (renamed from examples/sensors/grueapp/grueapp.pro)2
-rw-r--r--examples/sensors/grue/console_app/main.cpp (renamed from examples/sensors/grueapp/main.cpp)0
-rw-r--r--examples/sensors/grue/grue.pro8
-rw-r--r--examples/sensors/grue/import/import.pro19
-rw-r--r--examples/sensors/grue/import/main.cpp117
-rw-r--r--examples/sensors/grue/import/qmldir1
-rw-r--r--examples/sensors/grue/import/qsensorsimport.pri38
-rw-r--r--examples/sensors/grue/lib/gruesensor.cpp (renamed from examples/sensors/grueplugin/gruesensor.cpp)6
-rw-r--r--examples/sensors/grue/lib/gruesensor.h (renamed from examples/sensors/grueplugin/gruesensor.h)0
-rw-r--r--examples/sensors/grue/lib/gruesensor_p.h (renamed from examples/sensors/grueplugin/gruesensor_p.h)0
-rw-r--r--examples/sensors/grue/lib/lib.pro17
-rw-r--r--examples/sensors/grue/plugin/gruesensorimpl.cpp (renamed from examples/sensors/grueplugin/gruesensorimpl.cpp)0
-rw-r--r--examples/sensors/grue/plugin/gruesensorimpl.h (renamed from examples/sensors/grueplugin/gruesensorimpl.h)0
-rw-r--r--examples/sensors/grue/plugin/main.cpp (renamed from examples/sensors/grueplugin/main.cpp)0
-rw-r--r--examples/sensors/grue/plugin/plugin.pro20
-rw-r--r--examples/sensors/grue/qml_app/main.qml75
-rw-r--r--examples/sensors/grue/qml_app/qml_app.qmlproject20
-rw-r--r--examples/sensors/grueplugin/grueplugin.pri8
-rw-r--r--examples/sensors/grueplugin/grueplugin.pro15
-rw-r--r--examples/sensors/grueplugin/version.pri1
-rw-r--r--examples/sensors/sensors.pro3
21 files changed, 317 insertions, 33 deletions
diff --git a/examples/sensors/grueapp/grueapp.pro b/examples/sensors/grue/console_app/console_app.pro
index 65d59be1..fefc0157 100644
--- a/examples/sensors/grueapp/grueapp.pro
+++ b/examples/sensors/grue/console_app/console_app.pro
@@ -1,5 +1,5 @@
TEMPLATE=app
-TARGET=grueapp
+TARGET=detect_grue
QT=core sensors
SOURCES=main.cpp
diff --git a/examples/sensors/grueapp/main.cpp b/examples/sensors/grue/console_app/main.cpp
index 789e6451..789e6451 100644
--- a/examples/sensors/grueapp/main.cpp
+++ b/examples/sensors/grue/console_app/main.cpp
diff --git a/examples/sensors/grue/grue.pro b/examples/sensors/grue/grue.pro
new file mode 100644
index 00000000..5af352bc
--- /dev/null
+++ b/examples/sensors/grue/grue.pro
@@ -0,0 +1,8 @@
+TEMPLATE = subdirs
+
+SUBDIRS += lib plugin console_app
+SUBDIRS += import #qml_app
+
+plugin.depends = lib
+import.depends = lib
+
diff --git a/examples/sensors/grue/import/import.pro b/examples/sensors/grue/import/import.pro
new file mode 100644
index 00000000..fc163b61
--- /dev/null
+++ b/examples/sensors/grue/import/import.pro
@@ -0,0 +1,19 @@
+TARGET = declarative_grue
+TARGETPATH = Grue
+
+include(qsensorsimport.pri)
+
+QT = declarative sensors
+
+DESTDIR = $$QT.sensors.imports/$$TARGETPATH
+
+INCLUDEPATH += $$PWD/../lib
+LIBS += -L$$OUT_PWD/../lib -lgruesensor
+
+SOURCES = main.cpp
+
+symbian {
+ TARGET.EPOCALLOWDLLDATA = 1
+ TARGET.CAPABILITY = ALL -TCB
+}
+
diff --git a/examples/sensors/grue/import/main.cpp b/examples/sensors/grue/import/main.cpp
new file mode 100644
index 00000000..ec1d4709
--- /dev/null
+++ b/examples/sensors/grue/import/main.cpp
@@ -0,0 +1,117 @@
+/****************************************************************************
+**
+** 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 <QtDeclarative/qdeclarativeextensionplugin.h>
+#include <QtDeclarative/qdeclarative.h>
+
+#include <gruesensor.h>
+
+QT_BEGIN_NAMESPACE
+
+class GrueSensorQmlImport : public QDeclarativeExtensionPlugin
+{
+ Q_OBJECT
+public:
+ virtual void registerTypes(const char *uri)
+ {
+ char const * const package = "Grue";
+ if (QLatin1String(uri) != QLatin1String(package)) return;
+ int major;
+ int minor;
+
+ // Register the 1.0 interfaces
+ major = 1;
+ minor = 0;
+ qmlRegisterType <GrueSensor >(package, major, minor, "GrueSensor");
+ qmlRegisterUncreatableType<GrueSensorReading>(package, major, minor, "GrueSensorReading", QLatin1String("Cannot create GrueSensorReading"));
+ }
+};
+
+QT_END_NAMESPACE
+
+#include "main.moc"
+
+Q_EXPORT_PLUGIN2(gruesensorqmlimport, QT_PREPEND_NAMESPACE(GrueSensorQmlImport));
+
+/*!
+ \qmlclass GrueSensor GrueSensor
+ \inqmlmodule Grue 1
+ \brief The GrueSensor element reports on your chance of being eaten by a Grue.
+
+ The GrueSensor element reports on your chance of being eaten by a Grue.
+
+ This element wraps the GrueSensor class. Please see the documentation for
+ GrueSensor for details.
+
+ \sa {QtMobility.sensors QML Limitations}
+*/
+
+/*!
+ \qmlproperty GrueSensorReading Grue1::GrueSensor::reading
+ Holds the most recent Grue sensor reading.
+ Please see QSensor::reading for information about this property.
+*/
+
+/*!
+ \qmlsignal Grue1::GrueSensor::onReadingChanged()
+ Called when the reading object changes.
+ Please see QSensor::readingChanged() for information about this signal.
+*/
+
+/*!
+ \qmlclass GrueSensorReading GrueSensorReading
+ \inqmlmodule Grue 1
+ \inherits QtMobility.sensors1::SensorReading
+ \brief The GrueSensorReading element holds the most recent GrueSensor reading.
+
+ The GrueSensorReading element holds the most recent GrueSensor reading.
+
+ This element wraps the GrueSensorReading class. Please see the documentation for
+ GrueSensorReading for details.
+
+ This element cannot be directly created.
+*/
+
+/*!
+ \qmlproperty qreal Grue1::GrueSensorReading::chanceOfBeingEaten
+ Please see GrueSensorReading::chanceOfBeingEaten for information about this property.
+*/
+
diff --git a/examples/sensors/grue/import/qmldir b/examples/sensors/grue/import/qmldir
new file mode 100644
index 00000000..266b7c11
--- /dev/null
+++ b/examples/sensors/grue/import/qmldir
@@ -0,0 +1 @@
+plugin declarative_grue
diff --git a/examples/sensors/grue/import/qsensorsimport.pri b/examples/sensors/grue/import/qsensorsimport.pri
new file mode 100644
index 00000000..d5cfeffc
--- /dev/null
+++ b/examples/sensors/grue/import/qsensorsimport.pri
@@ -0,0 +1,38 @@
+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!")
+}
+
+QMLDIRFILE = $${_PRO_FILE_PWD_}/qmldir
+copy2build.input = QMLDIRFILE
+copy2build.output = $$QT.sensors.imports/$$TARGETPATH/qmldir
+!contains(TEMPLATE_PREFIX, vc):copy2build.variable_out = PRE_TARGETDEPS
+copy2build.commands = $$QMAKE_COPY ${QMAKE_FILE_IN} ${QMAKE_FILE_OUT}
+copy2build.name = COPY ${QMAKE_FILE_IN}
+copy2build.CONFIG += no_link
+# `clean' should leave the build in a runnable state, which means it shouldn't delete qmldir
+copy2build.CONFIG += no_clean
+QMAKE_EXTRA_COMPILERS += copy2build
+
+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/grueplugin/gruesensor.cpp b/examples/sensors/grue/lib/gruesensor.cpp
index c5ee030f..da322cb3 100644
--- a/examples/sensors/grueplugin/gruesensor.cpp
+++ b/examples/sensors/grue/lib/gruesensor.cpp
@@ -45,9 +45,7 @@ IMPLEMENT_READING(GrueSensorReading)
/*!
\class GrueSensorReading
- \ingroup sensors_reading
- \preliminary
\brief The GrueSensorReading class holds readings from the Grue sensor.
The Grue Sensor informs you of your chance of being eaten by a Grue.
@@ -84,9 +82,7 @@ void GrueSensorReading::setChanceOfBeingEaten(qreal chanceOfBeingEaten)
/*!
\class GrueFilter
- \ingroup sensors_filter
- \preliminary
\brief The GrueFilter class is a convenience wrapper around QSensorFilter.
The only difference is that the filter() method features a pointer to GrueSensorReading
@@ -105,9 +101,7 @@ char const * const GrueSensor::type("GrueSensor");
/*!
\class GrueSensor
- \ingroup sensors_type
- \preliminary
\brief The GrueSensor class is a convenience wrapper around QSensor.
The only behavioural difference is that this class sets the type properly.
diff --git a/examples/sensors/grueplugin/gruesensor.h b/examples/sensors/grue/lib/gruesensor.h
index 52b08e95..52b08e95 100644
--- a/examples/sensors/grueplugin/gruesensor.h
+++ b/examples/sensors/grue/lib/gruesensor.h
diff --git a/examples/sensors/grueplugin/gruesensor_p.h b/examples/sensors/grue/lib/gruesensor_p.h
index 5eff57e8..5eff57e8 100644
--- a/examples/sensors/grueplugin/gruesensor_p.h
+++ b/examples/sensors/grue/lib/gruesensor_p.h
diff --git a/examples/sensors/grue/lib/lib.pro b/examples/sensors/grue/lib/lib.pro
new file mode 100644
index 00000000..80bf1365
--- /dev/null
+++ b/examples/sensors/grue/lib/lib.pro
@@ -0,0 +1,17 @@
+TEMPLATE = lib
+TARGET = gruesensor
+
+QT = core sensors
+
+HEADERS += gruesensor.h\
+ gruesensor_p.h\
+
+SOURCES += gruesensor.cpp\
+
+DESTDIR=$$QT.sensors.libs
+
+symbian {
+ TARGET.EPOCALLOWDLLDATA = 1
+ TARGET.CAPABILITY = ALL -TCB
+}
+
diff --git a/examples/sensors/grueplugin/gruesensorimpl.cpp b/examples/sensors/grue/plugin/gruesensorimpl.cpp
index 4a277c91..4a277c91 100644
--- a/examples/sensors/grueplugin/gruesensorimpl.cpp
+++ b/examples/sensors/grue/plugin/gruesensorimpl.cpp
diff --git a/examples/sensors/grueplugin/gruesensorimpl.h b/examples/sensors/grue/plugin/gruesensorimpl.h
index bddca842..bddca842 100644
--- a/examples/sensors/grueplugin/gruesensorimpl.h
+++ b/examples/sensors/grue/plugin/gruesensorimpl.h
diff --git a/examples/sensors/grueplugin/main.cpp b/examples/sensors/grue/plugin/main.cpp
index d471ece3..d471ece3 100644
--- a/examples/sensors/grueplugin/main.cpp
+++ b/examples/sensors/grue/plugin/main.cpp
diff --git a/examples/sensors/grue/plugin/plugin.pro b/examples/sensors/grue/plugin/plugin.pro
new file mode 100644
index 00000000..fed8460b
--- /dev/null
+++ b/examples/sensors/grue/plugin/plugin.pro
@@ -0,0 +1,20 @@
+TEMPLATE = lib
+CONFIG += plugin
+TARGET = $$qtLibraryTarget(qtsensors_grue)
+PLUGIN_TYPE = sensors
+
+QT = core sensors
+
+INCLUDEPATH += $$PWD/../lib
+LIBS += -L$$QT.sensors.libs -lgruesensor
+
+HEADERS += gruesensorimpl.h\
+
+SOURCES += gruesensorimpl.cpp\
+ main.cpp\
+
+symbian {
+ TARGET.EPOCALLOWDLLDATA = 1
+ TARGET.CAPABILITY = ALL -TCB
+}
+
diff --git a/examples/sensors/grue/qml_app/main.qml b/examples/sensors/grue/qml_app/main.qml
new file mode 100644
index 00000000..278bf727
--- /dev/null
+++ b/examples/sensors/grue/qml_app/main.qml
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** 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 examples 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 QtQuick 2.0
+import Grue 1.0
+
+Item {
+ width: 200
+ height: 300
+
+ GrueSensor {
+ id: sensor
+ active: true
+ property int lastPercent: 0
+ onReadingChanged: {
+ var percent = Math.floor(reading.chanceOfBeingEaten * 100);
+ if (percent == 0) {
+ text.text = "It is light. You are safe from Grues.";
+ } else if (lastPercent == 0) {
+ text.text = "It is dark. You are likely to be eaten by a Grue.";
+ }
+ if (percent == 100) {
+ text.text += "You have been eaten by a Grue!";
+ sensor.active = false;
+ } else if (percent) {
+ text.text += "Your chance of being eaten by a Grue: "+percent+" percent.";
+ }
+ lastPercent = percent;
+ }
+ }
+
+ Text {
+ id: text
+ anchors.fill: parent
+ text: "I can't tell if you're going to be eaten by a Grue or not. You're on your own!"
+ wrapMode: Text.WordWrap
+ }
+}
diff --git a/examples/sensors/grue/qml_app/qml_app.qmlproject b/examples/sensors/grue/qml_app/qml_app.qmlproject
new file mode 100644
index 00000000..2218c43d
--- /dev/null
+++ b/examples/sensors/grue/qml_app/qml_app.qmlproject
@@ -0,0 +1,20 @@
+/* File generated by Qt Creator, version 2.2.0 */
+
+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/grueplugin/grueplugin.pri b/examples/sensors/grueplugin/grueplugin.pri
deleted file mode 100644
index 2cade0f0..00000000
--- a/examples/sensors/grueplugin/grueplugin.pri
+++ /dev/null
@@ -1,8 +0,0 @@
-HEADERS += gruesensor.h\
- gruesensor_p.h\
- gruesensorimpl.h\
-
-SOURCES += gruesensor.cpp\
- gruesensorimpl.cpp\
- main.cpp\
-
diff --git a/examples/sensors/grueplugin/grueplugin.pro b/examples/sensors/grueplugin/grueplugin.pro
deleted file mode 100644
index 0b39f910..00000000
--- a/examples/sensors/grueplugin/grueplugin.pro
+++ /dev/null
@@ -1,15 +0,0 @@
-TEMPLATE = lib
-CONFIG += plugin
-TARGET = $$qtLibraryTarget(qtsensors_grueplugin)
-PLUGIN_TYPE = sensors
-
-QT = core sensors
-
-include(version.pri)
-include(grueplugin.pri)
-
-symbian {
- TARGET.EPOCALLOWDLLDATA = 1
- TARGET.CAPABILITY = ALL -TCB
-}
-
diff --git a/examples/sensors/grueplugin/version.pri b/examples/sensors/grueplugin/version.pri
deleted file mode 100644
index 6fbe0253..00000000
--- a/examples/sensors/grueplugin/version.pri
+++ /dev/null
@@ -1 +0,0 @@
-VERSION = 0.1.1
diff --git a/examples/sensors/sensors.pro b/examples/sensors/sensors.pro
index 04033fcf..e7ecf2ca 100644
--- a/examples/sensors/sensors.pro
+++ b/examples/sensors/sensors.pro
@@ -3,8 +3,7 @@ TEMPLATE = subdirs
SUBDIRS += \
accel\
cubehouse\
- grueapp\
- grueplugin
+ grue
contains(QT_CONFIG,widgets):SUBDIRS += \
sensor_explorer