18#ifndef QGSTILEDOWNLOADMANAGER_H
19#define QGSTILEDOWNLOADMANAGER_H
27#include <QNetworkAccessManager>
28#include <QNetworkReply>
56 QByteArray
data()
const {
return mData; }
58 QUrl
url()
const {
return mUrl; }
60 QVariant attribute( QNetworkRequest::Attribute code );
62 QVariant header( QNetworkRequest::KnownHeaders header );
64 const QList<QNetworkReply::RawHeaderPair>
rawHeaderPairs()
const {
return mRawHeaderPairs; }
66 QNetworkReply::NetworkError
error()
const {
return mError; }
70 QNetworkRequest
request()
const {
return mRequest; }
77 void requestFinished( QByteArray data, QUrl url,
const QMap<QNetworkRequest::Attribute, QVariant> &attributes,
const QMap<QNetworkRequest::KnownHeaders, QVariant> &headers,
const QList<QNetworkReply::RawHeaderPair> rawHeaderPairs, QNetworkReply::NetworkError error,
const QString &errorString );
78 void cachedRangeRequestFinished();
88 QNetworkRequest mRequest;
89 bool mHasFinished =
false;
91 QNetworkReply::NetworkError mError = QNetworkReply::NoError;
94 QMap<QNetworkRequest::Attribute, QVariant> mAttributes;
95 QMap<QNetworkRequest::KnownHeaders, QVariant> mHeaders;
96 QList<QNetworkReply::RawHeaderPair> mRawHeaderPairs;
107class QgsTileDownloadManagerReplyWorkerObject :
public QObject
111 QgsTileDownloadManagerReplyWorkerObject(
QgsTileDownloadManager *manager,
const QNetworkRequest &request )
112 : mManager( manager ), mRequest( request ) {}
115 void replyFinished();
118 void finished( QByteArray data, QUrl url,
const QMap<QNetworkRequest::Attribute, QVariant> &attributes,
const QMap<QNetworkRequest::KnownHeaders, QVariant> &headers,
const QList<QNetworkReply::RawHeaderPair> rawHeaderPairs, QNetworkReply::NetworkError error,
const QString &errorString );
123 QNetworkRequest mRequest;
132class QgsTileDownloadManagerWorker :
public QObject
140 void startIdleTimer();
144 void idleTimerTimeout();
147 void requestFinished( QString url, QByteArray data );
209 bool isValid()
const {
return !request.url().isEmpty(); }
212 QNetworkRequest request;
214 QgsTileDownloadManagerReplyWorkerObject *objWorker =
nullptr;
216 QNetworkReply *networkReply =
nullptr;
230 int requestsTotal = 0;
232 int requestsMerged = 0;
234 int requestsEarlyDeleted = 0;
237 int networkRequestsStarted = 0;
239 int networkRequestsOk = 0;
241 int networkRequestsFailed = 0;
254 bool hasPendingRequests()
const;
260 bool waitForPendingRequests(
int msec = -1 )
const;
269 bool hasWorkerThreadRunning()
const;
281 void resetStatistics();
283 friend class QgsTileDownloadManagerWorker;
285 friend class QgsTileDownloadManagerReplyWorkerObject;
290 QueueEntry findEntryForRequest(
const QNetworkRequest &request );
291 void addEntry(
const QueueEntry &entry );
292 void updateEntry(
const QueueEntry &entry );
293 void removeEntry(
const QNetworkRequest &request );
294 void processStagedEntryRemovals();
296 void signalQueueModified();
298 bool isRangeRequest(
const QNetworkRequest &request );
299 bool isCachedRangeRequest(
const QNetworkRequest &request );
303 std::vector<QueueEntry> mQueue;
305 bool mStageQueueRemovals =
false;
306 std::vector< QNetworkRequest > mStagedQueueRemovals;
308 bool mShuttingDown =
false;
309 mutable QRecursiveMutex mMutex;
311 QThread *mWorkerThread =
nullptr;
312 QgsTileDownloadManagerWorker *mWorker =
nullptr;
315 int mIdleThreadTimeoutMs = 10000;
317 std::unique_ptr<QgsRangeRequestCache> mRangesCache;
A custom cache for handling the storage and retrieval of HTTP range requests on disk.
Reply object for tile download manager requests returned from calls to QgsTileDownloadManager::get().
QString errorString() const
Returns error string (only valid when already finished)
bool hasFinished() const
Returns whether the reply has already finished (with success/failure)
QNetworkRequest request() const
Returns the original request for this reply object.
const QList< QNetworkReply::RawHeaderPair > rawHeaderPairs() const
Returns a list of raw header pairs.
QByteArray data() const
Returns binary data returned in the reply (only valid when already finished)
QNetworkReply::NetworkError error() const
Returns error code (only valid when already finished)
QUrl url() const
Returns the reply URL.
void finished()
Emitted when the reply has finished (either with a success or with a failure)
Encapsulates any statistics we would like to keep about requests.
Tile download manager handles downloads of map tiles for the purpose of map rendering.
Stats statistics() const
Returns basic statistics of the queries handled by this class.
void setIdleThreadTimeout(int timeoutMs)
Sets after how many milliseconds the idle worker therad should terminate.