Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a QgsTask subclass for proxying progress reports from a
blocking operation via task manager Allows use of the task manager progress reporting system from operations which are blocking (and cannot be made background tasks!), e.g. layout exporting, project loading.
- Loading branch information
1 parent
d8adad8
commit 21693bd
Showing
5 changed files
with
179 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/qgsproxyprogresstask.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
|
||
class QgsProxyProgressTask : QgsTask | ||
{ | ||
%Docstring | ||
|
||
A QgsTask shell which proxies progress reports. | ||
|
||
Simple task shell which runs until finalized and reports progress only. | ||
This is usually used to expose a blocking operation's progress via | ||
task manager. | ||
|
||
.. versionadded:: 3.4 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgsproxyprogresstask.h" | ||
%End | ||
public: | ||
|
||
QgsProxyProgressTask( const QString &description ); | ||
%Docstring | ||
Constructor for QgsProxyProgressTask, with the specified ``description``. | ||
%End | ||
|
||
void finalize( bool result ); | ||
%Docstring | ||
Finalizes the task, with the specified ``result``. | ||
|
||
This should be called when the operation being proxied has completed, | ||
to remove this proxy task from the task manager. | ||
%End | ||
|
||
virtual bool run(); | ||
|
||
|
||
void setProxyProgress( double progress ); | ||
%Docstring | ||
Sets the ``progress`` (from 0 to 100) for the proxied operation. | ||
|
||
This method is safe to call from the main thread. | ||
%End | ||
|
||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/qgsproxyprogresstask.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/*************************************************************************** | ||
qgsproxyprogresstask.cpp | ||
------------------------ | ||
begin : August 2018 | ||
copyright : (C) 2018 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsproxyprogresstask.h" | ||
|
||
QgsProxyProgressTask::QgsProxyProgressTask( const QString &description ) | ||
: QgsTask( description, QgsTask::Flags() ) | ||
{ | ||
} | ||
|
||
void QgsProxyProgressTask::finalize( bool result ) | ||
{ | ||
mResult = result; | ||
mNotFinishedWaitCondition.wakeAll(); | ||
} | ||
|
||
bool QgsProxyProgressTask::run() | ||
{ | ||
mNotFinishedMutex.lock(); | ||
mNotFinishedWaitCondition.wait( &mNotFinishedMutex ); | ||
mNotFinishedMutex.unlock(); | ||
|
||
return mResult; | ||
} | ||
|
||
void QgsProxyProgressTask::setProxyProgress( double progress ) | ||
{ | ||
QMetaObject::invokeMethod( this, "setProgress", Qt::AutoConnection, Q_ARG( double, progress ) ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/*************************************************************************** | ||
qgsproxyprogresstask.h | ||
---------------------- | ||
begin : August 2018 | ||
copyright : (C) 2018 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSPROXYPROGRESSTASK_H | ||
#define QGSPROXYPROGRESSTASK_H | ||
|
||
#include "qgsvectorlayer.h" | ||
#include "qgsvirtuallayerdefinition.h" | ||
#include "qgstaskmanager.h" | ||
|
||
/** | ||
* \ingroup core | ||
* | ||
* A QgsTask shell which proxies progress reports. | ||
* | ||
* Simple task shell which runs until finalized and reports progress only. | ||
* This is usually used to expose a blocking operation's progress via | ||
* task manager. | ||
* | ||
* \since QGIS 3.4 | ||
*/ | ||
class CORE_EXPORT QgsProxyProgressTask : public QgsTask | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
|
||
/** | ||
* Constructor for QgsProxyProgressTask, with the specified \a description. | ||
*/ | ||
QgsProxyProgressTask( const QString &description ); | ||
|
||
/** | ||
* Finalizes the task, with the specified \a result. | ||
* | ||
* This should be called when the operation being proxied has completed, | ||
* to remove this proxy task from the task manager. | ||
*/ | ||
void finalize( bool result ); | ||
|
||
bool run() override; | ||
|
||
/** | ||
* Sets the \a progress (from 0 to 100) for the proxied operation. | ||
* | ||
* This method is safe to call from the main thread. | ||
*/ | ||
void setProxyProgress( double progress ); | ||
|
||
private: | ||
|
||
QWaitCondition mNotFinishedWaitCondition; | ||
QMutex mNotFinishedMutex; | ||
bool mResult = true; | ||
|
||
}; | ||
|
||
#endif // QGSPROXYPROGRESSTASK_H |