QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
18 #ifndef QGSTASKMANAGER_H
19 #define QGSTASKMANAGER_H
25 #include <QReadWriteLock>
27 #include "qgis_core.h"
31 class QgsTaskRunnableWrapper;
52 class CORE_EXPORT
QgsTask :
public QObject
73 CancelWithoutPrompt = 1 << 2,
76 Q_DECLARE_FLAGS( Flags, Flag )
83 QgsTask(
const QString &description = QString(), QgsTask::Flags flags = AllFlags );
90 Flags
flags()
const {
return mFlags; }
97 void setDescription(
const QString &description );
108 bool isActive()
const {
return mOverallStatus == Running; }
132 qint64 elapsedTime()
const;
143 virtual void cancel();
165 SubTaskIndependent = 0,
190 SubTaskDependency subTaskDependency = SubTaskIndependent );
197 void setDependentLayers(
const QList<QgsMapLayer *> &dependentLayers );
204 QList< QgsMapLayer * > dependentLayers()
const;
215 bool waitForFinished(
int timeout = 30000 );
280 virtual void finished(
bool result ) { Q_UNUSED( result ) }
287 bool isCanceled()
const;
296 void setProgress(
double progress );
299 void subTaskStatusChanged(
int status );
304 QString mDescription;
306 TaskStatus mStatus = Queued;
308 TaskStatus mOverallStatus = Queued;
314 QMutex mNotFinishedMutex;
320 QSemaphore mNotStartedMutex;
323 double mProgress = 0.0;
325 double mTotalProgress = 0.0;
326 bool mShouldTerminate =
false;
327 mutable QMutex mShouldTerminateMutex;
332 SubTask(
QgsTask *task,
const QgsTaskList &dependencies, SubTaskDependency dependency )
334 , dependencies( dependencies )
335 , dependency( dependency )
339 SubTaskDependency dependency;
341 QList< SubTask > mSubTasks;
345 QElapsedTimer mElapsedTime;
364 void processSubTasksForHold();
367 friend class QgsTaskRunnableWrapper;
368 friend class TestQgsTaskManager;
372 void processSubTasksForCompletion();
374 void processSubTasksForTermination();
414 , dependentTasks( dependentTasks )
454 QgsTask *task(
long id )
const;
459 QList<QgsTask *> tasks()
const;
469 long taskId(
QgsTask *task )
const;
479 bool dependenciesSatisfied(
long taskId )
const;
485 QSet< long > dependencies(
long taskId )
const SIP_SKIP;
494 QList< QgsMapLayer * > dependentLayers(
long taskId )
const;
500 QList< QgsTask * > tasksDependentOnLayer(
QgsMapLayer *layer )
const;
506 QList< QgsTask * > activeTasks()
const;
513 int countActiveTasks()
const;
521 void triggerTask(
QgsTask *task );
580 void taskProgressChanged(
double progress );
581 void taskStatusChanged(
int status );
582 void layersWillBeRemoved(
const QList<QgsMapLayer *> &layers );
588 TaskInfo(
QgsTask *task =
nullptr,
int priority = 0 );
589 void createRunnable();
593 QgsTaskRunnableWrapper *runnable =
nullptr;
596 bool mInitialized =
false;
598 mutable QMutex *mTaskMutex;
600 QMap< long, TaskInfo > mTasks;
601 QMap< long, QgsTaskList > mTaskDependencies;
602 QMap< long, QgsWeakMapLayerPointerList > mLayerDependencies;
605 long mNextTaskId = 1;
608 QSet< QgsTask * > mActiveTasks;
610 QSet< QgsTask * > mParentTasks;
612 QSet< QgsTask * > mSubTasks;
614 QSet< QgsTask * > mPendingDeletion;
616 long addTaskPrivate(
QgsTask *task,
621 bool cleanupAndDeleteTask(
QgsTask *task );
634 void cancelDependentTasks(
long taskId );
636 bool resolveDependencies(
long firstTaskId,
long currentTaskId, QSet< long > &results )
const;
639 bool hasCircularDependencies(
long taskId )
const;
641 friend class TestQgsTaskManager;
644 #endif //QGSTASKMANAGER_H
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
QgsTaskList dependentTasks
List of dependent tasks which must be completed before task can run.
void progressChanged(long taskId, double progress)
Will be emitted when a task reports a progress change.
SubTaskDependency
Controls how subtasks relate to their parent task.
@ Complete
Task successfully completed.
void progressChanged(double progress)
Will be emitted by task when its progress changes.
void statusChanged(long taskId, int status)
Will be emitted when a task reports a status change.
QString description() const
Returns the task's description.
@ Running
Task is currently running.
void finalTaskProgressChanged(double progress)
Will be emitted when only a single task remains to complete and that task has reported a progress cha...
virtual void finished(bool result)
If the task is managed by a QgsTaskManager, this will be called after the task has finished (whether ...
void taskAboutToBeDeleted(long taskId)
Emitted when a task is about to be deleted.
void taskCompleted()
Will be emitted by task to indicate its successful completion.
@ Queued
Task is queued and has not begun.
Definition of a task for inclusion in the manager.
TaskDefinition(QgsTask *task, const QgsTaskList &dependentTasks=QgsTaskList())
Constructor for TaskDefinition.
TaskStatus status() const
Returns the current task status.
void statusChanged(int status)
Will be emitted by task when its status changes.
bool canCancel() const
Returns true if the task can be canceled.
TaskStatus
Status of tasks.
Task manager for managing a set of long-running QgsTask tasks.
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.
@ ParentDependsOnSubTask
Subtask must complete before parent can begin.
void taskTerminated()
Will be emitted by task if it has terminated for any reason other then completion (e....
bool isActive() const
Returns true if the task is active, ie it is not complete and has not been canceled.
QList< QgsTask * > QgsTaskList
List of QgsTask objects.
@ Terminated
Task was terminated or errored.
Base class for all map layer types.
void taskAdded(long taskId)
Emitted when a new task has been added to the manager.
void countActiveTasksChanged(int count)
Emitted when the number of active tasks changes.
void taskTriggered(QgsTask *task)
Emitted when a task is triggered.
Flags flags() const
Returns the flags associated with the task.
virtual bool run()=0
Performs the task's operation.
@ OnHold
Task is queued but on hold and will not be started.
void begun()
Will be emitted by task to indicate its commencement.
void allTasksFinished()
Emitted when all tasks are complete.
double progress() const
Returns the task's progress (between 0.0 and 100.0)
Abstract base class for long running background tasks.