Skip to content

Commit

Permalink
Add method to 'trigger' QgsTasks
Browse files Browse the repository at this point in the history
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 16, 2018
1 parent a3a999e commit 7603487
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 0 deletions.
18 changes: 18 additions & 0 deletions python/core/qgstaskmanager.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

};
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgstaskmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand Down
16 changes: 16 additions & 0 deletions src/core/qgstaskmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:

/**
Expand Down Expand Up @@ -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 );
Expand Down
12 changes: 12 additions & 0 deletions src/gui/qgstaskmanagerwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

QgsTaskManagerWidget::QgsTaskManagerWidget( QgsTaskManager *manager, QWidget *parent )
: QWidget( parent )
, mManager( manager )
{
Q_ASSERT( manager );

Expand All @@ -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 );
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgstaskmanagerwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit 7603487

Please sign in to comment.