Mantid
Loading...
Searching...
No Matches
AlgorithmProgressDialogWidget.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#include <QHeaderView>
11#include <QIcon>
12#include <QProgressBar>
13#include <QPushButton>
14#include <QStringList>
15#include <QTreeWidget>
16#include <QVBoxLayout>
17
19
21 : QDialog(parent), m_tree{new QTreeWidget(this)}, m_presenter{std::make_unique<AlgorithmProgressDialogPresenter>(
22 parent, this, model)} {
23
24 m_tree->setColumnCount(3);
25 m_tree->setSelectionMode(QTreeWidget::NoSelection);
26 m_tree->setColumnWidth(0, 220);
27 m_tree->setHeaderLabels({"Algorithm", "Progress", ""});
28 auto header = m_tree->header();
29 header->setSectionResizeMode(1, QHeaderView::Stretch);
30 header->setStretchLastSection(false);
31
32 auto buttonLayout = new QHBoxLayout();
33 const auto button = new QPushButton("Close", this);
34
35 connect(button, &QPushButton::clicked, this, &AlgorithmProgressDialogWidget::close);
36
37 buttonLayout->addStretch();
38 buttonLayout->addWidget(button);
39
40 auto layout = new QVBoxLayout();
41 layout->addWidget(m_tree);
42 layout->addLayout(buttonLayout);
43
44 setLayout(layout);
45 setWindowTitle("Mantid - Algorithm Progress");
46 setWindowIcon(QIcon(":/images/MantidIcon.ico"));
47 resize(500, 300);
48}
49
54std::pair<QTreeWidgetItem *, QProgressBar *>
56 const auto name = alg->name();
57 const auto &properties = alg->getProperties();
58 const auto item = new QTreeWidgetItem(m_tree, QStringList{QString::fromStdString(name)});
59
60 m_tree->addTopLevelItem(item);
61 auto progressBar = new QProgressBar(m_tree);
62 progressBar->setAlignment(Qt::AlignHCenter);
63
64 const auto cancelButton = new AlgorithmProgressDialogWidgetCancelButton(alg, m_tree);
65
66 m_tree->setItemWidget(item, 1, progressBar);
67 m_tree->setItemWidget(item, 2, cancelButton);
68
69 for (const auto &prop : properties) {
70 const auto &propAsString = prop->value();
71 if (!propAsString.empty()) {
72 item->addChild(new QTreeWidgetItem(item, QStringList{QString::fromStdString(propAsString)}));
73 }
74 }
75
76 return std::make_pair(item, progressBar);
77}
78
80 // stops the any incoming signals for widget making/updating/deleting
81 // the window is closing so we don't care about processing them
82 m_presenter->blockSignals(true);
83 QDialog::closeEvent(event);
84}
85
86} // namespace MantidQt::MantidWidgets
AlgorithmProgressDialogWidget(QWidget *parent, AlgorithmProgressModel &model)
QTreeWidget * m_tree
Owned by this dialog, will be deleted on close.
std::pair< QTreeWidgetItem *, QProgressBar * > addAlgorithm(Mantid::API::IAlgorithm_sptr alg) override
Adds an algorithm to the dialog.
std::unique_ptr< AlgorithmProgressDialogPresenter > m_presenter
std::shared_ptr< IAlgorithm > IAlgorithm_sptr
shared pointer to Mantid::API::IAlgorithm
STL namespace.