Skip to content
Permalink
Browse files

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)
  • Loading branch information
nyalldawson committed Jan 9, 2018
1 parent a3a999e commit 7603487e6ad7a2851aabd6d4f56ef681e231c2fe
@@ -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

};
@@ -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() );
@@ -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 );
@@ -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
@@ -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;
};

0 comments on commit 7603487

Please sign in to comment.
You can’t perform that action at this time.