QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
QgsTileDownloadManager Class Reference

Tile download manager handles downloads of map tiles for the purpose of map rendering. More...

#include <qgstiledownloadmanager.h>

Classes

class  Stats
 Encapsulates any statistics we would like to keep about requests. More...

Public Member Functions

 QgsTileDownloadManager ()
 ~QgsTileDownloadManager ()
QgsTileDownloadManagerReplyget (const QNetworkRequest &request)
 Starts a request.
bool hasPendingRequests () const
 Returns whether there are any pending requests in the queue.
bool hasWorkerThreadRunning () const
 Returns whether the worker thread is running currently (it may be stopped if there were no requests recently.
void resetStatistics ()
 Resets statistics of numbers of queries handled by this class.
void setIdleThreadTimeout (int timeoutMs)
 Sets after how many milliseconds the idle worker therad should terminate.
void shutdown ()
 Asks the worker thread to stop and blocks until it is not stopped.
Stats statistics () const
 Returns basic statistics of the queries handled by this class.
bool waitForPendingRequests (int msec=-1) const
 Blocks the current thread until the queue is empty.

Friends

class QgsTileDownloadManagerReply
class QgsTileDownloadManagerReplyWorkerObject
class QgsTileDownloadManagerWorker

Detailed Description

Tile download manager handles downloads of map tiles for the purpose of map rendering.

The purpose of this class is to handle a couple of situations that may happen:

  • a map rendering job starts which requests tiles from a remote server, then in a short while user zooms/pans map, which would normally mean that all pending requests get aborted and then restarted soon afterwards. The download manager allows the requests to finish to avoid excessive load on servers and needless aborts and repeated requests.
  • multiple map rendering jobs start at a similar time, requesting the same map tiles. Normally they could be requested multiple times from the server - the download manager groups these requests and only does a single request at a time.

At this point, it is not recommended to use this class for other scenarios than map rendering: using it elsewhere could slow down map rendering or have some unexpected negative effects.

How do things work:

  • Upon a request, a QgsTileDownloadManagerReply object (based on QObject) is returned, encapsulating the pending reply. Client can wait for its finished() signal - when it gets emitted, the request has finished with success or failure. Client can delete the reply object before the request is processed - download manager will finish its download (and it will get cached for a future use).
  • All requests are done by QgsNetworkAccessManager
  • A worker thread responsible for all network tile requests is started first time a tile is requested. Having a dedicated thread rather than reusing main thread makes things more predictable as we won't get stuck in case the main thread is doing some work or it is waiting for map rendering to finish.
  • There is a shared download queue (protected by a mutex) with a list of active requests and requests waiting to be processed.
  • Added in QGIS 3.26: If the request is an HTTP range request, the data may be cached into a local directory using QgsRangeRequestCache to avoid requesting the same data excessively. Caching will be disabled for requests with CacheLoadControlAttribute set to AlwaysNetwork or CacheSaveControlAttribute set to false
Since
QGIS 3.18

Definition at line 201 of file qgstiledownloadmanager.h.

Constructor & Destructor Documentation

◆ QgsTileDownloadManager()

QgsTileDownloadManager::QgsTileDownloadManager ( )

Definition at line 196 of file qgstiledownloadmanager.cpp.

◆ ~QgsTileDownloadManager()

QgsTileDownloadManager::~QgsTileDownloadManager ( )

Definition at line 214 of file qgstiledownloadmanager.cpp.

Member Function Documentation

◆ get()

QgsTileDownloadManagerReply * QgsTileDownloadManager::get ( const QNetworkRequest & request)

Starts a request.

Returns a new object that should be deleted by the caller when not needed anymore.

Definition at line 220 of file qgstiledownloadmanager.cpp.

◆ hasPendingRequests()

bool QgsTileDownloadManager::hasPendingRequests ( ) const

Returns whether there are any pending requests in the queue.

Definition at line 272 of file qgstiledownloadmanager.cpp.

◆ hasWorkerThreadRunning()

bool QgsTileDownloadManager::hasWorkerThreadRunning ( ) const

Returns whether the worker thread is running currently (it may be stopped if there were no requests recently.

Definition at line 322 of file qgstiledownloadmanager.cpp.

◆ resetStatistics()

void QgsTileDownloadManager::resetStatistics ( )

Resets statistics of numbers of queries handled by this class.

Definition at line 327 of file qgstiledownloadmanager.cpp.

◆ setIdleThreadTimeout()

void QgsTileDownloadManager::setIdleThreadTimeout ( int timeoutMs)
inline

Sets after how many milliseconds the idle worker therad should terminate.

This function is meant mainly for unit testing.

Definition at line 274 of file qgstiledownloadmanager.h.

◆ shutdown()

void QgsTileDownloadManager::shutdown ( )

Asks the worker thread to stop and blocks until it is not stopped.

Definition at line 297 of file qgstiledownloadmanager.cpp.

◆ statistics()

Stats QgsTileDownloadManager::statistics ( ) const
inline

Returns basic statistics of the queries handled by this class.

Definition at line 277 of file qgstiledownloadmanager.h.

◆ waitForPendingRequests()

bool QgsTileDownloadManager::waitForPendingRequests ( int msec = -1) const

Blocks the current thread until the queue is empty.

This should not be used in production code, it is however useful for auto tests

Definition at line 279 of file qgstiledownloadmanager.cpp.

◆ QgsTileDownloadManagerReply

friend class QgsTileDownloadManagerReply
friend

Definition at line 283 of file qgstiledownloadmanager.h.

◆ QgsTileDownloadManagerReplyWorkerObject

friend class QgsTileDownloadManagerReplyWorkerObject
friend

Definition at line 284 of file qgstiledownloadmanager.h.

◆ QgsTileDownloadManagerWorker

friend class QgsTileDownloadManagerWorker
friend

Definition at line 282 of file qgstiledownloadmanager.h.


The documentation for this class was generated from the following files: