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 | #include "qgeotiledmapreply_p.h" |
38 | #include "qgeotiledmapreply_p_p.h" |
39 | |
40 | #include <qdebug.h> |
41 | |
42 | QT_BEGIN_NAMESPACE |
43 | /*! |
44 | \class QGeoTiledMapReply |
45 | \inmodule QtLocation |
46 | \ingroup QtLocation-impl |
47 | \since 5.6 |
48 | \internal |
49 | |
50 | \brief The QGeoTiledMapReply class manages a tile fetch operation started |
51 | by an instance of QGeoTiledManagerEngine. |
52 | |
53 | Instances of QGeoTiledMapReply manage the state and results of these |
54 | operations. |
55 | |
56 | The isFinished(), error() and errorString() methods provide information |
57 | on whether the operation has completed and if it completed successfully. |
58 | |
59 | The finished() and error(QGeoTiledMapReply::Error,QString) |
60 | signals can be used to monitor the progress of the operation. |
61 | |
62 | It is possible that a newly created QGeoTiledMapReply may be in a finished |
63 | state, most commonly because an error has occurred. Since such an instance |
64 | will never emit the finished() or |
65 | error(QGeoTiledMapReply::Error,QString) signals, it is |
66 | important to check the result of isFinished() before making the connections |
67 | to the signals. |
68 | |
69 | If the operation completes successfully the results are accessed by |
70 | mapImageData() and mapImageFormat(). |
71 | */ |
72 | |
73 | /*! |
74 | \enum QGeoTiledMapReply::Error |
75 | |
76 | Describes an error which prevented the completion of the operation. |
77 | |
78 | \value NoError |
79 | No error has occurred. |
80 | \value CommunicationError |
81 | An error occurred while communicating with the service provider. |
82 | \value ParseError |
83 | The response from the service provider was in an unrecognizable format |
84 | supported by the service provider. |
85 | \value UnknownError |
86 | An error occurred which does not fit into any of the other categories. |
87 | */ |
88 | |
89 | /*! |
90 | Constructs a tiled map reply object based on \a request, with parent \a parent. |
91 | */ |
92 | QGeoTiledMapReply::QGeoTiledMapReply(const QGeoTileSpec &spec, QObject *parent) |
93 | : QObject(parent), |
94 | d_ptr(new QGeoTiledMapReplyPrivate(spec)) |
95 | { |
96 | } |
97 | |
98 | /*! |
99 | Constructs a tiled map reply object with a given \a error and \a errorString and the specified \a parent. |
100 | */ |
101 | QGeoTiledMapReply::QGeoTiledMapReply(Error error, const QString &errorString, QObject *parent) |
102 | : QObject(parent), |
103 | d_ptr(new QGeoTiledMapReplyPrivate(error, errorString)) {} |
104 | |
105 | /*! |
106 | Destroys this tiled map reply object. |
107 | */ |
108 | QGeoTiledMapReply::~QGeoTiledMapReply() |
109 | { |
110 | delete d_ptr; |
111 | } |
112 | |
113 | /*! |
114 | Sets whether or not this reply has finished to \a finished. |
115 | |
116 | If \a finished is true, this will cause the finished() signal to be |
117 | emitted. |
118 | |
119 | If the operation completed successfully, |
120 | QGeoTiledMapReply::setMapImageData() should be called before this |
121 | function. If an error occurred, QGeoTiledMapReply::setError() should be used |
122 | instead. |
123 | */ |
124 | void QGeoTiledMapReply::setFinished(bool finished) |
125 | { |
126 | d_ptr->isFinished = finished; |
127 | if (d_ptr->isFinished) |
128 | emit this->finished(); |
129 | } |
130 | |
131 | /*! |
132 | Return true if the operation completed successfully or encountered an |
133 | error which cause the operation to come to a halt. |
134 | */ |
135 | bool QGeoTiledMapReply::isFinished() const |
136 | { |
137 | return d_ptr->isFinished; |
138 | } |
139 | |
140 | /*! |
141 | Sets the error state of this reply to \a error and the textual |
142 | representation of the error to \a errorString. |
143 | |
144 | This will also cause error() and finished() signals to be emitted, in that |
145 | order. |
146 | */ |
147 | void QGeoTiledMapReply::setError(QGeoTiledMapReply::Error error, const QString &errorString) |
148 | { |
149 | d_ptr->error = error; |
150 | d_ptr->errorString = errorString; |
151 | emit this->error(error, errorString); |
152 | setFinished(true); |
153 | } |
154 | |
155 | /*! |
156 | Returns the error state of this reply. |
157 | |
158 | If the result is QGeoTiledMapReply::NoError then no error has occurred. |
159 | */ |
160 | QGeoTiledMapReply::Error QGeoTiledMapReply::error() const |
161 | { |
162 | return d_ptr->error; |
163 | } |
164 | |
165 | /*! |
166 | Returns the textual representation of the error state of this reply. |
167 | |
168 | If no error has occurred this will return an empty string. It is possible |
169 | that an error occurred which has no associated textual representation, in |
170 | which case this will also return an empty string. |
171 | |
172 | To determine whether an error has occurred, check to see if |
173 | QGeoTiledMapReply::error() is equal to QGeoTiledMapReply::NoError. |
174 | */ |
175 | QString QGeoTiledMapReply::errorString() const |
176 | { |
177 | return d_ptr->errorString; |
178 | } |
179 | |
180 | /*! |
181 | Returns whether the reply is coming from a cache. |
182 | */ |
183 | bool QGeoTiledMapReply::isCached() const |
184 | { |
185 | return d_ptr->isCached; |
186 | } |
187 | |
188 | /*! |
189 | Sets whether the reply is coming from a cache to \a cached. |
190 | */ |
191 | void QGeoTiledMapReply::setCached(bool cached) |
192 | { |
193 | d_ptr->isCached = cached; |
194 | } |
195 | |
196 | /*! |
197 | Returns the request which corresponds to this reply. |
198 | */ |
199 | QGeoTileSpec QGeoTiledMapReply::tileSpec() const |
200 | { |
201 | return d_ptr->spec; |
202 | } |
203 | |
204 | /*! |
205 | Returns the tile image data. |
206 | */ |
207 | QByteArray QGeoTiledMapReply::mapImageData() const |
208 | { |
209 | return d_ptr->mapImageData; |
210 | } |
211 | |
212 | /*! |
213 | Sets the tile image data to \a data. |
214 | */ |
215 | void QGeoTiledMapReply::setMapImageData(const QByteArray &data) |
216 | { |
217 | d_ptr->mapImageData = data; |
218 | } |
219 | |
220 | /*! |
221 | Returns the format of the tile image. |
222 | */ |
223 | QString QGeoTiledMapReply::mapImageFormat() const |
224 | { |
225 | return d_ptr->mapImageFormat; |
226 | } |
227 | |
228 | /*! |
229 | Sets the format of the tile image to \a format. |
230 | */ |
231 | void QGeoTiledMapReply::setMapImageFormat(const QString &format) |
232 | { |
233 | d_ptr->mapImageFormat = format; |
234 | } |
235 | |
236 | /*! |
237 | Cancels the operation immediately. |
238 | |
239 | This will do nothing if the reply is finished. |
240 | */ |
241 | void QGeoTiledMapReply::abort() |
242 | { |
243 | if (!isFinished()) |
244 | setFinished(true); |
245 | emit aborted(); |
246 | } |
247 | |
248 | /* |
249 | \fn void QGeoTiledMapReply::finished() |
250 | |
251 | This signal is emitted when this reply has finished processing. |
252 | |
253 | If error() equals QGeoTiledMapReply::NoError then the processing |
254 | finished successfully. |
255 | |
256 | This signal and QGeoRoutingManager::finished() will be |
257 | emitted at the same time. |
258 | |
259 | \note Do not delete this reply object in the slot connected to this |
260 | signal. Use deleteLater() instead. |
261 | |
262 | \fn void QGeoTiledMapReply::error(QGeoTiledMapReply::Error error, const QString &errorString) |
263 | |
264 | This signal is emitted when an error has been detected in the processing of |
265 | this reply. The finished() signal will probably follow. |
266 | |
267 | The error will be described by the error code \a error. If \a errorString is |
268 | not empty it will contain a textual description of the error. |
269 | |
270 | This signal and QGeoRoutingManager::error() will be emitted at the same time. |
271 | |
272 | \note Do not delete this reply object in the slot connected to this |
273 | signal. Use deleteLater() instead. |
274 | */ |
275 | |
276 | /*! |
277 | \fn void QGeoTiledMapReply::finished() |
278 | |
279 | This signal is emitted when this reply has finished processing. |
280 | |
281 | If error() equals QGeoTiledMapReply::NoError then the processing |
282 | finished successfully. |
283 | |
284 | \note Do not delete this reply object in the slot connected to this |
285 | signal. Use deleteLater() instead. |
286 | */ |
287 | /*! |
288 | \fn void QGeoTiledMapReply::error(QGeoTiledMapReply::Error error, const QString &errorString) |
289 | |
290 | This signal is emitted when an error has been detected in the processing of |
291 | this reply. The finished() signal will probably follow. |
292 | |
293 | The error will be described by the error code \a error. If \a errorString is |
294 | not empty it will contain a textual description of the error. |
295 | |
296 | \note Do not delete this reply object in the slot connected to this |
297 | signal. Use deleteLater() instead. |
298 | */ |
299 | |
300 | /******************************************************************************* |
301 | *******************************************************************************/ |
302 | |
303 | QGeoTiledMapReplyPrivate::QGeoTiledMapReplyPrivate(const QGeoTileSpec &spec) |
304 | : error(QGeoTiledMapReply::NoError), |
305 | isFinished(false), |
306 | isCached(false), |
307 | spec(spec) {} |
308 | |
309 | QGeoTiledMapReplyPrivate::QGeoTiledMapReplyPrivate(QGeoTiledMapReply::Error error, const QString &errorString) |
310 | : error(error), |
311 | errorString(errorString), |
312 | isFinished(true), |
313 | isCached(false) {} |
314 | |
315 | QGeoTiledMapReplyPrivate::~QGeoTiledMapReplyPrivate() {} |
316 | |
317 | QT_END_NAMESPACE |
318 | |