20 qCDebug(QGCCachedTileSetLog) <<
this;
25 qCDebug(QGCCachedTileSetLog) <<
this;
34 if (_totalTileCount <= _savedTileCount) {
66 _batchRequested =
true;
71 _cancelPending =
false;
83 _cancelPending =
true;
86void QGCCachedTileSet::_tileListFetched(
const QQueue<QGCTile*> &tiles)
88 _batchRequested =
false;
89 if (tiles.size() < kTileBatchSize) {
93 if (tiles.isEmpty()) {
98 if (!_networkManager) {
99 _networkManager =
new QNetworkAccessManager(
this);
103 _tilesToDownload.append(tiles);
107void QGCCachedTileSet::_doneWithDownload()
109 if (_errorCount == 0) {
114 if (_savedTileCount != 0) {
115 avg = _savedTileSize / _savedTileCount;
117 qCWarning(QGCCachedTileSetLog) <<
"_savedTileCount=0";
128void QGCCachedTileSet::_prepareDownload()
130 if (_tilesToDownload.isEmpty()) {
133 }
else if (!_batchRequested) {
140 if (_tilesToDownload.isEmpty()) {
144 QGCTile*
const tile = _tilesToDownload.dequeue();
146 if (!request.url().isValid()) {
147 qCWarning(QGCCachedTileSetLog) <<
"Invalid URL for tile" << tile->
hash <<
"- skipping";
152 request.setOriginatingObject(
this);
153 request.setAttribute(QNetworkRequest::User, tile->
hash);
155 QNetworkReply*
const reply = _networkManager->get(request);
156 reply->setParent(
this);
158 (void) connect(reply, &QNetworkReply::finished,
this, &QGCCachedTileSet::_networkReplyFinished);
159 (void) connect(reply, &QNetworkReply::errorOccurred,
this, &QGCCachedTileSet::_networkReplyError);
161 QMutexLocker lock(&_repliesMutex);
162 (void) _replies.insert(tile->
hash, reply);
172void QGCCachedTileSet::_networkReplyFinished()
174 QNetworkReply*
const reply = qobject_cast<QNetworkReply*>(QObject::sender());
176 qCWarning(QGCCachedTileSetLog) <<
"NULL Reply";
179 reply->deleteLater();
181 if (reply->error() != QNetworkReply::NoError) {
185 if (!reply->isOpen()) {
186 qCWarning(QGCCachedTileSetLog) <<
"Empty Reply";
190 const QString hash = reply->request().attribute(QNetworkRequest::User).toString();
191 if (hash.isEmpty()) {
192 qCWarning(QGCCachedTileSetLog) <<
"Empty Hash";
197 QMutexLocker lock(&_repliesMutex);
198 if (_replies.contains(hash)) {
199 (void) _replies.remove(hash);
201 qCWarning(QGCCachedTileSetLog) <<
"Reply not in list: " << hash;
204 qCDebug(QGCCachedTileSetLog) <<
"Tile fetched:" << hash;
206 QByteArray image = reply->readAll();
207 if (image.isEmpty()) {
208 qCWarning(QGCCachedTileSetLog) <<
"Empty Image";
215 qCWarning(QGCCachedTileSetLog) <<
"Invalid map provider for type:" <<
type;
219 if (mapProvider->isElevationProvider()) {
220 const SharedElevationProvider elevationProvider = std::dynamic_pointer_cast<const ElevationProvider>(mapProvider);
221 image = elevationProvider->serialize(image);
222 if (image.isEmpty()) {
223 qCWarning(QGCCachedTileSetLog) <<
"Failed to Serialize Terrain Tile";
228 const QString
format = mapProvider->getImageFormat(image);
230 qCWarning(QGCCachedTileSetLog) <<
"Empty Format";
244 if (_savedTileCount % 10 == 0) {
245 const quint32 avg = _savedTileSize / _savedTileCount;
253void QGCCachedTileSet::_networkReplyError(QNetworkReply::NetworkError
error)
255 QNetworkReply*
const reply = qobject_cast<QNetworkReply*>(QObject::sender());
259 qCDebug(QGCCachedTileSetLog) <<
"Error fetching tile" << reply->errorString();
263 const QString hash = reply->request().attribute(QNetworkRequest::User).toString();
264 if (hash.isEmpty()) {
265 qCWarning(QGCCachedTileSetLog) <<
"Empty Hash";
270 QMutexLocker lock(&_repliesMutex);
271 if (_replies.contains(hash)) {
272 (void) _replies.remove(hash);
274 qCWarning(QGCCachedTileSetLog) <<
"Reply not in list:" << hash;
278 if (
error != QNetworkReply::OperationCanceledError) {
279 qCWarning(QGCCachedTileSetLog) <<
"Error:" << reply->errorString();
292 if (sel != _selected) {
#define QGC_LOGGING_CATEGORY(name, categoryStr)
QGCMapEngine * getQGCMapEngine()
std::shared_ptr< const ElevationProvider > SharedElevationProvider
std::shared_ptr< const MapProvider > SharedMapProvider
Q_INVOKABLE void resumeDownloadTask()
void setTotalTileCount(quint32 num)
QString uniqueTileCountStr() const
void setErrorCount(quint32 count)
void setTotalTileSize(quint64 size)
void setSavedTileCount(quint32 num)
void setSavedTileSize(quint64 size)
QString savedTileCountStr() const
const QString & type() const
QString totalTileCountStr() const
QString downloadStatus() const
Q_INVOKABLE void cancelDownloadTask()
void setDownloading(bool down)
void totalTileCountChanged()
Q_INVOKABLE void createDownloadTask()
QString savedTileSizeStr() const
QString uniqueTileSizeStr() const
QString errorCountStr() const
void setSelected(bool sel)
void totalTilesSizeChanged()
QString totalTilesSizeStr() const
void setUniqueTileSize(quint64 size)
void tileListFetched(QQueue< QGCTile * > tiles)
void taskError(QGCMapTask::TaskType type, const QString &error)
void selectedCountChanged()
bool addTask(QGCMapTask *task)
void error(QGCMapTask::TaskType type, const QString &errorString)
static void cacheTile(const QString &type, int x, int y, int z, const QByteArray &image, const QString &format, qulonglong set=UINT64_MAX)
static uint32_t concurrentDownloads(const QString &type)
static QNetworkRequest getNetworkRequest(int mapId, int x, int y, int zoom)
static QString tileHashToType(QStringView tileHash)
static std::shared_ptr< const MapProvider > getMapProviderFromProviderType(QStringView type)
void configureProxy(QNetworkAccessManager *manager)
Set up default proxy configuration on a network manager.
void ignoreSslErrorsIfNeeded(QNetworkReply *reply)
QString numberToString(quint64 number)
Decimal integer (e.g. "1,234,567").
QString bigSizeToString(quint64 size)
Byte size with unit: B, KB, MB, GB, TB. 1 fractional digit above 1 KB.