QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
Signals | Public Member Functions | List of all members
QgsNetworkContentFetcherTask Class Reference

Handles HTTP network content fetching in a background task. More...

#include <qgsnetworkcontentfetchertask.h>

Inheritance diagram for QgsNetworkContentFetcherTask:
Inheritance graph
[legend]

Signals

void errorOccurred (QNetworkReply::NetworkError code, const QString &errorMsg)
 Emitted when an error with code error occurred while processing the request errorMsg is a textual description of the error.
 
void fetched ()
 Emitted when the network content has been fetched, regardless of whether the fetch was successful or not.
 
- Signals inherited from QgsTask
void begun ()
 Will be emitted by task to indicate its commencement.
 
void progressChanged (double progress)
 Will be emitted by task when its progress changes.
 
void statusChanged (int status)
 Will be emitted by task when its status changes.
 
void taskCompleted ()
 Will be emitted by task to indicate its successful completion.
 
void taskTerminated ()
 Will be emitted by task if it has terminated for any reason other then completion (e.g., when a task has been canceled or encountered an internal error).
 

Public Member Functions

 QgsNetworkContentFetcherTask (const QNetworkRequest &request, const QString &authcfg=QString(), QgsTask::Flags flags=QgsTask::CanCancel, const QString &description=QString())
 Constructor for a QgsNetworkContentFetcherTask which fetches the specified network request.
 
 QgsNetworkContentFetcherTask (const QUrl &url, const QString &authcfg=QString(), QgsTask::Flags flags=QgsTask::CanCancel, const QString &description=QString())
 Constructor for a QgsNetworkContentFetcherTask which fetches the specified url.
 
 ~QgsNetworkContentFetcherTask () override
 
void cancel () override
 Notifies the task that it should terminate.
 
QString contentAsString () const
 Returns the fetched content as a string.
 
QString contentDispositionFilename () const
 Returns the associated filename from the reply's content disposition header, if present.
 
QNetworkReply * reply ()
 Returns the network reply.
 
bool run () override
 Performs the task's operation.
 
- Public Member Functions inherited from QgsTask
 QgsTask (const QString &description=QString(), QgsTask::Flags flags=AllFlags)
 Constructor for QgsTask.
 
 ~QgsTask () override
 
void addSubTask (QgsTask *subTask, const QgsTaskList &dependencies=QgsTaskList(), SubTaskDependency subTaskDependency=SubTaskIndependent)
 Adds a subtask to this task.
 
bool canCancel () const
 Returns true if the task can be canceled.
 
QList< QgsMapLayer * > dependentLayers () const
 Returns the list of layers on which the task depends.
 
QString description () const
 Returns the task's description.
 
qint64 elapsedTime () const
 Returns the elapsed time since the task commenced, in milliseconds.
 
Flags flags () const
 Returns the flags associated with the task.
 
void hold ()
 Places the task on hold.
 
bool isActive () const
 Returns true if the task is active, ie it is not complete and has not been canceled.
 
double progress () const
 Returns the task's progress (between 0.0 and 100.0)
 
void setDependentLayers (const QList< QgsMapLayer * > &dependentLayers)
 Sets a list of layers on which the task depends.
 
void setDescription (const QString &description)
 Sets the task's description.
 
TaskStatus status () const
 Returns the current task status.
 
void unhold ()
 Releases the task from being held.
 
bool waitForFinished (int timeout=30000)
 Blocks the current thread until the task finishes or a maximum of timeout milliseconds.
 

Additional Inherited Members

- Public Types inherited from QgsTask
enum  Flag {
  CanCancel = 1 << 1 , CancelWithoutPrompt = 1 << 2 , Hidden = 1 << 3 , Silent = 1 << 4 ,
  AllFlags = CanCancel
}
 Task flags. More...
 
typedef QFlags< FlagFlags
 
enum  SubTaskDependency { SubTaskIndependent = 0 , ParentDependsOnSubTask }
 Controls how subtasks relate to their parent task. More...
 
enum  TaskStatus {
  Queued , OnHold , Running , Complete ,
  Terminated
}
 Status of tasks. More...
 
- Protected Slots inherited from QgsTask
void setProgress (double progress)
 Sets the task's current progress.
 
- Protected Member Functions inherited from QgsTask
virtual void finished (bool result)
 If the task is managed by a QgsTaskManager, this will be called after the task has finished (whether through successful completion or via early termination).
 
bool isCanceled () const
 Will return true if task should terminate ASAP.
 

Detailed Description

Handles HTTP network content fetching in a background task.

