diff --git a/qt/scientific_interfaces/Indirect/IndirectDataTablePresenter.cpp b/qt/scientific_interfaces/Indirect/IndirectDataTablePresenter.cpp index ee5d70be53c5..06478a8b7165 100644 --- a/qt/scientific_interfaces/Indirect/IndirectDataTablePresenter.cpp +++ b/qt/scientific_interfaces/Indirect/IndirectDataTablePresenter.cpp @@ -136,18 +136,17 @@ QString IndirectDataTablePresenter::getText(FitDomainIndex row, void IndirectDataTablePresenter::removeSelectedData() { auto selectedIndices = m_dataTable->selectionModel()->selectedIndexes(); - - for (auto item : selectedIndices) { - m_model->removeDataByIndex(FitDomainIndex(item.row())); + std::sort(selectedIndices.begin(), selectedIndices.end()); + for (auto item = selectedIndices.end(); item != selectedIndices.begin();) { + --item; + m_model->removeDataByIndex(FitDomainIndex(item->row())); } - updateTableFromModel(); } void IndirectDataTablePresenter::updateTableFromModel() { ScopedFalse _signalBlock(m_emitCellChanged); m_dataTable->setRowCount(0); - for (auto domainIndex = FitDomainIndex{0}; domainIndex < m_model->getNumberOfDomains(); domainIndex++) { addTableEntry(domainIndex); diff --git a/qt/scientific_interfaces/Indirect/IndirectFitData.cpp b/qt/scientific_interfaces/Indirect/IndirectFitData.cpp index a00135a8ddc4..7b74f8e8f03c 100644 --- a/qt/scientific_interfaces/Indirect/IndirectFitData.cpp +++ b/qt/scientific_interfaces/Indirect/IndirectFitData.cpp @@ -234,9 +234,11 @@ Spectra &Spectra::operator=(Spectra &&vec) { return *this; } -bool Spectra::empty() const { return m_vec.empty(); } +[[nodiscard]] bool Spectra::empty() const { return m_vec.empty(); } -FitDomainIndex Spectra::size() const { return FitDomainIndex{m_vec.size()}; } +FitDomainIndex Spectra::size() const { + return FitDomainIndex{m_vec.size()}; +} std::string Spectra::getString() const { if (empty()) @@ -348,7 +350,7 @@ Mantid::API::MatrixWorkspace_sptr IndirectFitData::workspace() const { const Spectra &IndirectFitData::spectra() const { return m_spectra; } -Spectra IndirectFitData::getMutableSpectra() { return m_spectra; } +Spectra &IndirectFitData::getMutableSpectra() { return m_spectra; } WorkspaceIndex IndirectFitData::getSpectrum(FitDomainIndex index) const { return m_spectra[index]; diff --git a/qt/scientific_interfaces/Indirect/IndirectFitData.h b/qt/scientific_interfaces/Indirect/IndirectFitData.h index 4b5cc7f773c5..53f9985b6438 100644 --- a/qt/scientific_interfaces/Indirect/IndirectFitData.h +++ b/qt/scientific_interfaces/Indirect/IndirectFitData.h @@ -120,7 +120,7 @@ class MANTIDQT_INDIRECT_DLL IndirectFitData { Mantid::API::MatrixWorkspace_sptr workspace() const; const Spectra &spectra() const; - Spectra getMutableSpectra(); + Spectra &getMutableSpectra(); WorkspaceIndex getSpectrum(FitDomainIndex index) const; FitDomainIndex numberOfSpectra() const; bool zeroSpectra() const; diff --git a/qt/scientific_interfaces/Indirect/IndirectFitDataModel.cpp b/qt/scientific_interfaces/Indirect/IndirectFitDataModel.cpp index 1713c524d384..eb3d3a8f0768 100644 --- a/qt/scientific_interfaces/Indirect/IndirectFitDataModel.cpp +++ b/qt/scientific_interfaces/Indirect/IndirectFitDataModel.cpp @@ -310,9 +310,13 @@ void IndirectFitDataModel::removeWorkspace(TableDatasetIndex index) { void IndirectFitDataModel::removeDataByIndex(FitDomainIndex fitDomainIndex) { auto subIndices = getSubIndices(fitDomainIndex); - m_fittingData->at(subIndices.first.value) - .getMutableSpectra() - .erase(subIndices.second); + auto &spectra = m_fittingData->at(subIndices.first.value).getMutableSpectra(); + spectra.erase(subIndices.second); + // If the spectra list corresponding to a workspace is empty, remove workspace + // at this index, else we'll have a workspace persist with no spectra loaded. + if (spectra.empty()) { + removeWorkspace(subIndices.first.value); + } } void IndirectFitDataModel::switchToSingleInputMode() {