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 test suite 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 QDECLARATIVELOCATIONTESTMODEL_H |
30 | #define QDECLARATIVELOCATIONTESTMODEL_H |
31 | |
32 | #include <QtQuick/QQuickItem> |
33 | #include <QAbstractListModel> |
34 | #include <QTimer> |
35 | #include <QDebug> |
36 | #include <QList> |
37 | #include <QtPositioning/QGeoCoordinate> |
38 | |
39 | QT_BEGIN_NAMESPACE |
40 | |
41 | class DataObject: public QObject |
42 | { |
43 | Q_OBJECT |
44 | Q_PROPERTY(QGeoCoordinate coordinate READ coordinate CONSTANT) |
45 | |
46 | public: |
47 | DataObject() {} |
48 | ~DataObject() {} |
49 | |
50 | QGeoCoordinate coordinate_; |
51 | QGeoCoordinate coordinate() const {return coordinate_;} |
52 | }; |
53 | |
54 | class QDeclarativeLocationTestModel : public QAbstractListModel, public QQmlParserStatus |
55 | { |
56 | Q_OBJECT |
57 | Q_PROPERTY(int datacount READ datacount WRITE setDatacount NOTIFY datacountChanged) |
58 | Q_PROPERTY(int delay READ delay WRITE setDelay NOTIFY delayChanged) |
59 | Q_PROPERTY(bool crazyMode READ crazyMode WRITE setCrazyMode NOTIFY crazyModeChanged) |
60 | Q_PROPERTY(int crazyLevel READ crazyLevel WRITE setCrazyLevel NOTIFY crazyLevelChanged) |
61 | Q_PROPERTY(QString datatype READ datatype WRITE setDatatype NOTIFY datatypeChanged) |
62 | Q_INTERFACES(QQmlParserStatus) |
63 | |
64 | public: |
65 | QDeclarativeLocationTestModel(QObject* parent = 0); |
66 | ~QDeclarativeLocationTestModel(); |
67 | |
68 | enum Roles { |
69 | TestDataRole = Qt::UserRole + 500 |
70 | }; |
71 | |
72 | // from QQmlParserStatus |
73 | virtual void componentComplete(); |
74 | virtual void classBegin() {} |
75 | |
76 | // From QAbstractListModel |
77 | virtual int rowCount(const QModelIndex &parent) const; |
78 | virtual QVariant data(const QModelIndex &index, int role) const; |
79 | virtual QHash<int, QByteArray> roleNames() const; |
80 | |
81 | int datacount() const; |
82 | void setDatacount(int datacount); |
83 | |
84 | int delay() const; |
85 | void setDelay(int delay); |
86 | |
87 | int crazyLevel() const; |
88 | void setCrazyLevel(int level); |
89 | |
90 | bool crazyMode() const; |
91 | void setCrazyMode(bool mode); |
92 | |
93 | QString datatype() const; |
94 | void setDatatype(QString datatype); |
95 | |
96 | //Q_INVOKABLE void clear(); |
97 | Q_INVOKABLE void reset(); |
98 | Q_INVOKABLE void update(); |
99 | //Q_INVOKABLE void reset(); |
100 | |
101 | signals: |
102 | void countChanged(); |
103 | void datacountChanged(); |
104 | void datatypeChanged(); |
105 | void delayChanged(); |
106 | void modelChanged(); |
107 | void crazyLevelChanged(); |
108 | void crazyModeChanged(); |
109 | |
110 | private slots: |
111 | void repopulate(); |
112 | void timerFired(); |
113 | |
114 | private: |
115 | void scheduleRepopulation(); |
116 | |
117 | private: |
118 | int delay_; |
119 | int datacount_; |
120 | bool componentCompleted_; |
121 | QString datatype_; |
122 | QTimer timer_; |
123 | QList<DataObject*> dataobjects_; |
124 | int crazyLevel_; |
125 | bool crazyMode_; |
126 | }; |
127 | |
128 | QT_END_NAMESPACE |
129 | |
130 | #endif |
131 |