task: improve threading
This commit is contained in:
@@ -93,6 +93,7 @@ public slots:
|
||||
bool Start()
|
||||
{
|
||||
start_time_ = QDateTime::currentMSecsSinceEpoch();
|
||||
emit Started(start_time_);
|
||||
|
||||
bool ret = Run();
|
||||
|
||||
@@ -150,6 +151,8 @@ protected:
|
||||
}
|
||||
|
||||
signals:
|
||||
void Started(qint64 start_time);
|
||||
|
||||
/**
|
||||
* @brief Signal emitted whenever progress is made
|
||||
*
|
||||
|
||||
@@ -29,6 +29,7 @@ TaskManager* TaskManager::instance_ = nullptr;
|
||||
|
||||
TaskManager::TaskManager()
|
||||
{
|
||||
thread_pool_.setMaxThreadCount(1);
|
||||
}
|
||||
|
||||
TaskManager::~TaskManager()
|
||||
@@ -95,9 +96,9 @@ void TaskManager::AddTask(Task* t)
|
||||
// Run task concurrently
|
||||
watcher->setFuture(
|
||||
#if QT_VERSION_MAJOR >= 6
|
||||
QtConcurrent::run(&Task::Start, t)
|
||||
QtConcurrent::run(&thread_pool_, &Task::Start, t)
|
||||
#else
|
||||
QtConcurrent::run(t, &Task::Start)
|
||||
QtConcurrent::run(&thread_pool_, t, &Task::Start)
|
||||
#endif
|
||||
);
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QHBoxLayout>
|
||||
#include <cmath>
|
||||
|
||||
#include "common/timecodefunctions.h"
|
||||
|
||||
@@ -80,7 +81,7 @@ void ElapsedCounterWidget::UpdateTimers()
|
||||
double ms_per_progress_unit = elapsed_ms / last_progress_;
|
||||
double remaining_progress = 1.0 - last_progress_;
|
||||
|
||||
remaining_ms = qRound64(ms_per_progress_unit * remaining_progress);
|
||||
remaining_ms = std::ceil(ms_per_progress_unit * remaining_progress);
|
||||
} else {
|
||||
elapsed_ms = 0;
|
||||
remaining_ms = 0;
|
||||
|
||||
@@ -37,8 +37,9 @@ public:
|
||||
|
||||
void SetProgress(double d);
|
||||
|
||||
void Start();
|
||||
public slots:
|
||||
void Start(qint64 start_time);
|
||||
void Start();
|
||||
|
||||
public slots:
|
||||
void Stop();
|
||||
|
||||
@@ -72,9 +72,9 @@ TaskViewItem::TaskViewItem(Task* task, QWidget *parent) :
|
||||
|
||||
// Set up elapsed timer
|
||||
status_stack_->setCurrentWidget(elapsed_timer_lbl_);
|
||||
elapsed_timer_lbl_->Start(task_->GetStartTime());
|
||||
|
||||
// Connect to the task
|
||||
connect(task_, &Task::Started, elapsed_timer_lbl_, qOverload<qint64>(&ElapsedCounterWidget::Start));
|
||||
connect(task_, &Task::ProgressChanged, this, &TaskViewItem::UpdateProgress);
|
||||
connect(cancel_btn_, &QPushButton::clicked, this, [this] { emit TaskCancelled(task_); });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user