QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
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 <QObject>
20
21#include "qgis_core.h"
22#include "qgis_sip.h"
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
53 bool isCanceled() const SIP_HOLDGIL { return mCanceled; }
54
61 void setProgress( double progress )
62 {
63 // avoid flooding with too many events
64 if ( static_cast< int >( mProgress * 10 ) != static_cast< int >( progress * 10 ) )
65 emit progressChanged( progress );
66
67 mProgress = progress;
68 }
69
77 double progress() const SIP_HOLDGIL { return mProgress; }
78
87 unsigned long long processedCount() const SIP_HOLDGIL { return mProcessedCount; }
88
96 void setProcessedCount( unsigned long long processedCount )
97 {
98 mProcessedCount = processedCount;
99 emit processedCountChanged( processedCount );
100 }
101
102 public slots:
103
105 void cancel()
106 {
107 if ( mCanceled )
108 return; // only emit the signal once
109 mCanceled = true;
110 emit canceled();
111 }
112
113 signals:
115 void canceled();
116
124 void progressChanged( double progress );
125
134 void processedCountChanged( unsigned long long processedCount );
135
136 private:
138 bool mCanceled = false;
139
140 double mProgress = 0.0;
141 unsigned long long mProcessedCount = 0;
142};
143
144
145#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:53
void setProcessedCount(unsigned long long processedCount)
Sets the current processed objects count for the feedback object.
Definition qgsfeedback.h:96
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:87
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:61
double progress() const
Returns the current progress reported by the feedback object.
Definition qgsfeedback.h:77
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_HOLDGIL
Definition qgis_sip.h:171