Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qgeocodingmanager.cpp
Go to the documentation of this file.
1// Copyright (C) 2015 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
7
9#include "qgeocircle.h"
10
11#include <QLocale>
12
13QT_BEGIN_NAMESPACE
14
15/*!
16 \class QGeoCodingManager
17 \inmodule QtLocation
18 \ingroup QtLocation-geocoding
19 \since 5.6
20
21 \brief The QGeoCodingManager class provides support for geocoding
22 operations.
23
24 The geocode() and reverseGeocode() functions return
25 QGeoCodeReply objects, which manage these operations and report on the
26 result of the operations and any errors which may have occurred.
27
28 The geocode() and reverseGeocode() functions can be used to convert
29 QGeoAddress instances to QGeoCoordinate instances and vice-versa.
30
31 The geocode() function is also overloaded to allow a user to perform a free text
32 geocoding operation, if the string provided can be interpreted as
33 an address it can be geocoded to coordinate information.
34
35 Instances of QGeoCodingManager can be accessed with
36 QGeoServiceProvider::geocodingManager().
37*/
38
39/*!
40 Constructs a new manager with the specified \a parent and with the
41 implementation provided by \a engine.
42
43 This constructor is used interally by QGeoServiceProviderFactory. Regular
44 users should acquire instances of QGeoCodingManager with
45 QGeoServiceProvider::geocodingManager();
46*/
47QGeoCodingManager::QGeoCodingManager(QGeoCodingManagerEngine *engine, QObject *parent)
48 : QObject(parent),
49 d_ptr(new QGeoCodingManagerPrivate())
50{
51 d_ptr->engine.reset(engine);
52 if (d_ptr->engine) {
53 d_ptr->engine->setParent(this);
54
55 connect(d_ptr->engine.get(), &QGeoCodingManagerEngine::finished,
56 this, &QGeoCodingManager::finished);
57
58 connect(d_ptr->engine.get(), &QGeoCodingManagerEngine::errorOccurred,
59 this, &QGeoCodingManager::errorOccurred);
60 } else {
61 qFatal("The geocoding manager engine that was set for this geocoding manager was NULL.");
62 }
63}
64
65/*!
66 Destroys this manager.
67*/
68QGeoCodingManager::~QGeoCodingManager()
69{
70 delete d_ptr;
71}
72
73/*!
74 Returns the name of the engine which implements the behaviour of this
75 geocoding manager.
76
77 The combination of managerName() and managerVersion() should be unique
78 amongst the plugin implementations.
79*/
80QString QGeoCodingManager::managerName() const
81{
82// if (!d_ptr->engine)
83// return QString();
84
85 return d_ptr->engine->managerName();
86}
87
88/*!
89 Returns the version of the engine which implements the behaviour of this
90 geocoding manager.
91
92 The combination of managerName() and managerVersion() should be unique
93 amongst the plugin implementations.
94*/
95int QGeoCodingManager::managerVersion() const
96{
97// if (!d_ptr->engine)
98// return -1;
99
100 return d_ptr->engine->managerVersion();
101}
102
103/*!
104 Begins the geocoding of \a address. Geocoding is the process of finding a
105 coordinate that corresponds to a given address.
106
107 A QGeoCodeReply object will be returned, which can be used to manage the
108 geocoding operation and to return the results of the operation.
109
110 This manager and the returned QGeoCodeReply object will emit signals
111 indicating if the operation completes or if errors occur.
112
113 If supportsGeocoding() returns false an
114 QGeoCodeReply::UnsupportedOptionError will occur.
115
116 Once the operation has completed, QGeoCodeReply::locations() can be used to
117 retrieve the results, which will consist of a list of QGeoLocation objects.
118 These objects represent a combination of coordinate and address data.
119
120 The address data returned in the results may be different from \a address.
121 This will usually occur if the geocoding service backend uses a different
122 canonical form of addresses or if \a address was only partially filled out.
123
124 If \a bounds is non-null and is a valid QGeoShape it will be used to
125 limit the results to those that are contained within \a bounds. This is
126 particularly useful if \a address is only partially filled out, as the
127 service will attempt to geocode all matches for the specified data.
128
129 The user is responsible for deleting the returned reply object, although
130 this can be done in the slot connected to QGeoCodingManager::finished(),
131 QGeoCodingManager::errorOccurred(), QGeoCodeReply::finished() or
132 QGeoCodeReply::errorOccurred() with deleteLater().
133*/
134QGeoCodeReply *QGeoCodingManager::geocode(const QGeoAddress &address, const QGeoShape &bounds)
135{
136 return d_ptr->engine->geocode(address, bounds);
137}
138
139
140/*!
141 Begins the reverse geocoding of \a coordinate. Reverse geocoding is the
142 process of finding an address that corresponds to a given coordinate.
143
144 A QGeoCodeReply object will be returned, which can be used to manage the
145 reverse geocoding operation and to return the results of the operation.
146
147 This manager and the returned QGeoCodeReply object will emit signals
148 indicating if the operation completes or if errors occur.
149
150 If supportsReverseGeocoding() returns false an
151 QGeoCodeReply::UnsupportedOptionError will occur.
152
153 At that point QGeoCodeReply::locations() can be used to retrieve the
154 results, which will consist of a list of QGeoLocation objects. These objects
155 represent a combination of coordinate and address data.
156
157 The coordinate data returned in the results may be different from \a
158 coordinate. This will usually occur if the reverse geocoding service
159 backend shifts the coordinates to be closer to the matching addresses, or
160 if the backend returns results at multiple levels of detail.
161
162 If multiple results are returned by the reverse geocoding service backend
163 they will be provided in order of specificity. This normally occurs if the
164 backend is configured to reverse geocode across multiple levels of detail.
165 As an example, some services will return address and coordinate pairs for
166 the street address, the city, the state and the country.
167
168 If \a bounds is non-null and a valid QGeoRectangle it will be used to
169 limit the results to those that are contained within \a bounds.
170
171 The user is responsible for deleting the returned reply object, although
172 this can be done in the slot connected to QGeoCodingManager::finished(),
173 QGeoCodingManager::errorOccurred(), QGeoCodeReply::finished() or
174 QGeoCodeReply::errorOccurred() with deleteLater().
175*/
176QGeoCodeReply *QGeoCodingManager::reverseGeocode(const QGeoCoordinate &coordinate, const QGeoShape &bounds)
177{
178 return d_ptr->engine->reverseGeocode(coordinate, bounds);
179}
180
181/*!
182 Begins geocoding for a location matching \a address.
183
184 A QGeoCodeReply object will be returned, which can be used to manage the
185 geocoding operation and to return the results of the operation.
186
187 This manager and the returned QGeoCodeReply object will emit signals
188 indicating if the operation completes or if errors occur.
189
190 Once the operation has completed, QGeoCodeReply::locations() can be used to
191 retrieve the results, which will consist of a list of QGeoLocation objects.
192 These objects represent a combination of coordinate and address data.
193
194 If \a limit is -1 the entire result set will be returned, otherwise at most
195 \a limit results will be returned.
196
197 The \a offset parameter is used to ask the geocoding service to not return the
198 first \a offset results.
199
200 The \a limit and \a offset results are used together to implement paging.
201
202 If \a bounds is non-null and a valid QGeoShape it will be used to
203 limit the results to those that are contained within \a bounds.
204
205 The user is responsible for deleting the returned reply object, although
206 this can be done in the slot connected to QGeoCodingManager::finished(),
207 QGeoCodingManager::errorOccurred(), QGeoCodeReply::finished() or
208 QGeoCodeReply::errorOccurred() with deleteLater().
209*/
210QGeoCodeReply *QGeoCodingManager::geocode(const QString &address,
211 int limit,
212 int offset,
213 const QGeoShape &bounds)
214{
215 QGeoCodeReply *reply = d_ptr->engine->geocode(address,
216 limit,
217 offset,
218 bounds);
219 return reply;
220}
221
222/*!
223 Sets the locale to be used by this manager to \a locale.
224
225 If this geocoding manager supports returning the results
226 in different languages, they will be returned in the language of \a locale.
227
228 The locale used defaults to the system locale if this is not set.
229*/
230void QGeoCodingManager::setLocale(const QLocale &locale)
231{
232 d_ptr->engine->setLocale(locale);
233}
234
235/*!
236 Returns the locale used to hint to this geocoding manager about what
237 language to use for the results.
238*/
239QLocale QGeoCodingManager::locale() const
240{
241 return d_ptr->engine->locale();
242}
243
244/*!
245\fn void QGeoCodingManager::finished(QGeoCodeReply *reply)
246
247 This signal is emitted when \a reply has finished processing.
248
249 If reply::error() equals QGeoCodeReply::NoError then the processing
250 finished successfully.
251
252 This signal and QGeoCodeReply::finished() will be emitted at the same
253 time.
254
255 \note Do not delete the \a reply object in the slot connected to this
256 signal. Use deleteLater() instead.
257*/
258
259/*!
260\fn void QGeoCodingManager::errorOccurred(QGeoCodeReply *reply, QGeoCodeReply::Error error, const QString &errorString)
261
262 This signal is emitted when an error has been detected in the processing of
263 \a reply. The QGeoCodingManager::finished() signal will probably follow.
264
265 The error will be described by the error code \a error. If \a errorString is
266 not empty it will contain a textual description of the error.
267
268 This signal and QGeoCodeReply::errorOccurred() will be emitted at the same time.
269
270 \note Do not delete the \a reply object in the slot connected to this
271 signal. Use deleteLater() instead.
272*/
273
274/*******************************************************************************
275*******************************************************************************/
276
277QT_END_NAMESPACE