@@ -61,14 +61,6 @@ class CORE_EXPORT QgsTask : public QObject
6161 Terminated, // !< Task was terminated or errored
6262 };
6363
64- // ! Result of running the task
65- enum TaskResult
66- {
67- ResultSuccess = 0 , // !< Task completed successfully
68- ResultFail, // !< Task was terminated within completion
69- ResultPending, // !< Task is still running
70- };
71-
7264 // ! Task flags
7365 enum Flag
7466 {
@@ -186,8 +178,8 @@ class CORE_EXPORT QgsTask : public QObject
186178 /* *
187179 * Will be emitted by task when its status changes.
188180 * @param status new task status
189- * @note derived classes should not emit this signal directly, instead they should call
190- * completed() or terminated()
181+ * @note derived classes should not emit this signal directly, it will automatically
182+ * be emitted
191183 */
192184 void statusChanged ( int status );
193185
@@ -200,17 +192,17 @@ class CORE_EXPORT QgsTask : public QObject
200192
201193 /* *
202194 * Will be emitted by task to indicate its successful completion.
203- * @note derived classes should not emit this signal directly, instead they should call
204- * completed()
195+ * @note derived classes should not emit this signal directly, it will automatically
196+ * be emitted
205197 */
206198 void taskCompleted ();
207199
208200 /* *
209201 * Will be emitted by task if it has terminated for any reason
210202 * other then completion (eg when a task has been cancelled or encountered
211203 * an internal error).
212- * @note derived classes should not emit this signal directly, instead they should call
213- * terminated()
204+ * @note derived classes should not emit this signal directly, it will automatically
205+ * be emitted
214206 */
215207 void taskTerminated ();
216208
@@ -221,21 +213,10 @@ class CORE_EXPORT QgsTask : public QObject
221213 * (ie via calling start() ), and subclasses should implement the operation they
222214 * wish to perform in the background within this method.
223215 *
224- * A task can return a ResultSuccess and ResultFail value to indicate that the
225- * task has finished and was either completed successfully or terminated before
226- * completion.
227- *
228- * Alternatively, tasks can also return the ResultPending value
229- * to indicate that the task is still operating and will manually report its
230- * completion by calling completed() or terminated(). This may be useful for
231- * tasks which rely on external events for completion, eg downloading a
232- * file. In this case Qt slots could be created which are connected to the
233- * download completion or termination and which call completed() or terminated()
234- * to indicate the task has finished operations.
235- * @see completed()
236- * @see terminated()
237- */
238- virtual TaskResult run () = 0;
216+ * A task must return a boolean value to indicate whether the
217+ * task was completed successfully or terminated before completion.
218+ */
219+ virtual bool run () = 0;
239220
240221 /* *
241222 * If the task is managed by a QgsTaskManager, this will be called after the
@@ -247,7 +228,7 @@ class CORE_EXPORT QgsTask : public QObject
247228 * for the duration of this method so tasks should avoid performing any
248229 * lengthy operations here.
249230 */
250- virtual void finished ( TaskResult result ) { Q_UNUSED ( result ); }
231+ virtual void finished ( bool result ) { Q_UNUSED ( result ); }
251232
252233 /* *
253234 * Will return true if task should terminate ASAP. If the task reports the CanCancel
@@ -256,29 +237,11 @@ class CORE_EXPORT QgsTask : public QObject
256237 */
257238 bool isCancelled () const { return mShouldTerminate ; }
258239
259- /* *
260- * Sets the task as completed. Calling this is only required for tasks which
261- * returned the ResultPending value as a result of run(). This should be called
262- * when the task is complete. Calling will automatically emit the statusChanged
263- * and taskCompleted signals.
264- */
265- void completed ();
266-
267- /* *
268- * Sets the task as terminated. Calling this is only required for tasks which
269- * returned the ResultPending value as a result of run().
270- * Should be called whenever the task ends for any reason other than successful
271- * completion. Calling will automatically emit the statusChanged and taskTerminated
272- * signals.
273- */
274- void terminated ();
275-
276240 protected slots:
277241
278242 /* *
279- * Sets the task's current progress. If task reports the CanReportProgress flag then
280- * the derived class should call this method whenever the task wants to update its
281- * progress. Calling will automatically emit the progressChanged signal.
243+ * Sets the task's current progress. The derived class should call this method whenever
244+ * the task wants to update its progress. Calling will automatically emit the progressChanged signal.
282245 * @param progress percent of progress, from 0.0 - 100.0
283246 */
284247 void setProgress ( double progress );
@@ -321,6 +284,16 @@ class CORE_EXPORT QgsTask : public QObject
321284 */
322285 void start ();
323286
287+ /* *
288+ * Called when the task has completed successfully.
289+ */
290+ void completed ();
291+
292+ /* *
293+ * Called when the task has failed, as either a result of an internal failure or via cancellation.
294+ */
295+ void terminated ();
296+
324297 void processSubTasksForCompletion ();
325298
326299 void processSubTasksForTermination ();
0 commit comments