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