@@ -47,9 +47,9 @@ class CORE_EXPORT QgsTask : public QObject
4747 // ! Task flags
4848 enum Flag
4949 {
50- CancelSupport = 1 << 1 , // !< Task can be cancelled
51- ProgressReport = 1 << 2 , // !< Task will report its progress
52- AllFlags = CancelSupport | ProgressReport , // !< Task supports all flags
50+ CanCancel = 1 << 1 , // !< Task can be cancelled
51+ CanReportProgress = 1 << 2 , // !< Task will report its progress
52+ AllFlags = CanCancel | CanReportProgress , // !< Task supports all flags
5353 };
5454 Q_DECLARE_FLAGS ( Flags, Flag )
5555
@@ -62,15 +62,8 @@ class CORE_EXPORT QgsTask : public QObject
6262 // ! Returns the flags associated with the task.
6363 Flags flags () const { return mFlags ; }
6464
65- // ! Starts the task.
66- void start ();
67-
68- // ! Notifies the task that it should terminate.
69- // ! @see isCancelled()
70- void cancel ();
71-
7265 // ! Returns true if the task can be cancelled.
73- bool canCancel () const { return mFlags & CancelSupport ; }
66+ bool canCancel () const { return mFlags & CanCancel ; }
7467
7568 // ! Returns true if the task is active, ie it is not complete and has
7669 // ! not been cancelled.
@@ -85,6 +78,30 @@ class CORE_EXPORT QgsTask : public QObject
8578 // ! Returns the task's progress (between 0.0 and 100.0)
8679 double progress () const { return mProgress ; }
8780
81+ public slots:
82+
83+ // ! Starts the task.
84+ void start ();
85+
86+ // ! Notifies the task that it should terminate.
87+ // ! @see isCancelled()
88+ void cancel ();
89+
90+ // ! Sets the task's current progress. If task reports the CanReportProgress flag then
91+ // ! the derived class should call this method whenever the task wants to update its
92+ // ! progress. Calling will automatically emit the progressChanged signal.
93+ // ! @param progress percent of progress, from 0.0 - 100.0
94+ void setProgress ( double progress );
95+
96+ // ! Sets the task as completed. Should be called when the task is complete.
97+ // ! Calling will automatically emit the statusChanged and taskCompleted signals.
98+ void completed ();
99+
100+ // ! Sets the task as stopped. Should be called whenever the task ends for any
101+ // ! reason other than successful completion.
102+ // ! Calling will automatically emit the statusChanged and taskStopped signals.
103+ void stopped ();
104+
88105 signals:
89106
90107 // ! Will be emitted by task when its progress changes
@@ -115,31 +132,15 @@ class CORE_EXPORT QgsTask : public QObject
115132 // ! stopped()//!
116133 void taskStopped ();
117134
118- public slots:
119-
120- // ! Sets the task's current progress. Should be called whenever the
121- // ! task wants to update it's progress. Calling will automatically emit the progressChanged
122- // ! signal.
123- // ! @param progress percent of progress, from 0.0 - 100.0
124- void setProgress ( double progress );
125-
126- // ! Sets the task as completed. Should be called when the task is complete.
127- // ! Calling will automatically emit the statusChanged and taskCompleted signals.
128- void completed ();
129-
130- // ! Sets the task as stopped. Should be called whenever the task ends for any
131- // ! reason other than successful completion.
132- // ! Calling will automatically emit the statusChanged and taskStopped signals.
133- void stopped ();
134-
135135 protected:
136136
137137 // ! Derived tasks must implement a run() method. This method will be called when the
138138 // ! task commences (ie via calling start() ).
139139 virtual void run () = 0;
140140
141- // ! Will return true if task should terminate ASAP. Derived classes run() methods
142- // ! should periodically check this and terminate in a safe manner.
141+ // ! Will return true if task should terminate ASAP. If the task reports the CanCancel
142+ // ! flag, then derived classes' run() methods should periodically check this and
143+ // ! terminate in a safe manner.
143144 bool isCancelled () const { return mShouldTerminate ; }
144145
145146 private:
0 commit comments