Add method to 'trigger' QgsTasks

Triggering occurs when a task is clicked in the task manager
widget, and this can be used to e.g. open a dialog showing
detailed task progress (or reopen a closed dialog which started
the task)
This commit is contained in:
Nyall Dawson 2018-01-09 14:41:38 +10:00
parent a3a999e416
commit 7603487e6a
5 changed files with 54 additions and 0 deletions

View File

@ -419,6 +419,15 @@ Returns the number of active (queued or running) tasks.
.. seealso:: :py:func:`activeTasks`
.. seealso:: :py:func:`countActiveTasksChanged`
%End
public slots:
void trigger( QgsTask *task );
%Docstring
Triggers a task, e.g. as a result of a GUI interaction.
.. seealso:: :py:func:`triggered()`
%End
signals:
@ -473,6 +482,15 @@ Emitted when all tasks are complete
Emitted when the number of active tasks changes
.. seealso:: :py:func:`countActiveTasks`
%End
void triggered( 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:`trigger()`
%End
};

View File

@ -607,6 +607,12 @@ int QgsTaskManager::countActiveTasks() const
return tasks.intersect( mParentTasks ).count();
}
void QgsTaskManager::trigger( QgsTask *task )
{
if ( task )
emit triggered( task );
}
void QgsTaskManager::taskProgressChanged( double progress )
{
QgsTask *task = qobject_cast< QgsTask * >( sender() );

View File

@ -485,6 +485,14 @@ class CORE_EXPORT QgsTaskManager : public QObject
*/
int countActiveTasks() const;
public slots:
/**
* Triggers a task, e.g. as a result of a GUI interaction.
* \see triggered()
*/
void trigger( QgsTask *task );
signals:
/**
@ -532,6 +540,14 @@ class CORE_EXPORT QgsTaskManager : public QObject
*/
void countActiveTasksChanged( int count );
/**
* Emitted when a \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.
* \see trigger()
*/
void triggered( QgsTask *task );
private slots:
void taskProgressChanged( double progress );

View File

@ -33,6 +33,7 @@
QgsTaskManagerWidget::QgsTaskManagerWidget( QgsTaskManager *manager, QWidget *parent )
: QWidget( parent )
, mManager( manager )
{
Q_ASSERT( manager );
@ -54,6 +55,8 @@ QgsTaskManagerWidget::QgsTaskManagerWidget( QgsTaskManager *manager, QWidget *pa
mTreeView->header()->setStretchLastSection( false );
mTreeView->header()->setSectionResizeMode( QgsTaskManagerModel::Description, QHeaderView::Stretch );
connect( mTreeView, &QTreeView::clicked, this, &QgsTaskManagerWidget::clicked );
vLayout->addWidget( mTreeView );
setLayout( vLayout );
@ -97,6 +100,15 @@ void QgsTaskManagerWidget::modelRowsInserted( const QModelIndex &, int start, in
}
}
void QgsTaskManagerWidget::clicked( const QModelIndex &index )
{
QgsTask *task = mModel->indexToTask( index );
if ( !task )
return;
mManager->trigger( task );
}
///@cond PRIVATE
//
// QgsTaskManagerModel

View File

@ -55,9 +55,11 @@ class GUI_EXPORT QgsTaskManagerWidget : public QWidget
private slots:
void modelRowsInserted( const QModelIndex &index, int start, int end );
void clicked( const QModelIndex &index );
private:
QgsTaskManager *mManager = nullptr;
QTreeView *mTreeView = nullptr;
QgsTaskManagerModel *mModel = nullptr;
};