Commit ac03705f authored by Anthony Lim's avatar Anthony Lim
Browse files

refs #26726 ALFView move stuff to model

parent d09c1482
......@@ -33,9 +33,6 @@ protected:
void initLayout() override;
private:
// std::unique_ptr<ALFView_view> m_view;
// std::unique_ptr<ALFView_model> m_model;
// std::unique_ptr<ALFView_presenter> m_presenter;
ALFView_view *m_view;
ALFView_model *m_model;
ALFView_presenter *m_presenter;
......
......@@ -41,9 +41,9 @@ void ALFView_model::loadEmptyInstrument() {
* Loads data for use in ALFView
* Loads data, normalise to current and then converts to d spacing
* @param name:: string name for ALF data
* @return int:: the run number
* @return std::pair<int,std::string>:: the run number and status
*/
int ALFView_model::loadData(const std::string &name) {
std::pair<int, std::string> ALFView_model::loadData(const std::string &name) {
auto alg = AlgorithmManager::Instance().create("Load");
alg->initialize();
alg->setProperty("Filename", name);
......@@ -51,7 +51,23 @@ int ALFView_model::loadData(const std::string &name) {
alg->execute();
auto ws =
AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(TMPNAME);
return ws->getRunNumber();
int runNumber = ws->getRunNumber();
std::string message = "success";
auto bools = isDataValid();
if (bools["IsValidInstrument"]) {
rename();
} else {
// reset to the previous data
message =
"Not the corrct instrument, expected " + INSTRUMENTNAME;
remove();
}
if (bools["IsValidInstrument"] && !bools["IsItDSpace"]) {
transformData();
}
return std::make_pair(runNumber, message);
}
/*
* Checks loaded data is from ALF
......@@ -61,7 +77,6 @@ int ALFView_model::loadData(const std::string &name) {
std::map<std::string, bool> ALFView_model::isDataValid() {
auto ws =
AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(TMPNAME);
bool isItALF = false;
bool isItDSpace = false;
......@@ -73,10 +88,7 @@ std::map<std::string, bool> ALFView_model::isDataValid() {
if (unit == "dSpacing") {
isItDSpace = true;
}
std::map<std::string, bool> result = {{"IsValidInstrument", isItALF},
{"IsItDSpace", isItDSpace}};
return result;
return {{"IsValidInstrument", isItALF}, {"IsItDSpace", isItDSpace}};
}
/*
......
......@@ -15,7 +15,7 @@ namespace CustomInterfaces {
class ALFView_model {
public:
void loadEmptyInstrument();
int loadData(const std::string &name);
std::pair<int, std::string> loadData(const std::string &name);
std::map<std::string, bool> isDataValid();
void transformData();
void rename();
......
......@@ -32,26 +32,17 @@ void ALFView_presenter::initLayout() {
void ALFView_presenter::loadAndAnalysis(const std::string &pathToRun) {
try {
int runNumber = m_model->loadData(pathToRun);
auto bools = m_model->isDataValid();
if (bools["IsValidInstrument"]) {
m_model->rename();
m_currentRun = runNumber;
auto loadedResult = m_model->loadData(pathToRun);
if (loadedResult.second == "success") {
m_currentRun = loadedResult.first;
m_currentFile = pathToRun;
} else {
// reset to the previous data
std::string message =
"Not the corrct instrument, expected " + m_model->getInstrument();
m_view->warningBox(message);
m_model->remove();
m_view->warningBox(loadedResult.second);
}
// make displayed run number be in sinc
m_view->setRunQuietly(std::to_string(m_currentRun));
if (bools["IsValidInstrument"] && !bools["IsItDSpace"]) {
m_model->transformData();
}
} catch (...) {
m_view->setRunQuietly(std::to_string(m_currentRun));
}
......
......@@ -23,7 +23,7 @@ class MANTIDQT_DIRECT_DLL ALFView_presenter : public QObject {
public:
ALFView_presenter(ALFView_view *view, ALFView_model *model);
~ALFView_presenter(){};
~ALFView_presenter() { delete m_loadRunObserver; };
void initLayout();
private slots:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment