Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Rename stopped to terminated for consistency
  • Loading branch information
nyalldawson committed Dec 5, 2016
1 parent e01c306 commit f71c78e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 37 deletions.
20 changes: 10 additions & 10 deletions python/core/qgstaskmanager.sip
Expand Up @@ -49,7 +49,7 @@ class QgsTask : QObject
};
typedef QFlags<QgsTask::Flag> Flags;

/**
/**
* Constructor for QgsTask.
* @param description text description of task
* @param flags task flags
Expand Down Expand Up @@ -135,7 +135,7 @@ class QgsTask : QObject
* Will be emitted by task when its status changes.
* @param status new task status
* @note derived classes should not emit this signal directly, instead they should call
* completed() or stopped()
* completed() or terminated()
*/
void statusChanged( int status );

Expand All @@ -158,9 +158,9 @@ class QgsTask : QObject
* other then completion (eg when a task has been cancelled or encountered
* an internal error).
* @note derived classes should not emit this signal directly, instead they should call
* stopped()
* terminated()
*/
void taskStopped();
void taskTerminated();

protected:

Expand All @@ -175,13 +175,13 @@ class QgsTask : QObject
*
* Alternatively, tasks can also return the ResultPending value
* to indicate that the task is still operating and will manually report its
* completion by calling completed() or stopped(). This may be useful for
* completion by calling completed() or terminated(). This may be useful for
* tasks which rely on external events for completion, eg downloading a
* file. In this case Qt slots could be created which are connected to the
* download completion or termination and which call completed() or stopped()
* download completion or termination and which call completed() or terminated()
* to indicate the task has finished operations.
* @see completed()
* @see stopped()
* @see terminated()
*/
virtual TaskResult run() = 0;

Expand All @@ -201,13 +201,13 @@ class QgsTask : QObject
void completed();

/**
* Sets the task as stopped. Calling this is only required for tasks which
* Sets the task as terminated. Calling this is only required for tasks which
* returned the ResultPending value as a result of run().
* Should be called whenever the task ends for any reason other than successful
* completion. Calling will automatically emit the statusChanged and taskStopped
* completion. Calling will automatically emit the statusChanged and taskTerminated
* signals.
*/
void stopped();
void terminated();

protected slots:

Expand Down
10 changes: 5 additions & 5 deletions src/core/qgstaskmanager.cpp
Expand Up @@ -46,7 +46,7 @@ void QgsTask::start()
break;

case ResultFail:
stopped();
terminated();
break;

case ResultPending:
Expand All @@ -63,7 +63,7 @@ void QgsTask::cancel()
if ( mStatus == Queued || mStatus == OnHold )
{
// immediately terminate unstarted jobs
stopped();
terminated();
}
}

Expand Down Expand Up @@ -98,11 +98,11 @@ void QgsTask::completed()
emit taskCompleted();
}

void QgsTask::stopped()
void QgsTask::terminated()
{
mStatus = Terminated;
emit statusChanged( Terminated );
emit taskStopped();
emit taskTerminated();
}


