Mantid
Loading...
Searching...
No Matches
AlgorithmProgressDialogPresenter.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 +
12
14
18 : AlgorithmProgressPresenterBase(parent), m_view{view}, m_model{model}, m_progressBars{RunningAlgorithms()} {
19 model.setDialog(this);
20
21 // Intital setup of any running algorithms
22 auto runningAlgorithms = Mantid::API::AlgorithmManager::Instance().runningInstances();
23
24 for (const auto &alg : runningAlgorithms) {
25 if ((alg) && (alg->isRunning())) {
26 if (m_progressBars.count(alg->getAlgorithmID()) == 0) {
27 algorithmStartedSlot(alg->getAlgorithmID());
28 }
29 }
30 }
31}
32
36
37 const auto algInstance = Mantid::API::AlgorithmManager::Instance().getAlgorithm(alg);
38
39 // There is a chance that the algorithm has already finished
40 // -> if the updateProgressBarSlot triggers this algorithmStartedSlot, but the
41 // original algorithm has already finished, before we got a shared pointer.
42 // This ensures that the tracking only looks after an algorithm that has not
43 // finished
44 if (m_progressBars.find(alg) == m_progressBars.end()) {
45 if (algInstance) {
46 auto treeItem = m_view->addAlgorithm(algInstance);
47 m_progressBars.insert(std::make_pair(alg, treeItem));
48 }
49 }
50}
62 const QString message, const double estimatedTime,
63 const int progressPrecision) {
64 // if the algorithm isn't contained in the progress bar tree, then pretend it
65 // just started
66 if (m_progressBars.count(alg) == 0) {
68
69 // the algorithm did not have an active instance, and was not created,
70 // it has already finished, so don't do any work updating
71 if (m_progressBars.count(alg) == 0) {
72 return;
73 }
74 }
75 setProgressBar(m_progressBars.at(alg).second, progress, message, estimatedTime, progressPrecision);
76}
77
83 // if the algorithm has an active widget, then delete it
84 // if the count is actually 0, then the algorithm ended
85 // before a widget was ever made or displayed, so we avoid doing any work
86 if (m_progressBars.count(alg) != 0) {
87 // keep the pointer to the QTreeItemWidget
88 const auto item = m_progressBars.at(alg).first;
89 m_progressBars.erase(alg);
90 // this removes the item from the tree widget, and deletes all its children
91 delete item;
92 }
93}
95
96} // namespace MantidQt::MantidWidgets
RunningAlgorithms m_progressBars
Container for all the progress bars that are currently being displayed This container does NOT own an...
void algorithmStartedSlot(Mantid::API::AlgorithmID) override
This slot is triggered whenever an algorithm has started executing.
AlgorithmProgressDialogPresenter(QWidget *parent, IAlgorithmProgressDialogWidget *view, AlgorithmProgressModel &model)
std::unordered_map< Mantid::API::AlgorithmID, std::pair< QTreeWidgetItem *, QProgressBar * > > RunningAlgorithms
void updateProgressBarSlot(Mantid::API::AlgorithmID, const double progress, const QString message, const double estimatedTime, const int progressPrecision) override
This slot is triggered whenever an algorithm reports progress.
void algorithmEndedSlot(Mantid::API::AlgorithmID) override
This slot is triggered whenever an algorithms ends.
void setDialog(AlgorithmProgressDialogPresenter *)
void setProgressBar(QProgressBar *, const double, const QString &, const double, const int)
Sets the parameter progress bar to show the progress and message.
virtual std::pair< QTreeWidgetItem *, QProgressBar * > addAlgorithm(Mantid::API::IAlgorithm_sptr alg)=0
Adds an algorithm to the dialog.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
void * AlgorithmID
As we have multiple interfaces to the same logical algorithm we need a way of uniquely identifying ma...
Definition: IAlgorithm.h:28