| 59 | } |
| 60 | |
| 61 | int ProgressDialog::execWithTask(Task* task) |
| 62 | { |
| 63 | this->task = task; |
| 64 | |
| 65 | if (!task) { |
| 66 | qDebug() << "Programmer error: Progress dialog created with null task."; |
| 67 | return QDialog::DialogCode::Accepted; |
| 68 | } |
| 69 | |
| 70 | QDialog::DialogCode result; |
| 71 | if (handleImmediateResult(result)) { |
| 72 | return result; |
| 73 | } |
| 74 | |
| 75 | // Connect signals. |
| 76 | connect(task, &Task::started, this, &ProgressDialog::onTaskStarted); |
| 77 | connect(task, &Task::failed, this, &ProgressDialog::onTaskFailed); |
| 78 | connect(task, &Task::succeeded, this, &ProgressDialog::onTaskSucceeded); |
| 79 | connect(task, &Task::status, this, &ProgressDialog::changeStatus); |
| 80 | connect(task, &Task::stepStatus, this, &ProgressDialog::changeStatus); |
| 81 | connect(task, &Task::progress, this, &ProgressDialog::changeProgress); |
| 82 | |
| 83 | connect(task, &Task::aborted, [this] { QDialog::reject(); }); |
| 84 | connect(task, &Task::abortStatusChanged, ui->skipButton, &QPushButton::setEnabled); |
| 85 | |
| 86 | m_is_multi_step = task->isMultiStep(); |
| 87 | if (!m_is_multi_step) { |
| 88 | ui->globalStatusLabel->setHidden(true); |
| 89 | ui->globalProgressBar->setHidden(true); |
| 90 | } |
| 91 | |
| 92 | // It's a good idea to start the task after we entered the dialog's event loop :^) |
| 93 | if (!task->isRunning()) { |
| 94 | QMetaObject::invokeMethod(task, &Task::start, Qt::QueuedConnection); |
| 95 | } else { |
| 96 | changeStatus(task->getStatus()); |
| 97 | changeProgress(task->getProgress(), task->getTotalProgress()); |
| 98 | } |
| 99 | |
| 100 | return QDialog::exec(); |
| 101 | } |
| 102 | |
| 103 | // TODO: only provide the unique_ptr overloads |
| 104 | int ProgressDialog::execWithTask(std::unique_ptr<Task>&& task) |
no test coverage detected