QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
Classes | Public Slots | Signals | Public Member Functions | Friends | List of all members
QgsTaskManager Class Reference

Task manager for managing a set of long-running QgsTask tasks. More...

#include <qgstaskmanager.h>

Inheritance diagram for QgsTaskManager:
Inheritance graph
[legend]

Classes

struct  TaskDefinition
 Definition of a task for inclusion in the manager. More...
 

Public Slots

void triggerTask (QgsTask *task)
 Triggers a task, e.g. More...
 

Signals

void allTasksFinished ()
 Emitted when all tasks are complete. More...
 
void countActiveTasksChanged (int count)
 Emitted when the number of active tasks changes. More...
 
void finalTaskProgressChanged (double progress)
 Will be emitted when only a single task remains to complete and that task has reported a progress change. More...
 
void progressChanged (long taskId, double progress)
 Will be emitted when a task reports a progress change. More...
 
void statusChanged (long taskId, int status)
 Will be emitted when a task reports a status change. More...
 
void taskAboutToBeDeleted (long taskId)
 Emitted when a task is about to be deleted. More...
 
void taskAdded (long taskId)
 Emitted when a new task has been added to the manager. More...
 
void taskTriggered (QgsTask *task)
 Emitted when a task is triggered. More...
 

Public Member Functions

 QgsTaskManager (QObject *parent=nullptr)
 Constructor for QgsTaskManager. More...
 
 ~QgsTaskManager () override
 
QList< QgsTask * > activeTasks () const
 Returns a list of the active (queued or running) tasks. More...
 
long addTask (const TaskDefinition &task, int priority=0)
 Adds a task to the manager, using a full task definition (including dependency handling). More...
 
long addTask (QgsTask *task, int priority=0)
 Adds a task to the manager. More...
 
void cancelAll ()
 Instructs all tasks tracked by the manager to terminate. More...
 
int count () const
 Returns the number of tasks tracked by the manager. More...
 
int countActiveTasks (bool includeHidden=true) const
 Returns the number of active (queued or running) tasks. More...
 
QSet< long > dependencies (long taskId) const
 Returns the set of task IDs on which a task is dependent. More...
 
bool dependenciesSatisfied (long taskId) const
 Returns true if all dependencies for the specified task are satisfied. More...
 
QList< QgsMapLayer * > dependentLayers (long taskId) const
 Returns a list of layers on which as task is dependent. More...
 
QgsTasktask (long id) const
 Returns the task with matching ID. More...
 
long taskId (QgsTask *task) const
 Returns the unique task ID corresponding to a task managed by the class. More...
 
QList< QgsTask * > tasks () const
 Returns all tasks tracked by the manager. More...
 
QList< QgsTask * > tasksDependentOnLayer (QgsMapLayer *layer) const
 Returns a list of tasks which depend on a layer. More...
 

Friends

class TestQgsTaskManager
 

Detailed Description

Task manager for managing a set of long-running QgsTask tasks.

This class can be created directly, or accessed via QgsApplication::taskManager().

Since
QGIS 3.0

Definition at line 392 of file qgstaskmanager.h.

Constructor & Destructor Documentation

◆ QgsTaskManager()

QgsTaskManager::QgsTaskManager ( QObject *  parent = nullptr)

Constructor for QgsTaskManager.

Parameters
parentparent QObject

Definition at line 390 of file qgstaskmanager.cpp.

◆ ~QgsTaskManager()

QgsTaskManager::~QgsTaskManager ( )
override

Definition at line 397 of file qgstaskmanager.cpp.

Member Function Documentation

◆ activeTasks()

QList< QgsTask * > QgsTaskManager::activeTasks ( ) const

Returns a list of the active (queued or running) tasks.

See also
countActiveTasks()

Definition at line 654 of file qgstaskmanager.cpp.

◆ addTask() [1/2]

long QgsTaskManager::addTask ( const TaskDefinition task,
int  priority = 0 
)

Adds a task to the manager, using a full task definition (including dependency handling).

Ownership of the task is transferred to the manager, and the task manager will be responsible for starting the task. The priority argument can be used to control the run queue's order of execution, with larger numbers taking precedence over lower priority numbers.

Returns
unique task ID, or 0 if task could not be added

Definition at line 421 of file qgstaskmanager.cpp.

◆ addTask() [2/2]

long QgsTaskManager::addTask ( QgsTask task,
int  priority = 0 
)

Adds a task to the manager.

Ownership of the task is transferred to the manager, and the task manager will be responsible for starting the task. The priority argument can be used to control the run queue's order of execution, with larger numbers taking precedence over lower priority numbers.

Returns
unique task ID, or 0 if task could not be added

Definition at line 416 of file qgstaskmanager.cpp.

