QGIS API Documentation 3.99.0-Master (a8882ad4560)
Loading...
Searching...
No Matches
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 "qgis_core.h"
20#include "qgis_sip.h"
21
22#include <QObject>
23
43class CORE_EXPORT QgsFeedback : public QObject
44{
45 Q_OBJECT
46 public:
48 QgsFeedback( QObject *parent SIP_TRANSFERTHIS = nullptr )
49 : QObject( parent )
50 {}
51
52 ~QgsFeedback() override;
53
55 bool isCanceled() const SIP_HOLDGIL { return mCanceled; }
56
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 ) )
68
69 mProgress = progress;
70 }
71
79 double progress() const SIP_HOLDGIL { return mProgress; }
80
89 unsigned long long processedCount() const SIP_HOLDGIL { return mProcessedCount; }
90
98 void setProcessedCount( unsigned long long processedCount )
99 {
100 mProcessedCount = processedCount;
102 }
103
115 static std::unique_ptr<QgsFeedback> createScaledFeedback(
116 QgsFeedback *parentFeedback, double startPercentage, double endPercentage );
117
118 public slots:
119
121 void cancel()
122 {
123 if ( mCanceled )
124 return; // only emit the signal once
125 mCanceled = true;
126 emit canceled();
127 }
128
129 signals:
131 void canceled();
132
140 void progressChanged( double progress );
141
150 void processedCountChanged( unsigned long long processedCount );
151
152 private:
154 bool mCanceled = false;
155
156 double mProgress = 0.0;
157 unsigned long long mProcessedCount = 0;
158};
159
160
161#endif // QGSFEEDBACK_H
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
bool isCanceled() const
Tells whether the operation has been canceled already.
Definition qgsfeedback.h:55
void setProcessedCount(unsigned long long processedCount)
Sets the current processed objects count for the feedback object.
Definition qgsfeedback.h:98
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:48
unsigned long long processedCount() const
Returns the current processed objects count reported by the feedback object.
Definition qgsfeedback.h:89
void processedCountChanged(unsigned long long processedCount)
Emitted when the feedback object reports a change in the number of processed objects.
void cancel()
Tells the internal routines that the current operation should be canceled. This should be run by the ...
void setProgress(double progress)
Sets the current progress for the feedback object.
Definition qgsfeedback.h:63
double progress() const
Returns the current progress reported by the feedback object.
Definition qgsfeedback.h:79
~QgsFeedback() override
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_HOLDGIL
Definition qgis_sip.h:179