QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
43 class 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 { return mCanceled; }
54 
62  void setProgress( double progress )
63  {
64  // avoid flooding with too many events
65  if ( static_cast< int >( mProgress * 10 ) != static_cast< int >( progress * 10 ) )
66  emit progressChanged( progress );
67 
68  mProgress = progress;
69  }
70 
79  double progress() const { return mProgress; }
80 
81  public slots:
82 
84  void cancel()
85  {
86  if ( mCanceled )
87  return; // only emit the signal once
88  mCanceled = true;
89  emit canceled();
90  }
91 
92  signals:
94  void canceled();
95 
104  void progressChanged( double progress );
105 
106  private:
108  bool mCanceled = false;
109 
110  double mProgress = 0.0;
111 };
112 
113 #endif // QGSFEEDBACK_H
QgsFeedback
Definition: qgsfeedback.h:43
qgis_sip.h
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53