| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtSensors module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
| 21 | ** included in the packaging of this file. Please review the following |
| 22 | ** information to ensure the GNU General Public License requirements will |
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 24 | ** |
| 25 | ** $QT_END_LICENSE$ |
| 26 | ** |
| 27 | ****************************************************************************/ |
| 28 | |
| 29 | #ifndef TEST_SENSOR2_H |
| 30 | #define TEST_SENSOR2_H |
| 31 | |
| 32 | #include "qsensor.h" |
| 33 | |
| 34 | #undef DECLARE_READING |
| 35 | #undef DECLARE_READING_D |
| 36 | |
| 37 | template <typename T> |
| 38 | class qTypedWrapper |
| 39 | { |
| 40 | public: |
| 41 | qTypedWrapper(QScopedPointer<QSensorReadingPrivate> *_ptr) |
| 42 | : ptr(_ptr) |
| 43 | { |
| 44 | } |
| 45 | |
| 46 | T *operator->() const |
| 47 | { |
| 48 | return static_cast<T*>(ptr->data()); |
| 49 | } |
| 50 | |
| 51 | private: |
| 52 | QScopedPointer<QSensorReadingPrivate> *ptr; |
| 53 | }; |
| 54 | |
| 55 | #define DECLARE_READING(classname)\ |
| 56 | DECLARE_READING_D(classname, classname ## Private) |
| 57 | |
| 58 | #define DECLARE_READING_D(classname, pclassname)\ |
| 59 | public:\ |
| 60 | classname(QObject *parent = 0);\ |
| 61 | virtual ~classname();\ |
| 62 | void copyValuesFrom(QSensorReading *other) override;\ |
| 63 | private:\ |
| 64 | qTypedWrapper<pclassname> d; |
| 65 | |
| 66 | class TestSensor2ReadingPrivate; |
| 67 | |
| 68 | class TestSensor2Reading : public QSensorReading |
| 69 | { |
| 70 | Q_OBJECT |
| 71 | Q_PROPERTY(int test READ test) |
| 72 | DECLARE_READING(TestSensor2Reading) |
| 73 | public: |
| 74 | int test() const; |
| 75 | void setTest(int test); |
| 76 | }; |
| 77 | |
| 78 | class TestSensor2Filter : public QSensorFilter |
| 79 | { |
| 80 | public: |
| 81 | virtual bool filter(TestSensor2Reading *reading) = 0; |
| 82 | private: |
| 83 | bool filter(QSensorReading *reading) override { return filter(reading: static_cast<TestSensor2Reading*>(reading)); } |
| 84 | }; |
| 85 | |
| 86 | class TestSensor2 : public QSensor |
| 87 | { |
| 88 | Q_OBJECT |
| 89 | public: |
| 90 | explicit TestSensor2(QObject *parent = 0) : QSensor(TestSensor2::type, parent) {} |
| 91 | virtual ~TestSensor2() {} |
| 92 | TestSensor2Reading *reading() const { return static_cast<TestSensor2Reading*>(QSensor::reading()); } |
| 93 | static char const * const type; |
| 94 | }; |
| 95 | |
| 96 | #endif |
| 97 | |