From 70d3aa65314357159cdca3e7848f10263f16733d Mon Sep 17 00:00:00 2001 From: Applin Date: Tue, 25 Jun 2024 16:42:15 +0100 Subject: [PATCH 1/4] Use RunWidget for MolDyn tab --- .../Indirect/Simulation/MolDyn.cpp | 58 +++++-------------- .../Indirect/Simulation/MolDyn.h | 17 +++--- .../Indirect/Simulation/MolDyn.ui | 53 +---------------- .../Common/RunWidget/IRunSubscriber.h | 2 +- 4 files changed, 22 insertions(+), 108 deletions(-) diff --git a/qt/scientific_interfaces/Indirect/Simulation/MolDyn.cpp b/qt/scientific_interfaces/Indirect/Simulation/MolDyn.cpp index 519871494dc1..368235123a90 100644 --- a/qt/scientific_interfaces/Indirect/Simulation/MolDyn.cpp +++ b/qt/scientific_interfaces/Indirect/Simulation/MolDyn.cpp @@ -6,6 +6,7 @@ // SPDX - License - Identifier: GPL - 3.0 + #include "MolDyn.h" +#include "Common/RunWidget/RunView.h" #include "MantidAPI/MatrixWorkspace.h" #include "MantidAPI/WorkspaceGroup.h" #include "MantidQtWidgets/Common/UserInputValidator.h" @@ -16,8 +17,9 @@ using namespace Mantid::API; namespace MantidQt::CustomInterfaces { -MolDyn::MolDyn(QWidget *parent) : SimulationTab(parent) { +MolDyn::MolDyn(QWidget *parent) : SimulationTab(parent), m_runPresenter() { m_uiForm.setupUi(parent); + m_runPresenter = std::make_unique(this, new RunView(m_uiForm.runWidget)); setOutputPlotOptionsPresenter( std::make_unique(m_uiForm.ipoPlotOptions, PlotWidget::SpectraSliceSurface, "0")); @@ -26,7 +28,6 @@ MolDyn::MolDyn(QWidget *parent) : SimulationTab(parent) { connect(m_uiForm.cbVersion, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(versionSelected(const QString &))); - connect(m_uiForm.pbRun, SIGNAL(clicked()), this, SLOT(runClicked())); connect(m_uiForm.pbSave, SIGNAL(clicked()), this, SLOT(saveClicked())); connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(algorithmComplete(bool))); @@ -35,17 +36,8 @@ MolDyn::MolDyn(QWidget *parent) : SimulationTab(parent) { m_uiForm.dsResolution->isOptional(true); } -void MolDyn::setup() {} - -/** - * Validate the form to check the program can be run - * - * @return :: Whether the form was valid - */ -bool MolDyn::validate() { - UserInputValidator uiv; - - if (uiv.checkFileFinderWidgetIsValid("Data", m_uiForm.mwRun)) { +void MolDyn::handleValidation(IUserInputValidator *validator) const { + if (validator->checkFileFinderWidgetIsValid("Data", m_uiForm.mwRun)) { QString filename = m_uiForm.mwRun->getFirstFilename(); QString version = m_uiForm.cbVersion->currentText(); QFileInfo finfo(filename); @@ -53,27 +45,21 @@ bool MolDyn::validate() { if (version == "3") { if (ext != "dat" && ext != "cdl") - uiv.addErrorMessage("File is not of expected type.\n File type must be .dat or .cdl"); + validator->addErrorMessage("File is not of expected type.\n File type must be .dat or .cdl"); QString functions = m_uiForm.leFunctionNames->text(); if (ext == "cdl" && functions.isEmpty()) - uiv.addErrorMessage("Must specify at least one function when loading CDL file."); + validator->addErrorMessage("Must specify at least one function when loading CDL file."); } } // Validate resolution if (m_uiForm.ckResolution->isChecked()) - uiv.checkDataSelectorIsValid("Resolution", m_uiForm.dsResolution); - - emit showMessageBox(uiv.generateErrorMessage()); - return uiv.isAllInputValid(); + validator->checkDataSelectorIsValid("Resolution", m_uiForm.dsResolution); } -/** - * Collect the settings on the GUI and run the MolDyn algorithm. - */ -void MolDyn::run() { - setRunIsRunning(true); +void MolDyn::handleRun() { + clearOutputPlotOptionsWorkspaces(); // Get filename and base filename (for naming output workspace group) auto const filename = m_uiForm.mwRun->getFirstFilename(); @@ -107,10 +93,9 @@ void MolDyn::run() { } void MolDyn::algorithmComplete(bool error) { - setRunIsRunning(false); - if (error) - setSaveEnabled(false); - else + m_runPresenter->setRunEnabled(true); + setSaveEnabled(!error); + if (!error) setOutputPlotOptionsWorkspaces({m_outputWsName}); } @@ -132,11 +117,6 @@ void MolDyn::versionSelected(const QString &version) { m_uiForm.mwRun->isForDirectory(version4); } -void MolDyn::runClicked() { - clearOutputPlotOptionsWorkspaces(); - runTab(); -} - /** * Handle saving workspaces */ @@ -151,18 +131,6 @@ void MolDyn::saveClicked() { m_batchAlgoRunner->executeBatchAsync(); } -void MolDyn::setRunIsRunning(bool running) { - m_uiForm.pbRun->setText(running ? "Running..." : "Run"); - setButtonsEnabled(!running); -} - -void MolDyn::setButtonsEnabled(bool enabled) { - setRunEnabled(enabled); - setSaveEnabled(enabled); -} - -void MolDyn::setRunEnabled(bool enabled) { m_uiForm.pbRun->setEnabled(enabled); } - void MolDyn::setSaveEnabled(bool enabled) { m_uiForm.pbSave->setEnabled(enabled); } } // namespace MantidQt::CustomInterfaces diff --git a/qt/scientific_interfaces/Indirect/Simulation/MolDyn.h b/qt/scientific_interfaces/Indirect/Simulation/MolDyn.h index b730dfa28b67..011148084d4b 100644 --- a/qt/scientific_interfaces/Indirect/Simulation/MolDyn.h +++ b/qt/scientific_interfaces/Indirect/Simulation/MolDyn.h @@ -7,37 +7,34 @@ #pragma once #include "../DllConfig.h" +#include "Common/RunWidget/IRunSubscriber.h" +#include "Common/RunWidget/RunPresenter.h" #include "SimulationTab.h" #include "ui_MolDyn.h" namespace MantidQt { namespace CustomInterfaces { -class MANTIDQT_INDIRECT_DLL MolDyn : public SimulationTab { +class MANTIDQT_INDIRECT_DLL MolDyn : public SimulationTab, public IRunSubscriber { Q_OBJECT public: MolDyn(QWidget *parent = nullptr); - // Inherited methods from InelasticTab - void setup() override; - bool validate() override; - void run() override; - /// Load default settings into the interface void loadSettings(const QSettings &settings) override; + void handleValidation(IUserInputValidator *validator) const override; + void handleRun() override; + private slots: void versionSelected(const QString & /*version*/); - void runClicked(); void saveClicked(); void algorithmComplete(bool error); private: - void setRunIsRunning(bool running); - void setButtonsEnabled(bool enabled); - void setRunEnabled(bool enabled); void setSaveEnabled(bool enabled); + std::unique_ptr m_runPresenter; std::string m_outputWsName; // The ui form Ui::MolDyn m_uiForm; diff --git a/qt/scientific_interfaces/Indirect/Simulation/MolDyn.ui b/qt/scientific_interfaces/Indirect/Simulation/MolDyn.ui index 98d9745d5c4a..c9265f463336 100644 --- a/qt/scientific_interfaces/Indirect/Simulation/MolDyn.ui +++ b/qt/scientific_interfaces/Indirect/Simulation/MolDyn.ui @@ -270,58 +270,7 @@ - - - Run - - - - 0 - - - 0 - - - 0 - - - 7 - - - - - Qt::Horizontal - - - - 194 - 20 - - - - - - - - Run - - - - - - - Qt::Horizontal - - - - 193 - 20 - - - - - - + diff --git a/qt/scientific_interfaces/Inelastic/Common/RunWidget/IRunSubscriber.h b/qt/scientific_interfaces/Inelastic/Common/RunWidget/IRunSubscriber.h index 0908608b177a..2f9afd25f1b6 100644 --- a/qt/scientific_interfaces/Inelastic/Common/RunWidget/IRunSubscriber.h +++ b/qt/scientific_interfaces/Inelastic/Common/RunWidget/IRunSubscriber.h @@ -6,7 +6,7 @@ // SPDX - License - Identifier: GPL - 3.0 + #pragma once -#include "DllConfig.h" +#include "../../DllConfig.h" namespace MantidQt { namespace CustomInterfaces { From e8fd3bf638d2a07da0a522b74f5e1d52b2c541b5 Mon Sep 17 00:00:00 2001 From: Applin Date: Tue, 25 Jun 2024 16:42:51 +0100 Subject: [PATCH 2/4] Use RunWidget for Sassena tab --- .../Indirect/Simulation/Sassena.cpp | 50 ++++------------- .../Indirect/Simulation/Sassena.h | 16 +++--- .../Indirect/Simulation/Sassena.ui | 53 +------------------ 3 files changed, 17 insertions(+), 102 deletions(-) diff --git a/qt/scientific_interfaces/Indirect/Simulation/Sassena.cpp b/qt/scientific_interfaces/Indirect/Simulation/Sassena.cpp index 82751fe2a17c..9eda78bbb4b0 100644 --- a/qt/scientific_interfaces/Indirect/Simulation/Sassena.cpp +++ b/qt/scientific_interfaces/Indirect/Simulation/Sassena.cpp @@ -6,6 +6,7 @@ // SPDX - License - Identifier: GPL - 3.0 + #include "Sassena.h" +#include "Common/RunWidget/RunView.h" #include "MantidQtWidgets/Common/UserInputValidator.h" #include @@ -14,41 +15,26 @@ namespace MantidQt::CustomInterfaces { Sassena::Sassena(QWidget *parent) : SimulationTab(parent) { m_uiForm.setupUi(parent); + m_runPresenter = std::make_unique(this, new RunView(m_uiForm.runWidget)); setOutputPlotOptionsPresenter( std::make_unique(m_uiForm.ipoPlotOptions, PlotWidget::Spectra)); connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(handleAlgorithmFinish(bool))); - connect(m_uiForm.pbRun, SIGNAL(clicked()), this, SLOT(runClicked())); connect(m_uiForm.pbSave, SIGNAL(clicked()), this, SLOT(saveClicked())); } -void Sassena::setup() {} - -/** - * Validate the form to check the program can be run. - * - * @return Whether the form was valid - */ -bool Sassena::validate() { - UserInputValidator uiv; - +void Sassena::handleValidation(IUserInputValidator *validator) const { auto const inputFileName = m_uiForm.mwInputFile->getFirstFilename(); if (inputFileName.isEmpty()) - uiv.addErrorMessage("Incorrect input file provided."); - - emit showMessageBox(uiv.generateErrorMessage()); - return uiv.isAllInputValid(); + validator->addErrorMessage("Incorrect input file provided."); } -/** - * Configures and executes the LoadSassena algorithm. - */ -void Sassena::run() { +void Sassena::handleRun() { using namespace Mantid::API; using MantidQt::API::BatchAlgorithmRunner; - setRunIsRunning(true); + clearOutputPlotOptionsWorkspaces(); QString const inputFileName = m_uiForm.mwInputFile->getFirstFilename(); m_outWsName = QFileInfo(inputFileName).baseName(); @@ -75,10 +61,9 @@ void Sassena::run() { * @param error If the batch was stopped due to error */ void Sassena::handleAlgorithmFinish(bool error) { - setRunIsRunning(false); - if (error) - setSaveEnabled(false); - else + m_runPresenter->setRunEnabled(true); + setSaveEnabled(!error); + if (!error) setOutputPlotOptionsWorkspaces({m_outWsName.toStdString()}); } @@ -90,11 +75,6 @@ void Sassena::handleAlgorithmFinish(bool error) { */ void Sassena::loadSettings(const QSettings &settings) { m_uiForm.mwInputFile->readSettings(settings.group()); } -void Sassena::runClicked() { - clearOutputPlotOptionsWorkspaces(); - runTab(); -} - /** * Handle saving of workspace */ @@ -104,18 +84,6 @@ void Sassena::saveClicked() { m_batchAlgoRunner->executeBatchAsync(); } -void Sassena::setRunIsRunning(bool running) { - m_uiForm.pbRun->setText(running ? "Running..." : "Run"); - setButtonsEnabled(!running); -} - -void Sassena::setButtonsEnabled(bool enabled) { - setRunEnabled(enabled); - setSaveEnabled(enabled); -} - -void Sassena::setRunEnabled(bool enabled) { m_uiForm.pbRun->setEnabled(enabled); } - void Sassena::setSaveEnabled(bool enabled) { m_uiForm.pbSave->setEnabled(enabled); } } // namespace MantidQt::CustomInterfaces diff --git a/qt/scientific_interfaces/Indirect/Simulation/Sassena.h b/qt/scientific_interfaces/Indirect/Simulation/Sassena.h index 50cd55f10f00..b77179704311 100644 --- a/qt/scientific_interfaces/Indirect/Simulation/Sassena.h +++ b/qt/scientific_interfaces/Indirect/Simulation/Sassena.h @@ -7,36 +7,34 @@ #pragma once #include "../DllConfig.h" +#include "Common/RunWidget/IRunSubscriber.h" +#include "Common/RunWidget/RunPresenter.h" #include "SimulationTab.h" #include "ui_Sassena.h" namespace MantidQt { namespace CustomInterfaces { -class MANTIDQT_INDIRECT_DLL Sassena : public SimulationTab { +class MANTIDQT_INDIRECT_DLL Sassena : public SimulationTab, public IRunSubscriber { Q_OBJECT public: Sassena(QWidget *parent = nullptr); - void setup() override; - bool validate() override; - void run() override; - /// Load default settings into the interface void loadSettings(const QSettings &settings) override; + void handleValidation(IUserInputValidator *validator) const override; + void handleRun() override; + private slots: /// Handle completion of the algorithm batch void handleAlgorithmFinish(bool error); - void runClicked(); void saveClicked(); private: - void setRunIsRunning(bool running); - void setButtonsEnabled(bool enabled); - void setRunEnabled(bool enabled); void setSaveEnabled(bool enabled); + std::unique_ptr m_runPresenter; /// The ui form Ui::Sassena m_uiForm; /// Name of the output workspace group diff --git a/qt/scientific_interfaces/Indirect/Simulation/Sassena.ui b/qt/scientific_interfaces/Indirect/Simulation/Sassena.ui index f0a923f19ca4..8430f6e6b78c 100644 --- a/qt/scientific_interfaces/Indirect/Simulation/Sassena.ui +++ b/qt/scientific_interfaces/Indirect/Simulation/Sassena.ui @@ -114,58 +114,7 @@ - - - Run - - - - 0 - - - 0 - - - 0 - - - 7 - - - - - Qt::Horizontal - - - - 194 - 20 - - - - - - - - Run - - - - - - - Qt::Horizontal - - - - 193 - 20 - - - - - - + From 9f346f3b7daffd85b3123fd2f5e646a1f4d6beff Mon Sep 17 00:00:00 2001 From: Applin Date: Tue, 25 Jun 2024 16:54:22 +0100 Subject: [PATCH 3/4] Use RunWidget for DensityOfStates tab --- .../Indirect/Simulation/DensityOfStates.cpp | 78 +++++-------------- .../Indirect/Simulation/DensityOfStates.h | 24 +++--- .../Indirect/Simulation/DensityOfStates.ui | 57 +------------- 3 files changed, 33 insertions(+), 126 deletions(-) diff --git a/qt/scientific_interfaces/Indirect/Simulation/DensityOfStates.cpp b/qt/scientific_interfaces/Indirect/Simulation/DensityOfStates.cpp index d287bf33c972..7da93f779885 100644 --- a/qt/scientific_interfaces/Indirect/Simulation/DensityOfStates.cpp +++ b/qt/scientific_interfaces/Indirect/Simulation/DensityOfStates.cpp @@ -6,10 +6,10 @@ // SPDX - License - Identifier: GPL - 3.0 + #include "DensityOfStates.h" -#include "MantidQtWidgets/Common/UserInputValidator.h" - +#include "Common/RunWidget/RunView.h" #include "MantidAPI/ITableWorkspace.h" #include "MantidAPI/TableRow.h" +#include "MantidQtWidgets/Common/UserInputValidator.h" #include #include @@ -23,61 +23,41 @@ Mantid::Kernel::Logger g_log("DensityOfStates"); namespace MantidQt::CustomInterfaces { DensityOfStates::DensityOfStates(QWidget *parent) : SimulationTab(parent) { m_uiForm.setupUi(parent); + m_runPresenter = std::make_unique(this, new RunView(m_uiForm.runWidget)); setOutputPlotOptionsPresenter( std::make_unique(m_uiForm.ipoPlotOptions, PlotWidget::Spectra)); connect(m_uiForm.mwInputFile, SIGNAL(filesFound()), this, SLOT(handleFileChange())); - connect(m_uiForm.pbRun, SIGNAL(clicked()), this, SLOT(runClicked())); connect(m_uiForm.pbSave, SIGNAL(clicked()), this, SLOT(saveClicked())); m_uiForm.lwIons->setSelectionMode(QAbstractItemView::MultiSelection); } -void DensityOfStates::setup() {} - -/** - * Validate the form to check the program can be run. - * - * @return Whether the form was valid - */ -bool DensityOfStates::validate() { - UserInputValidator uiv; - - const auto filename = m_uiForm.mwInputFile->getFirstFilename(); +void DensityOfStates::handleValidation(IUserInputValidator *validator) const { + const auto filename = m_uiForm.mwInputFile->getFirstFilename().toStdString(); InputFormat format = filenameToFormat(filename); QString specType = m_uiForm.cbSpectrumType->currentText(); auto items = m_uiForm.lwIons->selectedItems(); if (specType == "DensityOfStates" && isPdosFile(format) && items.size() < 1) - uiv.addErrorMessage("Must select at least one ion for DensityOfStates."); - - // Give error message when there are errors - if (!uiv.isAllInputValid()) - emit showMessageBox(uiv.generateErrorMessage()); - - return uiv.isAllInputValid(); + validator->addErrorMessage("Must select at least one ion for DensityOfStates."); } -/** - * Configures and executes the DensityOfStates algorithm. - */ -void DensityOfStates::run() { - setRunIsRunning(true); +void DensityOfStates::handleRun() { + clearOutputPlotOptionsWorkspaces(); // Get the SimulatedDensityOfStates algorithm auto dosAlgo = AlgorithmManager::Instance().create("SimulatedDensityOfStates"); - const auto filename = m_uiForm.mwInputFile->getFirstFilename(); + const auto filename = m_uiForm.mwInputFile->getFirstFilename().toStdString(); const auto specType = m_uiForm.cbSpectrumType->currentText(); const auto filePropName = formatToFilePropName(filenameToFormat(filename)); - // QFileInfo inputFileInfo(filename); - - m_outputWsName = QFileInfo(filename).baseName() + "_" + specType; + m_outputWsName = QFileInfo(QString::fromStdString(filename)).baseName() + "_" + specType; // Set common properties - dosAlgo->setProperty(filePropName, filename.toStdString()); + dosAlgo->setProperty(filePropName, filename); dosAlgo->setProperty("OutputWorkspace", m_outputWsName.toStdString()); const auto peakShape = m_uiForm.cbPeakShape->currentText().toStdString(); @@ -145,10 +125,9 @@ void DensityOfStates::run() { void DensityOfStates::dosAlgoComplete(bool error) { disconnect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(dosAlgoComplete(bool))); - setRunIsRunning(false); - if (error) - setSaveEnabled(false); - else + m_runPresenter->setRunEnabled(true); + setSaveEnabled(!error); + if (!error) setOutputPlotOptionsWorkspaces({m_outputWsName.toStdString()}); } @@ -156,7 +135,7 @@ void DensityOfStates::dosAlgoComplete(bool error) { * Handles a new file being selected by the browser. */ void DensityOfStates::handleFileChange() { - QString filename = m_uiForm.mwInputFile->getFirstFilename(); + auto const filename = m_uiForm.mwInputFile->getFirstFilename().toStdString(); InputFormat fileFormat = filenameToFormat(filename); bool pdosAvailable = isPdosFile(fileFormat); @@ -164,7 +143,7 @@ void DensityOfStates::handleFileChange() { // Load the ion table to populate the list of ions IAlgorithm_sptr ionTableAlgo = AlgorithmManager::Instance().create("SimulatedDensityOfStates"); ionTableAlgo->initialize(); - ionTableAlgo->setProperty(formatToFilePropName(fileFormat), filename.toStdString()); + ionTableAlgo->setProperty(formatToFilePropName(fileFormat), filename); ionTableAlgo->setProperty("SpectrumType", "IonTable"); ionTableAlgo->setProperty("OutputWorkspace", "__dos_ions"); @@ -227,11 +206,6 @@ void DensityOfStates::ionLoadComplete(bool error) { */ void DensityOfStates::loadSettings(const QSettings &settings) { m_uiForm.mwInputFile->readSettings(settings.group()); } -void DensityOfStates::runClicked() { - clearOutputPlotOptionsWorkspaces(); - runTab(); -} - /** * Handle saving of workspace */ @@ -241,18 +215,6 @@ void DensityOfStates::saveClicked() { m_batchAlgoRunner->executeBatchAsync(); } -void DensityOfStates::setRunIsRunning(bool running) { - m_uiForm.pbRun->setText(running ? "Running..." : "Run"); - setButtonsEnabled(!running); -} - -void DensityOfStates::setButtonsEnabled(bool enabled) { - setRunEnabled(enabled); - setSaveEnabled(enabled); -} - -void DensityOfStates::setRunEnabled(bool enabled) { m_uiForm.pbRun->setEnabled(enabled); } - void DensityOfStates::setSaveEnabled(bool enabled) { m_uiForm.pbSave->setEnabled(enabled); } /** @@ -261,8 +223,8 @@ void DensityOfStates::setSaveEnabled(bool enabled) { m_uiForm.pbSave->setEnabled enum class DensityOfStates::InputFormat : int { Unsupported = 0, Phonon, Castep, ForceConstants }; -DensityOfStates::InputFormat DensityOfStates::filenameToFormat(QString filename) { - QFileInfo inputFileInfo(filename); +DensityOfStates::InputFormat DensityOfStates::filenameToFormat(std::string const &filename) const { + QFileInfo inputFileInfo(QString::fromStdString(filename)); const auto suffix = inputFileInfo.suffix().toStdString(); InputFormat format; @@ -282,7 +244,7 @@ DensityOfStates::InputFormat DensityOfStates::filenameToFormat(QString filename) return format; } -std::string DensityOfStates::formatToFilePropName(InputFormat format) { +std::string DensityOfStates::formatToFilePropName(InputFormat const &format) const { std::string filePropName; switch (format) { @@ -302,7 +264,7 @@ std::string DensityOfStates::formatToFilePropName(InputFormat format) { return filePropName; } -bool DensityOfStates::isPdosFile(InputFormat dosFileFormat) { +bool DensityOfStates::isPdosFile(InputFormat const &dosFileFormat) const { return (dosFileFormat == InputFormat::Phonon) || (dosFileFormat == InputFormat::ForceConstants); } diff --git a/qt/scientific_interfaces/Indirect/Simulation/DensityOfStates.h b/qt/scientific_interfaces/Indirect/Simulation/DensityOfStates.h index 73a7a7722960..90b06eee6c48 100644 --- a/qt/scientific_interfaces/Indirect/Simulation/DensityOfStates.h +++ b/qt/scientific_interfaces/Indirect/Simulation/DensityOfStates.h @@ -7,44 +7,40 @@ #pragma once #include "../DllConfig.h" +#include "Common/RunWidget/IRunSubscriber.h" +#include "Common/RunWidget/RunPresenter.h" #include "SimulationTab.h" #include "ui_DensityOfStates.h" namespace MantidQt { namespace CustomInterfaces { -class MANTIDQT_INDIRECT_DLL DensityOfStates : public SimulationTab { +class MANTIDQT_INDIRECT_DLL DensityOfStates : public SimulationTab, public IRunSubscriber { Q_OBJECT public: DensityOfStates(QWidget *parent = nullptr); - QString help() { return "DensityOfStates"; }; - - void setup() override; - bool validate() override; - void run() override; - /// Load default settings into the interface void loadSettings(const QSettings &settings) override; + void handleValidation(IUserInputValidator *validator) const override; + void handleRun() override; + private slots: void dosAlgoComplete(bool error); void handleFileChange(); void ionLoadComplete(bool error); - void runClicked(); void saveClicked(); private: - void setRunIsRunning(bool running); - void setButtonsEnabled(bool enabled); - void setRunEnabled(bool enabled); void setSaveEnabled(bool enabled); enum class InputFormat : int; - InputFormat filenameToFormat(QString filename); - std::string formatToFilePropName(InputFormat format); - bool isPdosFile(InputFormat dosFileFormat); + InputFormat filenameToFormat(std::string const &filename) const; + std::string formatToFilePropName(InputFormat const &format) const; + bool isPdosFile(InputFormat const &dosFileFormat) const; + std::unique_ptr m_runPresenter; /// The ui form Ui::DensityOfStates m_uiForm; /// Name of output workspace diff --git a/qt/scientific_interfaces/Indirect/Simulation/DensityOfStates.ui b/qt/scientific_interfaces/Indirect/Simulation/DensityOfStates.ui index 737c1cefb569..deac6187401a 100644 --- a/qt/scientific_interfaces/Indirect/Simulation/DensityOfStates.ui +++ b/qt/scientific_interfaces/Indirect/Simulation/DensityOfStates.ui @@ -57,8 +57,8 @@ 0 0 - 480 - 329 + 500 + 381 @@ -515,58 +515,7 @@ - - - Run - - - - 0 - - - 0 - - - 0 - - - 7 - - - - - Qt::Horizontal - - - - 194 - 20 - - - - - - - - Run - - - - - - - Qt::Horizontal - - - - 193 - 20 - - - - - - + From a2c8749ff25e5d01d58bec0e56e6935250b64550 Mon Sep 17 00:00:00 2001 From: Applin Date: Thu, 27 Jun 2024 14:33:56 +0100 Subject: [PATCH 4/4] Fix crash after clicking Run on Density of states tab --- .../indirect/Indirect Simulation.rst | 2 ++ .../v6.11.0/Indirect/Bugfixes/37611.rst | 1 + .../Indirect/Simulation/DensityOfStates.cpp | 27 ++++++++++++------- 3 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 docs/source/release/v6.11.0/Indirect/Bugfixes/37611.rst diff --git a/docs/source/interfaces/indirect/Indirect Simulation.rst b/docs/source/interfaces/indirect/Indirect Simulation.rst index ce9c619b82cb..4894867f2c97 100644 --- a/docs/source/interfaces/indirect/Indirect Simulation.rst +++ b/docs/source/interfaces/indirect/Indirect Simulation.rst @@ -1,3 +1,5 @@ +.. _interface-indirect-simulation: + Indirect Simulation =================== diff --git a/docs/source/release/v6.11.0/Indirect/Bugfixes/37611.rst b/docs/source/release/v6.11.0/Indirect/Bugfixes/37611.rst new file mode 100644 index 000000000000..501dc0cd5204 --- /dev/null +++ b/docs/source/release/v6.11.0/Indirect/Bugfixes/37611.rst @@ -0,0 +1 @@ +- Fixed a crash on the :ref:`interface-indirect-simulation` interface after clicking "Run" without loading data. \ No newline at end of file diff --git a/qt/scientific_interfaces/Indirect/Simulation/DensityOfStates.cpp b/qt/scientific_interfaces/Indirect/Simulation/DensityOfStates.cpp index 7da93f779885..0157751161e0 100644 --- a/qt/scientific_interfaces/Indirect/Simulation/DensityOfStates.cpp +++ b/qt/scientific_interfaces/Indirect/Simulation/DensityOfStates.cpp @@ -21,6 +21,9 @@ Mantid::Kernel::Logger g_log("DensityOfStates"); } // namespace namespace MantidQt::CustomInterfaces { + +enum class DensityOfStates::InputFormat : int { Unsupported = 0, Phonon, Castep, ForceConstants }; + DensityOfStates::DensityOfStates(QWidget *parent) : SimulationTab(parent) { m_uiForm.setupUi(parent); m_runPresenter = std::make_unique(this, new RunView(m_uiForm.runWidget)); @@ -35,10 +38,20 @@ DensityOfStates::DensityOfStates(QWidget *parent) : SimulationTab(parent) { } void DensityOfStates::handleValidation(IUserInputValidator *validator) const { - const auto filename = m_uiForm.mwInputFile->getFirstFilename().toStdString(); - InputFormat format = filenameToFormat(filename); - QString specType = m_uiForm.cbSpectrumType->currentText(); - auto items = m_uiForm.lwIons->selectedItems(); + auto const filename = m_uiForm.mwInputFile->getFirstFilename().toStdString(); + if (filename.empty()) { + validator->addErrorMessage("A data file has not been loaded."); + return; + } + auto const format = filenameToFormat(filename); + if (format == InputFormat::Unsupported) { + validator->addErrorMessage("The provided file format is unsupported. The supported extensions are 'phonon', " + "'castep', 'castep_bin' and 'yaml'."); + return; + } + + auto const specType = m_uiForm.cbSpectrumType->currentText(); + auto const items = m_uiForm.lwIons->selectedItems(); if (specType == "DensityOfStates" && isPdosFile(format) && items.size() < 1) validator->addErrorMessage("Must select at least one ion for DensityOfStates."); @@ -217,12 +230,6 @@ void DensityOfStates::saveClicked() { void DensityOfStates::setSaveEnabled(bool enabled) { m_uiForm.pbSave->setEnabled(enabled); } -/** - * Handle file formats - */ - -enum class DensityOfStates::InputFormat : int { Unsupported = 0, Phonon, Castep, ForceConstants }; - DensityOfStates::InputFormat DensityOfStates::filenameToFormat(std::string const &filename) const { QFileInfo inputFileInfo(QString::fromStdString(filename)); const auto suffix = inputFileInfo.suffix().toStdString();