18 #ifndef QGSTILEDOWNLOADMANAGER_H
19 #define QGSTILEDOWNLOADMANAGER_H
27 #include <QNetworkAccessManager>
28 #include <QNetworkReply>
30 #include "qgis_core.h"
55 QByteArray
data()
const {
return mData; }
57 QNetworkReply::NetworkError
error()
const {
return mError; }
62 QNetworkRequest
request()
const {
return mRequest; }
69 void requestFinished( QByteArray data, QNetworkReply::NetworkError error,
const QString &errorString );
79 QNetworkRequest mRequest;
80 bool mHasFinished =
false;
82 QNetworkReply::NetworkError mError = QNetworkReply::NoError;
94 class QgsTileDownloadManagerReplyWorkerObject :
public QObject
99 : mManager( manager ), mRequest( request ) {}
102 void replyFinished();
105 void finished( QByteArray data, QNetworkReply::NetworkError error,
const QString &errorString );
110 QNetworkRequest mRequest;
119 class QgsTileDownloadManagerWorker :
public QObject
127 void startIdleTimer();
131 void idleTimerTimeout();
134 void requestFinished( QString url, QByteArray data );
192 bool isValid()
const {
return !request.url().isEmpty(); }
195 QNetworkRequest request;
197 QgsTileDownloadManagerReplyWorkerObject *objWorker =
nullptr;
199 QNetworkReply *networkReply =
nullptr;
213 int requestsTotal = 0;
215 int requestsMerged = 0;
217 int requestsEarlyDeleted = 0;
220 int networkRequestsStarted = 0;
222 int networkRequestsOk = 0;
224 int networkRequestsFailed = 0;
237 bool hasPendingRequests()
const;
243 bool waitForPendingRequests(
int msec = -1 );
252 bool hasWorkerThreadRunning()
const;
264 void resetStatistics();
266 friend class QgsTileDownloadManagerWorker;
268 friend class QgsTileDownloadManagerReplyWorkerObject;
273 QueueEntry findEntryForRequest(
const QNetworkRequest &request );
274 void addEntry(
const QueueEntry &entry );
275 void updateEntry(
const QueueEntry &entry );
276 void removeEntry(
const QNetworkRequest &request );
278 void signalQueueModified();
282 QList<QueueEntry> mQueue;
283 bool mShuttingDown =
false;
284 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
285 mutable QMutex mMutex;
287 mutable QRecursiveMutex mMutex;
289 QThread *mWorkerThread =
nullptr;
290 QgsTileDownloadManagerWorker *mWorker =
nullptr;
293 int mIdleThreadTimeoutMs = 10000;
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.
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)
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.
void setIdleThreadTimeout(int timeoutMs)
Sets after how many milliseconds the idle worker therad should terminate.
Stats statistics()
Returns basic statistics of the queries handled by this class.