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 branches found
No related tags found
No related merge requests found
Showing
with 109 additions and 67 deletions
...@@ -59,56 +59,16 @@ std::vector<std::string> ProjectRecoveryModel::getRow(int i) { ...@@ -59,56 +59,16 @@ std::vector<std::string> ProjectRecoveryModel::getRow(int i) {
return m_rows.at(i); return m_rows.at(i);
} }
void ProjectRecoveryModel::recoverLast() { std::vector<std::string>
// Clear the ADS ProjectRecoveryModel::getRow(std::string checkpointName) {
Mantid::API::AnalysisDataService::Instance().clear(); for (auto c : m_rows) {
if (c[0] == checkpointName) {
// Recover using the last checkpoint return c;
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, " "));
} }
return std::vector<std::string>({"", "", "0"});
// Close View
m_presenter->closeView();
} }
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() { void ProjectRecoveryModel::startMantidNormally() {
m_projRec->clearAllUnusedCheckpoints(); m_projRec->clearAllUnusedCheckpoints();
m_projRec->startProjectSaving(); m_projRec->startProjectSaving();
...@@ -216,4 +176,10 @@ void ProjectRecoveryModel::createThreadAndManage(const Poco::Path &checkpoint) { ...@@ -216,4 +176,10 @@ void ProjectRecoveryModel::createThreadAndManage(const Poco::Path &checkpoint) {
// Set failed run member to the value from the thread // Set failed run member to the value from the thread
m_failedRun = recoverThread->getFailedRun(); 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: ...@@ -20,12 +20,12 @@ public:
ProjectRecoveryModel(MantidQt::ProjectRecovery *projectRecovery, ProjectRecoveryModel(MantidQt::ProjectRecovery *projectRecovery,
ProjectRecoveryPresenter *presenter); ProjectRecoveryPresenter *presenter);
std::vector<std::string> getRow(int i); std::vector<std::string> getRow(int i);
void recoverLast(); std::vector<std::string> getRow(std::string checkpointName);
void openLastInEditor();
void startMantidNormally(); void startMantidNormally();
void recoverSelectedCheckpoint(std::string &selected); void recoverSelectedCheckpoint(std::string &selected);
void openSelectedInEditor(std::string &selected); void openSelectedInEditor(std::string &selected);
bool getFailedRun() const; bool getFailedRun() const;
std::string decideLastCheckpoint();
private: private:
void fillRows(); void fillRows();
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "ProjectRecoveryView.h" #include "ProjectRecoveryView.h"
#include "RecoveryFailureView.h" #include "RecoveryFailureView.h"
#include <QDialog>
#include <memory> #include <memory>
ProjectRecoveryPresenter::ProjectRecoveryPresenter( ProjectRecoveryPresenter::ProjectRecoveryPresenter(
...@@ -75,24 +76,31 @@ QStringList ProjectRecoveryPresenter::getRow(int i) { ...@@ -75,24 +76,31 @@ QStringList ProjectRecoveryPresenter::getRow(int i) {
return returnVal; 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() { void ProjectRecoveryPresenter::openLastInEditor() {
m_model->openLastInEditor(); auto checkpointToRecover = m_model->decideLastCheckpoint();
m_model->openSelectedInEditor(checkpointToRecover);
} }
void ProjectRecoveryPresenter::startMantidNormally() { void ProjectRecoveryPresenter::startMantidNormally() {
m_model->startMantidNormally(); m_model->startMantidNormally();
} }
void ProjectRecoveryPresenter::recoverSelectedCheckpoint(QString &selected) { void ProjectRecoveryPresenter::recoverSelectedCheckpoint(
std::string stdString = selected.toStdString(); QString &selected, boost::shared_ptr<QDialog> view) {
m_model->recoverSelectedCheckpoint(stdString); auto checkpointToRecover = selected.toStdString();
setUpProgressBar(checkpointToRecover, view);
m_model->recoverSelectedCheckpoint(checkpointToRecover);
} }
void ProjectRecoveryPresenter::openSelectedInEditor(QString &selected) { void ProjectRecoveryPresenter::openSelectedInEditor(QString &selected) {
std::string stdString = selected.toStdString(); auto checkpointToRecover = selected.toStdString();
m_model->openSelectedInEditor(stdString); m_model->openSelectedInEditor(checkpointToRecover);
} }
void ProjectRecoveryPresenter::closeView() { void ProjectRecoveryPresenter::closeView() {
...@@ -114,4 +122,17 @@ operator=(const ProjectRecoveryPresenter &obj) { ...@@ -114,4 +122,17 @@ operator=(const ProjectRecoveryPresenter &obj) {
m_mainWindow = obj.m_mainWindow; m_mainWindow = obj.m_mainWindow;
} }
return *this; 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 @@ ...@@ -8,7 +8,9 @@
#define PROJECTRECOVERYPRESENTER_H #define PROJECTRECOVERYPRESENTER_H
#include "ProjectRecoveryModel.h" #include "ProjectRecoveryModel.h"
#include <QDialog>
#include <QStringList> #include <QStringList>
#include <boost/shared_ptr.hpp>
#include <memory> #include <memory>
namespace MantidQt { namespace MantidQt {
...@@ -27,15 +29,20 @@ public: ...@@ -27,15 +29,20 @@ public:
bool startRecoveryView(); bool startRecoveryView();
bool startRecoveryFailure(); bool startRecoveryFailure();
QStringList getRow(int i); QStringList getRow(int i);
void recoverLast(); void recoverLast(boost::shared_ptr<QDialog> view);
void openLastInEditor(); void openLastInEditor();
void startMantidNormally(); void startMantidNormally();
void recoverSelectedCheckpoint(QString &selected); void recoverSelectedCheckpoint(QString &selected,
boost::shared_ptr<QDialog> view);
void openSelectedInEditor(QString &selected); void openSelectedInEditor(QString &selected);
void closeView(); void closeView();
ProjectRecoveryPresenter &operator=(const ProjectRecoveryPresenter &obj); ProjectRecoveryPresenter &operator=(const ProjectRecoveryPresenter &obj);
private: private:
void setUpProgressBar(std::string checkpointToRecover,
boost::shared_ptr<QDialog> view);
friend class ProjectRecoveryView;
friend class RecoveryFailureView;
ProjectRecoveryModel *m_model; ProjectRecoveryModel *m_model;
ProjectRecoveryView *m_recView; ProjectRecoveryView *m_recView;
RecoveryFailureView *m_failureView; RecoveryFailureView *m_failureView;
......
...@@ -6,16 +6,26 @@ ...@@ -6,16 +6,26 @@
// SPDX - License - Identifier: GPL - 3.0 + // SPDX - License - Identifier: GPL - 3.0 +
#include "ProjectRecoveryView.h" #include "ProjectRecoveryView.h"
#include "MantidKernel/UsageService.h" #include "MantidKernel/UsageService.h"
#include "ApplicationWindow.h"
#include "ScriptingWindow.h"
#include "ScriptFileInterpreter.h"
#include "Script.h"
#include "ui_ProjectRecoveryWidget.h" #include "ui_ProjectRecoveryWidget.h"
#include <boost/smart_ptr/make_shared.hpp>
ProjectRecoveryView::ProjectRecoveryView(QWidget *parent, ProjectRecoveryView::ProjectRecoveryView(QWidget *parent,
ProjectRecoveryPresenter *presenter) ProjectRecoveryPresenter *presenter)
: QDialog(parent), ui(new Ui::ProjectRecoveryWidget), : QDialog(parent), m_progressBarCounter(0) {
m_presenter(presenter) { 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->setupUi(this);
ui->tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch); ui->tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
ui->tableWidget->verticalHeader()->setResizeMode(QHeaderView::Stretch); ui->tableWidget->verticalHeader()->setResizeMode(QHeaderView::Stretch);
ui->progressBar->setMinimum(0);
// Set the table information // Set the table information
addDataToTable(ui); addDataToTable(ui);
Mantid::Kernel::UsageService::Instance().registerFeatureUsage( Mantid::Kernel::UsageService::Instance().registerFeatureUsage(
...@@ -32,7 +42,7 @@ void ProjectRecoveryView::addDataToTable(Ui::ProjectRecoveryWidget *ui) { ...@@ -32,7 +42,7 @@ void ProjectRecoveryView::addDataToTable(Ui::ProjectRecoveryWidget *ui) {
void ProjectRecoveryView::onClickLastCheckpoint() { void ProjectRecoveryView::onClickLastCheckpoint() {
// Recover last checkpoint // Recover last checkpoint
m_presenter->recoverLast(); m_presenter->recoverLast(boost::make_shared<QDialog>(this));
Mantid::Kernel::UsageService::Instance().registerFeatureUsage( Mantid::Kernel::UsageService::Instance().registerFeatureUsage(
"Feature", "ProjectRecoveryWindow->RecoverLastCheckpoint", false); "Feature", "ProjectRecoveryWindow->RecoverLastCheckpoint", false);
} }
...@@ -52,8 +62,18 @@ void ProjectRecoveryView::onClickStartMantidNormally() { ...@@ -52,8 +62,18 @@ void ProjectRecoveryView::onClickStartMantidNormally() {
} }
void ProjectRecoveryView::reject() { void ProjectRecoveryView::reject() {
// Do nothing just absorb request // Do the same as startMantidNormally
m_presenter->startMantidNormally(); m_presenter->startMantidNormally();
Mantid::Kernel::UsageService::Instance().registerFeatureUsage( Mantid::Kernel::UsageService::Instance().registerFeatureUsage(
"Feature", "ProjectRecoveryWindow->StartMantidNormally", false); "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: ...@@ -23,6 +23,10 @@ public:
ProjectRecoveryPresenter *presenter = nullptr); ProjectRecoveryPresenter *presenter = nullptr);
~ProjectRecoveryView(); ~ProjectRecoveryView();
void reject() override; void reject() override;
void setProgressBarMaximum(int newValue);
public slots:
void updateProgressBar(int newValue, bool err);
private slots: private slots:
void onClickLastCheckpoint(); void onClickLastCheckpoint();
...@@ -31,6 +35,7 @@ private slots: ...@@ -31,6 +35,7 @@ private slots:
private: private:
void addDataToTable(Ui::ProjectRecoveryWidget *ui); void addDataToTable(Ui::ProjectRecoveryWidget *ui);
unsigned int m_progressBarCounter;
Ui::ProjectRecoveryWidget *ui; Ui::ProjectRecoveryWidget *ui;
ProjectRecoveryPresenter *m_presenter; ProjectRecoveryPresenter *m_presenter;
}; };
......
...@@ -6,12 +6,14 @@ ...@@ -6,12 +6,14 @@
// SPDX - License - Identifier: GPL - 3.0 + // SPDX - License - Identifier: GPL - 3.0 +
#include "RecoveryFailureView.h" #include "RecoveryFailureView.h"
#include "ui_RecoveryFailure.h" #include "ui_RecoveryFailure.h"
#include "ApplicationWindow.h"
#include "MantidKernel/UsageService.h" #include "MantidKernel/UsageService.h"
#include <boost/smart_ptr/make_shared.hpp>
RecoveryFailureView::RecoveryFailureView(QWidget *parent, RecoveryFailureView::RecoveryFailureView(QWidget *parent,
ProjectRecoveryPresenter *presenter) 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->setupUi(this);
ui->tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch); ui->tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
ui->tableWidget->verticalHeader()->setResizeMode(QHeaderView::Stretch); ui->tableWidget->verticalHeader()->setResizeMode(QHeaderView::Stretch);
...@@ -48,7 +50,7 @@ void RecoveryFailureView::addDataToTable(Ui::RecoveryFailure *ui) { ...@@ -48,7 +50,7 @@ void RecoveryFailureView::addDataToTable(Ui::RecoveryFailure *ui) {
void RecoveryFailureView::onClickLastCheckpoint() { void RecoveryFailureView::onClickLastCheckpoint() {
// Recover last checkpoint // Recover last checkpoint
m_presenter->recoverLast(); m_presenter->recoverLast(boost::make_shared<QDialog>(this));
Mantid::Kernel::UsageService::Instance().registerFeatureUsage( Mantid::Kernel::UsageService::Instance().registerFeatureUsage(
"Feature", "ProjectRecoveryFailureWindow->RecoverLastCheckpoint", false); "Feature", "ProjectRecoveryFailureWindow->RecoverLastCheckpoint", false);
} }
...@@ -61,7 +63,8 @@ void RecoveryFailureView::onClickSelectedCheckpoint() { ...@@ -61,7 +63,8 @@ void RecoveryFailureView::onClickSelectedCheckpoint() {
if (text.toStdString() == "") { if (text.toStdString() == "") {
return; return;
} }
m_presenter->recoverSelectedCheckpoint(text); m_presenter->recoverSelectedCheckpoint(text,
boost::make_shared<QDialog>(this));
} }
Mantid::Kernel::UsageService::Instance().registerFeatureUsage( Mantid::Kernel::UsageService::Instance().registerFeatureUsage(
"Feature", "ProjectRecoveryFailureWindow->RecoverSelectedCheckpoint", "Feature", "ProjectRecoveryFailureWindow->RecoverSelectedCheckpoint",
...@@ -95,4 +98,12 @@ void RecoveryFailureView::reject() { ...@@ -95,4 +98,12 @@ void RecoveryFailureView::reject() {
m_presenter->startMantidNormally(); m_presenter->startMantidNormally();
Mantid::Kernel::UsageService::Instance().registerFeatureUsage( Mantid::Kernel::UsageService::Instance().registerFeatureUsage(
"Feature", "ProjectRecoveryFailureWindow->StartMantidNormally", false); "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: ...@@ -23,6 +23,8 @@ public:
ProjectRecoveryPresenter *presenter = nullptr); ProjectRecoveryPresenter *presenter = nullptr);
~RecoveryFailureView(); ~RecoveryFailureView();
void reject() override; void reject() override;
void updateProgressBar(int newValue);
void setProgressBarMaximum(int newValue);
private slots: private slots:
void onClickLastCheckpoint(); void onClickLastCheckpoint();
...@@ -33,6 +35,7 @@ private slots: ...@@ -33,6 +35,7 @@ private slots:
private: private:
void addDataToTable(Ui::RecoveryFailure *ui); void addDataToTable(Ui::RecoveryFailure *ui);
unsigned int m_progressBarCounter;
Ui::RecoveryFailure *ui; Ui::RecoveryFailure *ui;
ProjectRecoveryPresenter *m_presenter; ProjectRecoveryPresenter *m_presenter;
}; };
......
...@@ -57,6 +57,8 @@ public: ...@@ -57,6 +57,8 @@ public:
/// Is the script running /// Is the script running
virtual bool isExecuting() const; virtual bool isExecuting() const;
QSharedPointer<Script> getRunner() { return m_runner; }
public slots: public slots:
/// Save to the currently stored name /// Save to the currently stored name
virtual void saveToCurrentFile(); virtual void saveToCurrentFile();
......
...@@ -905,3 +905,7 @@ Script::ExecutionMode ScriptingWindow::getExecutionMode() const { ...@@ -905,3 +905,7 @@ Script::ExecutionMode ScriptingWindow::getExecutionMode() const {
else else
return Script::Serialised; return Script::Serialised;
} }
ScriptFileInterpreter *ScriptingWindow::getCurrentScriptInterpreter() {
return m_manager->m_current;
}
\ No newline at end of file
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
//---------------------------------------------------------- //----------------------------------------------------------
// Forward declarations // Forward declarations
//--------------------------------------------------------- //---------------------------------------------------------
class ScriptFileInterpreter;
class MultiTabScriptInterpreter; class MultiTabScriptInterpreter;
class ScriptingEnv; class ScriptingEnv;
class QTextEdit; class QTextEdit;
...@@ -76,6 +77,8 @@ public: ...@@ -76,6 +77,8 @@ public:
// We set a flag on failure to avoid problems with Async not returning success // We set a flag on failure to avoid problems with Async not returning success
bool getSynchronousErrorFlag() { return m_failureFlag; } bool getSynchronousErrorFlag() { return m_failureFlag; }
ScriptFileInterpreter *getCurrentScriptInterpreter();
signals: signals:
/// Show the scripting language dialog /// Show the scripting language dialog
void chooseScriptingLanguage(); 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