QGIS API Documentation
4.3.0-Master (52aa6503bed)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
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
#include "
qgsapplication.h
"
21
22
#include <QThreadPool>
23
24
#include "moc_qgsproxyprogresstask.cpp"
25
26
QgsProxyProgressTask::QgsProxyProgressTask
(
const
QString &
description
,
bool
canCancel
)
27
:
QgsTask
(
description
,
canCancel
?
QgsTask
::
CanCancel
:
QgsTask
::
Flags
() )
28
{}
29
30
void
QgsProxyProgressTask::finalize
(
bool
result )
31
{
32
const
QMutexLocker lock( &mNotFinishedMutex );
33
mAlreadyFinished =
true
;
34
35
mResult = result;
36
mNotFinishedWaitCondition.wakeAll();
37
}
38
39
bool
QgsProxyProgressTask::run
()
40
{
41
QgsApplication::taskManager
()->
threadPool
()->releaseThread();
42
mNotFinishedMutex.lock();
43
if
( !mAlreadyFinished )
44
{
45
mNotFinishedWaitCondition.wait( &mNotFinishedMutex );
46
}
47
mNotFinishedMutex.unlock();
48
49
QgsApplication::taskManager
()->
threadPool
()->reserveThread();
50
return
mResult;
51
}
52
53
void
QgsProxyProgressTask::setProxyProgress
(
double
progress
)
54
{
55
QMetaObject::invokeMethod(
this
,
"setProgress"
, Qt::AutoConnection, Q_ARG(
double
,
progress
) );
56
}
57
58
void
QgsProxyProgressTask::cancel
()
59
{
60
emit
canceled
();
61
62
QgsTask::cancel
();
63
}
64
65
//
66
// QgsScopedProxyProgressTask
67
//
68
69
QgsScopedProxyProgressTask::QgsScopedProxyProgressTask
(
const
QString &description )
70
: mTask( new
QgsProxyProgressTask
( description ) )
71
{
72
QgsApplication::taskManager
()->
addTask
( mTask );
73
}
74
75
QgsScopedProxyProgressTask::~QgsScopedProxyProgressTask
()
76
{
77
mTask->finalize(
true
);
78
}
79
80
void
QgsScopedProxyProgressTask::setProgress
(
double
progress )
81
{
82
mTask->setProxyProgress( progress );
83
}
QgsApplication::taskManager
static QgsTaskManager * taskManager()
Returns the application's task manager, used for managing application wide background task handling.
Definition
qgsapplication.cpp:2544
QgsProxyProgressTask
A QgsTask shell which proxies progress reports.
Definition
qgsproxyprogresstask.h:38
QgsProxyProgressTask::setProxyProgress
void setProxyProgress(double progress)
Sets the progress (from 0 to 100) for the proxied operation.
Definition
qgsproxyprogresstask.cpp:53
QgsProxyProgressTask::finalize
void finalize(bool result)
Finalizes the task, with the specified result.
Definition
qgsproxyprogresstask.cpp:30
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:58
QgsProxyProgressTask::run
bool run() override
Performs the task's operation.
Definition
qgsproxyprogresstask.cpp:39
QgsProxyProgressTask::QgsProxyProgressTask
QgsProxyProgressTask(const QString &description, bool canCancel=false)
Constructor for QgsProxyProgressTask, with the specified description.
Definition
qgsproxyprogresstask.cpp:26
QgsScopedProxyProgressTask::setProgress
void setProgress(double progress)
Sets the progress (from 0 to 100) for the proxied operation.
Definition
qgsproxyprogresstask.cpp:80
QgsScopedProxyProgressTask::~QgsScopedProxyProgressTask
~QgsScopedProxyProgressTask()
Definition
qgsproxyprogresstask.cpp:75
QgsScopedProxyProgressTask::QgsScopedProxyProgressTask
QgsScopedProxyProgressTask(const QString &description)
Constructor for QgsScopedProxyProgressTask, with the specified description.
Definition
qgsproxyprogresstask.cpp:69
QgsTaskManager::threadPool
QThreadPool * threadPool()
Returns the threadpool utilized by the task manager.
Definition
qgstaskmanager.cpp:419
QgsTaskManager::addTask
long addTask(QgsTask *task, int priority=0)
Adds a task to the manager.
Definition
qgstaskmanager.cpp:424
QgsTask::progress
double progress() const
Returns the task's progress (between 0.0 and 100.0).
Definition
qgstaskmanager.h:126
QgsTask::Flags
QFlags< Flag > Flags
Definition
qgstaskmanager.h:79
QgsTask::cancel
virtual void cancel()
Notifies the task that it should terminate.
Definition
qgstaskmanager.cpp:98
QgsTask::QgsTask
QgsTask(const QString &description=QString(), QgsTask::Flags flags=AllFlags)
Constructor for QgsTask.
Definition
qgstaskmanager.cpp:36
QgsTask::CanCancel
@ CanCancel
Task can be canceled.
Definition
qgstaskmanager.h:73
QgsTask::description
QString description() const
Returns the task's description.
Definition
qgstaskmanager.h:121
QgsTask::canCancel
bool canCancel() const
Returns true if the task can be canceled.
Definition
qgstaskmanager.h:105
qgsapplication.h
qgsproxyprogresstask.h
Generated on
for QGIS API Documentation by
1.17.0