diff options
Diffstat (limited to 'launcher/ui/dialogs/ProgressDialog.cpp')
-rw-r--r-- | launcher/ui/dialogs/ProgressDialog.cpp | 46 |
1 files changed, 19 insertions, 27 deletions
diff --git a/launcher/ui/dialogs/ProgressDialog.cpp b/launcher/ui/dialogs/ProgressDialog.cpp index 4243e291..0ca3a1bd 100644 --- a/launcher/ui/dialogs/ProgressDialog.cpp +++ b/launcher/ui/dialogs/ProgressDialog.cpp @@ -37,18 +37,17 @@ #include <QPoint> #include "ui_ProgressDialog.h" -#include <limits> #include <QDebug> #include <QKeyEvent> +#include <limits> #include "tasks/Task.h" #include "ui/widgets/SubTaskProgressBar.h" - // map a value in a numeric range of an arbitrary type to between 0 and INT_MAX // for getting the best precision out of the qt progress bar -template<typename T, std::enable_if_t<std::is_arithmetic_v<T>, bool> = true> +template <typename T, std::enable_if_t<std::is_arithmetic_v<T>, bool> = true> std::tuple<int, int> map_int_zero_max(T current, T range_max, T range_min) { int int_max = std::numeric_limits<int>::max(); @@ -57,10 +56,9 @@ std::tuple<int, int> map_int_zero_max(T current, T range_max, T range_min) double percentage = static_cast<double>(current - range_min) / static_cast<double>(type_range); int mapped_current = percentage * int_max; - return {mapped_current, int_max}; + return { mapped_current, int_max }; } - ProgressDialog::ProgressDialog(QWidget* parent) : QDialog(parent), ui(new Ui::ProgressDialog) { ui->setupUi(this); @@ -87,7 +85,7 @@ void ProgressDialog::on_skipButton_clicked(bool checked) { Q_UNUSED(checked); if (ui->skipButton->isEnabled()) // prevent other triggers from aborting - task->abort(); + m_task->abort(); } ProgressDialog::~ProgressDialog() @@ -96,7 +94,7 @@ ProgressDialog::~ProgressDialog() } void ProgressDialog::updateSize(bool recenterParent) -{ +{ QSize lastSize = this->size(); QPoint lastPos = this->pos(); int minHeight = ui->globalStatusDetailsLabel->minimumSize().height() + (ui->verticalLayout->spacing() * 2); @@ -118,28 +116,25 @@ void ProgressDialog::updateSize(bool recenterParent) auto newX = std::max(0, parent->x() + ((parent->width() - newSize.width()) / 2)); auto newY = std::max(0, parent->y() + ((parent->height() - newSize.height()) / 2)); this->move(newX, newY); - } - else if (lastSize != newSize) - { + } else if (lastSize != newSize) { // center on old position after resize - QSize sizeDiff = lastSize - newSize; // last size was smaller, the results should be negative + QSize sizeDiff = lastSize - newSize; // last size was smaller, the results should be negative auto newX = std::max(0, lastPos.x() + (sizeDiff.width() / 2)); auto newY = std::max(0, lastPos.y() + (sizeDiff.height() / 2)); this->move(newX, newY); } - } int ProgressDialog::execWithTask(Task* task) { - this->task = task; + this->m_task = task; if (!task) { qDebug() << "Programmer error: Progress dialog created with null task."; return QDialog::DialogCode::Accepted; } - QDialog::DialogCode result {}; + QDialog::DialogCode result{}; if (handleImmediateResult(result)) { return result; } @@ -184,8 +179,8 @@ int ProgressDialog::execWithTask(std::unique_ptr<Task>& task) bool ProgressDialog::handleImmediateResult(QDialog::DialogCode& result) { - if (task->isFinished()) { - if (task->wasSuccessful()) { + if (m_task->isFinished()) { + if (m_task->wasSuccessful()) { result = QDialog::Accepted; } else { result = QDialog::Rejected; @@ -197,12 +192,12 @@ bool ProgressDialog::handleImmediateResult(QDialog::DialogCode& result) Task* ProgressDialog::getTask() { - return task; + return m_task; } void ProgressDialog::onTaskStarted() {} -void ProgressDialog::onTaskFailed(QString failure) +void ProgressDialog::onTaskFailed([[maybe_unused]] QString failure) { reject(); hide(); @@ -214,11 +209,11 @@ void ProgressDialog::onTaskSucceeded() hide(); } -void ProgressDialog::changeStatus(const QString& status) +void ProgressDialog::changeStatus([[maybe_unused]] const QString& status) { - ui->globalStatusLabel->setText(task->getStatus()); + ui->globalStatusLabel->setText(m_task->getStatus()); ui->globalStatusLabel->adjustSize(); - ui->globalStatusDetailsLabel->setText(task->getDetails()); + ui->globalStatusDetailsLabel->setText(m_task->getDetails()); ui->globalStatusDetailsLabel->adjustSize(); updateSize(); @@ -234,16 +229,15 @@ void ProgressDialog::addTaskProgress(TaskStepProgress const& progress) void ProgressDialog::changeStepProgress(TaskStepProgress const& task_progress) { m_is_multi_step = true; - if(ui->taskProgressScrollArea->isHidden()) { + if (ui->taskProgressScrollArea->isHidden()) { ui->taskProgressScrollArea->setHidden(false); updateSize(); } - + if (!taskProgress.contains(task_progress.uid)) addTaskProgress(task_progress); auto task_bar = taskProgress.value(task_progress.uid); - auto const [mapped_current, mapped_total] = map_int_zero_max<qint64>(task_progress.current, task_progress.total, 0); if (task_progress.total <= 0) { task_bar->setRange(0, 0); @@ -258,14 +252,12 @@ void ProgressDialog::changeStepProgress(TaskStepProgress const& task_progress) if (task_progress.isDone()) { task_bar->setVisible(false); } - } void ProgressDialog::changeProgress(qint64 current, qint64 total) { ui->globalProgressBar->setMaximum(total); ui->globalProgressBar->setValue(current); - } void ProgressDialog::keyPressEvent(QKeyEvent* e) @@ -287,7 +279,7 @@ void ProgressDialog::keyPressEvent(QKeyEvent* e) void ProgressDialog::closeEvent(QCloseEvent* e) { - if (task && task->isRunning()) { + if (m_task && m_task->isRunning()) { e->ignore(); } else { QDialog::closeEvent(e); |