QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
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.
 

Signals

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

Public Member Functions

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

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().

Definition at line 393 of file qgstaskmanager.h.

Constructor & Destructor Documentation

◆ QgsTaskManager()

QgsTaskManager::QgsTaskManager ( QObject *  parent = nullptr)

Constructor for QgsTaskManager.

Parameters
parentparent QObject

Definition at line 393 of file qgstaskmanager.cpp.

◆ ~QgsTaskManager()

QgsTaskManager::~QgsTaskManager ( )
override

Definition at line 401 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 666 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 431 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 426 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 548 of file qgstaskmanager.cpp.

◆ count()

int QgsTaskManager::count ( ) const

Returns the number of tasks tracked by the manager.

Definition at line 530 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 674 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 582 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 562 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 643 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 515 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 536 of file qgstaskmanager.cpp.

◆ tasks()

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

Returns all tasks tracked by the manager.

Definition at line 524 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 649 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()

◆ threadPool()

QThreadPool * QgsTaskManager::threadPool ( )

Returns the threadpool utilized by the task manager.

Since
QGIS 3.34

Definition at line 421 of file qgstaskmanager.cpp.

◆ 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 694 of file qgstaskmanager.cpp.

Friends And Related Symbol Documentation

◆ TestQgsTaskManager

friend class TestQgsTaskManager
friend

Definition at line 659 of file qgstaskmanager.h.


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