◆ allTasksFinished

void QgsTaskManager::allTasksFinished ( )
signal

Emitted when all tasks are complete.

See also
countActiveTasksChanged()

◆ cancelAll()

void QgsTaskManager::cancelAll ( )

Instructs all tasks tracked by the manager to terminate.

Individual tasks may take some time to cancel, or may totally ignore this instruction. Calling this does not block but will instead signal the tasks to cancel and then return immediately.

Definition at line 542 of file qgstaskmanager.cpp.

◆ count()

int QgsTaskManager::count ( ) const

Returns the number of tasks tracked by the manager.

Definition at line 519 of file qgstaskmanager.cpp.

◆ countActiveTasks()

int QgsTaskManager::countActiveTasks ( bool  includeHidden = true) const

Returns the number of active (queued or running) tasks.

The includeHidden argument dictates whether hidden tasks should be shown.

See also
activeTasks()
countActiveTasksChanged()

Definition at line 662 of file qgstaskmanager.cpp.

◆ countActiveTasksChanged

void QgsTaskManager::countActiveTasksChanged ( int  count)
signal

Emitted when the number of active tasks changes.

See also
countActiveTasks()

◆ dependencies()

QSet< long > QgsTaskManager::dependencies ( long  taskId) const

Returns the set of task IDs on which a task is dependent.

Note
not available in Python bindings

Definition at line 576 of file qgstaskmanager.cpp.

◆ dependenciesSatisfied()

bool QgsTaskManager::dependenciesSatisfied ( long  taskId) const

Returns true if all dependencies for the specified task are satisfied.

Definition at line 556 of file qgstaskmanager.cpp.

◆ dependentLayers()

QList< QgsMapLayer * > QgsTaskManager::dependentLayers ( long  taskId) const

Returns a list of layers on which as task is dependent.

The task will automatically be canceled if any of these layers are about to be removed.

Parameters
taskIdtask ID
Returns
list of layers
See also
tasksDependentOnLayer()

Definition at line 631 of file qgstaskmanager.cpp.

◆ finalTaskProgressChanged

void QgsTaskManager::finalTaskProgressChanged ( double  progress)
signal

Will be emitted when only a single task remains to complete and that task has reported a progress change.

Parameters
progresspercent of progress, from 0.0 - 100.0

◆ progressChanged

void QgsTaskManager::progressChanged ( long  taskId,
double  progress 
)
signal

Will be emitted when a task reports a progress change.

Parameters
taskIdID of task
progresspercent of progress, from 0.0 - 100.0

◆ statusChanged

void QgsTaskManager::statusChanged ( long  taskId,
int  status 
)
signal

Will be emitted when a task reports a status change.

Parameters
taskIdID of task
statusnew task status

◆ task()

QgsTask * QgsTaskManager::task ( long  id) const

Returns the task with matching ID.

Parameters
idtask ID
Returns
task if found, or nullptr

Definition at line 504 of file qgstaskmanager.cpp.

◆ taskAboutToBeDeleted

void QgsTaskManager::taskAboutToBeDeleted ( long  taskId)
signal

Emitted when a task is about to be deleted.

Parameters
taskIdID of task

◆ taskAdded

void QgsTaskManager::taskAdded ( long  taskId)
signal

Emitted when a new task has been added to the manager.

Parameters
taskIdID of task

◆ taskId()

long QgsTaskManager::taskId ( QgsTask task) const

Returns the unique task ID corresponding to a task managed by the class.

Parameters
tasktask to find
Returns
task ID, or -1 if task not found

Definition at line 525 of file qgstaskmanager.cpp.

◆ tasks()

QList< QgsTask * > QgsTaskManager::tasks ( ) const

Returns all tasks tracked by the manager.

Definition at line 513 of file qgstaskmanager.cpp.

◆ tasksDependentOnLayer()

QList< QgsTask * > QgsTaskManager::tasksDependentOnLayer ( QgsMapLayer layer) const

Returns a list of tasks which depend on a layer.

See also
dependentLayers()

Definition at line 637 of file qgstaskmanager.cpp.

◆ taskTriggered

void QgsTaskManager::taskTriggered ( QgsTask task)
signal

Emitted when a task is triggered.

This occurs when a user clicks on the task from the QGIS GUI, and can be used to show detailed progress reports or re-open a related dialog.

See also
triggerTask()

◆ triggerTask

void QgsTaskManager::triggerTask ( QgsTask task)
slot

Triggers a task, e.g.

as a result of a GUI interaction.

See also
taskTriggered()

Definition at line 682 of file qgstaskmanager.cpp.

Friends And Related Function Documentation

◆ TestQgsTaskManager

friend class TestQgsTaskManager
friend

Definition at line 648 of file qgstaskmanager.h.


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