QGIS API Documentation  3.4.15-Madeira (e83d02e274)
qgsproxyprogresstask.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsproxyprogresstask.cpp
3  ------------------------
4  begin : August 2018
5  copyright : (C) 2018 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "qgsproxyprogresstask.h"
19 
20 QgsProxyProgressTask::QgsProxyProgressTask( const QString &description )
21  : QgsTask( description, QgsTask::Flags() )
22 {
23 }
24 
25 void QgsProxyProgressTask::finalize( bool result )
26 {
27  QMutexLocker lock( &mNotFinishedMutex );
28  mAlreadyFinished = true;
29 
30  mResult = result;
31  mNotFinishedWaitCondition.wakeAll();
32 }
33 
35 {
36  mNotFinishedMutex.lock();
37  if ( !mAlreadyFinished )
38  {
39  mNotFinishedWaitCondition.wait( &mNotFinishedMutex );
40  }
41  mNotFinishedMutex.unlock();
42 
43  return mResult;
44 }
45 
47 {
48  QMetaObject::invokeMethod( this, "setProgress", Qt::AutoConnection, Q_ARG( double, progress ) );
49 }
50 
51 //
52 // QgsScopedProxyProgressTask
53 //
54 
56  : mTask( new QgsProxyProgressTask( description ) )
57 {
59 }
60 
62 {
63  mTask->finalize( true );
64 }
65 
67 {
68  mTask->setProxyProgress( progress );
69 }
double progress() const
Returns the task's progress (between 0.0 and 100.0)
void setProxyProgress(double progress)
Sets the progress (from 0 to 100) for the proxied operation.
static QgsTaskManager * taskManager()
Returns the application's task manager, used for managing application wide background task handling...
long addTask(QgsTask *task, int priority=0)
Adds a task to the manager.
Abstract base class for long running background tasks.
bool run() override
Performs the task's operation.
QString description() const
Returns the task's description.
void setProgress(double progress)
Sets the progress (from 0 to 100) for the proxied operation.
QgsProxyProgressTask(const QString &description)
Constructor for QgsProxyProgressTask, with the specified description.
QgsScopedProxyProgressTask(const QString &description)
Constructor for QgsScopedProxyProgressTask, with the specified description.
A QgsTask shell which proxies progress reports.
void finalize(bool result)
Finalizes the task, with the specified result.