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
qgeocodereply.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
6
7#include <QtCore/QVariant>
8#include <QtPositioning/QGeoLocation>
9
11/*!
12 \class QGeoCodeReply
13 \inmodule QtLocation
14 \ingroup QtLocation-geocoding
15 \since 5.6
16
17 \brief The QGeoCodeReply class manages an operation started by an
18 instance of QGeoCodingManager.
19
20 Instances of QGeoCodeReply manage the state and results of these
21 operations.
22
23 The isFinished(), error() and errorString() methods provide information
24 on whether the operation has completed and if it completed successfully.
25
26 The finished() and errorOccurred(QGeoCodeReply::Error,QString)
27 signals can be used to monitor the progress of the operation.
28
29 It is possible that a newly created QGeoCodeReply may be in a finished
30 state, most commonly because an error has occurred. Since such an instance
31 will never emit the finished() or
32 errorOccurred(QGeoCodeReply::Error,QString) signals, it is
33 important to check the result of isFinished() before making the connections
34 to the signals. The documentation for QGeoCodingManager demonstrates how
35 this might be carried out.
36
37 If the operation completes successfully the results will be able to be
38 accessed with locations().
39*/
40
41/*!
42 \enum QGeoCodeReply::Error
43
44 Describes an error which prevented the completion of the operation.
45
46 \value NoError
47 No error has occurred.
48 \value EngineNotSetError
49 The geocoding manager that was used did not have a QGeoCodingManagerEngine instance associated with it.
50 \value CommunicationError
51 An error occurred while communicating with the service provider.
52 \value ParseError
53 The response from the service provider was in an unrecognizable format.
54 \value UnsupportedOptionError
55 The requested operation or one of the options for the operation are not
56 supported by the service provider.
57 \value CombinationError
58 An error occurred while results where being combined from multiple sources.
59 \value UnknownError
60 An error occurred which does not fit into any of the other categories.
61*/
62
63/*!
64 Constructs a geocode reply with the specified \a parent.
65*/
66QGeoCodeReply::QGeoCodeReply(QObject *parent)
67 : QObject(parent),
68 d_ptr(new QGeoCodeReplyPrivate()) {}
69
70/*!
71 Constructs a geocode reply with a given \a error and \a errorString and the specified \a parent.
72*/
73QGeoCodeReply::QGeoCodeReply(Error error, const QString &errorString, QObject *parent)
74 : QObject(parent),
75 d_ptr(new QGeoCodeReplyPrivate(error, errorString))
76{}
77
78/*!
79 Destroys this reply object.
80*/
81QGeoCodeReply::~QGeoCodeReply()
82{
83 delete d_ptr;
84}
85
86/*!
87 Sets whether or not this reply has finished to \a finished.
88
89 If \a finished is true, this will cause the finished() signal to be
90 emitted.
91
92 If the operation completed successfully, QGeoCodeReply::setLocations()
93 should be called before this function. If an error occurred,
94 QGeoCodeReply::setError() should be used instead.
95*/
96void QGeoCodeReply::setFinished(bool finished)
97{
98 d_ptr->isFinished = finished;
99 if (d_ptr->isFinished)
100 emit this->finished();
101}
102
103/*!
104 Return true if the operation completed successfully or encountered an
105 error which cause the operation to come to a halt.
106*/
107bool QGeoCodeReply::isFinished() const
108{
109 return d_ptr->isFinished;
110}
111
112/*!
113 Sets the error state of this reply to \a error and the textual
114 representation of the error to \a errorString.
115
116 This will also cause errorOccurred() and finished() signals to be
117 emitted, in that order.
118*/
119void QGeoCodeReply::setError(QGeoCodeReply::Error error, const QString &errorString)
120{
121 d_ptr->error = error;
122 d_ptr->errorString = errorString;
123 emit this->errorOccurred(error, errorString);
124 setFinished(true);
125}
126
127/*!
128 Returns the error state of this reply.
129
130 If the result is QGeoCodeReply::NoError then no error has occurred.
131*/
132QGeoCodeReply::Error QGeoCodeReply::error() const
133{
134 return d_ptr->error;
135}
136
137/*!
138 Returns the textual representation of the error state of this reply.
139
140 If no error has occurred this will return an empty string. It is possible
141 that an error occurred which has no associated textual representation, in
142 which case this will also return an empty string.
143
144 To determine whether an error has occurred, check to see if
145 QGeoCodeReply::error() is equal to QGeoCodeReply::NoError.
146*/
147QString QGeoCodeReply::errorString() const
148{
149 return d_ptr->errorString;
150}
151
152/*!
153 Sets the viewport which contains the results to \a viewport.
154*/
155void QGeoCodeReply::setViewport(const QGeoShape &viewport)
156{
157 d_ptr->viewport = viewport;
158}
159
160/*!
161 Returns the viewport which contains the results.
162
163 This function will return \nullptr if no viewport bias
164 was specified in the QGeoCodingManager function which created this reply.
165*/
166QGeoShape QGeoCodeReply::viewport() const
167{
168 return d_ptr->viewport;
169}
170
171/*!
172 Returns a list of locations.
173
174 The locations are the results of the operation corresponding to the
175 QGeoCodingManager function which created this reply.
176*/
177QList<QGeoLocation> QGeoCodeReply::locations() const
178{
179 return d_ptr->locations;
180}
181
182/*!
183 Adds \a location to the list of locations in this reply.
184*/
185void QGeoCodeReply::addLocation(const QGeoLocation &location)
186{
187 d_ptr->locations.append(location);
188}
189
190/*!
191 Sets the list of \a locations in the reply.
192*/
193void QGeoCodeReply::setLocations(const QList<QGeoLocation> &locations)
194{
195 d_ptr->locations = locations;
196}
197
198/*!
199 \fn void QGeoCodeReply::aborted()
200 \since 5.9
201
202 This signal is emitted when the operation has been cancelled.
203
204 \sa abort()
205*/
206
207/*!
208 Cancels the operation immediately.
209
210 This will do nothing if the reply is finished.
211
212 \sa aborted()
213*/
214void QGeoCodeReply::abort()
215{
216 if (!isFinished())
217 setFinished(true);
218 emit aborted();
219}
220
221/*!
222 Returns the limit on the number of responses from each data source.
223
224 If no limit was set this function will return -1.
225
226 This may be more than locations().length() if the number of responses
227 was less than the number requested.
228*/
229qsizetype QGeoCodeReply::limit() const
230{
231 return d_ptr->limit;
232}
233
234/*!
235 Returns the offset into the entire result set at which to start
236 fetching results.
237*/
238qsizetype QGeoCodeReply::offset() const
239{
240 return d_ptr->offset;
241}
242
243/*!
244 Sets the limit on the number of responses from each data source to \a limit.
245
246 If \a limit is -1 then all available responses will be returned.
247*/
248void QGeoCodeReply::setLimit(qsizetype limit)
249{
250 d_ptr->limit = limit;
251}
252
253/*!
254 Sets the offset in the entire result set at which to start
255 fetching result to \a offset.
256*/
257void QGeoCodeReply::setOffset(qsizetype offset)
258{
259 d_ptr->offset = offset;
260}
261
262/*!
263 \fn void QGeoCodeReply::finished()
264
265 This signal is emitted when this reply has finished processing.
266
267 If error() equals QGeoCodeReply::NoError then the processing
268 finished successfully.
269
270 This signal and QGeoCodingManager::finished() will be
271 emitted at the same time.
272
273 \note Do not delete this reply object in the slot connected to this
274 signal. Use deleteLater() instead.
275*/
276/*!
277 \fn void QGeoCodeReply::errorOccurred(QGeoCodeReply::Error error, const QString &errorString)
278
279 This signal is emitted when an error has been detected in the processing of
280 this reply. The finished() signal will probably follow.
281
282 The error will be described by the error code \a error. If \a errorString is
283 not empty it will contain a textual description of the error.
284
285 This signal and QGeoCodingManager::errorOccurred() will be emitted at the same time.
286
287 \note Do not delete this reply object in the slot connected to this
288 signal. Use deleteLater() instead.
289*/
290
291/*******************************************************************************
292*******************************************************************************/
293
294QGeoCodeReplyPrivate::QGeoCodeReplyPrivate() = default;
295
296QGeoCodeReplyPrivate::QGeoCodeReplyPrivate(QGeoCodeReply::Error error, const QString &errorString)
297 : error(error), errorString(errorString), isFinished(true)
298{}
299
300const QGeoCodeReplyPrivate *QGeoCodeReplyPrivate::get(const QGeoCodeReply &reply)
301{
302 return reply.d_ptr;
303}
304
305QGeoCodeReplyPrivate *QGeoCodeReplyPrivate::get(QGeoCodeReply &reply)
306{
307 return reply.d_ptr;
308}
309
310QT_END_NAMESPACE