Skip to content

Commit a2c8749

Browse files
committed
Fix crash after clicking Run on Density of states tab
1 parent 9f346f3 commit a2c8749

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

docs/source/interfaces/indirect/Indirect Simulation.rst

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _interface-indirect-simulation:
2+
13
Indirect Simulation
24
===================
35

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fixed a crash on the :ref:`interface-indirect-simulation` interface after clicking "Run" without loading data.

qt/scientific_interfaces/Indirect/Simulation/DensityOfStates.cpp

+17-10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ Mantid::Kernel::Logger g_log("DensityOfStates");
2121
} // namespace
2222

2323
namespace MantidQt::CustomInterfaces {
24+
25+
enum class DensityOfStates::InputFormat : int { Unsupported = 0, Phonon, Castep, ForceConstants };
26+
2427
DensityOfStates::DensityOfStates(QWidget *parent) : SimulationTab(parent) {
2528
m_uiForm.setupUi(parent);
2629
m_runPresenter = std::make_unique<RunPresenter>(this, new RunView(m_uiForm.runWidget));
@@ -35,10 +38,20 @@ DensityOfStates::DensityOfStates(QWidget *parent) : SimulationTab(parent) {
3538
}
3639

3740
void DensityOfStates::handleValidation(IUserInputValidator *validator) const {
38-
const auto filename = m_uiForm.mwInputFile->getFirstFilename().toStdString();
39-
InputFormat format = filenameToFormat(filename);
40-
QString specType = m_uiForm.cbSpectrumType->currentText();
41-
auto items = m_uiForm.lwIons->selectedItems();
41+
auto const filename = m_uiForm.mwInputFile->getFirstFilename().toStdString();
42+
if (filename.empty()) {
43+
validator->addErrorMessage("A data file has not been loaded.");
44+
return;
45+
}
46+
auto const format = filenameToFormat(filename);
47+
if (format == InputFormat::Unsupported) {
48+
validator->addErrorMessage("The provided file format is unsupported. The supported extensions are 'phonon', "
49+
"'castep', 'castep_bin' and 'yaml'.");
50+
return;
51+
}
52+
53+
auto const specType = m_uiForm.cbSpectrumType->currentText();
54+
auto const items = m_uiForm.lwIons->selectedItems();
4255

4356
if (specType == "DensityOfStates" && isPdosFile(format) && items.size() < 1)
4457
validator->addErrorMessage("Must select at least one ion for DensityOfStates.");
@@ -217,12 +230,6 @@ void DensityOfStates::saveClicked() {
217230

218231
void DensityOfStates::setSaveEnabled(bool enabled) { m_uiForm.pbSave->setEnabled(enabled); }
219232

220-
/**
221-
* Handle file formats
222-
*/
223-
224-
enum class DensityOfStates::InputFormat : int { Unsupported = 0, Phonon, Castep, ForceConstants };
225-
226233
DensityOfStates::InputFormat DensityOfStates::filenameToFormat(std::string const &filename) const {
227234
QFileInfo inputFileInfo(QString::fromStdString(filename));
228235
const auto suffix = inputFileInfo.suffix().toStdString();

0 commit comments

Comments
 (0)