From 20cb97a35af5097e9d3b2062c0dfcb5f2e5fff5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 6 Sep 2014 18:16:56 +0200 Subject: Sync from quickmods --- logic/tasks/SequentialTask.cpp | 45 ++++++++++-------------------------------- 1 file changed, 10 insertions(+), 35 deletions(-) (limited to 'logic/tasks/SequentialTask.cpp') diff --git a/logic/tasks/SequentialTask.cpp b/logic/tasks/SequentialTask.cpp index e0f8fcdd..e08206f8 100644 --- a/logic/tasks/SequentialTask.cpp +++ b/logic/tasks/SequentialTask.cpp @@ -1,31 +1,7 @@ #include "SequentialTask.h" -SequentialTask::SequentialTask(QObject *parent) : - Task(parent), m_currentIndex(-1) +SequentialTask::SequentialTask(QObject *parent) : Task(parent), m_currentIndex(-1) { - -} - -QString SequentialTask::getStatus() const -{ - if (m_queue.isEmpty() || m_currentIndex >= m_queue.size()) - { - return QString(); - } - return m_queue.at(m_currentIndex)->getStatus(); -} - -void SequentialTask::getProgress(qint64 ¤t, qint64 &total) -{ - current = 0; - total = 0; - for (int i = 0; i < m_queue.size(); ++i) - { - qint64 subCurrent, subTotal; - m_queue.at(i)->getProgress(subCurrent, subTotal); - current += subCurrent; - total += subTotal; - } } void SequentialTask::addTask(std::shared_ptr task) @@ -55,10 +31,9 @@ void SequentialTask::startNext() std::shared_ptr next = m_queue[m_currentIndex]; connect(next.get(), SIGNAL(failed(QString)), this, SLOT(subTaskFailed(QString))); connect(next.get(), SIGNAL(status(QString)), this, SLOT(subTaskStatus(QString))); - connect(next.get(), SIGNAL(progress(qint64,qint64)), this, SLOT(subTaskProgress())); + connect(next.get(), SIGNAL(progress(qint64, qint64)), this, SLOT(subTaskProgress(qint64, qint64))); connect(next.get(), SIGNAL(succeeded()), this, SLOT(startNext())); next->start(); - emit status(getStatus()); } void SequentialTask::subTaskFailed(const QString &msg) @@ -69,16 +44,16 @@ void SequentialTask::subTaskStatus(const QString &msg) { setStatus(msg); } -void SequentialTask::subTaskProgress() +void SequentialTask::subTaskProgress(qint64 current, qint64 total) { - qint64 current, total; - getProgress(current, total); - if (total == 0) + if(total == 0) { setProgress(0); + return; } - else - { - setProgress(100 * current / total); - } + auto dcurrent = (double) current; + auto dtotal = (double) total; + auto partial = ((dcurrent / dtotal) * 100.0f)/* / double(m_queue.size())*/; + // auto bigpartial = double(m_currentIndex) * 100.0f / double(m_queue.size()); + setProgress(partial); } -- cgit v1.2.3