QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 #include "qgsapplication.h"
20 
21 QgsProxyProgressTask::QgsProxyProgressTask( const QString &description, bool canCancel )
22  : QgsTask( description, canCancel ? QgsTask::CanCancel : QgsTask::Flags() )
23 {
24 }
25 
26 void QgsProxyProgressTask::finalize( bool result )
27 {
28  const QMutexLocker lock( &mNotFinishedMutex );
29  mAlreadyFinished = true;
30 
31  mResult = result;
32  mNotFinishedWaitCondition.wakeAll();
33 }
34 
36 {
37  mNotFinishedMutex.lock();
38  if ( !mAlreadyFinished )
39  {
40  mNotFinishedWaitCondition.wait( &mNotFinishedMutex );
41  }
42  mNotFinishedMutex.unlock();
43 
44  return mResult;
45 }
46 
48 {
49  QMetaObject::invokeMethod( this, "setProgress", Qt::AutoConnection, Q_ARG( double, progress ) );
50 }
51 
53 {
54  emit canceled();
55 
57 }
58 
59 //
60 // QgsScopedProxyProgressTask
61 //
62 
64  : mTask( new QgsProxyProgressTask( description ) )
65 {
67 }
68 
70 {
71  mTask->finalize( true );
72 }
73 
75 {
76  mTask->setProxyProgress( progress );
77 }
QgsProxyProgressTask::run
bool run() override
Performs the task's operation.
Definition: qgsproxyprogresstask.cpp:35
qgsproxyprogresstask.h
QgsProxyProgressTask::QgsProxyProgressTask
QgsProxyProgressTask(const QString &description, bool canCancel=false)
Constructor for QgsProxyProgressTask, with the specified description.
Definition: qgsproxyprogresstask.cpp:21
QgsProxyProgressTask
A QgsTask shell which proxies progress reports.
Definition: qgsproxyprogresstask.h:37
QgsTaskManager::addTask
long addTask(QgsTask *task, int priority=0)
Adds a task to the manager.
Definition: qgstaskmanager.cpp:420
qgsapplication.h
QgsTask::cancel
virtual void cancel()
Notifies the task that it should terminate.
Definition: qgstaskmanager.cpp:91
QgsScopedProxyProgressTask::~QgsScopedProxyProgressTask
~QgsScopedProxyProgressTask()
Definition: qgsproxyprogresstask.cpp:69
QgsApplication::taskManager
static QgsTaskManager * taskManager()
Returns the application's task manager, used for managing application wide background task handling.
Definition: qgsapplication.cpp:2300
QgsProxyProgressTask::canceled
void canceled()
Emitted when the task is canceled.
QgsProxyProgressTask::cancel
void cancel() override
Notifies the task that it should terminate.
Definition: qgsproxyprogresstask.cpp:52
QgsScopedProxyProgressTask::setProgress
void setProgress(double progress)
Sets the progress (from 0 to 100) for the proxied operation.
Definition: qgsproxyprogresstask.cpp:74
QgsScopedProxyProgressTask::QgsScopedProxyProgressTask
QgsScopedProxyProgressTask(const QString &description)
Constructor for QgsScopedProxyProgressTask, with the specified description.
Definition: qgsproxyprogresstask.cpp:63
QgsProxyProgressTask::finalize
void finalize(bool result)
Finalizes the task, with the specified result.
Definition: qgsproxyprogresstask.cpp:26
QgsProxyProgressTask::setProxyProgress
void setProxyProgress(double progress)
Sets the progress (from 0 to 100) for the proxied operation.
Definition: qgsproxyprogresstask.cpp:47
QgsTask::progress
double progress() const
Returns the task's progress (between 0.0 and 100.0)
Definition: qgstaskmanager.h:127
QgsTask
Abstract base class for long running background tasks. Tasks can be controlled directly,...
Definition: qgstaskmanager.h:54