Skip to content

Commit cf5eeb7

Browse files
committedDec 5, 2016
API cleanups
1 parent 5d46892 commit cf5eeb7

File tree

3 files changed

+67
-65
lines changed

3 files changed

+67
-65
lines changed
 

‎python/core/qgstaskmanager.sip

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class QgsTask : QObject
2323
//! Task flags
2424
enum Flag
2525
{
26-
CancelSupport, //!< Task can be cancelled
27-
ProgressReport, //!< Task will report its progress
26+
CanCancel, //!< Task can be cancelled
27+
CanReportProgress, //!< Task will report its progress
2828
AllFlags, //!< Task supports all flags
2929
};
3030
typedef QFlags<QgsTask::Flag> Flags;
@@ -38,13 +38,6 @@ class QgsTask : QObject
3838
//! Returns the flags associated with the task.
3939
Flags flags() const;
4040

41-
//! Starts the task.
42-
void start();
43-
44-
//! Notifies the task that it should terminate.
45-
//! @see isCancelled()
46-
void cancel();
47-
4841
//! Returns true if the task can be cancelled.
4942
bool canCancel() const;
5043

@@ -61,6 +54,30 @@ class QgsTask : QObject
6154
//! Returns the task's progress (between 0.0 and 100.0)
6255
double progress() const;
6356

57+
public slots:
58+
59+
//! Starts the task.
60+
void start();
61+
62+
//! Notifies the task that it should terminate.
63+
//! @see isCancelled()
64+
void cancel();
65+
66+
//! Sets the task's current progress. If task reports the CanReportProgress flag then
67+
//! the derived class should call this method whenever the task wants to update its
68+
//! progress. Calling will automatically emit the progressChanged signal.
69+
//! @param progress percent of progress, from 0.0 - 100.0
70+
void setProgress( double progress );
71+
72+
//! Sets the task as completed. Should be called when the task is complete.
73+
//! Calling will automatically emit the statusChanged and taskCompleted signals.
74+
void completed();
75+
76+
//! Sets the task as stopped. Should be called whenever the task ends for any
77+
//! reason other than successful completion.
78+
//! Calling will automatically emit the statusChanged and taskStopped signals.
79+
void stopped();
80+
6481
signals:
6582

6683
//! Will be emitted by task when its progress changes
@@ -91,31 +108,15 @@ class QgsTask : QObject
91108
//! stopped()//!
92109
void taskStopped();
93110

94-
public slots:
95-
96-
//! Sets the task's current progress. Should be called whenever the
97-
//! task wants to update it's progress. Calling will automatically emit the progressChanged
98-
//! signal.
99-
//! @param progress percent of progress, from 0.0 - 100.0
100-
void setProgress( double progress );
101-
102-
//! Sets the task as completed. Should be called when the task is complete.
103-
//! Calling will automatically emit the statusChanged and taskCompleted signals.
104-
void completed();
105-
106-
//! Sets the task as stopped. Should be called whenever the task ends for any
107-
//! reason other than successful completion.
108-
//! Calling will automatically emit the statusChanged and taskStopped signals.
109-
void stopped();
110-
111111
protected:
112112

113113
//! Derived tasks must implement a run() method. This method will be called when the
114114
//! task commences (ie via calling start() ).
115115
virtual void run() = 0;
116116

117-
//! Will return true if task should terminate ASAP. Derived classes run() methods
118-
//! should periodically check this and terminate in a safe manner.
117+
//! Will return true if task should terminate ASAP. If the task reports the CanCancel
118+
//! flag, then derived classes' run() methods should periodically check this and
119+
//! terminate in a safe manner.
119120
bool isCancelled() const;
120121

121122
};

‎src/core/qgstaskmanager.h

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -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:

‎tests/src/core/testqgstaskmanager.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void TestQgsTaskManager::task()
116116
QCOMPARE( task->description(), QString( "desc" ) );
117117
QVERIFY( !task->isActive() );
118118
QVERIFY( task->canCancel() );
119-
QVERIFY( task->flags() & QgsTask::ProgressReport );
119+
QVERIFY( task->flags() & QgsTask::CanReportProgress );
120120

121121
QSignalSpy startedSpy( task.data(), SIGNAL( begun() ) );
122122
QSignalSpy statusSpy( task.data(), SIGNAL( statusChanged( int ) ) );
@@ -150,14 +150,14 @@ void TestQgsTaskManager::task()
150150
QCOMPARE( static_cast< QgsTask::TaskStatus >( statusSpy2.last().at( 0 ).toInt() ), QgsTask::Complete );
151151

152152
// test flags
153-
task.reset( new TestTask( "desc", QgsTask::ProgressReport ) );
153+
task.reset( new TestTask( "desc", QgsTask::CanReportProgress ) );
154154
QVERIFY( !task->canCancel() );
155-
QVERIFY( task->flags() & QgsTask::ProgressReport );
156-
QVERIFY( !( task->flags() & QgsTask::CancelSupport ) );
157-
task.reset( new TestTask( "desc", QgsTask::CancelSupport ) );
155+
QVERIFY( task->flags() & QgsTask::CanReportProgress );
156+
QVERIFY( !( task->flags() & QgsTask::CanCancel ) );
157+
task.reset( new TestTask( "desc", QgsTask::CanCancel ) );
158158
QVERIFY( task->canCancel() );
159-
QVERIFY( !( task->flags() & QgsTask::ProgressReport ) );
160-
QVERIFY( task->flags() & QgsTask::CancelSupport );
159+
QVERIFY( !( task->flags() & QgsTask::CanReportProgress ) );
160+
QVERIFY( task->flags() & QgsTask::CanCancel );
161161
}
162162

163163

0 commit comments

Comments
 (0)
Please sign in to comment.