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
    75     Q_DECLARE_FLAGS( Flags, 
Flag )
    82     QgsTask( 
const QString &description = QString(), QgsTask::Flags flags = AllFlags );
    89     Flags 
flags()
 const { 
return mFlags; }
    96     void setDescription( 
const QString &description );
   107     bool isActive()
 const { 
return mOverallStatus == Running; }
   131     qint64 elapsedTime() 
const;
   142     virtual void cancel();
   164       SubTaskIndependent = 0, 
   196     void setDependentLayers( 
const QList<QgsMapLayer *> &dependentLayers );
   203     QList< QgsMapLayer * > dependentLayers() 
const;
   214     bool waitForFinished( 
int timeout = 30000 );
   224     void progressChanged( 
double progress );
   232     void statusChanged( 
int status );
   246     void taskCompleted();
   255     void taskTerminated();
   267     virtual bool run() = 0;
   279     virtual void finished( 
bool result ) { Q_UNUSED( result ) }
   295     void setProgress( 
double progress );
   298     void subTaskStatusChanged( 
int status );
   303     QString mDescription;
   313     QMutex mNotFinishedMutex;
   319     QSemaphore mNotStartedMutex;
   322     double mProgress = 0.0;
   324     double mTotalProgress = 0.0;
   325     bool mShouldTerminate = 
false;
   332         , dependencies( dependencies )
   333         , dependency( dependency )
   339     QList< SubTask > mSubTasks;
   343     QElapsedTimer mElapsedTime;
   361     void processSubTasksForCompletion();
   363     void processSubTasksForTermination();
   365     void processSubTasksForHold();
   368     friend class QgsTaskRunnableWrapper;
   369     friend class TestQgsTaskManager;
   374 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsTask::Flags )
   409         , dependentTasks( dependentTasks )
   449     QgsTask *task( 
long id ) 
const;
   454     QList<QgsTask *> tasks() 
const;
   464     long taskId( 
QgsTask *task ) 
const;
   474     bool dependenciesSatisfied( 
long taskId ) 
const;
   480     QSet< long > dependencies( 
long taskId ) 
const SIP_SKIP;
   489     QList< QgsMapLayer * > dependentLayers( 
long taskId ) 
const;
   495     QList< QgsTask * > tasksDependentOnLayer( 
QgsMapLayer *layer ) 
const;
   501     QList< QgsTask * > activeTasks() 
const;
   508     int countActiveTasks() 
const;
   516     void triggerTask( 
QgsTask *task );
   525     void progressChanged( 
long taskId, 
double progress );
   532     void finalTaskProgressChanged( 
double progress );
   539     void statusChanged( 
long taskId, 
int status );
   545     void taskAdded( 
long taskId );
   551     void taskAboutToBeDeleted( 
long taskId );
   557     void allTasksFinished();
   563     void countActiveTasksChanged( 
int count );
   571     void taskTriggered( 
QgsTask *task );
   575     void taskProgressChanged( 
double progress );
   576     void taskStatusChanged( 
int status );
   577     void layersWillBeRemoved( 
const QList<QgsMapLayer *> &layers );
   583       TaskInfo( 
QgsTask *task = 
nullptr, 
int priority = 0 );
   584       void createRunnable();
   588       QgsTaskRunnableWrapper *runnable = 
nullptr;
   591     mutable QMutex *mTaskMutex;
   593     QMap< long, TaskInfo > mTasks;
   594     QMap< long, QgsTaskList > mTaskDependencies;
   595     QMap< long, QgsWeakMapLayerPointerList > mLayerDependencies;
   598     long mNextTaskId = 1;
   601     QSet< QgsTask * > mActiveTasks;
   603     QSet< QgsTask * > mParentTasks;
   605     QSet< QgsTask * > mSubTasks;
   607     QSet< QgsTask * > mPendingDeletion;
   609     long addTaskPrivate( 
QgsTask *task,
   614     bool cleanupAndDeleteTask( 
QgsTask *task );
   627     void cancelDependentTasks( 
long taskId );
   629     bool resolveDependencies( 
long firstTaskId, 
long currentTaskId, QSet< long > &results ) 
const;
   632     bool hasCircularDependencies( 
long taskId ) 
const;
   634     friend class TestQgsTaskManager;
   637 #endif //QGSTASKMANAGER_H Base class for all map layer types. 
 
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. 
 
Subtask must complete before parent can begin. 
 
TaskStatus
Status of tasks. 
 
bool isCanceled() const
Will return true if task should terminate ASAP. 
 
SubTaskDependency
Controls how subtasks relate to their parent task. 
 
QgsTaskList dependentTasks
List of dependent tasks which must be completed before task can run. 
 
Task was terminated or errored. 
 
QString description() const
Returns the task's description. 
 
Definition of a task for inclusion in the manager. 
 
Task is queued but on hold and will not be started. 
 
Abstract base class for long running background tasks. 
 
bool canCancel() const
Returns true if the task can be canceled. 
 
Task successfully completed. 
 
Task manager for managing a set of long-running QgsTask tasks. 
 
Task is queued and has not begun. 
 
TaskDefinition(QgsTask *task, const QgsTaskList &dependentTasks=QgsTaskList())
Constructor for TaskDefinition. 
 
double progress() const
Returns the task's progress (between 0.0 and 100.0) 
 
Task is currently running. 
 
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers. 
 
virtual void finished(bool result)
If the task is managed by a QgsTaskManager, this will be called after the task has finished (whether ...
 
TaskStatus status() const
Returns the current task status. 
 
Flags flags() const
Returns the flags associated with the task.