Mantid
Loading...
Searching...
No Matches
AlgorithmProgressWidget.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2019 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
10
11#include <QProgressBar>
12#include <QString>
13
15
17 : QWidget(parent), m_progressBar{new QProgressBar(this)}, m_layout{new QHBoxLayout(this)},
18 m_detailsButton{new QPushButton("Details")},
19 m_presenter{std::make_unique<AlgorithmProgressPresenter>(parent, this)} {
20 m_progressBar->setAlignment(Qt::AlignHCenter);
21 m_progressBar->setStyleSheet(R"(
22 QProgressBar {
23 text-align: center;
24 border-radius: 3px;
25 }
26 QProgressBar::chunk {
27 background-color: lightgreen;
28 border-radius: 3px;
29 }
30 )");
31 m_progressBar->setValue(0);
32 m_progressBar->setFormat("Idle.");
33 m_layout->addWidget(m_progressBar);
34 m_layout->addWidget(m_detailsButton);
35 this->setLayout(m_layout);
36
37 connect(m_detailsButton, &QPushButton::clicked, this, &AlgorithmProgressWidget::showDetailsDialog);
38}
39
41 // remove the word idle as we are doing something now
42 m_progressBar->setFormat("Running ...");
43}
44
46 m_progressBar->setValue(0);
47 m_progressBar->setFormat("Idle.");
48}
49
51 // If the dialog exist but is not visible, then just show it again
52 if (m_details && !m_details->isVisible()) {
53 m_details->show();
54 } else if (!m_details) {
55 // If the dialog does not exist we create it. The dialog has the attribute
56 // DeleteOnClose so it will delete itself when the user closes it
57 const auto parent = this->parentWidget();
59 // the widget will be deleted when the closeEvent triggers, the
60 // QPointer that is storing it will automatically set it to nullptr
61 // when the widget deletes itself, so there will be no dangling pointer
62 m_details->setAttribute(Qt::WA_DeleteOnClose);
63 m_details->show();
64 }
65}
66
67void AlgorithmProgressWidget::updateProgress(const double progress, const QString &message, const double estimatedTime,
68 const int progressPrecision) {
69 m_presenter->setProgressBar(m_progressBar, progress, message, estimatedTime, progressPrecision);
70}
71
72void AlgorithmProgressWidget::blockUpdates(bool block) { m_presenter->blockSignals(block); }
73
74} // namespace MantidQt::MantidWidgets
void algorithmEnded() override
Setup the view for whenever an algorithm has ended.
void algorithmStarted() override
Setup the view for whenever an algorithm has started.
QPushButton *const m_detailsButton
Button to display the Details window.
void updateProgress(const double progress, const QString &message, const double estimatedTime, const int progressPrecision) override
Update the progress bar.
QPointer< AlgorithmProgressDialogWidget > m_details
Pointer to the details dialog.
QProgressBar *const m_progressBar
Progress bar shown on the workbench.
std::unique_ptr< AlgorithmProgressPresenter > m_presenter
The presenter of the ProgressWidget.
void blockUpdates(bool block=true)
Enable or disable the processing of updates to the algorithm progress.
QHBoxLayout *const m_layout
Layout that contains all the widget for displaying.
STL namespace.