1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590
|
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgstaskmanager.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.py again *
************************************************************************/
typedef QList< QgsTask * > QgsTaskList;
class QgsTask : QObject
{
%Docstring(signature="appended")
Abstract base class for long running background tasks.
Tasks can be controlled directly, or added to a
:py:class:`QgsTaskManager` for automatic management.
Derived classes should implement the process they want to execute in the
background within the :py:func:`~run` method. This method will be called
when the task commences (ie via calling :py:func:`~run` ).
Long running tasks should periodically check the :py:func:`~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.
%End
%TypeHeaderCode
#include "qgstaskmanager.h"
%End
public:
enum TaskStatus /BaseType=IntEnum/
{
Queued,
OnHold,
Running,
Complete,
Terminated,
};
enum Flag /BaseType=IntEnum/
{
CanCancel,
CancelWithoutPrompt,
Hidden,
Silent,
AllFlags,
};
typedef QFlags<QgsTask::Flag> Flags;
QgsTask( const QString &description = QString(), QgsTask::Flags flags = AllFlags );
%Docstring
Constructor for QgsTask.
:param description: text description of task
:param flags: task flags
%End
~QgsTask();
Flags flags() const;
%Docstring
Returns the flags associated with the task.
%End
void setDescription( const QString &description );
%Docstring
Sets the task's ``description``. This must be called before adding the
task to a :py:class:`QgsTaskManager`, changing the description after
queuing the task has no effect.
.. versionadded:: 3.10
%End
bool canCancel() const;
%Docstring
Returns ``True`` if the task can be canceled.
%End
bool isActive() const;
%Docstring
Returns ``True`` if the task is active, ie it is not complete and has
not been canceled.
%End
TaskStatus status() const;
%Docstring
Returns the current task status.
%End
QString description() const;
%Docstring
Returns the task's description.
%End
double progress() const;
%Docstring
Returns the task's progress (between 0.0 and 100.0)
%End
qint64 elapsedTime() const;
%Docstring
Returns the elapsed time since the task commenced, in milliseconds.
The value is undefined for tasks which have not begun.
.. versionadded:: 3.4
%End
virtual void cancel();
%Docstring
Notifies the task that it should terminate. Calling this is not
guaranteed to immediately end the task, rather it sets the
:py:func:`~QgsTask.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`
%End
void hold();
%Docstring
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
:py:class:`QgsTaskManager`.
.. seealso:: :py:func:`unhold`
%End
void unhold();
%Docstring
Releases the task from being held. For tasks managed by a
:py:class:`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`
%End
enum SubTaskDependency /BaseType=IntEnum/
{
SubTaskIndependent,
ParentDependsOnSubTask,
};
void addSubTask( QgsTask *subTask /Transfer/, const QgsTaskList &dependencies = QgsTaskList(),
SubTaskDependency subTaskDependency = SubTaskIndependent );
%Docstring
Adds a subtask to this task.
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.
The parent task must be added to a :py:class:`QgsTaskManager` for
subtasks to be utilized. Subtasks should not be added manually to a
:py:class:`QgsTaskManager`, rather, only the parent task should be added
to the manager.
Subtasks can be nested, ie a subtask can legally be a parent task itself
with its own set of subtasks.
%End
void setDependentLayers( const QList<QgsMapLayer *> &dependentLayers );
%Docstring
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.
.. seealso:: :py:func:`dependentLayers`
%End
QList< QgsMapLayer * > dependentLayers() const;
%Docstring
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`
%End
bool waitForFinished( int timeout = 30000 );
%Docstring
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.
%End
signals:
void progressChanged( double progress );
%Docstring
Will be emitted by task when its progress changes.
:param progress: percent of progress, from 0.0 - 100.0
.. note::
derived classes should not emit this signal directly, instead they should call
:py:func:`~QgsTask.setProgress`
%End
void statusChanged( int status );
%Docstring
Will be emitted by task when its status changes.
:param status: new task status
.. note::
derived classes should not emit this signal directly, it will automatically
be emitted
%End
void begun();
%Docstring
Will be emitted by task to indicate its commencement.
.. note::
derived classes should not emit this signal directly, it will automatically
be emitted when the task begins
%End
void taskCompleted();
%Docstring
Will be emitted by task to indicate its successful completion.
.. note::
derived classes should not emit this signal directly, it will automatically
be emitted
%End
void taskTerminated();
%Docstring
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).
.. note::
derived classes should not emit this signal directly, it will automatically
be emitted
%End
protected:
virtual bool run() = 0;
%Docstring
Performs the task's operation. This method will be called when the task
commences (ie via calling :py:func:`~QgsTask.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.
%End
virtual void finished( bool result );
%Docstring
If the task is managed by a :py:class:`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.
%End
bool isCanceled() const;
%Docstring
Will return ``True`` if task should terminate ASAP. If the task reports
the CanCancel flag, then derived classes' :py:func:`~QgsTask.run`
methods should periodically check this and terminate in a safe manner.
%End
protected slots:
void setProgress( double progress );
%Docstring
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.
:param progress: percent of progress, from 0.0 - 100.0
%End
};
QFlags<QgsTask::Flag> operator|(QgsTask::Flag f1, QFlags<QgsTask::Flag> f2);
class QgsTaskManager : QObject
{
%Docstring(signature="appended")
Task manager for managing a set of long-running :py:class:`QgsTask`
tasks.
This class can be created directly, or accessed via
:py:func:`QgsApplication.taskManager()`.
%End
%TypeHeaderCode
#include "qgstaskmanager.h"
%End
public:
QgsTaskManager( QObject *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsTaskManager.
:param parent: parent QObject
%End
~QgsTaskManager();
struct TaskDefinition
{
explicit TaskDefinition( QgsTask *task, const QgsTaskList &dependentTasks = QgsTaskList() );
%Docstring
Constructor for TaskDefinition. Ownership of the task is not transferred
to the definition, but will be transferred to a QgsTaskManager.
%End
QgsTask *task;
QgsTaskList dependentTasks;
};
QThreadPool *threadPool();
%Docstring
Returns the threadpool utilized by the task manager.
.. versionadded:: 3.34
%End
long addTask( QgsTask *task /Transfer/, int priority = 0 );
%Docstring
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
%End
long addTask( const TaskDefinition &task /Transfer/, int priority = 0 );
%Docstring
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
%End
QgsTask *task( long id ) const;
%Docstring
Returns the task with matching ID.
:param id: task ID
:return: task if found, or ``None``
%End
QList<QgsTask *> tasks() const;
%Docstring
Returns all tasks tracked by the manager.
%End
int count() const;
%Docstring
Returns the number of tasks tracked by the manager.
%End
long taskId( QgsTask *task ) const;
%Docstring
Returns the unique task ID corresponding to a task managed by the class.
:param task: task to find
:return: task ID, or -1 if task not found
%End
void cancelAll();
%Docstring
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.
%End
bool dependenciesSatisfied( long taskId ) const;
%Docstring
Returns ``True`` if all dependencies for the specified task are
satisfied
%End
QList< QgsMapLayer * > dependentLayers( long taskId ) const;
%Docstring
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.
:param taskId: task ID
:return: list of layers
.. seealso:: :py:func:`tasksDependentOnLayer`
%End
QList< QgsTask * > tasksDependentOnLayer( QgsMapLayer *layer ) const;
%Docstring
Returns a list of tasks which depend on a layer.
.. seealso:: :py:func:`dependentLayers`
%End
QList< QgsTask * > activeTasks() const;
%Docstring
Returns a list of the active (queued or running) tasks.
.. seealso:: :py:func:`countActiveTasks`
%End
int countActiveTasks( bool includeHidden = true ) const;
%Docstring
Returns the number of active (queued or running) tasks.
The ``includeHidden`` argument dictates whether hidden tasks should be
shown.
.. seealso:: :py:func:`activeTasks`
.. 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`
%End
signals:
void progressChanged( long taskId, double progress );
%Docstring
Will be emitted when a task reports a progress change
:param taskId: ID of task
:param progress: percent of progress, from 0.0 - 100.0
%End
void finalTaskProgressChanged( double progress );
%Docstring
Will be emitted when only a single task remains to complete and that
task has reported a progress change
:param progress: percent of progress, from 0.0 - 100.0
%End
void statusChanged( long taskId, int status );
%Docstring
Will be emitted when a task reports a status change
:param taskId: ID of task
:param status: new task status
%End
void taskAdded( long taskId );
%Docstring
Emitted when a new task has been added to the manager
:param taskId: ID of task
%End
void taskAboutToBeDeleted( long taskId );
%Docstring
Emitted when a task is about to be deleted
:param taskId: ID of task
%End
void allTasksFinished();
%Docstring
Emitted when all tasks are complete
.. seealso:: :py:func:`countActiveTasksChanged`
%End
void countActiveTasksChanged( int count );
%Docstring
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`
%End
};
class QgsTaskWithSerialSubTasks : QgsTask
{
%Docstring(signature="appended")
Task that is composed of sub-tasks to be executed in a serial way, which
may be useful for example to add several layers in a single target
dataset which does not support concurrent updates.
.. versionadded:: 3.36
%End
%TypeHeaderCode
#include "qgstaskmanager.h"
%End
public:
QgsTaskWithSerialSubTasks( const QString &desc = QString() );
%Docstring
Constructor
%End
~QgsTaskWithSerialSubTasks();
void addSubTask( QgsTask *subTask /Transfer/ );
%Docstring
Add a subtask and transfer its ownership
The parent task must be added to a :py:class:`QgsTaskManager` for
subtasks to be utilized. Subtasks should not be added manually to a
:py:class:`QgsTaskManager`, rather, only the parent task should be added
to the manager.
For now, subtasks can *NOT* be nested.
%End
virtual void cancel();
protected:
virtual bool run();
};
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgstaskmanager.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.py again *
************************************************************************/
|