QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
qgsfeedback.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsfeedback.h
3 --------------------------------------
4 Date : July 2016
5 Copyright : (C) 2016 by Martin Dobias
6 Email : wonder dot sk at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSFEEDBACK_H
17#define QGSFEEDBACK_H
18
19#include <QObject>
20
21#include "qgis_core.h"
22#include "qgis_sip.h"
23
44class CORE_EXPORT QgsFeedback : public QObject
45{
46 Q_OBJECT
47 public:
49 QgsFeedback( QObject *parent SIP_TRANSFERTHIS = nullptr )
50 : QObject( parent )
51 {}
52
54 bool isCanceled() const SIP_HOLDGIL { return mCanceled; }
55
63 void setProgress( double progress )
64 {
65 // avoid flooding with too many events
66 if ( static_cast< int >( mProgress * 10 ) != static_cast< int >( progress * 10 ) )
67 emit progressChanged( progress );
68
69 mProgress = progress;
70 }
71
80 double progress() const SIP_HOLDGIL { return mProgress; }
81
90 unsigned long long processedCount() const SIP_HOLDGIL { return mProcessedCount; }
91
99 void setProcessedCount( unsigned long long processedCount )
100 {
101 mProcessedCount = processedCount;
102 emit processedCountChanged( processedCount );
103 }
104
105 public slots:
106
108 void cancel()
109 {
110 if ( mCanceled )
111 return; // only emit the signal once
112 mCanceled = true;
113 emit canceled();
114 }
115
116 signals:
118 void canceled();
119
128 void progressChanged( double progress );
129
138 void processedCountChanged( unsigned long long processedCount );
139
140 private:
142 bool mCanceled = false;
143
144 double mProgress = 0.0;
145 unsigned long long mProcessedCount = 0;
146};
147
148
149#endif // QGSFEEDBACK_H
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:45
void setProcessedCount(unsigned long long processedCount)
Sets the current processed objects count for the feedback object.
Definition: qgsfeedback.h:99
void progressChanged(double progress)
Emitted when the feedback object reports a progress change.
void canceled()
Internal routines can connect to this signal if they use event loop.
QgsFeedback(QObject *parent=nullptr)
Construct a feedback object.
Definition: qgsfeedback.h:49
void processedCountChanged(unsigned long long processedCount)
Emitted when the feedback object reports a change in the number of processed objects.
double progress() const SIP_HOLDGIL
Returns the current progress reported by the feedback object.
Definition: qgsfeedback.h:80
void cancel()
Tells the internal routines that the current operation should be canceled. This should be run by the ...
Definition: qgsfeedback.h:108
bool isCanceled() const SIP_HOLDGIL
Tells whether the operation has been canceled already.
Definition: qgsfeedback.h:54
void setProgress(double progress)
Sets the current progress for the feedback object.
Definition: qgsfeedback.h:63
unsigned long long processedCount() const SIP_HOLDGIL
Returns the current processed objects count reported by the feedback object.
Definition: qgsfeedback.h:90
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_HOLDGIL
Definition: qgis_sip.h:166