Skip to content

Commit 7603487

Browse files
committedJan 16, 2018
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)
1 parent a3a999e commit 7603487

File tree

5 files changed

+54
-0
lines changed

5 files changed

+54
-0
lines changed
 

‎python/core/qgstaskmanager.sip

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,15 @@ Returns the number of active (queued or running) tasks.
419419
.. seealso:: :py:func:`activeTasks`
420420

421421
.. seealso:: :py:func:`countActiveTasksChanged`
422+
%End
423+
424+
public slots:
425+
426+
void trigger( QgsTask *task );
427+
%Docstring
428+
Triggers a task, e.g. as a result of a GUI interaction.
429+
430+
.. seealso:: :py:func:`triggered()`
422431
%End
423432

424433
signals:
@@ -473,6 +482,15 @@ Emitted when all tasks are complete
473482
Emitted when the number of active tasks changes
474483

475484
.. seealso:: :py:func:`countActiveTasks`
485+
%End
486+
487+
void triggered( QgsTask *task );
488+
%Docstring
489+
Emitted when a ``task`` is triggered. This occurs when a user clicks on
490+
the task from the QGIS GUI, and can be used to show detailed progress
491+
reports or re-open a related dialog.
492+
493+
.. seealso:: :py:func:`trigger()`
476494
%End
477495

478496
};

‎src/core/qgstaskmanager.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,12 @@ int QgsTaskManager::countActiveTasks() const
607607
return tasks.intersect( mParentTasks ).count();
608608
}
609609

610+
void QgsTaskManager::trigger( QgsTask *task )
611+
{
612+
if ( task )
613+
emit triggered( task );
614+
}
615+
610616
void QgsTaskManager::taskProgressChanged( double progress )
611617
{
612618
QgsTask *task = qobject_cast< QgsTask * >( sender() );

‎src/core/qgstaskmanager.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,14 @@ class CORE_EXPORT QgsTaskManager : public QObject
485485
*/
486486
int countActiveTasks() const;
487487

488+
public slots:
489+
490+
/**
491+
* Triggers a task, e.g. as a result of a GUI interaction.
492+
* \see triggered()
493+
*/
494+
void trigger( QgsTask *task );
495+
488496
signals:
489497

490498
/**
@@ -532,6 +540,14 @@ class CORE_EXPORT QgsTaskManager : public QObject
532540
*/
533541
void countActiveTasksChanged( int count );
534542

543+
/**
544+
* Emitted when a \a task is triggered. This occurs when a user clicks on
545+
* the task from the QGIS GUI, and can be used to show detailed progress
546+
* reports or re-open a related dialog.
547+
* \see trigger()
548+
*/
549+
void triggered( QgsTask *task );
550+
535551
private slots:
536552

537553
void taskProgressChanged( double progress );

‎src/gui/qgstaskmanagerwidget.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
QgsTaskManagerWidget::QgsTaskManagerWidget( QgsTaskManager *manager, QWidget *parent )
3535
: QWidget( parent )
36+
, mManager( manager )
3637
{
3738
Q_ASSERT( manager );
3839

@@ -54,6 +55,8 @@ QgsTaskManagerWidget::QgsTaskManagerWidget( QgsTaskManager *manager, QWidget *pa
5455
mTreeView->header()->setStretchLastSection( false );
5556
mTreeView->header()->setSectionResizeMode( QgsTaskManagerModel::Description, QHeaderView::Stretch );
5657

58+
connect( mTreeView, &QTreeView::clicked, this, &QgsTaskManagerWidget::clicked );
59+
5760
vLayout->addWidget( mTreeView );
5861

5962
setLayout( vLayout );
@@ -97,6 +100,15 @@ void QgsTaskManagerWidget::modelRowsInserted( const QModelIndex &, int start, in
97100
}
98101
}
99102

103+
void QgsTaskManagerWidget::clicked( const QModelIndex &index )
104+
{
105+
QgsTask *task = mModel->indexToTask( index );
106+
if ( !task )
107+
return;
108+
109+
mManager->trigger( task );
110+
}
111+
100112
///@cond PRIVATE
101113
//
102114
// QgsTaskManagerModel

‎src/gui/qgstaskmanagerwidget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ class GUI_EXPORT QgsTaskManagerWidget : public QWidget
5555
private slots:
5656

5757
void modelRowsInserted( const QModelIndex &index, int start, int end );
58+
void clicked( const QModelIndex &index );
5859

5960
private:
6061

62+
QgsTaskManager *mManager = nullptr;
6163
QTreeView *mTreeView = nullptr;
6264
QgsTaskManagerModel *mModel = nullptr;
6365
};

0 commit comments

Comments
 (0)
Please sign in to comment.