QGIS API Documentation 3.41.0-Master (d5b93354e9c)
Loading...
Searching...
No Matches
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
19#include "moc_qgsproxyprogresstask.cpp"
20#include "qgsapplication.h"
21#include <QThreadPool>
22
23QgsProxyProgressTask::QgsProxyProgressTask( const QString &description, bool canCancel )
24 : QgsTask( description, canCancel ? QgsTask::CanCancel : QgsTask::Flags() )
25{
26}
27
29{
30 const QMutexLocker lock( &mNotFinishedMutex );
31 mAlreadyFinished = true;
32
33 mResult = result;
34 mNotFinishedWaitCondition.wakeAll();
35}
36
38{
39 QgsApplication::taskManager()->threadPool()->releaseThread();
40 mNotFinishedMutex.lock();
41 if ( !mAlreadyFinished )
42 {
43 mNotFinishedWaitCondition.wait( &mNotFinishedMutex );
44 }
45 mNotFinishedMutex.unlock();
46
47 QgsApplication::taskManager()->threadPool()->reserveThread();
48 return mResult;
49}
50
52{
53 QMetaObject::invokeMethod( this, "setProgress", Qt::AutoConnection, Q_ARG( double, progress ) );
54}
55
57{
58 emit canceled();
59
61}
62
63//
64// QgsScopedProxyProgressTask
65//
66
68 : mTask( new QgsProxyProgressTask( description ) )
69{
71}
72
77
79{
80 mTask->setProxyProgress( progress );
81}
static QgsTaskManager * taskManager()
Returns the application's task manager, used for managing application wide background task handling.
A QgsTask shell which proxies progress reports.
void setProxyProgress(double progress)
Sets the progress (from 0 to 100) for the proxied operation.
void finalize(bool result)
Finalizes the task, with the specified result.
void canceled()
Emitted when the task is canceled.
void cancel() override
Notifies the task that it should terminate.
bool run() override
Performs the task's operation.
QgsProxyProgressTask(const QString &description, bool canCancel=false)
Constructor for QgsProxyProgressTask, with the specified description.
void setProgress(double progress)
Sets the progress (from 0 to 100) for the proxied operation.
QgsScopedProxyProgressTask(const QString &description)
Constructor for QgsScopedProxyProgressTask, with the specified description.
QThreadPool * threadPool()
Returns the threadpool utilized by the task manager.
long addTask(QgsTask *task, int priority=0)
Adds a task to the manager.
Abstract base class for long running background tasks.
double progress() const
Returns the task's progress (between 0.0 and 100.0)
QFlags< Flag > Flags
virtual void cancel()
Notifies the task that it should terminate.