QGIS/python/core/auto_generated/qgstaskmanager.sip.in

505 lines
14 KiB
Plaintext
Raw Normal View History

2017-05-10 13:01:31 +02:00
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgstaskmanager.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
typedef QList< QgsTask * > QgsTaskList;
class QgsTask : QObject
{
2017-05-10 13:01:31 +02:00
%Docstring
Abstract base class for long running background tasks. Tasks can be controlled directly,
2017-12-15 10:36:55 -04:00
or added to a QgsTaskManager for automatic management.
2017-05-10 13:01:31 +02:00
2017-12-15 10:36:55 -04:00
Derived classes should implement the process they want to execute in the background
within the run() method. This method will be called when the
task commences (ie via calling run() ).
2017-05-10 13:01:31 +02:00
2017-12-15 10:36:55 -04:00
Long running tasks should periodically check the isCanceled() flag to detect if the task
has been canceled via some external event. If this flag is true then the task should
clean up and terminate at the earliest possible convenience.
2017-05-10 13:01:31 +02:00
.. versionadded:: 3.0
%End
%TypeHeaderCode
2017-05-10 13:01:31 +02:00
#include "qgstaskmanager.h"
%End
public:
enum TaskStatus
{
2017-05-10 13:01:31 +02:00
Queued,
OnHold,
Running,
Complete,
Terminated,
};
2016-04-19 22:24:34 +10:00
enum Flag
{
2017-05-10 13:01:31 +02:00
CanCancel,
AllFlags,
2016-04-19 22:24:34 +10:00
};
typedef QFlags<QgsTask::Flag> Flags;
2017-05-10 13:01:31 +02:00
QgsTask( const QString &description = QString(), QgsTask::Flags flags = AllFlags );
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Constructor for QgsTask.
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param description: text description of task
:param flags: task flags
2017-05-10 13:01:31 +02:00
%End
~QgsTask();
2016-04-19 22:24:34 +10:00
Flags flags() const;
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Returns the flags associated with the task.
2017-05-10 13:01:31 +02:00
%End
2016-04-19 22:24:34 +10:00
bool canCancel() const;
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Returns true if the task can be canceled.
2017-05-10 13:01:31 +02:00
%End
bool isActive() const;
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Returns true if the task is active, ie it is not complete and has
not been canceled.
2017-05-10 13:01:31 +02:00
%End
TaskStatus status() const;
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Returns the current task status.
2017-05-10 13:01:31 +02:00
%End
QString description() const;
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Returns the task's description.
2017-05-10 13:01:31 +02:00
%End
double progress() const;
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Returns the task's progress (between 0.0 and 100.0)
2017-05-10 13:01:31 +02:00
%End
virtual void cancel();
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
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.
.. seealso:: :py:func:`isCanceled`
2017-05-10 13:01:31 +02:00
%End
2016-04-20 07:22:38 +10:00
void hold();
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Places the task on hold. If the task in not queued
(ie it is already running or has finished) then calling this has no effect.
Calling this method only has an effect for tasks which are managed
by a QgsTaskManager.
.. seealso:: :py:func:`unhold`
2017-05-10 13:01:31 +02:00
%End
void unhold();
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Releases the task from being held. For tasks managed by a QgsTaskManager
calling this will re-add them to the queue. If the
task in not currently being held then calling this has no effect.
.. seealso:: :py:func:`hold`
2017-05-10 13:01:31 +02:00
%End
enum SubTaskDependency
{
2017-05-10 13:01:31 +02:00
SubTaskIndependent,
ParentDependsOnSubTask,
};
2017-05-10 13:01:31 +02:00
void addSubTask( QgsTask *subTask /Transfer/, const QgsTaskList &dependencies = QgsTaskList(),
SubTaskDependency subTaskDependency = SubTaskIndependent );
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Adds a subtask to this task.
2017-05-10 13:01:31 +02:00
2017-12-15 10:36:55 -04:00
Subtasks allow a single task to be created which
consists of multiple smaller tasks. Subtasks are not visible or indepedently
controllable by users. Ownership of the subtask is transferred.
Subtasks can have an optional list of dependent tasks, which must be completed
before the subtask can begin. By default subtasks are considered independent
of the parent task, ie they can be run either before, after, or at the same
time as the parent task. This behavior can be overridden through the subTaskDependency
argument. Note that subtasks should NEVER be dependent on their parent task, and violating
this constraint will prevent the task from completing successfully.
2017-05-10 13:01:31 +02:00
2017-12-15 10:36:55 -04:00
The parent task must be added to a QgsTaskManager for subtasks to be utilized.
Subtasks should not be added manually to a QgsTaskManager, rather, only the parent
task should be added to the manager.
2017-05-10 13:01:31 +02:00
2017-12-15 10:36:55 -04:00
Subtasks can be nested, ie a subtask can legally be a parent task itself with
its own set of subtasks.
2017-05-10 13:01:31 +02:00
%End
void setDependentLayers( const QList<QgsMapLayer *> &dependentLayers );
%Docstring
2017-12-15 10:36:55 -04:00
Sets a list of layers on which the task depends. The task will automatically
be canceled if any of these layers are about to be removed.
2018-05-25 09:00:58 +10:00
.. seealso:: :py:func:`dependentLayers`
2017-05-10 13:01:31 +02:00
%End
QList< QgsMapLayer * > dependentLayers() const;
%Docstring
2017-12-15 10:36:55 -04:00
Returns the list of layers on which the task depends. The task will automatically
be canceled if any of these layers are about to be removed.
.. seealso:: :py:func:`setDependentLayers`
2017-05-10 13:01:31 +02:00
%End
bool waitForFinished( unsigned long timeout = 30000 );
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Blocks the current thread until the task finishes or a maximum of ``timeout`` milliseconds.
If ``timeout`` is ``0`` the thread will be blocked forever.
In case of a timeout, the task will still be running.
In case the task already is finished, the method will return immediately while
returning ``true``.
The result will be false if the wait timed out and true in any other case.
2017-05-10 13:01:31 +02:00
%End
signals:
void progressChanged( double progress );
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Will be emitted by task when its progress changes.
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param progress: percent of progress, from 0.0 - 100.0
2017-05-10 13:01:31 +02:00
.. note::
derived classes should not emit this signal directly, instead they should call
2018-01-12 20:51:17 -04:00
setProgress()
2017-05-10 13:01:31 +02:00
%End
void statusChanged( int status );
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Will be emitted by task when its status changes.
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param status: new task status
2017-05-10 13:01:31 +02:00
.. note::
derived classes should not emit this signal directly, it will automatically
2018-01-12 20:51:17 -04:00
be emitted
2017-05-10 13:01:31 +02:00
%End
void begun();
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Will be emitted by task to indicate its commencement.
2017-05-10 13:01:31 +02:00
.. note::
derived classes should not emit this signal directly, it will automatically
2018-01-12 20:51:17 -04:00
be emitted when the task begins
2017-05-10 13:01:31 +02:00
%End
void taskCompleted();
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Will be emitted by task to indicate its successful completion.
2017-05-10 13:01:31 +02:00
.. note::
derived classes should not emit this signal directly, it will automatically
2018-01-12 20:51:17 -04:00
be emitted
2017-05-10 13:01:31 +02:00
%End
void taskTerminated();
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
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).
2017-05-10 13:01:31 +02:00
.. note::
derived classes should not emit this signal directly, it will automatically
2018-01-12 20:51:17 -04:00
be emitted
2017-05-10 13:01:31 +02:00
%End
protected:
virtual bool run() = 0;
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
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.
2017-05-10 13:01:31 +02:00
%End
virtual void finished( bool result );
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
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). The result argument reflects whether
the task was successfully completed or not. This method is always called
from the main thread, so it is safe to create widgets and perform other
operations which require the main thread. However, the GUI will be blocked
for the duration of this method so tasks should avoid performing any
lengthy operations here.
2017-05-10 13:01:31 +02:00
%End
bool isCanceled() const;
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Will return true if task should terminate ASAP. If the task reports the CanCancel
flag, then derived classes' run() methods should periodically check this and
terminate in a safe manner.
2017-05-10 13:01:31 +02:00
%End
protected slots:
void setProgress( double progress );
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Sets the task's current progress. The derived class should call this method whenever
the task wants to update its progress. Calling will automatically emit the progressChanged signal.
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param progress: percent of progress, from 0.0 - 100.0
2017-05-10 13:01:31 +02:00
%End
};
2017-05-10 13:01:31 +02:00
2016-04-19 22:24:34 +10:00
QFlags<QgsTask::Flag> operator|(QgsTask::Flag f1, QFlags<QgsTask::Flag> f2);
class QgsTaskManager : QObject
{
2017-05-10 13:01:31 +02:00
%Docstring
Task manager for managing a set of long-running QgsTask tasks. This class can be created directly,
2017-12-19 11:43:52 -04:00
or accessed via :py:func:`QgsApplication.taskManager()`
2017-12-15 10:36:55 -04:00
2017-05-10 13:01:31 +02:00
.. versionadded:: 3.0
%End
%TypeHeaderCode
2017-05-10 13:01:31 +02:00
#include "qgstaskmanager.h"
%End
public:
QgsTaskManager( QObject *parent /TransferThis/ = 0 );
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Constructor for QgsTaskManager.
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param parent: parent QObject
2017-05-10 13:01:31 +02:00
%End
~QgsTaskManager();
struct TaskDefinition
{
2017-05-10 13:01:31 +02:00
explicit TaskDefinition( QgsTask *task, const QgsTaskList &dependentTasks = QgsTaskList() );
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Constructor for TaskDefinition. Ownership of the task is not transferred to the definition,
but will be transferred to a QgsTaskManager.
2017-05-10 13:01:31 +02:00
%End
QgsTask *task;
2016-12-05 14:03:55 +10:00
QgsTaskList dependentTasks;
2017-05-10 13:01:31 +02:00
};
long addTask( QgsTask *task /Transfer/, int priority = 0 );
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
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.
:return: unique task ID, or 0 if task could not be added
2017-05-10 13:01:31 +02:00
%End
long addTask( const TaskDefinition &task /Transfer/, int priority = 0 );
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
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.
:return: unique task ID, or 0 if task could not be added
2017-05-10 13:01:31 +02:00
%End
2016-11-29 13:30:17 +10:00
QgsTask *task( long id ) const;
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Returns the task with matching ID.
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param id: task ID
:return: task if found, or None
2017-05-10 13:01:31 +02:00
%End
2017-05-10 13:01:31 +02:00
QList<QgsTask *> tasks() const;
%Docstring
2017-12-15 10:36:55 -04:00
Returns all tasks tracked by the manager.
2017-05-10 13:01:31 +02:00
%End
int count() const;
2017-05-10 13:01:31 +02:00
%Docstring
Returns the number of tasks tracked by the manager.
%End
long taskId( QgsTask *task ) const;
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Returns the unique task ID corresponding to a task managed by the class.
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param task: task to find
:return: task ID, or -1 if task not found
2017-05-10 13:01:31 +02:00
%End
2016-04-19 22:24:34 +10:00
void cancelAll();
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
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.
2017-05-10 13:01:31 +02:00
%End
bool dependenciesSatisfied( long taskId ) const;
2017-05-10 13:01:31 +02:00
%Docstring
Returns true if all dependencies for the specified task are satisfied
%End
2016-04-21 21:56:31 +10:00
2017-05-10 13:01:31 +02:00
QList< QgsMapLayer * > dependentLayers( long taskId ) const;
%Docstring
2017-12-15 10:36:55 -04:00
Returns a list of layers on which as task is dependent. The task will automatically
be canceled if any of these layers are above to be removed.
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param taskId: task ID
:return: list of layers
.. seealso:: :py:func:`tasksDependentOnLayer`
2017-05-10 13:01:31 +02:00
%End
2017-05-10 13:01:31 +02:00
QList< QgsTask * > tasksDependentOnLayer( QgsMapLayer *layer ) const;
%Docstring
2017-12-15 10:36:55 -04:00
Returns a list of tasks which depend on a layer.
.. seealso:: :py:func:`dependentLayers`
2017-05-10 13:01:31 +02:00
%End
2017-05-10 13:01:31 +02:00
QList< QgsTask * > activeTasks() const;
%Docstring
2017-12-15 10:36:55 -04:00
Returns a list of the active (queued or running) tasks.
.. seealso:: :py:func:`countActiveTasks`
2017-05-10 13:01:31 +02:00
%End
2016-04-26 15:54:30 +10:00
int countActiveTasks() const;
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Returns the number of active (queued or running) tasks.
.. seealso:: :py:func:`activeTasks`
2017-12-15 10:36:55 -04:00
.. seealso:: :py:func:`countActiveTasksChanged`
%End
public slots:
void triggerTask( QgsTask *task );
%Docstring
Triggers a task, e.g. as a result of a GUI interaction.
.. seealso:: :py:func:`taskTriggered`
2017-05-10 13:01:31 +02:00
%End
2016-04-26 15:54:30 +10:00
signals:
void progressChanged( long taskId, double progress );
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Will be emitted when a task reports a progress change
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param taskId: ID of task
:param progress: percent of progress, from 0.0 - 100.0
2017-05-10 13:01:31 +02:00
%End
void finalTaskProgressChanged( double progress );
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Will be emitted when only a single task remains to complete
and that task has reported a progress change
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param progress: percent of progress, from 0.0 - 100.0
2017-05-10 13:01:31 +02:00
%End
void statusChanged( long taskId, int status );
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Will be emitted when a task reports a status change
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param taskId: ID of task
:param status: new task status
2017-05-10 13:01:31 +02:00
%End
void taskAdded( long taskId );
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Emitted when a new task has been added to the manager
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param taskId: ID of task
2017-05-10 13:01:31 +02:00
%End
void taskAboutToBeDeleted( long taskId );
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Emitted when a task is about to be deleted
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param taskId: ID of task
2017-05-10 13:01:31 +02:00
%End
2016-04-26 15:54:30 +10:00
void allTasksFinished();
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Emitted when all tasks are complete
.. seealso:: :py:func:`countActiveTasksChanged`
2017-05-10 13:01:31 +02:00
%End
2016-04-26 15:54:30 +10:00
void countActiveTasksChanged( int count );
2017-05-10 13:01:31 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Emitted when the number of active tasks changes
.. seealso:: :py:func:`countActiveTasks`
%End
void taskTriggered( QgsTask *task );
%Docstring
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.
.. seealso:: :py:func:`triggerTask`
2017-05-10 13:01:31 +02:00
%End
2016-04-26 15:54:30 +10:00
};
2017-05-10 13:01:31 +02:00
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgstaskmanager.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/