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
geotiledmapreply_esri.cpp
Go to the documentation of this file.
1// Copyright (C) 2013-2018 Esri <contracts@esri.com>
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
6#include <QtLocation/private/qgeotilespec_p.h>
7
9
10static const unsigned char pngSignature[] = {0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00};
11static const unsigned char jpegSignature[] = {0xFF, 0xD8, 0xFF, 0x00};
12static const unsigned char gifSignature[] = {0x47, 0x49, 0x46, 0x38, 0x00};
13
14GeoTiledMapReplyEsri::GeoTiledMapReplyEsri(QNetworkReply *reply, const QGeoTileSpec &spec,
15 QObject *parent) :
16 QGeoTiledMapReply(spec, parent)
17{
18 if (!reply) {
19 setError(UnknownError, QStringLiteral("Null reply"));
20 return;
21 }
22 connect(reply, &QNetworkReply::finished,
23 this, &GeoTiledMapReplyEsri::networkReplyFinished);
24 connect(reply, &QNetworkReply::errorOccurred,
25 this, &GeoTiledMapReplyEsri::networkReplyError);
26 connect(this, &QGeoTiledMapReply::aborted, reply, &QNetworkReply::abort);
27 connect(this, &QObject::destroyed, reply, &QObject::deleteLater);
28}
29
30GeoTiledMapReplyEsri::~GeoTiledMapReplyEsri()
31{
32}
33
34void GeoTiledMapReplyEsri::networkReplyFinished()
35{
36 QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
37 reply->deleteLater();
38
39 if (reply->error() != QNetworkReply::NoError)
40 return;
41
42 QByteArray const& imageData = reply->readAll();
43
44 bool validFormat = true;
45 if (imageData.startsWith(reinterpret_cast<const char*>(pngSignature)))
46 setMapImageFormat(QStringLiteral("png"));
47 else if (imageData.startsWith(reinterpret_cast<const char*>(jpegSignature)))
48 setMapImageFormat(QStringLiteral("jpg"));
49 else if (imageData.startsWith(reinterpret_cast<const char*>(gifSignature)))
50 setMapImageFormat(QStringLiteral("gif"));
51 else
52 validFormat = false;
53
54 if (validFormat)
55 setMapImageData(imageData);
56
57 setFinished(true);
58}
59
60void GeoTiledMapReplyEsri::networkReplyError(QNetworkReply::NetworkError error)
61{
62 QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
63 reply->deleteLater();
64 if (error == QNetworkReply::OperationCanceledError)
65 setFinished(true);
66 else
67 setError(QGeoTiledMapReply::CommunicationError, reply->errorString());
68}
69
70QT_END_NAMESPACE
static QT_BEGIN_NAMESPACE const unsigned char pngSignature[]
static const unsigned char jpegSignature[]
static const unsigned char gifSignature[]