Skip to content
Snippets Groups Projects
Commit debdffdf authored by Samuel Jones's avatar Samuel Jones
Browse files

Re #23570 Initial progress bar implementation

parent 11717db7
No related merge requests found
Showing
with 109 additions and 67 deletions
......@@ -59,56 +59,16 @@ std::vector<std::string> ProjectRecoveryModel::getRow(int i) {
return m_rows.at(i);
}
void ProjectRecoveryModel::recoverLast() {
// Clear the ADS
Mantid::API::AnalysisDataService::Instance().clear();
// Recover using the last checkpoint
Poco::Path output(Mantid::Kernel::ConfigService::Instance().getAppDataDir());
output.append("ordered_recovery.py");
auto mostRecentCheckpoints = m_projRec->getRecoveryFolderCheckpointsPR(
m_projRec->getRecoveryFolderLoadPR());
auto mostRecentCheckpoint = mostRecentCheckpoints.back();
m_projRec->openInEditor(mostRecentCheckpoint, output);
if (m_failedRun) {
createThreadAndManage(mostRecentCheckpoint);
auto checkpointToCheck =
mostRecentCheckpoint.directory(mostRecentCheckpoint.depth() - 1);
updateCheckpointTried(
checkpointToCheck.replace(checkpointToCheck.find("T"), 1, " "));
std::vector<std::string>
ProjectRecoveryModel::getRow(std::string checkpointName) {
for (auto c : m_rows) {
if (c[0] == checkpointName) {
return c;
}
}
// Close View
m_presenter->closeView();
return std::vector<std::string>({"", "", "0"});
}
void ProjectRecoveryModel::openLastInEditor() {
// Clear the ADS
Mantid::API::AnalysisDataService::Instance().clear();
// Open the last made checkpoint in editor
auto beforeCheckpoints = m_projRec->getRecoveryFolderLoadPR();
auto mostRecentCheckpoints =
m_projRec->getRecoveryFolderCheckpointsPR(beforeCheckpoints);
auto mostRecentCheckpoint = mostRecentCheckpoints.back();
Poco::Path output(Mantid::Kernel::ConfigService::Instance().getAppDataDir());
output.append("ordered_recovery.py");
m_projRec->openInEditor(mostRecentCheckpoint, output);
// Restart project recovery as we stay synchronous
m_projRec->clearAllCheckpoints(beforeCheckpoints);
m_projRec->startProjectSaving();
if (m_failedRun) {
auto checkpointToRecover =
mostRecentCheckpoint.directory(mostRecentCheckpoint.depth() - 1);
checkpointToRecover.replace(checkpointToRecover.find("T"), 1, " ");
updateCheckpointTried(checkpointToRecover);
}
m_failedRun = false;
// Close View
m_presenter->closeView();
}
void ProjectRecoveryModel::startMantidNormally() {
m_projRec->clearAllUnusedCheckpoints();
m_projRec->startProjectSaving();
......@@ -216,4 +176,10 @@ void ProjectRecoveryModel::createThreadAndManage(const Poco::Path &checkpoint) {
// Set failed run member to the value from the thread
m_failedRun = recoverThread->getFailedRun();
}
std::string ProjectRecoveryModel::decideLastCheckpoint() {
auto mostRecentCheckpoints = m_projRec->getRecoveryFolderCheckpointsPR(
m_projRec->getRecoveryFolderLoadPR());
return mostRecentCheckpoints.back().toString();
}
\ No newline at end of file
......@@ -20,12 +20,12 @@ public:
ProjectRecoveryModel(MantidQt::ProjectRecovery *projectRecovery,
ProjectRecoveryPresenter *presenter);
std::vector<std::string> getRow(int i);
void recoverLast();
void openLastInEditor();
std::vector<std::string> getRow(std::string checkpointName);
void startMantidNormally();
void recoverSelectedCheckpoint(std::string &selected);
void openSelectedInEditor(std::string &selected);
bool getFailedRun() const;
std::string decideLastCheckpoint();
private:
void fillRows();
......
......@@ -11,6 +11,7 @@
#include "ProjectRecoveryView.h"
#include "RecoveryFailureView.h"
#include <QDialog>
#include <memory>
ProjectRecoveryPresenter::ProjectRecoveryPresenter(
......@@ -75,24 +76,31 @@ QStringList ProjectRecoveryPresenter::getRow(int i) {
return returnVal;
}
void ProjectRecoveryPresenter::recoverLast() { m_model->recoverLast(); }
void ProjectRecoveryPresenter::recoverLast(boost::shared_ptr<QDialog> view) {
auto checkpointToRecover = m_model->decideLastCheckpoint();
setUpProgressBar(checkpointToRecover, view);
m_model->recoverSelectedCheckpoint(checkpointToRecover);
}
void ProjectRecoveryPresenter::openLastInEditor() {
m_model->openLastInEditor();
auto checkpointToRecover = m_model->decideLastCheckpoint();
m_model->openSelectedInEditor(checkpointToRecover);
}
void ProjectRecoveryPresenter::startMantidNormally() {
m_model->startMantidNormally();
}
void ProjectRecoveryPresenter::recoverSelectedCheckpoint(QString &selected) {
std::string stdString = selected.toStdString();
m_model->recoverSelectedCheckpoint(stdString);
void ProjectRecoveryPresenter::recoverSelectedCheckpoint(
QString &selected, boost::shared_ptr<QDialog> view) {
auto checkpointToRecover = selected.toStdString();
setUpProgressBar(checkpointToRecover, view);
m_model->recoverSelectedCheckpoint(checkpointToRecover);
}
void ProjectRecoveryPresenter::openSelectedInEditor(QString &selected) {
std::string stdString = selected.toStdString();
m_model->openSelectedInEditor(stdString);
auto checkpointToRecover = selected.toStdString();
m_model->openSelectedInEditor(checkpointToRecover);
}
void ProjectRecoveryPresenter::closeView() {
......@@ -114,4 +122,17 @@ operator=(const ProjectRecoveryPresenter &obj) {
m_mainWindow = obj.m_mainWindow;
}
return *this;
}
void ProjectRecoveryPresenter::setUpProgressBar(
std::string checkpointToRecover, boost::shared_ptr<QDialog> view) {
auto row = m_model->getRow(checkpointToRecover);
auto firstView = boost::dynamic_pointer_cast<ProjectRecoveryView>(view);
auto secondView = boost::dynamic_pointer_cast<RecoveryFailureView>(view);
if (firstView) {
firstView->setProgressBarMaximum(std::stoi(row[2]));
}
if (secondView) {
secondView->setProgressBarMaximum(std::stoi(row[2]));
}
}
\ No newline at end of file
......@@ -8,7 +8,9 @@
#define PROJECTRECOVERYPRESENTER_H
#include "ProjectRecoveryModel.h"
#include <QDialog>
#include <QStringList>
#include <boost/shared_ptr.hpp>
#include <memory>
namespace MantidQt {
......@@ -27,15 +29,20 @@ public:
bool startRecoveryView();
bool startRecoveryFailure();
QStringList getRow(int i);
void recoverLast();
void recoverLast(boost::shared_ptr<QDialog> view);
void openLastInEditor();
void startMantidNormally();
void recoverSelectedCheckpoint(QString &selected);
void recoverSelectedCheckpoint(QString &selected,
boost::shared_ptr<QDialog> view);
void openSelectedInEditor(QString &selected);
void closeView();
ProjectRecoveryPresenter &operator=(const ProjectRecoveryPresenter &obj);
private:
void setUpProgressBar(std::string checkpointToRecover,
boost::shared_ptr<QDialog> view);
friend class ProjectRecoveryView;
friend class RecoveryFailureView;
ProjectRecoveryModel *m_model;
ProjectRecoveryView *m_recView;
RecoveryFailureView *m_failureView;
......
......@@ -6,16 +6,26 @@
// SPDX - License - Identifier: GPL - 3.0 +
#include "ProjectRecoveryView.h"
#include "MantidKernel/UsageService.h"
#include "ApplicationWindow.h"
#include "ScriptingWindow.h"
#include "ScriptFileInterpreter.h"
#include "Script.h"
#include "ui_ProjectRecoveryWidget.h"
#include <boost/smart_ptr/make_shared.hpp>
ProjectRecoveryView::ProjectRecoveryView(QWidget *parent,
ProjectRecoveryPresenter *presenter)
: QDialog(parent), ui(new Ui::ProjectRecoveryWidget),
m_presenter(presenter) {
: QDialog(parent), m_progressBarCounter(0) {
ui = new Ui::ProjectRecoveryWidget;
m_presenter = presenter;
connect(m_presenter->m_mainWindow->getScriptWindowHandle()
->getCurrentScriptInterpreter()->getRunner().data(),
SIGNAL(currentLineChanged(int, bool)), this,
SLOT(updateProgressBar(int, bool)));
ui->setupUi(this);
ui->tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
ui->tableWidget->verticalHeader()->setResizeMode(QHeaderView::Stretch);
ui->progressBar->setMinimum(0);
// Set the table information
addDataToTable(ui);
Mantid::Kernel::UsageService::Instance().registerFeatureUsage(
......@@ -32,7 +42,7 @@ void ProjectRecoveryView::addDataToTable(Ui::ProjectRecoveryWidget *ui) {
void ProjectRecoveryView::onClickLastCheckpoint() {
// Recover last checkpoint
m_presenter->recoverLast();
m_presenter->recoverLast(boost::make_shared<QDialog>(this));
Mantid::Kernel::UsageService::Instance().registerFeatureUsage(
"Feature", "ProjectRecoveryWindow->RecoverLastCheckpoint", false);
}
......@@ -52,8 +62,18 @@ void ProjectRecoveryView::onClickStartMantidNormally() {
}
void ProjectRecoveryView::reject() {
// Do nothing just absorb request
// Do the same as startMantidNormally
m_presenter->startMantidNormally();
Mantid::Kernel::UsageService::Instance().registerFeatureUsage(
"Feature", "ProjectRecoveryWindow->StartMantidNormally", false);
}
void ProjectRecoveryView::updateProgressBar(int newValue, bool err) {
if (!err) {
ui->progressBar->setValue(newValue);
}
}
void ProjectRecoveryView::setProgressBarMaximum(int newValue) {
ui->progressBar->setMaximum(newValue);
}
\ No newline at end of file
......@@ -23,6 +23,10 @@ public:
ProjectRecoveryPresenter *presenter = nullptr);
~ProjectRecoveryView();
void reject() override;
void setProgressBarMaximum(int newValue);
public slots:
void updateProgressBar(int newValue, bool err);
private slots:
void onClickLastCheckpoint();
......@@ -31,6 +35,7 @@ private slots:
private:
void addDataToTable(Ui::ProjectRecoveryWidget *ui);
unsigned int m_progressBarCounter;
Ui::ProjectRecoveryWidget *ui;
ProjectRecoveryPresenter *m_presenter;
};
......
......@@ -6,12 +6,14 @@
// SPDX - License - Identifier: GPL - 3.0 +
#include "RecoveryFailureView.h"
#include "ui_RecoveryFailure.h"
#include "ApplicationWindow.h"
#include "MantidKernel/UsageService.h"
#include <boost/smart_ptr/make_shared.hpp>
RecoveryFailureView::RecoveryFailureView(QWidget *parent,
ProjectRecoveryPresenter *presenter)
: QDialog(parent), ui(new Ui::RecoveryFailure), m_presenter(presenter) {
: QDialog(parent), ui(new Ui::RecoveryFailure), m_presenter(presenter),
m_progressBarCounter(0) {
ui->setupUi(this);
ui->tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
ui->tableWidget->verticalHeader()->setResizeMode(QHeaderView::Stretch);
......@@ -48,7 +50,7 @@ void RecoveryFailureView::addDataToTable(Ui::RecoveryFailure *ui) {
void RecoveryFailureView::onClickLastCheckpoint() {
// Recover last checkpoint
m_presenter->recoverLast();
m_presenter->recoverLast(boost::make_shared<QDialog>(this));
Mantid::Kernel::UsageService::Instance().registerFeatureUsage(
"Feature", "ProjectRecoveryFailureWindow->RecoverLastCheckpoint", false);
}
......@@ -61,7 +63,8 @@ void RecoveryFailureView::onClickSelectedCheckpoint() {
if (text.toStdString() == "") {
return;
}
m_presenter->recoverSelectedCheckpoint(text);
m_presenter->recoverSelectedCheckpoint(text,
boost::make_shared<QDialog>(this));
}
Mantid::Kernel::UsageService::Instance().registerFeatureUsage(
"Feature", "ProjectRecoveryFailureWindow->RecoverSelectedCheckpoint",
......@@ -95,4 +98,12 @@ void RecoveryFailureView::reject() {
m_presenter->startMantidNormally();
Mantid::Kernel::UsageService::Instance().registerFeatureUsage(
"Feature", "ProjectRecoveryFailureWindow->StartMantidNormally", false);
}
void RecoveryFailureView::updateProgressBar(int newValue) {
ui->progressBar->setValue(newValue);
}
void RecoveryFailureView::setProgressBarMaximum(int newValue) {
ui->progressBar->setMaximum(newValue);
}
\ No newline at end of file
......@@ -23,6 +23,8 @@ public:
ProjectRecoveryPresenter *presenter = nullptr);
~RecoveryFailureView();
void reject() override;
void updateProgressBar(int newValue);
void setProgressBarMaximum(int newValue);
private slots:
void onClickLastCheckpoint();
......@@ -33,6 +35,7 @@ private slots:
private:
void addDataToTable(Ui::RecoveryFailure *ui);
unsigned int m_progressBarCounter;
Ui::RecoveryFailure *ui;
ProjectRecoveryPresenter *m_presenter;
};
......
......@@ -57,6 +57,8 @@ public:
/// Is the script running
virtual bool isExecuting() const;
QSharedPointer<Script> getRunner() { return m_runner; }
public slots:
/// Save to the currently stored name
virtual void saveToCurrentFile();
......
......@@ -905,3 +905,7 @@ Script::ExecutionMode ScriptingWindow::getExecutionMode() const {
else
return Script::Serialised;
}
ScriptFileInterpreter *ScriptingWindow::getCurrentScriptInterpreter() {
return m_manager->m_current;
}
\ No newline at end of file
......@@ -19,6 +19,7 @@
//----------------------------------------------------------
// Forward declarations
//---------------------------------------------------------
class ScriptFileInterpreter;
class MultiTabScriptInterpreter;
class ScriptingEnv;
class QTextEdit;
......@@ -76,6 +77,8 @@ public:
// We set a flag on failure to avoid problems with Async not returning success
bool getSynchronousErrorFlag() { return m_failureFlag; }
ScriptFileInterpreter *getCurrentScriptInterpreter();
signals:
/// Show the scripting language dialog
void chooseScriptingLanguage();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment