1/****************************************************************************
2**
3** Copyright (C) 2015 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the QtLocation module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL3$
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 http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPLv3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or later as published by the Free
28** Software Foundation and appearing in the file LICENSE.GPL included in
29** the packaging of this file. Please review the following information to
30** ensure the GNU General Public License version 2.0 requirements will be
31** met: http://www.gnu.org/licenses/gpl-2.0.html.
32**
33** $QT_END_LICENSE$
34**
35****************************************************************************/
36
37#ifndef QDECLARATIVEGEOCODEMODEL_H
38#define QDECLARATIVEGEOCODEMODEL_H
39
40//
41// W A R N I N G
42// -------------
43//
44// This file is not part of the Qt API. It exists purely as an
45// implementation detail. This header file may change from version to
46// version without notice, or even be removed.
47//
48// We mean it.
49//
50
51#include <QtLocation/private/qlocationglobal_p.h>
52#include <QtLocation/private/qdeclarativegeoserviceprovider_p.h>
53
54#include <QtLocation/qgeocodereply.h>
55#include <QtPositioningQuick/private/qdeclarativegeoaddress_p.h>
56#include <QtPositioningQuick/private/qdeclarativegeolocation_p.h>
57
58#include <QtQml/qqml.h>
59#include <QtQml/QQmlParserStatus>
60#include <QAbstractListModel>
61#include <QPointer>
62
63
64QT_BEGIN_NAMESPACE
65
66class QGeoServiceProvider;
67class QGeoCodingManager;
68class QDeclarativeGeoLocation;
69
70class Q_LOCATION_PRIVATE_EXPORT QDeclarativeGeocodeModel : public QAbstractListModel, public QQmlParserStatus
71{
72 Q_OBJECT
73 Q_ENUMS(Status)
74 Q_ENUMS(GeocodeError)
75
76 Q_PROPERTY(QDeclarativeGeoServiceProvider *plugin READ plugin WRITE setPlugin NOTIFY pluginChanged)
77 Q_PROPERTY(bool autoUpdate READ autoUpdate WRITE setAutoUpdate NOTIFY autoUpdateChanged)
78 Q_PROPERTY(Status status READ status NOTIFY statusChanged)
79 Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged)
80 Q_PROPERTY(int count READ count NOTIFY countChanged)
81 Q_PROPERTY(int limit READ limit WRITE setLimit NOTIFY limitChanged)
82 Q_PROPERTY(int offset READ offset WRITE setOffset NOTIFY offsetChanged)
83 Q_PROPERTY(QVariant query READ query WRITE setQuery NOTIFY queryChanged)
84 Q_PROPERTY(QVariant bounds READ bounds WRITE setBounds NOTIFY boundsChanged)
85 Q_PROPERTY(GeocodeError error READ error NOTIFY errorChanged)
86 Q_INTERFACES(QQmlParserStatus)
87
88public:
89 enum Status {
90 Null,
91 Ready,
92 Loading,
93 Error
94 };
95
96 enum GeocodeError {
97 NoError = QGeoCodeReply::NoError,
98 EngineNotSetError = QGeoCodeReply::EngineNotSetError, //TODO Qt6 consider merge with NotSupportedError
99 CommunicationError = QGeoCodeReply::CommunicationError, //TODO Qt6 merge with Map's ConnectionError
100 ParseError = QGeoCodeReply::ParseError,
101 UnsupportedOptionError = QGeoCodeReply::UnsupportedOptionError, //TODO Qt6 consider rename UnsupportedOperationError
102 CombinationError = QGeoCodeReply::CombinationError,
103 UnknownError = QGeoCodeReply::UnknownError,
104 //we leave gap for future QGeoCodeReply errors
105
106 //QGeoServiceProvider related errors start here
107 UnknownParameterError = 100,
108 MissingRequiredParameterError
109 };
110
111 enum Roles {
112 LocationRole = Qt::UserRole + 1
113 };
114
115 explicit QDeclarativeGeocodeModel(QObject *parent = 0);
116 virtual ~QDeclarativeGeocodeModel();
117
118 // From QQmlParserStatus
119 virtual void classBegin() {}
120 virtual void componentComplete();
121
122 // From QAbstractListModel
123 virtual int rowCount(const QModelIndex &parent) const;
124 virtual QVariant data(const QModelIndex &index, int role) const;
125 virtual QHash<int,QByteArray> roleNames() const;
126
127 void setPlugin(QDeclarativeGeoServiceProvider *plugin);
128 QDeclarativeGeoServiceProvider *plugin() const;
129
130 void setBounds(const QVariant &boundingArea);
131 QVariant bounds() const;
132
133 Status status() const;
134 QString errorString() const;
135 GeocodeError error() const;
136
137 bool autoUpdate() const;
138 void setAutoUpdate(bool update);
139
140 int count() const;
141 Q_INVOKABLE QDeclarativeGeoLocation *get(int index);
142
143 int limit() const;
144 void setLimit(int limit);
145 int offset() const;
146 void setOffset(int offset);
147
148 QVariant query() const;
149 void setQuery(const QVariant &query);
150 Q_INVOKABLE void reset();
151 Q_INVOKABLE void cancel();
152
153Q_SIGNALS:
154 void countChanged();
155 void pluginChanged();
156 void statusChanged();
157 void errorChanged(); //emitted also for errorString notification
158 void locationsChanged();
159 void autoUpdateChanged();
160 void boundsChanged();
161 void queryChanged();
162 void limitChanged();
163 void offsetChanged();
164
165public Q_SLOTS:
166 void update();
167
168protected Q_SLOTS:
169 void queryContentChanged();
170 void geocodeFinished(QGeoCodeReply *reply);
171 void geocodeError(QGeoCodeReply *reply,
172 QGeoCodeReply::Error error,
173 const QString &errorString);
174 void pluginReady();
175
176protected:
177 QGeoCodingManager *searchManager();
178 void setStatus(Status status);
179 void setError(GeocodeError error, const QString &errorString);
180 bool autoUpdate_;
181 bool complete_;
182
183private:
184 void setLocations(const QList<QGeoLocation> &locations);
185 void abortRequest();
186 QGeoCodeReply *reply_;
187
188 QDeclarativeGeoServiceProvider *plugin_;
189 QGeoShape boundingArea_;
190
191 QList<QDeclarativeGeoLocation *> declarativeLocations_;
192
193 Status status_;
194 QString errorString_;
195 GeocodeError error_;
196 QVariant queryVariant_;
197 QGeoCoordinate coordinate_;
198 QDeclarativeGeoAddress *address_;
199 QString searchString_;
200
201 int limit_;
202 int offset_;
203};
204
205QT_END_NAMESPACE
206
207#endif
208

source code of qtlocation/src/location/declarativemaps/qdeclarativegeocodemodel_p.h