feat: Propogated subtask progress

Oh boy this is big.

> TaskStepProgress struct is now QMetaObject compatabile and can be sent through signals
> Task now has a method to propogates sub task progress it must be signal bound by each task containing a task wishing to report progress of it's children.
> Downloads report speed
> Tasks now have UUIDS to track them
  - use when reporting
  - use when logging
  - use when storeing them or objects related to them

Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
This commit is contained in:
Rachel Powers
2023-03-30 23:50:29 -07:00
parent f997529cd4
commit 9d2f0e4dc8
25 changed files with 275 additions and 103 deletions

View File

@ -48,10 +48,12 @@
template<typename T>
int map_int_range(T value)
{
auto type_min = std::numeric_limits<T>::min();
// auto type_min = std::numeric_limits<T>::min();
auto type_min = 0;
auto type_max = std::numeric_limits<T>::max();
auto int_min = std::numeric_limits<int>::min();
// auto int_min = std::numeric_limits<int>::min();
auto int_min = 0;
auto int_max = std::numeric_limits<int>::max();
auto type_range = type_max - type_min;
@ -64,6 +66,7 @@ int map_int_range(T value)
ProgressDialog::ProgressDialog(QWidget* parent) : QDialog(parent), ui(new Ui::ProgressDialog)
{
ui->setupUi(this);
ui->taskProgressScrollArea->setHidden(true);
this->setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
setAttribute(Qt::WidgetAttribute::WA_QuitOnClose, true);
setSkipButton(false);
@ -94,10 +97,17 @@ ProgressDialog::~ProgressDialog()
}
void ProgressDialog::updateSize()
{
{
QSize lastSize = this->size();
QSize qSize = QSize(480, minimumSizeHint().height());
resize(qSize);
setFixedSize(qSize);
// keep the dialog in the center after a resize
if (lastSize != qSize)
this->move(
this->parentWidget()->x() + (this->parentWidget()->width() - this->width()) / 2,
this->parentWidget()->y() + (this->parentWidget()->height() - this->height()) / 2
);
}
int ProgressDialog::execWithTask(Task* task)
@ -126,10 +136,8 @@ int ProgressDialog::execWithTask(Task* task)
connect(task, &Task::abortStatusChanged, ui->skipButton, &QPushButton::setEnabled);
m_is_multi_step = task->isMultiStep();
if (!m_is_multi_step) {
ui->globalStatusLabel->setHidden(true);
ui->globalProgressBar->setHidden(true);
}
ui->taskProgressScrollArea->setHidden(!m_is_multi_step);
updateSize();
// It's a good idea to start the task after we entered the dialog's event loop :^)
if (!task->isRunning()) {
@ -139,6 +147,9 @@ int ProgressDialog::execWithTask(Task* task)
changeProgress(task->getProgress(), task->getTotalProgress());
}
// auto size_hint = ui->verticalLayout->sizeHint();
// resize(size_hint.width(), size_hint.height());
return QDialog::exec();
}
@ -189,40 +200,45 @@ void ProgressDialog::onTaskSucceeded()
void ProgressDialog::changeStatus(const QString& status)
{
ui->globalStatusLabel->setText(task->getStatus());
// ui->statusLabel->setText(task->getStepStatus());
ui->globalStatusDetailsLabel->setText(task->getDetails());
updateSize();
}
void ProgressDialog::addTaskProgress(TaskStepProgress progress)
void ProgressDialog::addTaskProgress(TaskStepProgress* progress)
{
SubTaskProgressBar* task_bar = new SubTaskProgressBar(this);
taskProgress.insert(progress.uid, task_bar);
ui->taskProgressLayout->addWidget(task_bar);
taskProgress.insert(progress->uid, task_bar);
ui->taskProgressLayout->insertWidget(0, task_bar);
}
void ProgressDialog::changeStepProgress(QList<TaskStepProgress> task_progress)
void ProgressDialog::changeStepProgress(TaskStepProgressList task_progress)
{
m_is_multi_step = true;
ui->taskProgressScrollArea->setHidden(false);
for (auto tp : task_progress) {
if (!taskProgress.contains(tp.uid))
addTaskProgress(tp);
auto task_bar = taskProgress.value(tp.uid);
if (!taskProgress.contains(tp->uid))
addTaskProgress(tp.get());
auto task_bar = taskProgress.value(tp->uid);
if (tp.total < 0) {
if (tp->total < 0) {
task_bar->setRange(0, 0);
} else {
task_bar->setRange(0, map_int_range<qint64>(tp.total));
task_bar->setRange(0, map_int_range<qint64>(tp->total));
}
task_bar->setValue(map_int_range<qint64>(tp.current));
task_bar->setStatus(tp.status);
task_bar->setDetails(tp.details);
task_bar->setValue(map_int_range<qint64>(tp->current));
task_bar->setStatus(tp->status);
task_bar->setDetails(tp->details);
if (tp.isDone()) {
if (tp->isDone()) {
task_bar->setVisible(false);
}
}
updateSize();
}
void ProgressDialog::changeProgress(qint64 current, qint64 total)
@ -230,13 +246,6 @@ void ProgressDialog::changeProgress(qint64 current, qint64 total)
ui->globalProgressBar->setMaximum(total);
ui->globalProgressBar->setValue(current);
// if (!m_is_multi_step) {
// ui->taskProgressBar->setMaximum(total);
// ui->taskProgressBar->setValue(current);
// } else {
// ui->taskProgressBar->setMaximum(task->getStepProgress());
// ui->taskProgressBar->setValue(task->getStepTotalProgress());
// }
}
void ProgressDialog::keyPressEvent(QKeyEvent* e)

View File

@ -80,7 +80,7 @@ slots:
void changeStatus(const QString &status);
void changeProgress(qint64 current, qint64 total);
void changeStepProgress(QList<TaskStepProgress> task_progress);
void changeStepProgress(TaskStepProgressList task_progress);
private
@ -93,7 +93,7 @@ protected:
private:
bool handleImmediateResult(QDialog::DialogCode &result);
void addTaskProgress(TaskStepProgress progress);
void addTaskProgress(TaskStepProgress* progress);
private:
Ui::ProgressDialog *ui;

View File

@ -6,20 +6,20 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>109</height>
<width>600</width>
<height>260</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>400</width>
<height>0</height>
<width>600</width>
<height>260</height>
</size>
</property>
<property name="maximumSize">
@ -31,21 +31,103 @@
<property name="windowTitle">
<string>Please wait...</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0">
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0">
<item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,0">
<item>
<widget class="QLabel" name="globalStatusLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>15</height>
</size>
</property>
<property name="text">
<string>Global Task Status...</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="globalStatusDetailsLabel">
<property name="text">
<string>Global Status Details...</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QProgressBar" name="globalProgressBar">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>24</height>
</size>
</property>
<property name="value">
<number>24</number>
</property>
</widget>
</item>
<item row="4" column="0">
<item>
<widget class="QScrollArea" name="taskProgressScrollArea">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>100</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAsNeeded</enum>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContents</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="taskProgressContainer">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>584</width>
<height>146</height>
</rect>
</property>
<layout class="QVBoxLayout" name="taskProgressLayout">
<property name="spacing">
<number>2</number>
</property>
</layout>
</widget>
</widget>
</item>
<item>
<widget class="QPushButton" name="skipButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -55,22 +137,6 @@
</property>
</widget>
</item>
<item row="3" column="0">
<layout class="QVBoxLayout" name="taskProgressLayout"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="globalStatusLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Global Task Status...</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>

View File

@ -6,12 +6,12 @@
<rect>
<x>0</x>
<y>0</y>
<width>265</width>
<height>65</height>
<width>597</width>
<height>61</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Ignored">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -20,29 +20,45 @@
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0">
<property name="spacing">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,0">
<item>
<widget class="QLabel" name="statusLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
</font>
</property>
<property name="text">
<string>Sub Task Status...</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="statusDetailsLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
</font>
</property>
<property name="text">
<string>Status Details</string>
</property>
@ -55,6 +71,11 @@
</item>
<item>
<widget class="QProgressBar" name="progressBar">
<property name="font">
<font>
<pointsize>8</pointsize>
</font>
</property>
<property name="value">
<number>24</number>
</property>