From cb383d760b54fb30866f391d87b574d385cd8814 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Tue, 19 May 2020 02:44:38 +1000 Subject: [PATCH] tasks now emit floats rather than integers Simplifies code for tasks. --- app/codec/decoder.cpp | 2 +- app/codec/decoder.h | 2 +- app/dialog/progress/progress.cpp | 8 +++++--- app/dialog/progress/progress.h | 2 +- app/task/render/render.cpp | 2 +- app/task/task.h | 4 ++-- app/widget/taskview/taskviewitem.cpp | 7 ++++++- app/widget/taskview/taskviewitem.h | 3 +++ app/window/mainwindow/mainstatusbar.cpp | 7 ++++++- app/window/mainwindow/mainstatusbar.h | 2 ++ 10 files changed, 28 insertions(+), 11 deletions(-) diff --git a/app/codec/decoder.cpp b/app/codec/decoder.cpp index b224e5f99..6c7ed066c 100644 --- a/app/codec/decoder.cpp +++ b/app/codec/decoder.cpp @@ -333,7 +333,7 @@ bool Decoder::HasConformedVersion(const AudioRenderingParams ¶ms) void Decoder::SignalProcessingProgress(const int64_t &ts) { if (stream()->duration() != AV_NOPTS_VALUE && stream()->duration() != 0) { - emit IndexProgress(qRound(100.0 * static_cast(ts) / static_cast(stream()->duration()))); + emit IndexProgress(static_cast(ts) / static_cast(stream()->duration())); } } diff --git a/app/codec/decoder.h b/app/codec/decoder.h index d6adbe0c4..31b183f88 100644 --- a/app/codec/decoder.h +++ b/app/codec/decoder.h @@ -242,7 +242,7 @@ signals: * @brief While indexing, this signal will provide progress as a percentage (0-100 inclusive) if * available */ - void IndexProgress(int); + void IndexProgress(double); protected: void SignalProcessingProgress(const int64_t& ts); diff --git a/app/dialog/progress/progress.cpp b/app/dialog/progress/progress.cpp index 9002f00ca..90c3b72e0 100644 --- a/app/dialog/progress/progress.cpp +++ b/app/dialog/progress/progress.cpp @@ -77,12 +77,14 @@ void ProgressDialog::closeEvent(QCloseEvent *e) #endif } -void ProgressDialog::SetProgress(int value) +void ProgressDialog::SetProgress(double value) { - bar_->setValue(value); + int percent = qRound(100.0 * value); + + bar_->setValue(percent); #ifdef Q_OS_WINDOWS - Core::instance()->main_window()->SetTaskbarButtonProgress(value, 100); + Core::instance()->main_window()->SetTaskbarButtonProgress(percent, 100); #endif } diff --git a/app/dialog/progress/progress.h b/app/dialog/progress/progress.h index a608fb849..a4a233e19 100644 --- a/app/dialog/progress/progress.h +++ b/app/dialog/progress/progress.h @@ -40,7 +40,7 @@ protected: virtual void closeEvent(QCloseEvent *) override; public slots: - void SetProgress(int value); + void SetProgress(double value); signals: void Cancelled(); diff --git a/app/task/render/render.cpp b/app/task/render/render.cpp index 2b1c4345d..effebbe4b 100644 --- a/app/task/render/render.cpp +++ b/app/task/render/render.cpp @@ -172,7 +172,7 @@ void RenderTask::Render(TimeRangeList range_to_cache, int divider) // Signal process counter++; - emit ProgressChanged(qRound(100.0 * static_cast(counter) / static_cast(nb_frames))); + emit ProgressChanged(static_cast(counter) / static_cast(nb_frames)); j = download_futures.erase(j); } else { diff --git a/app/task/task.h b/app/task/task.h index fd4aaaf98..43d271a2c 100644 --- a/app/task/task.h +++ b/app/task/task.h @@ -135,9 +135,9 @@ signals: * * @param p * - * A value (percentage) between 0 and 100. + * A progress value between 0.0 and 1.0. */ - void ProgressChanged(int p); + void ProgressChanged(double d); private: QString title_; diff --git a/app/widget/taskview/taskviewitem.cpp b/app/widget/taskview/taskviewitem.cpp index 19b4f4b73..00c597f19 100644 --- a/app/widget/taskview/taskviewitem.cpp +++ b/app/widget/taskview/taskviewitem.cpp @@ -60,7 +60,7 @@ TaskViewItem::TaskViewItem(Task* task, QWidget *parent) : layout->addWidget(task_status_lbl_); // Connect to the task - connect(task_, &Task::ProgressChanged, progress_bar_, &QProgressBar::setValue); + connect(task_, &Task::ProgressChanged, this, &TaskViewItem::UpdateProgress); connect(cancel_btn_, &QPushButton::clicked, task_, &Task::Cancel, Qt::DirectConnection); } @@ -69,4 +69,9 @@ void TaskViewItem::Failed() task_status_lbl_->setText(task_->GetError()); } +void TaskViewItem::UpdateProgress(double d) +{ + progress_bar_->setValue(qRound(100.0 * d)); +} + OLIVE_NAMESPACE_EXIT diff --git a/app/widget/taskview/taskviewitem.h b/app/widget/taskview/taskviewitem.h index 35f1bc958..a727a68f5 100644 --- a/app/widget/taskview/taskviewitem.h +++ b/app/widget/taskview/taskviewitem.h @@ -55,6 +55,9 @@ private: Task* task_; +private slots: + void UpdateProgress(double d); + }; OLIVE_NAMESPACE_EXIT diff --git a/app/window/mainwindow/mainstatusbar.cpp b/app/window/mainwindow/mainstatusbar.cpp index 568718e44..0d0815c0e 100644 --- a/app/window/mainwindow/mainstatusbar.cpp +++ b/app/window/mainwindow/mainstatusbar.cpp @@ -72,10 +72,15 @@ void MainStatusBar::UpdateStatus() } bar_->setVisible(true); - connect(t, &Task::ProgressChanged, bar_, &QProgressBar::setValue); + connect(t, &Task::ProgressChanged, this, &MainStatusBar::SetProgressBarValue); } } +void MainStatusBar::SetProgressBarValue(double d) +{ + bar_->setValue(qRound(100.0 * d)); +} + void MainStatusBar::mouseDoubleClickEvent(QMouseEvent* e) { QStatusBar::mouseDoubleClickEvent(e); diff --git a/app/window/mainwindow/mainstatusbar.h b/app/window/mainwindow/mainstatusbar.h index 96e8dee5e..5951c2dd7 100644 --- a/app/window/mainwindow/mainstatusbar.h +++ b/app/window/mainwindow/mainstatusbar.h @@ -48,6 +48,8 @@ protected: private slots: void UpdateStatus(); + void SetProgressBarValue(double d); + private: TaskManager* manager_;