diff options
Diffstat (limited to 'examples/sensors/grue')
26 files changed, 0 insertions, 1399 deletions
diff --git a/examples/sensors/grue/console_app/console_app.pro b/examples/sensors/grue/console_app/console_app.pro deleted file mode 100644 index 7b082d39..00000000 --- a/examples/sensors/grue/console_app/console_app.pro +++ /dev/null @@ -1,14 +0,0 @@ -TEMPLATE = app -TARGET = detect_grue -CONFIG += console -CONFIG -= app_bundle -QT = core sensors - -DESTDIR = $$OUT_PWD/.. - -SOURCES = main.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/sensors/grue -INSTALLS += target - -CONFIG += install_ok # Do not cargo-cult this! diff --git a/examples/sensors/grue/console_app/main.cpp b/examples/sensors/grue/console_app/main.cpp deleted file mode 100644 index 29a629b5..00000000 --- a/examples/sensors/grue/console_app/main.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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 <QtCore> -#include <qsensor.h> - -class Filter : public QSensorFilter -{ - int lastPercent; -public: - Filter() - : QSensorFilter() - , lastPercent(0) - { - } - - bool filter(QSensorReading *reading) override - { - int percent = reading->property("chanceOfBeingEaten").value<int>(); - if (percent == 0) { - qDebug() << "It is light. You are safe from Grues."; - } else if (lastPercent == 0) { - qDebug() << "It is dark. You are likely to be eaten by a Grue."; - } - if (percent == 100) { - qDebug() << "You have been eaten by a Grue!"; - QCoreApplication::instance()->quit(); - } else if (percent) - qDebug() << "Your chance of being eaten by a Grue:" << percent << "percent."; - lastPercent = percent; - return false; - } -}; - -int main(int argc, char **argv) -{ - QCoreApplication app(argc, argv); - - QSensor sensor("GrueSensor"); - - Filter filter; - sensor.addFilter(&filter); - sensor.start(); - - if (!sensor.isActive()) { - qWarning("The Grue sensor didn't start. You're on your own!"); - return 1; - } - - return app.exec(); -} - diff --git a/examples/sensors/grue/doc/images/qtsensors-examples-grue.png b/examples/sensors/grue/doc/images/qtsensors-examples-grue.png Binary files differdeleted file mode 100644 index f4348271..00000000 --- a/examples/sensors/grue/doc/images/qtsensors-examples-grue.png +++ /dev/null diff --git a/examples/sensors/grue/doc/src/grue.qdoc b/examples/sensors/grue/doc/src/grue.qdoc deleted file mode 100644 index 146a8de0..00000000 --- a/examples/sensors/grue/doc/src/grue.qdoc +++ /dev/null @@ -1,153 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: https://www.gnu.org/licenses/fdl-1.3.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! - \example grue - \title Qt Sensors - Grue Sensor Example - \brief The Qt Sensors - Grue sensor example demonstrates all the steps from creating a new sensor to using it. - \ingroup qtsensors-examples - - \image qtsensors-examples-grue.png - - The Qt Sensors - Grue sensor example demonstrates all the steps from creating a new sensor to using it. - - The sensor definition is placed in a library where client apps can access it. The actual implementation - lives in a plugin. - - \list - \li \l{Grue Sensor Definition} - \li \l{Grue Sensor Implementation} - \endlist - - The sensor can now be used by a C++ application, even if the application does not have access to the - definition. - - \list - \li \l{Grue Sensor Console Application} - \endlist - - To make the sensor available to a QML application an import must be created. - - \list - \li \l{Grue Sensor QML Import} - \li \l{Grue Sensor QML Application} - \endlist - - \section1 Grue Sensor Definition - - The Grue sensor is defined in a library so that applications can use it. - The source code is available in the \c{grue/lib} subdirectory. - - First up is the sensor type. This is the interface for sensors that report - on your likelihood of being eaten by a Grue. Such sensors are very important - to adventurers, particularly if they are going into dark places as this is - where Grues live. - - The interface is a simple one. It provides only 1 piece of information, your - chance of being eaten. For the details on how this is property should be - interpreted please see the documentation in gruesensor.cpp. - - This example was created using the make_sensor.pl script which can be found in - src/sensors. As such, it contains some generated code that defines the convenience - classes GrueFilter and GrueSensor. - - \section1 Grue Sensor Implementation - - The Grue sensor implementation lives in a plugin that is loaded by the Qt Sensors - library. The source code is available in the \c{grue/plugin} subdirectory. - - The Grue sensor needs a backend before it can be used. The backend provided - is rather basic and it relies on some kind of light sensor to work but it - gets the job done. If new hardware that can detect the actual presence of Grues - becomes available a backend could be created that supports this hardware and - applications using the Grue sensor would be able to use it without any changes. - - There are a few mandatory parts to a backend. They are the start and stop methods - and the setReading call. The start and stop methods are used to start and stop - any underlying hardware. In the case of this backend they start and stop a - light sensor. In the start method, the backend should be sure to call the - sensorStopped() or sensorBusy() methods if it cannot start. - - \snippet grue/plugin/gruesensorimpl.cpp start - - The setReading method is needed so that the sensors library knows where the - readings are coming from. This backend has a local copy of the reading so - it passes a pointer to the function. - - \snippet grue/plugin/gruesensorimpl.cpp setReading - - However it is also possible to pass null to the setReading method in which - case the sensors library will create an instance and return a pointer. - - \code - // Create a reading instance for us to use - m_reading = setReading<GrueSensorReading>(0); - \endcode - - The Grue sensor backend also supplies some metadata. - - The backend checks 2 things, how dark it is and how long you have been in the dark. - It uses the readingChanged() signal to know when to check the light sensor's - value. Once it is dark, it uses a timer to increase your chance of being eaten. - - The Grue sensor backend is delivered as a plugin. The plugin has a factory object - that registers the types available and does the actual instantiation of the backend. - - \section1 Grue Sensor Console Application - - The Grue sensor console application demonstrates use of the Grue sensor. - The source code is available in the \c{grue/console_app} subdirectory. - - This is a simple commandline application. It demonstrates how to use the generic - access feature of Qt Sensors to avoid a link-time dependency on the Grue Sensor - library. - - \section1 Grue Sensor QML Import - - The Grue sensor QML import exports the GrueSensor class as a QML type. - The source code is available in the \c{grue/import} subdirectory. - - This creates the \e {Grue 1.0} import. - - \section1 Grue Sensor QML Application - - The Grue sensor QML application demonstrates the use of GrueSensor QML type. - - The application consists of a single QML file and an image. It is built as an - exucutable 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 'grue' project before trying to run - this example or it will not be able to find its dependencies. - - \code - qmlscene -I . grue.qml - \endcode - - Above, the \c{-I .} parameter adds the current directory as a module import - path to locate the Grue QML module. -*/ diff --git a/examples/sensors/grue/grue.png b/examples/sensors/grue/grue.png Binary files differdeleted file mode 100644 index 2727d393..00000000 --- a/examples/sensors/grue/grue.png +++ /dev/null diff --git a/examples/sensors/grue/grue.pro b/examples/sensors/grue/grue.pro deleted file mode 100644 index 7290cd34..00000000 --- a/examples/sensors/grue/grue.pro +++ /dev/null @@ -1,9 +0,0 @@ -TEMPLATE = subdirs - -SUBDIRS += lib plugin console_app - -qtHaveModule(quick): SUBDIRS += import qml.pro - -plugin.depends = lib -import.depends = lib - diff --git a/examples/sensors/grue/grue.qml b/examples/sensors/grue/grue.qml deleted file mode 100644 index 02b1bd0f..00000000 --- a/examples/sensors/grue/grue.qml +++ /dev/null @@ -1,129 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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 QtSensors 5.0 -import Grue 1.0 - -Rectangle { - id: root - width: 320 - height: 480 - color: "black" - - property int percent: 0 - property string text: "" - property real grueOpacity: 0.0 - - function updateStatus(newPercent, newOpacity, newText) { - if (root.percent === newPercent) - return; - - // Delay updating the visual status to prevent flicker - timer.interval = (newPercent < root.percent) ? 500 : 0; - - root.percent = newPercent; - root.text = newText; - root.grueOpacity = newOpacity; - - timer.start() - } - - Timer { - id: timer - running: false - repeat: false - onTriggered: { - text.text = root.text - grueimg.opacity = root.grueOpacity - } - } - - GrueSensor { - id: sensor - active: true - onReadingChanged: { - var percent = reading.chanceOfBeingEaten; - if (percent === 0) { - updateStatus(percent, 0.0, "It is light.<br>You are safe from Grues."); - } - else if (percent === 100) { - updateStatus(percent, 1.0, "You have been eaten by a Grue!"); - sensor.active = false; - } - else if (percent > 0) { - updateStatus(percent, 0.05 + (percent * 0.001), - "It is dark.<br>You are " + percent +" % " + - "likely to be eaten by a Grue."); - } - } - } - - Text { - id: text - anchors.top: parent.top - anchors.topMargin: 0 - anchors.left: parent.left - anchors.right: parent.right - wrapMode: Text.WordWrap - text: "I can't tell if you're going to be eaten by a Grue or not. You're on your own!" - font.pixelSize: 30 - color: "lightgray" - } - - Image { - id: grueimg - anchors.bottom: parent.bottom - anchors.horizontalCenter: parent.horizontalCenter - source: "grue.png" - opacity: 0.0 - Behavior on opacity { PropertyAnimation { duration: 250 } } - } -} diff --git a/examples/sensors/grue/grue.xcf b/examples/sensors/grue/grue.xcf Binary files differdeleted file mode 100644 index 2837ed7e..00000000 --- a/examples/sensors/grue/grue.xcf +++ /dev/null diff --git a/examples/sensors/grue/icon.xcf b/examples/sensors/grue/icon.xcf Binary files differdeleted file mode 100644 index 8416c49f..00000000 --- a/examples/sensors/grue/icon.xcf +++ /dev/null diff --git a/examples/sensors/grue/import/import.json b/examples/sensors/grue/import/import.json deleted file mode 100644 index 0967ef42..00000000 --- a/examples/sensors/grue/import/import.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/examples/sensors/grue/import/import.pro b/examples/sensors/grue/import/import.pro deleted file mode 100644 index 17d7713e..00000000 --- a/examples/sensors/grue/import/import.pro +++ /dev/null @@ -1,37 +0,0 @@ -TEMPLATE = lib -CONFIG += plugin - -TARGET = $$qtLibraryTarget(declarative_grue) - -macos: DESTDIR = ../grue_app.app/Contents/MacOS/Grue -else: DESTDIR = ../Grue - -QT = core gui qml sensors - -include(../lib/lib.pri) - -# Shared gruesensor library will be installed in parent directory. -# Define rpath so that this plugin will know where to look for it. -unix:!mac: QMAKE_LFLAGS += -Wl,-rpath,\\\$\$ORIGIN/.. -macos: QMAKE_RPATHDIR += @loader_path/../../Frameworks - -SOURCES = main.cpp - -DESTPATH=$$[QT_INSTALL_EXAMPLES]/sensors/grue/Grue - -target.path=$$DESTPATH -INSTALLS += target - -CONFIG += install_ok # Do not cargo-cult this! - -qmldir.files=$$PWD/qmldir -qmldir.path=$$DESTPATH -INSTALLS += qmldir - -OTHER_FILES += \ - import.json qmldir - -# Copy the qmldir file to the same folder as the plugin binary -cpqmldir.files = $$PWD/qmldir -cpqmldir.path = $$DESTDIR -COPIES += cpqmldir diff --git a/examples/sensors/grue/import/main.cpp b/examples/sensors/grue/import/main.cpp deleted file mode 100644 index 4827af48..00000000 --- a/examples/sensors/grue/import/main.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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 <QtQml/qqmlextensionplugin.h> -#include <QtQml/qqml.h> - -#include <gruesensor.h> -#include <QDebug> - -#ifdef BUNDLED_PLUGIN -#include <QPluginLoader> -#include <QSensorPluginInterface> -#endif - -QT_BEGIN_NAMESPACE - -class GrueSensorQmlImport : public QQmlExtensionPlugin -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid FILE "import.json") -public: - void registerTypes(const char *uri) override - { - char const * const package = "Grue"; - if (QLatin1String(uri) != QLatin1String(package)) return; - int major; - int minor; - - // Register the 1.0 interfaces - major = 1; - minor = 0; - // @uri Grue - qmlRegisterType <GrueSensor >(package, major, minor, "GrueSensor"); - qmlRegisterUncreatableType<GrueSensorReading>(package, major, minor, "GrueSensorReading", QLatin1String("Cannot create GrueSensorReading")); - } - -#ifdef BUNDLED_PLUGIN - GrueSensorQmlImport() - { - // For now, this is getting called after Sensors has loaded - // Ensure that a change later does not break this by forcing - // sensors to load now - (void)QSensor::sensorTypes(); - - // Load the bundled sensor plugin - QPluginLoader loader(QString::fromLocal8Bit(BUNDLED_PLUGIN)); - QObject *instance = loader.instance(); - m_changes = qobject_cast<QSensorChangesInterface*>(instance); - if (m_changes) { - QSensor *sensor = new QSensor(QByteArray(), this); - connect(sensor, SIGNAL(availableSensorsChanged()), this, SLOT(sensorsChanged())); - m_changes->sensorsChanged(); - } - QSensorPluginInterface *plugin = qobject_cast<QSensorPluginInterface*>(instance); - if (plugin) { - plugin->registerSensors(); - } - } - -private slots: - void sensorsChanged() - { - m_changes->sensorsChanged(); - } - -private: - QSensorChangesInterface *m_changes; -#endif -}; - -QT_END_NAMESPACE - -#include "main.moc" - -/* - \omit - \qmltype GrueSensor - \instantiates GrueSensor - \inherits Sensor - \inqmlmodule Grue - \brief The GrueSensor type reports on your chance of being eaten by a Grue. - - The GrueSensor type reports on your chance of being eaten by a Grue. - - This type wraps the GrueSensor class. Please see the documentation for - GrueSensor for details. - \endomit -*/ - -/* - \omit - \qmltype GrueSensorReading - \instantiates GrueSensorReading - \inherits SensorReading - \inqmlmodule Grue - \brief The GrueSensorReading type holds the most recent GrueSensor reading. - - The GrueSensorReading type holds the most recent GrueSensor reading. - - This type wraps the GrueSensorReading class. Please see the documentation for - GrueSensorReading for details. - - This type cannot be directly created. - \endomit -*/ - -/* - \omit - \qmlproperty qreal Grue1::GrueSensorReading::chanceOfBeingEaten - Please see GrueSensorReading::chanceOfBeingEaten for information about this property. - \endomit -*/ diff --git a/examples/sensors/grue/import/qmldir b/examples/sensors/grue/import/qmldir deleted file mode 100644 index 529b9093..00000000 --- a/examples/sensors/grue/import/qmldir +++ /dev/null @@ -1,2 +0,0 @@ -module Grue -plugin declarative_grue diff --git a/examples/sensors/grue/lib/gruesensor.cpp b/examples/sensors/grue/lib/gruesensor.cpp deleted file mode 100644 index 1de2f4e8..00000000 --- a/examples/sensors/grue/lib/gruesensor.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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 "gruesensor.h" -#include "gruesensor_p.h" - -IMPLEMENT_READING(GrueSensorReading) - -/* - \omit - \class GrueSensorReading - - \brief The GrueSensorReading class holds readings from the Grue sensor. - - The Grue Sensor informs you of your chance of being eaten by a Grue. - - Grues love the dark so as long as your surroundings are relatively light - you are safe. However the more time you spend in the dark, the higher - your chances are of being eaten by a Grue. -*/ - -/* - \property GrueSensorReading::chanceOfBeingEaten - \brief holds your chance of being eaten. - - The value is the probability (from 0 to 100) that a Grue will eat you. - A probability of 100 means you are currently being eaten. The darker - it is, the more likely you are to be eaten by a Grue. The longer you - stay in a dark area, the more likely you are to be eaten by a Grue. - If you are in a lit room, the probability will be 0 as Grues fear light. - \endomit -*/ - -int GrueSensorReading::chanceOfBeingEaten() const -{ - return d->chanceOfBeingEaten; -} - -void GrueSensorReading::setChanceOfBeingEaten(int chanceOfBeingEaten) -{ - d->chanceOfBeingEaten = chanceOfBeingEaten; -} - -// ===================================================================== - -// begin generated code - -/* - \omit - \class GrueFilter - - \brief The GrueFilter class is a convenience wrapper around QSensorFilter. - - The only difference is that the filter() method features a pointer to GrueSensorReading - instead of QSensorReading. - \endomit -*/ - -/* - \omit - \fn GrueFilter::filter(GrueSensorReading *reading) - - Called when \a reading changes. Returns false to prevent the reading from propagating. - - \sa QSensorFilter::filter() - \endomit -*/ - -char const * const GrueSensor::type("GrueSensor"); - -/* - \omit - \class GrueSensor - - \brief The GrueSensor class is a convenience wrapper around QSensor. - - The only behavioural difference is that this class sets the type properly. - - This class also features a reading() function that returns a GrueSensorReading instead of a QSensorReading. - - For details about how the sensor works, see \l GrueSensorReading. - - \sa GrueSensorReading - \endomit -*/ - -/* - \omit - \fn GrueSensor::GrueSensor(QObject *parent) - - Construct the sensor as a child of \a parent. - \endomit -*/ - -/* - \fn GrueSensor::~GrueSensor() - - Destroy the sensor. Stops the sensor if it has not already been stopped. -*/ - -/* - \omit - \fn GrueSensor::reading() const - - Returns the reading class for this sensor. - - \sa QSensor::reading() - \endomit -*/ -// end generated code - -#include "moc_gruesensor.cpp" diff --git a/examples/sensors/grue/lib/gruesensor.h b/examples/sensors/grue/lib/gruesensor.h deleted file mode 100644 index 90379939..00000000 --- a/examples/sensors/grue/lib/gruesensor.h +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ - -#ifndef GRUESENSOR_H -#define GRUESENSOR_H - -#include <qsensor.h> - -class GrueSensorReadingPrivate; - -#if defined(QT_BUILD_GRUE_LIB) -# define Q_GRUE_EXPORT Q_DECL_EXPORT -#else -# define Q_GRUE_EXPORT Q_DECL_IMPORT -#endif - -class Q_GRUE_EXPORT GrueSensorReading : public QSensorReading -{ - Q_OBJECT - Q_PROPERTY(int chanceOfBeingEaten READ chanceOfBeingEaten WRITE setChanceOfBeingEaten) - DECLARE_READING(GrueSensorReading) -public: - int chanceOfBeingEaten() const; - void setChanceOfBeingEaten(int chanceOfBeingEaten); -}; - -// begin generated code - -class Q_GRUE_EXPORT GrueFilter : public QSensorFilter -{ -public: - virtual bool filter(GrueSensorReading *reading) = 0; -private: - bool filter(QSensorReading *reading) override { return filter(static_cast<GrueSensorReading*>(reading)); } -}; - -class Q_GRUE_EXPORT GrueSensor : public QSensor -{ - Q_OBJECT - Q_PROPERTY(GrueSensorReading* reading READ reading) -public: - explicit GrueSensor(QObject *parent = 0) : QSensor(GrueSensor::type, parent) {} - virtual ~GrueSensor() {} - GrueSensorReading *reading() const { return static_cast<GrueSensorReading*>(QSensor::reading()); } - static char const * const type; -}; -// end generated code - -#endif diff --git a/examples/sensors/grue/lib/gruesensor_p.h b/examples/sensors/grue/lib/gruesensor_p.h deleted file mode 100644 index 0216d06b..00000000 --- a/examples/sensors/grue/lib/gruesensor_p.h +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ - -#ifndef GRUESENSOR_P_H -#define GRUESENSOR_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -class GrueSensorReadingPrivate -{ -public: - GrueSensorReadingPrivate() - : chanceOfBeingEaten(-1) - { - } - - int chanceOfBeingEaten; -}; - -#endif diff --git a/examples/sensors/grue/lib/lib.pri b/examples/sensors/grue/lib/lib.pri deleted file mode 100644 index 0e3da252..00000000 --- a/examples/sensors/grue/lib/lib.pri +++ /dev/null @@ -1,6 +0,0 @@ -INCLUDEPATH += $$PWD - -macos: LIBS += -L$$OUT_PWD/../grue_app.app/Contents/Frameworks -else: LIBS += -L$$OUT_PWD/.. - -LIBS += -lgruesensor diff --git a/examples/sensors/grue/lib/lib.pro b/examples/sensors/grue/lib/lib.pro deleted file mode 100644 index cc10e5c4..00000000 --- a/examples/sensors/grue/lib/lib.pro +++ /dev/null @@ -1,20 +0,0 @@ -TEMPLATE = lib -TARGET = gruesensor - -macos: DESTDIR = ../grue_app.app/Contents/Frameworks -else: DESTDIR = $$OUT_PWD/.. - -macos: QMAKE_SONAME_PREFIX = @rpath - -DEFINES *= QT_BUILD_GRUE_LIB -QT = core sensors - -HEADERS += gruesensor.h \ - gruesensor_p.h - -SOURCES += gruesensor.cpp - -target.path=$$[QT_INSTALL_EXAMPLES]/sensors/grue -INSTALLS += target - -CONFIG += install_ok # Do not cargo-cult this! diff --git a/examples/sensors/grue/main.cpp b/examples/sensors/grue/main.cpp deleted file mode 100644 index 499a3432..00000000 --- a/examples/sensors/grue/main.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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 "../stub.h" -SENSORS_EXAMPLE_MAIN(grue) diff --git a/examples/sensors/grue/plugin/gruesensorimpl.cpp b/examples/sensors/grue/plugin/gruesensorimpl.cpp deleted file mode 100644 index d8012b54..00000000 --- a/examples/sensors/grue/plugin/gruesensorimpl.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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 "gruesensorimpl.h" -#include <QDebug> -#include <QTimer> - -char const * const gruesensorimpl::id("grue.gruesensor"); - -gruesensorimpl::gruesensorimpl(QSensor *sensor) - : QSensorBackend(sensor) - , lightLevel(QAmbientLightReading::Undefined) -{ - // We need a light sensor - lightSensor = new QAmbientLightSensor(this); - connect(lightSensor, SIGNAL(readingChanged()), this, SLOT(lightChanged())); - lightSensor->connectToBackend(); - - // We need a timer - darkTimer = new QTimer(this); - darkTimer->setInterval(1000); - connect(darkTimer, SIGNAL(timeout()), this, SLOT(increaseChance())); - - // We use this as our timestamp source - timer.start(); - -//! [setReading] - // Register our reading instance - setReading<GrueSensorReading>(&m_reading); -//! [setReading] - -//! [metadata] - // Supply metadata - // We can run as fast as the light sensor does - setDataRates(lightSensor); - // Only one output range, 0 to 1 in .1 increments - addOutputRange(0, 1, 0.1); - setDescription(QLatin1String("Grue Sensor")); -//! [metadata] -} - -void gruesensorimpl::start() -{ -//! [start] - lightSensor->setDataRate(sensor()->dataRate()); - lightSensor->start(); - // If the light sensor doesn't work we don't work either - if (!lightSensor->isActive()) - sensorStopped(); - if (lightSensor->isBusy()) - sensorBusy(); -//! [start] -} - -void gruesensorimpl::stop() -{ - lightSensor->stop(); -} - -void gruesensorimpl::lightChanged() -{ - if (lightLevel == lightSensor->reading()->lightLevel()) - return; - - lightLevel = lightSensor->reading()->lightLevel(); - - int chance = 0; - darkTimer->stop(); - - switch (lightSensor->reading()->lightLevel()) { - case QAmbientLightReading::Dark: - // It is dark. You are likely to be eaten by a grue. - chance = 10; - darkTimer->start(); - break; - default: - break; - } - - // Only send an update if the value has changed. - if (chance != m_reading.chanceOfBeingEaten() || m_reading.timestamp() == 0) { - m_reading.setTimestamp(timer.elapsed()); - m_reading.setChanceOfBeingEaten(chance); - newReadingAvailable(); - } -} - -void gruesensorimpl::increaseChance() -{ - // The longer you stay in the dark, the higher your chance of being eaten - int chance = m_reading.chanceOfBeingEaten() + 10; - - m_reading.setTimestamp(timer.elapsed()); - m_reading.setChanceOfBeingEaten(chance); - - newReadingAvailable(); - - // No point in using the timer anymore if we've hit 100... you can't get more - // likely to be eaten than 100% - if (chance >= 100) - darkTimer->stop(); -} - diff --git a/examples/sensors/grue/plugin/gruesensorimpl.h b/examples/sensors/grue/plugin/gruesensorimpl.h deleted file mode 100644 index 8a4a9565..00000000 --- a/examples/sensors/grue/plugin/gruesensorimpl.h +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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$ -** -****************************************************************************/ - -#ifndef GRUESENSORIMPL_H -#define GRUESENSORIMPL_H - -#include <qsensorbackend.h> -#include "gruesensor.h" -#include <qambientlightsensor.h> -#include <QElapsedTimer> - -QT_BEGIN_NAMESPACE -class QTimer; -QT_END_NAMESPACE - -class gruesensorimpl : public QSensorBackend -{ - Q_OBJECT -public: - static char const * const id; - - gruesensorimpl(QSensor *sensor); - - void start() override; - void stop() override; - -private Q_SLOTS: - void lightChanged(); - void increaseChance(); - -private: - GrueSensorReading m_reading; - QAmbientLightSensor *lightSensor; - QTimer *darkTimer; - QElapsedTimer timer; - QAmbientLightReading::LightLevel lightLevel; -}; - -#endif - diff --git a/examples/sensors/grue/plugin/main.cpp b/examples/sensors/grue/plugin/main.cpp deleted file mode 100644 index 4c5da15d..00000000 --- a/examples/sensors/grue/plugin/main.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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 "gruesensorimpl.h" -#include <qsensorplugin.h> -#include <qsensorbackend.h> -#include <qsensormanager.h> -#include <QFile> -#include <QDebug> - -class GrueSensorPlugin : public QObject, public QSensorPluginInterface, public QSensorChangesInterface, public QSensorBackendFactory -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID "com.qt-project.Qt.QSensorPluginInterface/1.0" FILE "plugin.json") - Q_INTERFACES(QSensorPluginInterface QSensorChangesInterface) -public: - void registerSensors() override - { - qDebug() << "loaded the grue plugin"; - } - - void sensorsChanged() override - { - if (!QSensor::defaultSensorForType(QAmbientLightSensor::type).isEmpty()) { - // There is a light sensor available. Register the backend - if (!QSensorManager::isBackendRegistered(GrueSensor::type, gruesensorimpl::id)) - QSensorManager::registerBackend(GrueSensor::type, gruesensorimpl::id, this); - } else { - if (QSensorManager::isBackendRegistered(GrueSensor::type, gruesensorimpl::id)) - QSensorManager::unregisterBackend(GrueSensor::type, gruesensorimpl::id); - } - } - - QSensorBackend *createBackend(QSensor *sensor) override - { - if (sensor->identifier() == gruesensorimpl::id) - return new gruesensorimpl(sensor); - - return 0; - } -}; - -#include "main.moc" - diff --git a/examples/sensors/grue/plugin/plugin.json b/examples/sensors/grue/plugin/plugin.json deleted file mode 100644 index ab372059..00000000 --- a/examples/sensors/grue/plugin/plugin.json +++ /dev/null @@ -1 +0,0 @@ -{ "Keys": [ "grue" ] } diff --git a/examples/sensors/grue/plugin/plugin.pro b/examples/sensors/grue/plugin/plugin.pro deleted file mode 100644 index e198140d..00000000 --- a/examples/sensors/grue/plugin/plugin.pro +++ /dev/null @@ -1,30 +0,0 @@ -TEMPLATE = lib -CONFIG += plugin -TARGET = $$qtLibraryTarget(qtsensors_grue) -PLUGIN_TYPE = sensors - -QT = core sensors - -macos: DESTDIR = ../grue_app.app/Contents/MacOS/$$PLUGIN_TYPE -else: DESTDIR = ../$$PLUGIN_TYPE - -include(../lib/lib.pri) - -# Shared gruesensor library will be installed in parent directory. -# Define rpath so that this plugin will know where to look for it. -unix:!mac: QMAKE_LFLAGS += -Wl,-rpath,\\\$\$ORIGIN/.. - -HEADERS += gruesensorimpl.h - -SOURCES += gruesensorimpl.cpp \ - main.cpp - - -# Install the plugin under Grue example directory -target.path=$$[QT_INSTALL_EXAMPLES]/sensors/grue/$$PLUGIN_TYPE -INSTALLS += target - -CONFIG += install_ok # Do not cargo-cult this! - -OTHER_FILES += \ - plugin.json diff --git a/examples/sensors/grue/qml.pro b/examples/sensors/grue/qml.pro deleted file mode 100644 index 3293c4f2..00000000 --- a/examples/sensors/grue/qml.pro +++ /dev/null @@ -1,22 +0,0 @@ -TEMPLATE = app -TARGET = grue_app -QT += quick - -# Avoid going to release/debug subdirectory -win32: DESTDIR = ./ - -SOURCES = main.cpp - -RESOURCES += \ - qml.qrc - -OTHER_FILES = \ - $$files(*.qml) \ - grue.png - -target.path = $$[QT_INSTALL_EXAMPLES]/sensors/grue -INSTALLS += target - -EXAMPLE_FILES += \ - grue.xcf \ - icon.xcf diff --git a/examples/sensors/grue/qml.qrc b/examples/sensors/grue/qml.qrc deleted file mode 100644 index 55b269b9..00000000 --- a/examples/sensors/grue/qml.qrc +++ /dev/null @@ -1,6 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file>grue.qml</file> - <file>grue.png</file> - </qresource> -</RCC> |