fix: always update global progress of sequential tasks

Previously, it would not update the global counter if the subTask didn't
update its progress, even though progress was being made.

This also prevents a segmentation fault while aborting the task.

Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
flow 2022-05-09 10:53:52 -03:00 committed by flow
parent 43b9db6e45
commit 882c82f82c
No known key found for this signature in database
GPG Key ID: 8D0F221F0A59F469
2 changed files with 16 additions and 6 deletions

View File

@ -1,5 +1,7 @@
#include "SequentialTask.h" #include "SequentialTask.h"
#include <QDebug>
SequentialTask::SequentialTask(QObject* parent, const QString& task_name) : Task(parent), m_name(task_name), m_currentIndex(-1) {} SequentialTask::SequentialTask(QObject* parent, const QString& task_name) : Task(parent), m_name(task_name), m_currentIndex(-1) {}
SequentialTask::~SequentialTask() SequentialTask::~SequentialTask()
@ -39,14 +41,15 @@ bool SequentialTask::abort()
emit aborted(); emit aborted();
emit finished(); emit finished();
} }
m_queue.clear();
m_aborted = true;
return true; return true;
} }
bool succeeded = m_queue[m_currentIndex]->abort(); bool succeeded = m_queue[m_currentIndex]->abort();
m_queue.clear(); m_aborted = succeeded;
if(succeeded) if (succeeded)
emitAborted(); emitAborted();
return succeeded; return succeeded;
@ -54,10 +57,14 @@ bool SequentialTask::abort()
void SequentialTask::startNext() void SequentialTask::startNext()
{ {
if (m_currentIndex != -1) { if (m_aborted)
Task::Ptr previous = m_queue[m_currentIndex]; return;
if (m_currentIndex != -1 && m_currentIndex < m_queue.size()) {
Task::Ptr previous = m_queue.at(m_currentIndex);
disconnect(previous.get(), 0, this, 0); disconnect(previous.get(), 0, this, 0);
} }
m_currentIndex++; m_currentIndex++;
if (m_queue.isEmpty() || m_currentIndex >= m_queue.size()) { if (m_queue.isEmpty() || m_currentIndex >= m_queue.size()) {
emitSucceeded(); emitSucceeded();
@ -76,6 +83,8 @@ void SequentialTask::startNext()
setStatus(tr("Executing task %1 out of %2").arg(m_currentIndex + 1).arg(m_queue.size())); setStatus(tr("Executing task %1 out of %2").arg(m_currentIndex + 1).arg(m_queue.size()));
setStepStatus(next->isMultiStep() ? next->getStepStatus() : next->getStatus()); setStepStatus(next->isMultiStep() ? next->getStepStatus() : next->getStatus());
setProgress(m_currentIndex + 1, m_queue.count());
next->start(); next->start();
} }
@ -93,7 +102,6 @@ void SequentialTask::subTaskProgress(qint64 current, qint64 total)
setProgress(0, 100); setProgress(0, 100);
return; return;
} }
setProgress(m_currentIndex + 1, m_queue.count());
m_stepProgress = current; m_stepProgress = current;
m_stepTotalProgress = total; m_stepTotalProgress = total;

View File

@ -44,4 +44,6 @@ protected:
qint64 m_stepProgress = 0; qint64 m_stepProgress = 0;
qint64 m_stepTotalProgress = 100; qint64 m_stepTotalProgress = 100;
bool m_aborted = false;
}; };