mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
Add QgsTask::waitForFinished
This commit is contained in:
parent
05a713f444
commit
1f041884bb
@ -142,6 +142,27 @@ QList<QgsMapLayer *> QgsTask::dependentLayers() const
|
||||
return _qgis_listQPointerToRaw( mDependentLayers );
|
||||
}
|
||||
|
||||
bool QgsTask::waitForFinished( int timeout )
|
||||
{
|
||||
QEventLoop loop;
|
||||
bool rv = true;
|
||||
|
||||
connect( this, &QgsTask::taskCompleted, &loop, &QEventLoop::quit );
|
||||
connect( this, &QgsTask::taskTerminated, &loop, &QEventLoop::quit );
|
||||
QTimer timer;
|
||||
|
||||
if ( timeout != -1 )
|
||||
{
|
||||
timer.start( timeout );
|
||||
connect( &timer, &QTimer::timeout, [&rv]() { rv = false; } );
|
||||
connect( &timer, &QTimer::timeout, &loop, &QEventLoop::quit );
|
||||
}
|
||||
|
||||
loop.exec();
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
void QgsTask::setDependentLayers( const QList< QgsMapLayer * > &dependentLayers )
|
||||
{
|
||||
mDependentLayers = _qgis_listRawToQPointer( dependentLayers );
|
||||
|
@ -186,6 +186,14 @@ class CORE_EXPORT QgsTask : public QObject
|
||||
*/
|
||||
QList< QgsMapLayer * > dependentLayers() const;
|
||||
|
||||
/**
|
||||
* Blocks the current thread until the task finishes or a maximum of \a timeout milliseconds.
|
||||
* If the \a timeout is ``-1`` the thread will be blocked forever.
|
||||
*
|
||||
* The result will be false if the wait timed out and true in any other case.
|
||||
*/
|
||||
bool waitForFinished( int timeout = 30000 );
|
||||
|
||||
signals:
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user