Skip to content

Commit

Permalink
Merge pull request #29638 from mantidproject/29635_Qens_remove_data
Browse files Browse the repository at this point in the history
Fix remove workspaces in QENS interfaces
  • Loading branch information
martyngigg authored Sep 29, 2020
2 parents 8ffd873 + b063aa2 commit 4bf80a7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions qt/scientific_interfaces/Indirect/IndirectFitData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion qt/scientific_interfaces/Indirect/IndirectFitData.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions qt/scientific_interfaces/Indirect/IndirectFitDataModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 4bf80a7

Please sign in to comment.