Provides a simple method for fetching remote HTTP content in a QgsTask. Url redirects are automatically handled.

After constructing a QgsNetworkContentFetcherTask, callers should connect to the QgsNetworkContentFetcherTask::fetched signal. They can then safely access the network reply() from the connected slot without danger of the task being first removed by the QgsTaskManager.

See also
QgsNetworkContentFetcher
Since
QGIS 3.2

Definition at line 47 of file qgsnetworkcontentfetchertask.h.

Constructor & Destructor Documentation

◆ QgsNetworkContentFetcherTask() [1/2]

QgsNetworkContentFetcherTask::QgsNetworkContentFetcherTask ( const QUrl &  url,
const QString &  authcfg = QString(),
QgsTask::Flags  flags = QgsTask::CanCancel,
const QString &  description = QString() 
)

Constructor for a QgsNetworkContentFetcherTask which fetches the specified url.

Optionally, authentication configuration can be set via the authcfg argument.

Since QGIS 3.28 the optional description can be explicitly set. If not specified, a default task description will be generated.

Definition at line 25 of file qgsnetworkcontentfetchertask.cpp.

◆ QgsNetworkContentFetcherTask() [2/2]

QgsNetworkContentFetcherTask::QgsNetworkContentFetcherTask ( const QNetworkRequest &  request,
const QString &  authcfg = QString(),
QgsTask::Flags  flags = QgsTask::CanCancel,
const QString &  description = QString() 
)

Constructor for a QgsNetworkContentFetcherTask which fetches the specified network request.

Optionally, authentication configuration can be set via the authcfg argument.

Since QGIS 3.28 the optional description can be explicitly set. If not specified, a default task description will be generated.

Definition at line 30 of file qgsnetworkcontentfetchertask.cpp.

◆ ~QgsNetworkContentFetcherTask()

QgsNetworkContentFetcherTask::~QgsNetworkContentFetcherTask ( )
override

Definition at line 37 of file qgsnetworkcontentfetchertask.cpp.

Member Function Documentation

◆ cancel()

void QgsNetworkContentFetcherTask::cancel ( )
overridevirtual

Notifies the task that it should terminate.

Calling this is not guaranteed to immediately end the task, rather it sets the isCanceled() flag which task subclasses can check and terminate their operations at an appropriate time. Any subtasks owned by this task will also be canceled. Derived classes must ensure that the base class implementation is called from any overridden version.

See also
isCanceled()

Reimplemented from QgsTask.

Definition at line 82 of file qgsnetworkcontentfetchertask.cpp.

◆ contentAsString()

QString QgsNetworkContentFetcherTask::contentAsString ( ) const

Returns the fetched content as a string.

Warning
This should only be accessed from a slot connected directly to the QgsNetworkContentFetcherTask::fetched() signal.
Since
QGIS 3.10

Definition at line 100 of file qgsnetworkcontentfetchertask.cpp.

◆ contentDispositionFilename()

QString QgsNetworkContentFetcherTask::contentDispositionFilename ( ) const

Returns the associated filename from the reply's content disposition header, if present.

Since
QGIS 3.28

Definition at line 95 of file qgsnetworkcontentfetchertask.cpp.

◆ errorOccurred

void QgsNetworkContentFetcherTask::errorOccurred ( QNetworkReply::NetworkError  code,
const QString &  errorMsg 
)
signal

Emitted when an error with code error occurred while processing the request errorMsg is a textual description of the error.

Since
QGIS 3.22

◆ fetched

void QgsNetworkContentFetcherTask::fetched ( )
signal

Emitted when the network content has been fetched, regardless of whether the fetch was successful or not.

Users of QgsNetworkContentFetcherTask should connect to this signal, and from the associated slot they can then safely access the network reply() without danger of the task being first removed by the QgsTaskManager.

◆ reply()

QNetworkReply * QgsNetworkContentFetcherTask::reply ( )

Returns the network reply.

Ownership is not transferred.

May return nullptr if the request has not yet completed.

Warning
This should only be accessed from a slot connected directly to the QgsNetworkContentFetcherTask::fetched() signal.

Definition at line 90 of file qgsnetworkcontentfetchertask.cpp.

◆ run()

bool QgsNetworkContentFetcherTask::run ( )
overridevirtual

Performs the task's operation.

This method will be called when the task commences (ie via calling start() ), and subclasses should implement the operation they wish to perform in the background within this method.

A task must return a boolean value to indicate whether the task was completed successfully or terminated before completion.

Implements QgsTask.

Definition at line 43 of file qgsnetworkcontentfetchertask.cpp.


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