| 129 | } |
| 130 | |
| 131 | int ProgressDialog::execWithTask(Task* task) |
| 132 | { |
| 133 | this->m_task = task; |
| 134 | |
| 135 | if (!task) { |
| 136 | qDebug() << "Programmer error: Progress dialog created with null task."; |
| 137 | return QDialog::DialogCode::Accepted; |
| 138 | } |
| 139 | |
| 140 | QDialog::DialogCode result{}; |
| 141 | if (handleImmediateResult(result)) { |
| 142 | return result; |
| 143 | } |
| 144 | |
| 145 | // Connect signals. |
| 146 | this->m_taskConnections.push_back(connect(task, &Task::started, this, &ProgressDialog::onTaskStarted)); |
| 147 | this->m_taskConnections.push_back(connect(task, &Task::failed, this, &ProgressDialog::onTaskFailed)); |
| 148 | this->m_taskConnections.push_back(connect(task, &Task::succeeded, this, &ProgressDialog::onTaskSucceeded)); |
| 149 | this->m_taskConnections.push_back(connect(task, &Task::status, this, &ProgressDialog::changeStatus)); |
| 150 | this->m_taskConnections.push_back(connect(task, &Task::details, this, &ProgressDialog::changeStatus)); |
| 151 | this->m_taskConnections.push_back(connect(task, &Task::stepProgress, this, &ProgressDialog::changeStepProgress)); |
| 152 | this->m_taskConnections.push_back(connect(task, &Task::progress, this, &ProgressDialog::changeProgress)); |
| 153 | this->m_taskConnections.push_back(connect(task, &Task::aborted, this, &ProgressDialog::hide)); |
| 154 | this->m_taskConnections.push_back(connect(task, &Task::abortStatusChanged, ui->skipButton, &QPushButton::setEnabled)); |
| 155 | |
| 156 | m_is_multi_step = task->isMultiStep(); |
| 157 | ui->taskProgressScrollArea->setHidden(!m_is_multi_step); |
| 158 | updateSize(); |
| 159 | |
| 160 | // It's a good idea to start the task after we entered the dialog's event loop :^) |
| 161 | if (!task->isRunning()) { |
| 162 | QMetaObject::invokeMethod(task, &Task::start, Qt::QueuedConnection); |
| 163 | } else { |
| 164 | changeStatus(task->getStatus()); |
| 165 | changeProgress(task->getProgress(), task->getTotalProgress()); |
| 166 | } |
| 167 | |
| 168 | return QDialog::exec(); |
| 169 | } |
| 170 | |
| 171 | // TODO: only provide the unique_ptr overloads |
| 172 | int ProgressDialog::execWithTask(std::unique_ptr<Task>&& task) |
no test coverage detected