QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
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 
45 class CORE_EXPORT QgsFeedback : public QObject
46 {
47  Q_OBJECT
48  public:
50  QgsFeedback( QObject *parent SIP_TRANSFERTHIS = nullptr )
51  : QObject( parent )
52  {}
53 
55  bool isCanceled() const { return mCanceled; }
56 
64  void setProgress( double progress )
65  {
66  // avoid flooding with too many events
67  if ( static_cast< int >( mProgress * 10 ) != static_cast< int >( progress * 10 ) )
68  emit progressChanged( progress );
69 
70  mProgress = progress;
71  }
72 
81  double progress() const { return mProgress; }
82 
83  public slots:
84 
86  void cancel()
87  {
88  if ( mCanceled )
89  return; // only emit the signal once
90  mCanceled = true;
91  emit canceled();
92  }
93 
94  signals:
96  void canceled();
97 
106  void progressChanged( double progress );
107 
108  private:
110  bool mCanceled = false;
111 
112  double mProgress = 0.0;
113 };
114 
115 #endif // QGSFEEDBACK_H
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
void cancel()
Tells the internal routines that the current operation should be canceled. This should be run by the ...
Definition: qgsfeedback.h:86
double progress() const
Returns the current progress reported by the feedback object.
Definition: qgsfeedback.h:81
void setProgress(double progress)
Sets the current progress for the feedback object.
Definition: qgsfeedback.h:64
Base class for feedback objects to be used for cancellation of something running in a worker thread...
Definition: qgsfeedback.h:45
bool isCanceled() const
Tells whether the operation has been canceled already.
Definition: qgsfeedback.h:55
QgsFeedback(QObject *parent=nullptr)
Construct a feedback object.
Definition: qgsfeedback.h:50