Expand Down Expand Up @@ -413,7 +413,7 @@ bool QgsTaskManager::cleanupAndDeleteTask( QgsTask *task )
task->cancel();
// delete task when it's terminated
connect( task, &QgsTask::taskCompleted, task, &QgsTask::deleteLater );
connect( task, &QgsTask::taskStopped, task, &QgsTask::deleteLater );
connect( task, &QgsTask::taskTerminated, task, &QgsTask::deleteLater );
}
else
{
Expand Down
18 changes: 9 additions & 9 deletions src/core/qgstaskmanager.h
Expand Up @@ -157,7 +157,7 @@ class CORE_EXPORT QgsTask : public QObject
* Will be emitted by task when its status changes.
* @param status new task status
* @note derived classes should not emit this signal directly, instead they should call
* completed() or stopped()
* completed() or terminated()
*/
void statusChanged( int status );

Expand All @@ -180,9 +180,9 @@ class CORE_EXPORT QgsTask : public QObject
* other then completion (eg when a task has been cancelled or encountered
* an internal error).
* @note derived classes should not emit this signal directly, instead they should call
* stopped()
* terminated()
*/
void taskStopped();
void taskTerminated();

protected:

Expand All @@ -197,13 +197,13 @@ class CORE_EXPORT QgsTask : public QObject
*
* Alternatively, tasks can also return the ResultPending value
* to indicate that the task is still operating and will manually report its
* completion by calling completed() or stopped(). This may be useful for
* completion by calling completed() or terminated(). This may be useful for
* tasks which rely on external events for completion, eg downloading a
* file. In this case Qt slots could be created which are connected to the
* download completion or termination and which call completed() or stopped()
* download completion or termination and which call completed() or terminated()
* to indicate the task has finished operations.
* @see completed()
* @see stopped()
* @see terminated()
*/
virtual TaskResult run() = 0;

Expand All @@ -223,13 +223,13 @@ class CORE_EXPORT QgsTask : public QObject
void completed();

/**
* Sets the task as stopped. Calling this is only required for tasks which
* Sets the task as terminated. Calling this is only required for tasks which
* returned the ResultPending value as a result of run().
* Should be called whenever the task ends for any reason other than successful
* completion. Calling will automatically emit the statusChanged and taskStopped
* completion. Calling will automatically emit the statusChanged and taskTerminated
* signals.
*/
void stopped();
void terminated();

protected slots:

Expand Down
26 changes: 13 additions & 13 deletions tests/src/core/testqgstaskmanager.cpp
Expand Up @@ -33,7 +33,7 @@ class TestTask : public QgsTask
TestTask( const QString& desc, const QgsTask::Flags& flags ) : QgsTask( desc, flags ), runCalled( false ) {}

void emitProgressChanged( double progress ) { setProgress( progress ); }
void emitTaskStopped() { stopped(); }
void emitTaskStopped() { terminated(); }
void emitTaskCompleted() { completed(); }

bool runCalled;
Expand Down Expand Up @@ -153,8 +153,8 @@ void TestQgsTaskManager::task()
QVERIFY( task->canCancel() );
QVERIFY( task->flags() & QgsTask::CanReportProgress );

QSignalSpy startedSpy( task.data(), SIGNAL( begun() ) );
QSignalSpy statusSpy( task.data(), SIGNAL( statusChanged( int ) ) );
QSignalSpy startedSpy( task.data(), &QgsTask::begun );
QSignalSpy statusSpy( task.data(), &QgsTask::statusChanged );

task->start();
QCOMPARE( task->status(), QgsTask::Running );
Expand All @@ -165,7 +165,7 @@ void TestQgsTaskManager::task()
QCOMPARE( static_cast< QgsTask::TaskStatus >( statusSpy.last().at( 0 ).toInt() ), QgsTask::Running );

//test that calling stopped sets correct state
QSignalSpy stoppedSpy( task.data(), SIGNAL( taskStopped() ) );
QSignalSpy stoppedSpy( task.data(), &QgsTask::taskTerminated );
task->emitTaskStopped();
QCOMPARE( task->status(), QgsTask::Terminated );
QVERIFY( !task->isActive() );
Expand All @@ -175,8 +175,8 @@ void TestQgsTaskManager::task()

//test that calling completed sets correct state
task.reset( new TestTask() );
QSignalSpy completeSpy( task.data(), SIGNAL( taskCompleted() ) );
QSignalSpy statusSpy2( task.data(), SIGNAL( statusChanged( int ) ) );
QSignalSpy completeSpy( task.data(), &QgsTask::taskCompleted );
QSignalSpy statusSpy2( task.data(), &QgsTask::statusChanged );
task->emitTaskCompleted();
QCOMPARE( task->status(), QgsTask::Complete );
QVERIFY( !task->isActive() );
Expand Down Expand Up @@ -208,7 +208,7 @@ void TestQgsTaskManager::taskResult()
{
QScopedPointer< TestTask > task( new SuccessTask() );
QCOMPARE( task->status(), QgsTask::Queued );
QSignalSpy statusSpy( task.data(), SIGNAL( statusChanged( int ) ) );
QSignalSpy statusSpy( task.data(), &QgsTask::statusChanged );

task->start();
QCOMPARE( statusSpy.count(), 2 );
Expand All @@ -218,7 +218,7 @@ void TestQgsTaskManager::taskResult()

task.reset( new FailTask() );
QCOMPARE( task->status(), QgsTask::Queued );
QSignalSpy statusSpy2( task.data(), SIGNAL( statusChanged( int ) ) );
QSignalSpy statusSpy2( task.data(), &QgsTask::statusChanged );

task->start();
QCOMPARE( statusSpy2.count(), 2 );
Expand All @@ -243,7 +243,7 @@ void TestQgsTaskManager::addTask()
QCOMPARE( manager.count(), 0 );
QVERIFY( !manager.task( 0L ) );

QSignalSpy spy( &manager, SIGNAL( taskAdded( long ) ) );
QSignalSpy spy( &manager, &QgsTaskManager::taskAdded );

//add a task
TestTask* task = new TestTask();
Expand Down Expand Up @@ -284,7 +284,7 @@ void TestQgsTaskManager::deleteTask()
manager.addTask( task2 );
manager.addTask( task3 );

QSignalSpy spy( &manager, SIGNAL( taskAboutToBeDeleted( long ) ) );
QSignalSpy spy( &manager, &QgsTaskManager::taskAboutToBeDeleted );

//try deleting a non-existant task
QVERIFY( !manager.deleteTask( 56 ) );
Expand Down Expand Up @@ -407,7 +407,7 @@ void TestQgsTaskManager::statusChanged()
manager.addTask( task );
manager.addTask( task2 );

QSignalSpy spy( &manager, SIGNAL( statusChanged( long, int ) ) );
QSignalSpy spy( &manager, &QgsTaskManager::statusChanged );

task->start();
QCOMPARE( spy.count(), 1 );
Expand Down Expand Up @@ -435,7 +435,7 @@ void TestQgsTaskManager::allTasksFinished()
manager.addTask( task2 );
while ( task2->status() != QgsTask::Running ) { }

QSignalSpy spy( &manager, SIGNAL( allTasksFinished() ) );
QSignalSpy spy( &manager, &QgsTaskManager::allTasksFinished );

task->emitTaskStopped();
while ( task->status() == QgsTask::Running ) { }
Expand Down Expand Up @@ -470,7 +470,7 @@ void TestQgsTaskManager::activeTasks()
QgsTaskManager manager;
TestTask* task = new TestTask();
TestTask* task2 = new TestTask();
QSignalSpy spy( &manager, SIGNAL( countActiveTasksChanged( int ) ) );
QSignalSpy spy( &manager, &QgsTaskManager::countActiveTasksChanged );
manager.addTask( task );
QCOMPARE( manager.activeTasks().toSet(), ( QList< QgsTask* >() << task ).toSet() );
QCOMPARE( manager.countActiveTasks(), 1 );
Expand Down

0 comments on commit f71c78e

Please sign in to comment.