Add deleteAllTasks to manager

This commit is contained in:
Nyall Dawson 2016-05-28 18:48:28 +10:00
parent b64025df5c
commit 95dbb3a7e3
3 changed files with 24 additions and 1 deletions

View File

@ -187,6 +187,11 @@ class QgsTaskManager : QObject
*/
bool deleteTask( QgsTask* task );
/** Deletes all tasks in the manager, first terminating them if they are currently
* running.
*/
void deleteAllTasks();
/** Returns the task with matching ID.
* @param id task ID
* @returns task if found, or nullptr

View File

@ -184,7 +184,20 @@ bool QgsTaskManager::deleteTask( QgsTask *task )
return result;
}
QgsTask*QgsTaskManager::task( long id ) const
void QgsTaskManager::deleteAllTasks()
{
//first tell all tasks to cancel
cancelAll();
QMutexLocker ml( mTaskMutex );
Q_FOREACH ( QgsTask* task, tasks() )
{
deleteTask( task );
}
emit allTasksFinished();
}
QgsTask* QgsTaskManager::task( long id ) const
{
QMutexLocker ml( mTaskMutex );
return mTasks.value( id ).task;

View File

@ -218,6 +218,11 @@ class CORE_EXPORT QgsTaskManager : public QObject
*/
bool deleteTask( QgsTask* task );
/** Deletes all tasks in the manager, first terminating them if they are currently
* running.
*/
void deleteAllTasks();
/** Returns the task with matching ID.
* @param id task ID
* @returns task if found, or nullptr