From e1dd356d7ecb437a10e4894f4a0edeb9621368d8 Mon Sep 17 00:00:00 2001 From: Robert Applin <robert.applin@stfc.ac.uk> Date: Wed, 17 Mar 2021 17:58:18 +0000 Subject: [PATCH] Refs 30686. Tidy the templates. --- .../Common/FitScriptGeneratorPresenter.h | 13 +++- .../src/FitScriptGeneratorPresenter.cpp | 76 +++++++++++-------- 2 files changed, 54 insertions(+), 35 deletions(-) diff --git a/qt/widgets/common/inc/MantidQtWidgets/Common/FitScriptGeneratorPresenter.h b/qt/widgets/common/inc/MantidQtWidgets/Common/FitScriptGeneratorPresenter.h index 3cea1f795a9..48e12f09658 100644 --- a/qt/widgets/common/inc/MantidQtWidgets/Common/FitScriptGeneratorPresenter.h +++ b/qt/widgets/common/inc/MantidQtWidgets/Common/FitScriptGeneratorPresenter.h @@ -93,12 +93,21 @@ private: template <void (FitScriptGeneratorPresenter::*func)( std::string const &workspaceName, WorkspaceIndex workspaceIndex, FitDomainIndex domainIndex)> - void updateDomainXRange(); + void updateXLimitForDomainInModel(); + template <void (FitScriptGeneratorPresenter::*func)( + std::string const &workspaceName, WorkspaceIndex workspaceIndex, + FitDomainIndex domainIndex)> + void updateXLimitForDomainInModel(FitDomainIndex domainIndex); template <void (IFitScriptGeneratorModel::*func)( std::string const &workspaceName, WorkspaceIndex workspaceIndex, std::string const &function)> - void updateDomainFunctions(std::string const &function); + void updateFunctionForDomainsInModel(std::string const &function); + template <void (IFitScriptGeneratorModel::*func)( + std::string const &workspaceName, WorkspaceIndex workspaceIndex, + std::string const &function)> + void updateFunctionForDomainInModel(FitDomainIndex domainIndex, + std::string const &function); [[nodiscard]] std::vector<FitDomainIndex> getRowIndices() const; diff --git a/qt/widgets/common/src/FitScriptGeneratorPresenter.cpp b/qt/widgets/common/src/FitScriptGeneratorPresenter.cpp index ad67a2f87cb..fdf4d2cac3c 100644 --- a/qt/widgets/common/src/FitScriptGeneratorPresenter.cpp +++ b/qt/widgets/common/src/FitScriptGeneratorPresenter.cpp @@ -137,11 +137,11 @@ void FitScriptGeneratorPresenter::handleAddWorkspaceClicked() { } void FitScriptGeneratorPresenter::handleStartXChanged() { - updateDomainXRange<&FitScriptGeneratorPresenter::updateStartX>(); + updateXLimitForDomainInModel<&FitScriptGeneratorPresenter::updateStartX>(); } void FitScriptGeneratorPresenter::handleEndXChanged() { - updateDomainXRange<&FitScriptGeneratorPresenter::updateEndX>(); + updateXLimitForDomainInModel<&FitScriptGeneratorPresenter::updateEndX>(); } void FitScriptGeneratorPresenter::handleSelectionChanged() { @@ -161,34 +161,24 @@ void FitScriptGeneratorPresenter::handleSelectionChanged() { void FitScriptGeneratorPresenter::handleFunctionRemoved( std::string const &function) { - if (m_view->hasLoadedData()) { - updateDomainFunctions<&IFitScriptGeneratorModel::removeFunction>(function); - handleSelectionChanged(); - } + updateFunctionForDomainsInModel<&IFitScriptGeneratorModel::removeFunction>( + function); } void FitScriptGeneratorPresenter::handleFunctionAdded( std::string const &function) { - if (m_view->hasLoadedData()) { - try { - updateDomainFunctions<&IFitScriptGeneratorModel::addFunction>(function); - } catch (std::invalid_argument const &ex) { - m_view->displayWarning(ex.what()); - } - } else { - m_view->displayWarning("Data needs to be loaded before adding a function."); - m_view->clearFunction(); + try { + updateFunctionForDomainsInModel<&IFitScriptGeneratorModel::addFunction>( + function); + } catch (std::invalid_argument const &ex) { + m_view->displayWarning(ex.what()); } } void FitScriptGeneratorPresenter::handleFunctionReplaced( std::string const &function) { - if (m_view->hasLoadedData()) { - updateDomainFunctions<&IFitScriptGeneratorModel::setFunction>(function); - } else { - m_view->displayWarning("Data needs to be loaded before adding a function."); - m_view->clearFunction(); - } + updateFunctionForDomainsInModel<&IFitScriptGeneratorModel::setFunction>( + function); } void FitScriptGeneratorPresenter::handleParameterChanged( @@ -375,28 +365,48 @@ void FitScriptGeneratorPresenter::updateParameterTie( template <void (FitScriptGeneratorPresenter::*func)( std::string const &workspaceName, WorkspaceIndex workspaceIndex, FitDomainIndex domainIndex)> -void FitScriptGeneratorPresenter::updateDomainXRange() { - if (m_view->hasLoadedData()) { - auto const domainIndex = m_view->currentRow(); - auto const workspaceName = m_view->workspaceName(domainIndex); - auto const workspaceIndex = m_view->workspaceIndex(domainIndex); +void FitScriptGeneratorPresenter::updateXLimitForDomainInModel() { + if (m_view->hasLoadedData()) + updateXLimitForDomainInModel<func>(m_view->currentRow()); +} - (this->*func)(workspaceName, workspaceIndex, domainIndex); - } +template <void (FitScriptGeneratorPresenter::*func)( + std::string const &workspaceName, WorkspaceIndex workspaceIndex, + FitDomainIndex domainIndex)> +void FitScriptGeneratorPresenter::updateXLimitForDomainInModel( + FitDomainIndex domainIndex) { + auto const workspaceName = m_view->workspaceName(domainIndex); + auto const workspaceIndex = m_view->workspaceIndex(domainIndex); + + (this->*func)(workspaceName, workspaceIndex, domainIndex); } template <void (IFitScriptGeneratorModel::*func)( std::string const &workspaceName, WorkspaceIndex workspaceIndex, std::string const &function)> -void FitScriptGeneratorPresenter::updateDomainFunctions( +void FitScriptGeneratorPresenter::updateFunctionForDomainsInModel( std::string const &function) { - for (auto const &domainIndex : getRowIndices()) { - auto const workspaceName = m_view->workspaceName(domainIndex); - auto const workspaceIndex = m_view->workspaceIndex(domainIndex); - (m_model->*func)(workspaceName, workspaceIndex, function); + if (m_view->hasLoadedData()) { + for (auto const &domainIndex : getRowIndices()) { + updateFunctionForDomainInModel<func>(domainIndex, function); + } + } else { + m_view->displayWarning("Data needs to be loaded using Add Workspace."); + m_view->clearFunction(); } } +template <void (IFitScriptGeneratorModel::*func)( + std::string const &workspaceName, WorkspaceIndex workspaceIndex, + std::string const &function)> +void FitScriptGeneratorPresenter::updateFunctionForDomainInModel( + FitDomainIndex domainIndex, std::string const &function) { + auto const workspaceName = m_view->workspaceName(domainIndex); + auto const workspaceIndex = m_view->workspaceIndex(domainIndex); + + (m_model->*func)(workspaceName, workspaceIndex, function); +} + std::vector<FitDomainIndex> FitScriptGeneratorPresenter::getRowIndices() const { return m_view->applyFunctionChangesToAll() ? m_view->allRows() : m_view->selectedRows(); -- GitLab