Mantid
Loading...
Searching...
No Matches
AlgorithmProgressPresenterBase.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 +
8#include <QProgressBar>
9
11
13 const auto connection = Qt::QueuedConnection;
16
19
22}
23
29 emit algorithmStartedSignal(alg);
30}
44void AlgorithmProgressPresenterBase::setProgressBar(QProgressBar *progressBar, const double progress,
45 const QString &message, const double estimatedTime,
46 const int progressPrecision) {
47 progressBar->setValue(static_cast<int>(progress * 100));
48 // Make the progress string
49 std::ostringstream mess;
50 if (!message.isEmpty()) {
51 mess << message.toStdString() << " ";
52 }
53 mess.precision(progressPrecision);
54 mess << std::fixed << progress * 100 << "%";
55 if (estimatedTime > 0.5) {
56 mess.precision(0);
57 mess << " (~";
58 if (estimatedTime < 60)
59 mess << static_cast<int>(estimatedTime) << "s";
60 else if (estimatedTime < 60 * 60) {
61 int min = static_cast<int>(estimatedTime / 60);
62 int sec = static_cast<int>(estimatedTime - min * 60);
63 mess << min << "m" << std::setfill('0') << std::setw(2) << sec << "s";
64 } else {
65 int hours = static_cast<int>(estimatedTime / 3600);
66 int min = static_cast<int>((estimatedTime - hours * 3600) / 60);
67 mess << hours << "h" << std::setfill('0') << std::setw(2) << min << "m";
68 }
69 mess << ")";
70 }
71 QString formatStr = QString::fromStdString(mess.str());
72 progressBar->setFormat(formatStr);
73}
83 const std::string &msg, const double estimatedTime,
84 const int progressPrecision) {
85 emit updateProgressBarSignal(alg, progress, QString::fromStdString(msg), estimatedTime, progressPrecision);
86}
87} // namespace MantidQt::MantidWidgets
void setProgressBar(QProgressBar *, const double, const QString &, const double, const int)
Sets the parameter progress bar to show the progress and message.
void updateProgressBar(Mantid::API::AlgorithmID, double, const std::string &, const double estimatedTime, const int progressPrecision)
Signals to the presenters that there has been progress in one of the algorithms.
void algorithmStarted(Mantid::API::AlgorithmID)
Signals to the presenters that an algorithm has started.
void updateProgressBarSignal(Mantid::API::AlgorithmID, double progress, QString message, double estimatedTime, int progressPrecision)
virtual void algorithmStartedSlot(Mantid::API::AlgorithmID)=0
virtual void algorithmEndedSlot(Mantid::API::AlgorithmID)=0
void algorithmStartedSignal(Mantid::API::AlgorithmID)
void algorithmEnded(Mantid::API::AlgorithmID)
Signals to the presenters that an algorithm has ended.
virtual void updateProgressBarSlot(Mantid::API::AlgorithmID, const double, const QString, const double, const int)=0
void * AlgorithmID
As we have multiple interfaces to the same logical algorithm we need a way of uniquely identifying ma...
Definition: IAlgorithm.h:28