@@ -47,9 +47,9 @@ class CORE_EXPORT QgsTask : public QObject
47
47
// ! Task flags
48
48
enum Flag
49
49
{
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
53
53
};
54
54
Q_DECLARE_FLAGS ( Flags, Flag )
55
55
@@ -62,15 +62,8 @@ class CORE_EXPORT QgsTask : public QObject
62
62
// ! Returns the flags associated with the task.
63
63
Flags flags () const { return mFlags ; }
64
64
65
- // ! Starts the task.
66
- void start ();
67
-
68
- // ! Notifies the task that it should terminate.
69
- // ! @see isCancelled()
70
- void cancel ();
71
-
72
65
// ! Returns true if the task can be cancelled.
73
- bool canCancel () const { return mFlags & CancelSupport ; }
66
+ bool canCancel () const { return mFlags & CanCancel ; }
74
67
75
68
// ! Returns true if the task is active, ie it is not complete and has
76
69
// ! not been cancelled.
@@ -85,6 +78,30 @@ class CORE_EXPORT QgsTask : public QObject
85
78
// ! Returns the task's progress (between 0.0 and 100.0)
86
79
double progress () const { return mProgress ; }
87
80
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
+
88
105
signals:
89
106
90
107
// ! Will be emitted by task when its progress changes
@@ -115,31 +132,15 @@ class CORE_EXPORT QgsTask : public QObject
115
132
// ! stopped()//!
116
133
void taskStopped ();
117
134
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
-
135
135
protected:
136
136
137
137
// ! Derived tasks must implement a run() method. This method will be called when the
138
138
// ! task commences (ie via calling start() ).
139
139
virtual void run () = 0;
140
140
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.
143
144
bool isCancelled () const { return mShouldTerminate ; }
144
145
145
146
private:
0 commit comments