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
qgeoroutereply.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 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
7
9
10/*!
11 \class QGeoRouteReply
12 \inmodule QtLocation
13 \ingroup QtLocation-routing
14 \since 5.6
15
16 \brief The QGeoRouteReply class manages an operation started by an instance
17 of QGeoRoutingManager.
18
19 Instances of QGeoRouteReply manage the state and results of these
20 operations.
21
22 The isFinished(), error() and errorString() methods provide information
23 on whether the operation has completed and if it completed successfully.
24
25 The finished() and errorOccurred(QGeoRouteReply::Error,QString)
26 signals can be used to monitor the progress of the operation.
27
28 It is possible that a newly created QGeoRouteReply may be in a finished
29 state, most commonly because an error has occurred. Since such an instance
30 will never emit the finished() or
31 errorOccurred(QGeoRouteReply::Error,QString) signals, it is
32 important to check the result of isFinished() before making the connections
33 to the signals. The documentation for QGeoRoutingManager demonstrates how
34 this might be carried out.
35
36 If the operation completes successfully the results will be able to be
37 accessed with routes().
38*/
39
40/*!
41 \enum QGeoRouteReply::Error
42
43 Describes an error which prevented the completion of the operation.
44
45 \value NoError
46 No error has occurred.
47 \value EngineNotSetError
48 The routing manager that was used did not have a QGeoRoutingManagerEngine instance associated with it.
49 \value CommunicationError
50 An error occurred while communicating with the service provider.
51 \value ParseError
52 The response from the service provider was in an unrecognizable format.
53 \value UnsupportedOptionError
54 The requested operation or one of the options for the operation are not
55 supported by the service provider.
56 \value UnknownError
57 An error occurred which does not fit into any of the other categories.
58*/
59
60/*!
61 Constructs a route reply object based on \a request, with the specified \a parent.
62*/
63QGeoRouteReply::QGeoRouteReply(const QGeoRouteRequest &request, QObject *parent)
64 : QObject(parent),
65 d_ptr(new QGeoRouteReplyPrivate(request))
66{
67}
68
69/*!
70 Constructs a route reply with a given \a error and \a errorString and the specified \a parent.
71*/
72QGeoRouteReply::QGeoRouteReply(Error error, const QString &errorString, QObject *parent)
73 : QObject(parent),
74 d_ptr(new QGeoRouteReplyPrivate(error, errorString)) {}
75
76/*!
77 Destroys this route reply object.
78*/
79QGeoRouteReply::~QGeoRouteReply()
80{
81 delete d_ptr;
82}
83
84/*!
85 Sets whether or not this reply has finished to \a finished.
86
87 If \a finished is true, this will cause the finished() signal to be
88 emitted.
89
90 If the operation completed successfully, QGeoRouteReply::setRoutes() should
91 be called before this function. If an error occurred,
92 QGeoRouteReply::setError() should be used instead.
93*/
94void QGeoRouteReply::setFinished(bool finished)
95{
96 d_ptr->isFinished = finished;
97 if (d_ptr->isFinished)
98 emit this->finished();
99}
100
101/*!
102 Return true if the operation completed successfully or encountered an
103 error which cause the operation to come to a halt.
104*/
105bool QGeoRouteReply::isFinished() const
106{
107 return d_ptr->isFinished;
108}
109
110/*!
111 Sets the error state of this reply to \a error and the textual
112 representation of the error to \a errorString.
113
114 This will also cause errorOccurred() and finished() signals to be emitted, in that
115 order.
116*/
117void QGeoRouteReply::setError(QGeoRouteReply::Error error, const QString &errorString)
118{
119 d_ptr->error = error;
120 d_ptr->errorString = errorString;
121 emit errorOccurred(error, errorString);
122 setFinished(true);
123}
124
125/*!
126 Returns the error state of this reply.
127
128 If the result is QGeoRouteReply::NoError then no error has occurred.
129*/
130QGeoRouteReply::Error QGeoRouteReply::error() const
131{
132 return d_ptr->error;
133}
134
135/*!
136 Returns the textual representation of the error state of this reply.
137
138 If no error has occurred this will return an empty string. It is possible
139 that an error occurred which has no associated textual representation, in
140 which case this will also return an empty string.
141
142 To determine whether an error has occurred, check to see if
143 QGeoRouteReply::error() is equal to QGeoRouteReply::NoError.
144*/
145QString QGeoRouteReply::errorString() const
146{
147 return d_ptr->errorString;
148}
149
150/*!
151 Returns the route request which specified the route.
152*/
153QGeoRouteRequest QGeoRouteReply::request() const
154{
155 return d_ptr->request;
156}
157
158/*!
159 Returns the list of routes which were requested.
160*/
161QList<QGeoRoute> QGeoRouteReply::routes() const
162{
163 return d_ptr->routes;
164}
165
166/*!
167 Sets the list of routes in the reply to \a routes.
168*/
169void QGeoRouteReply::setRoutes(const QList<QGeoRoute> &routes)
170{
171 d_ptr->routes = routes;
172}
173
174/*!
175 Appends the list of \a routes to the existing list.
176*/
177void QGeoRouteReply::addRoutes(const QList<QGeoRoute> &routes)
178{
179 d_ptr->routes.append(routes);
180}
181
182/*!
183 \fn void QGeoRouteReply::aborted()
184 \since 5.9
185
186 This signal is emitted when the operation has been cancelled.
187
188 \sa abort()
189*/
190
191/*!
192 Cancels the operation immediately.
193
194 This will do nothing if the reply is finished.
195*/
196void QGeoRouteReply::abort()
197{
198 emit aborted();
199}
200
201/*!
202 \fn void QGeoRouteReply::finished()
203
204 This signal is emitted when this reply has finished processing.
205
206 If error() equals QGeoRouteReply::NoError then the processing
207 finished successfully.
208
209 This signal and QGeoRoutingManager::finished() will be
210 emitted at the same time.
211
212 \note Do not delete this reply object in the slot connected to this
213 signal. Use deleteLater() instead.
214*/
215/*!
216 \fn void QGeoRouteReply::errorOccurred(QGeoRouteReply::Error error, const QString &errorString)
217
218 This signal is emitted when an error has been detected in the processing of
219 this reply. The finished() signal will probably follow.
220
221 The error will be described by the error code \a error. If \a errorString is
222 not empty it will contain a textual description of the error.
223
224 This signal and QGeoRoutingManager::errorOccurred() will be emitted at the same time.
225
226 \note Do not delete this reply object in the slot connected to this
227 signal. Use deleteLater() instead.
228*/
229
230/*******************************************************************************
231*******************************************************************************/
232
233QGeoRouteReplyPrivate::QGeoRouteReplyPrivate(const QGeoRouteRequest &request)
235{}
236
237QGeoRouteReplyPrivate::QGeoRouteReplyPrivate(QGeoRouteReply::Error error, QString errorString)
238 : error(error),
239 errorString(errorString),
240 isFinished(true)
241{}
242
243QT_END_NAMESPACE
QGeoRouteReplyPrivate(const QGeoRouteRequest &request)
Combined button and popup list for selecting options.