From 1cadd9b9c92fa1e88ac561b2b91a0785aa8ee7bb Mon Sep 17 00:00:00 2001 From: Matthew Andrew <matthew.andrew@tessella.com> Date: Thu, 19 Mar 2020 15:35:12 +0000 Subject: [PATCH] Removed Legacy files Re #28057 --- .../Indirect/CMakeLists.txt | 55 - .../Indirect/IIndirectFitDataViewLegacy.h | 67 - .../Indirect/IIndirectFitPlotViewLegacy.h | 106 -- .../IndirectDataTablePresenterLegacy.cpp | 604 --------- .../IndirectDataTablePresenterLegacy.h | 128 -- .../Indirect/IndirectFitAnalysisTabLegacy.cpp | 1143 ----------------- .../Indirect/IndirectFitAnalysisTabLegacy.h | 242 ---- .../Indirect/IndirectFitDataLegacy.cpp | 435 ------- .../Indirect/IndirectFitDataLegacy.h | 198 --- .../IndirectFitDataPresenterLegacy.cpp | 275 ---- .../Indirect/IndirectFitDataPresenterLegacy.h | 113 -- .../Indirect/IndirectFitDataViewLegacy.cpp | 187 --- .../Indirect/IndirectFitDataViewLegacy.h | 72 -- .../Indirect/IndirectFitDataViewLegacy.ui | 129 -- .../Indirect/IndirectFitOutputLegacy.cpp | 433 ------- .../Indirect/IndirectFitOutputLegacy.h | 130 -- .../Indirect/IndirectFitPlotModelLegacy.cpp | 421 ------ .../Indirect/IndirectFitPlotModelLegacy.h | 104 -- .../IndirectFitPlotPresenterLegacy.cpp | 414 ------ .../Indirect/IndirectFitPlotPresenterLegacy.h | 116 -- .../Indirect/IndirectFitPlotViewLegacy.cpp | 406 ------ .../Indirect/IndirectFitPlotViewLegacy.h | 167 --- .../Indirect/IndirectFittingModel.cpp | 4 +- .../Indirect/IndirectFittingModelLegacy.cpp | 908 ------------- .../Indirect/IndirectFittingModelLegacy.h | 226 ---- ...directSpectrumSelectionPresenterLegacy.cpp | 286 ----- ...IndirectSpectrumSelectionPresenterLegacy.h | 74 -- .../IndirectSpectrumSelectionViewLegacy.cpp | 285 ---- .../IndirectSpectrumSelectionViewLegacy.h | 102 -- .../Indirect/test/IndirectFitOutputTest.h | 2 +- .../Indirect/test/IndirectFitPlotModelTest.h | 64 +- .../test/IndirectFitPlotPresenterTest.h | 7 +- .../IndirectSpectrumSelectionPresenterTest.h | 24 +- 33 files changed, 48 insertions(+), 7879 deletions(-) delete mode 100644 qt/scientific_interfaces/Indirect/IIndirectFitDataViewLegacy.h delete mode 100644 qt/scientific_interfaces/Indirect/IIndirectFitPlotViewLegacy.h delete mode 100644 qt/scientific_interfaces/Indirect/IndirectDataTablePresenterLegacy.cpp delete mode 100644 qt/scientific_interfaces/Indirect/IndirectDataTablePresenterLegacy.h delete mode 100644 qt/scientific_interfaces/Indirect/IndirectFitAnalysisTabLegacy.cpp delete mode 100644 qt/scientific_interfaces/Indirect/IndirectFitAnalysisTabLegacy.h delete mode 100644 qt/scientific_interfaces/Indirect/IndirectFitDataLegacy.cpp delete mode 100644 qt/scientific_interfaces/Indirect/IndirectFitDataLegacy.h delete mode 100644 qt/scientific_interfaces/Indirect/IndirectFitDataPresenterLegacy.cpp delete mode 100644 qt/scientific_interfaces/Indirect/IndirectFitDataPresenterLegacy.h delete mode 100644 qt/scientific_interfaces/Indirect/IndirectFitDataViewLegacy.cpp delete mode 100644 qt/scientific_interfaces/Indirect/IndirectFitDataViewLegacy.h delete mode 100644 qt/scientific_interfaces/Indirect/IndirectFitDataViewLegacy.ui delete mode 100644 qt/scientific_interfaces/Indirect/IndirectFitOutputLegacy.cpp delete mode 100644 qt/scientific_interfaces/Indirect/IndirectFitOutputLegacy.h delete mode 100644 qt/scientific_interfaces/Indirect/IndirectFitPlotModelLegacy.cpp delete mode 100644 qt/scientific_interfaces/Indirect/IndirectFitPlotModelLegacy.h delete mode 100644 qt/scientific_interfaces/Indirect/IndirectFitPlotPresenterLegacy.cpp delete mode 100644 qt/scientific_interfaces/Indirect/IndirectFitPlotPresenterLegacy.h delete mode 100644 qt/scientific_interfaces/Indirect/IndirectFitPlotViewLegacy.cpp delete mode 100644 qt/scientific_interfaces/Indirect/IndirectFitPlotViewLegacy.h delete mode 100644 qt/scientific_interfaces/Indirect/IndirectFittingModelLegacy.cpp delete mode 100644 qt/scientific_interfaces/Indirect/IndirectFittingModelLegacy.h delete mode 100644 qt/scientific_interfaces/Indirect/IndirectSpectrumSelectionPresenterLegacy.cpp delete mode 100644 qt/scientific_interfaces/Indirect/IndirectSpectrumSelectionPresenterLegacy.h delete mode 100644 qt/scientific_interfaces/Indirect/IndirectSpectrumSelectionViewLegacy.cpp delete mode 100644 qt/scientific_interfaces/Indirect/IndirectSpectrumSelectionViewLegacy.h diff --git a/qt/scientific_interfaces/Indirect/CMakeLists.txt b/qt/scientific_interfaces/Indirect/CMakeLists.txt index e90d44340aa..7b6be2d73a1 100644 --- a/qt/scientific_interfaces/Indirect/CMakeLists.txt +++ b/qt/scientific_interfaces/Indirect/CMakeLists.txt @@ -27,17 +27,11 @@ set( IndirectDataAnalysisTab.cpp IndirectDataReduction.cpp IndirectDataReductionTab.cpp - IndirectDataTablePresenterLegacy.cpp IndirectDataTablePresenter.cpp IndirectDataValidationHelper.cpp IndirectDiffractionReduction.cpp IndirectEditResultsDialog.cpp - IndirectFitAnalysisTabLegacy.cpp IndirectFitAnalysisTab.cpp - IndirectFitDataLegacy.cpp - IndirectFitDataPresenterLegacy.cpp - IndirectFitDataViewLegacy.cpp - IndirectFitOutputLegacy.cpp IndirectFitData.cpp IndirectFitDataPresenter.cpp IndirectFitDataView.cpp @@ -45,10 +39,6 @@ set( IndirectFitOutputOptionsModel.cpp IndirectFitOutputOptionsPresenter.cpp IndirectFitOutputOptionsView.cpp - IndirectFitPlotModelLegacy.cpp - IndirectFitPlotPresenterLegacy.cpp - IndirectFitPlotViewLegacy.cpp - IndirectFittingModelLegacy.cpp IndirectFitPlotModel.cpp IndirectFitPlotPresenter.cpp IndirectFitPlotView.cpp @@ -70,8 +60,6 @@ set( IndirectSettingsView.cpp IndirectSimulation.cpp IndirectSimulationTab.cpp - IndirectSpectrumSelectionPresenterLegacy.cpp - IndirectSpectrumSelectionViewLegacy.cpp IndirectSpectrumSelectionPresenter.cpp IndirectSpectrumSelectionView.cpp IndirectSqw.cpp @@ -119,14 +107,9 @@ set( DllConfig.h IndexTypes.h IndirectDataValidationHelper.h - IndirectFitDataLegacy.h - IndirectFitOutputLegacy.h IndirectFitData.h IndirectFitOutput.h IndirectFitOutputOptionsModel.h - IndirectFitPlotModelLegacy.h - IndirectFitPlotPresenterLegacy.h - IndirectFittingModelLegacy.h IndirectFitPlotModel.h IndirectFitPlotPresenter.h IndirectFittingModel.h @@ -160,10 +143,8 @@ set( Elwin.h FunctionTemplateBrowser.h IAddWorkspaceDialog.h - IIndirectFitDataViewLegacy.h IIndirectFitDataView.h IIndirectFitOutputOptionsView.h - IIndirectFitPlotViewLegacy.h IIndirectFitPlotView.h IIndirectSettingsView.h ILLEnergyTransfer.h @@ -175,20 +156,14 @@ set( IndirectDataAnalysisTab.h IndirectDataReduction.h IndirectDataReductionTab.h - IndirectDataTablePresenterLegacy.h IndirectDataTablePresenter.h IndirectDiffractionReduction.h IndirectEditResultsDialog.h - IndirectFitAnalysisTabLegacy.h IndirectFitAnalysisTab.h - IndirectFitDataPresenterLegacy.h - IndirectFitDataViewLegacy.h IndirectFitDataPresenter.h IndirectFitDataView.h IndirectFitOutputOptionsPresenter.h IndirectFitOutputOptionsView.h - IndirectFitPlotPresenterLegacy.h - IndirectFitPlotViewLegacy.h IndirectFitPlotPresenter.h IndirectFitPlotView.h IndirectInstrumentConfig.h @@ -205,8 +180,6 @@ set( IndirectSettingsView.h IndirectSimulation.h IndirectSimulationTab.h - IndirectSpectrumSelectionPresenterLegacy.h - IndirectSpectrumSelectionViewLegacy.h IndirectSpectrumSelectionPresenter.h IndirectSpectrumSelectionView.h IndirectSqw.h @@ -259,7 +232,6 @@ set( IndirectDataReduction.ui IndirectDiffractionReduction.ui IndirectEditResultsDialog.ui - IndirectFitDataViewLegacy.ui IndirectFitDataView.ui IndirectFitOutputOptions.ui IndirectFitPreviewPlot.ui @@ -357,32 +329,22 @@ set( IndirectDataReduction.cpp IndirectDataReductionTab.cpp IndirectDataTablePresenter.cpp - IndirectDataTablePresenterLegacy.cpp IndirectDataValidationHelper.cpp IndirectDiffractionReduction.cpp IndirectEditResultsDialog.cpp IndirectFitAnalysisTab.cpp - IndirectFitAnalysisTabLegacy.cpp IndirectFitData.cpp - IndirectFitDataLegacy.cpp IndirectFitDataPresenter.cpp - IndirectFitDataPresenterLegacy.cpp IndirectFitDataView.cpp - IndirectFitDataViewLegacy.cpp IndirectFitOutput.cpp - IndirectFitOutputLegacy.cpp IndirectFitOutputOptionsModel.cpp IndirectFitOutputOptionsPresenter.cpp IndirectFitOutputOptionsView.cpp IndirectFitPropertyBrowser.cpp IndirectFitPlotModel.cpp - IndirectFitPlotModelLegacy.cpp IndirectFitPlotPresenter.cpp - IndirectFitPlotPresenterLegacy.cpp IndirectFitPlotView.cpp - IndirectFitPlotViewLegacy.cpp IndirectFittingModel.cpp - IndirectFittingModelLegacy.cpp IndirectInstrumentConfig.cpp IndirectInterface.cpp IndirectLoadILL.cpp @@ -401,9 +363,7 @@ set( IndirectSimulation.cpp IndirectSimulationTab.cpp IndirectSpectrumSelectionPresenter.cpp - IndirectSpectrumSelectionPresenterLegacy.cpp IndirectSpectrumSelectionView.cpp - IndirectSpectrumSelectionViewLegacy.cpp IndirectSqw.cpp IndirectSymmetrise.cpp IndirectTab.cpp @@ -459,10 +419,8 @@ set( ISISEnergyTransfer.h IAddWorkspaceDialog.h IIndirectFitDataView.h - IIndirectFitDataViewLegacy.h IIndirectFitOutputOptionsView.h IIndirectFitPlotView.h - IIndirectFitPlotViewLegacy.h IIndirectSettingsView.h IndirectAddWorkspaceDialog.h IndirectBayes.h @@ -473,22 +431,16 @@ set( IndirectDataReduction.h IndirectDataReductionTab.h IndirectDataTablePresenter.h - IndirectDataTablePresenterLegacy.h IndirectDiffractionReduction.h IndirectEditResultsDialog.h IndirectFitAnalysisTab.h - IndirectFitAnalysisTabLegacy.h IndirectFitDataPresenter.h - IndirectFitDataPresenterLegacy.h IndirectFitDataView.h - IndirectFitDataViewLegacy.h IndirectFitOutputOptionsPresenter.h IndirectFitOutputOptionsView.h IndirectFitPropertyBrowser.h IndirectFitPlotPresenter.h - IndirectFitPlotPresenterLegacy.h IndirectFitPlotView.h - IndirectFitPlotViewLegacy.h IndirectInstrumentConfig.h IndirectInterface.h IndirectLoadILL.h @@ -504,9 +456,7 @@ set( IndirectSimulation.h IndirectSimulationTab.h IndirectSpectrumSelectionPresenter.h - IndirectSpectrumSelectionPresenterLegacy.h IndirectSpectrumSelectionView.h - IndirectSpectrumSelectionViewLegacy.h IndirectSqw.h IndirectSymmetrise.h IndirectTab.h @@ -540,16 +490,11 @@ set( ConvFitModel.h IndirectDataValidationHelper.h IndirectFitData.h - IndirectFitDataLegacy.h IndirectFitOutput.h - IndirectFitOutputLegacy.h IndirectFitOutputOptionsModel.h IndirectFitPlotModel.h - IndirectFitPlotModelLegacy.h IndirectFitPlotPresenter.h - IndirectFitPlotPresenterLegacy.h IndirectFittingModel.h - IndirectFittingModelLegacy.h IndirectPlotOptionsModel.h IndirectSettingsHelper.h IPythonRunner.h diff --git a/qt/scientific_interfaces/Indirect/IIndirectFitDataViewLegacy.h b/qt/scientific_interfaces/Indirect/IIndirectFitDataViewLegacy.h deleted file mode 100644 index 48724c922a3..00000000000 --- a/qt/scientific_interfaces/Indirect/IIndirectFitDataViewLegacy.h +++ /dev/null @@ -1,67 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -#pragma once - -#include "DllConfig.h" -#include "MantidQtWidgets/Common/UserInputValidator.h" - -#include <QObject> -#include <QTabWidget> -#include <QTableWidget> - -namespace MantidQt { -namespace CustomInterfaces { -namespace IDA { - -class MANTIDQT_INDIRECT_DLL IIndirectFitDataViewLegacy : public QTabWidget { - Q_OBJECT - -public: - IIndirectFitDataViewLegacy(QWidget *parent = nullptr) : QTabWidget(parent){}; - virtual ~IIndirectFitDataViewLegacy() = default; - - virtual QTableWidget *getDataTable() const = 0; - virtual bool isMultipleDataTabSelected() const = 0; - virtual bool isResolutionHidden() const = 0; - virtual void setResolutionHidden(bool hide) = 0; - virtual void setStartAndEndHidden(bool hidden) = 0; - virtual void disableMultipleDataTab() = 0; - - virtual std::string getSelectedSample() const = 0; - virtual std::string getSelectedResolution() const = 0; - - virtual QStringList getSampleWSSuffices() const = 0; - virtual QStringList getSampleFBSuffices() const = 0; - virtual QStringList getResolutionWSSuffices() const = 0; - virtual QStringList getResolutionFBSuffices() const = 0; - - virtual void setSampleWSSuffices(QStringList const &suffices) = 0; - virtual void setSampleFBSuffices(QStringList const &suffices) = 0; - virtual void setResolutionWSSuffices(QStringList const &suffices) = 0; - virtual void setResolutionFBSuffices(QStringList const &suffices) = 0; - - virtual bool isSampleWorkspaceSelectorVisible() const = 0; - virtual void - setSampleWorkspaceSelectorIndex(QString const &workspaceName) = 0; - - virtual void readSettings(QSettings const &settings) = 0; - virtual UserInputValidator &validate(UserInputValidator &validator) = 0; - -public slots: - virtual void displayWarning(std::string const &warning) = 0; - -signals: - void sampleLoaded(QString const & /*_t1*/); - void resolutionLoaded(QString const & /*_t1*/); - void addClicked(); - void removeClicked(); - void multipleDataViewSelected(); - void singleDataViewSelected(); -}; -} // namespace IDA -} // namespace CustomInterfaces -} // namespace MantidQt diff --git a/qt/scientific_interfaces/Indirect/IIndirectFitPlotViewLegacy.h b/qt/scientific_interfaces/Indirect/IIndirectFitPlotViewLegacy.h deleted file mode 100644 index 6532dbcfd32..00000000000 --- a/qt/scientific_interfaces/Indirect/IIndirectFitPlotViewLegacy.h +++ /dev/null @@ -1,106 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -#pragma once - -#include "DllConfig.h" -#include "MantidAPI/MatrixWorkspace.h" -#include "MantidQtWidgets/Common/MantidWidget.h" - -#include <QObject> - -namespace MantidQt { -namespace CustomInterfaces { -namespace IDA { - -class MANTIDQT_INDIRECT_DLL IIndirectFitPlotViewLegacy - : public API::MantidWidget { - Q_OBJECT - -public: - IIndirectFitPlotViewLegacy(QWidget *parent = nullptr) - : API::MantidWidget(parent){}; - virtual ~IIndirectFitPlotViewLegacy(){}; - - virtual void watchADS(bool watch) = 0; - - virtual std::size_t getSelectedSpectrum() const = 0; - virtual int getSelectedSpectrumIndex() const = 0; - virtual int getSelectedDataIndex() const = 0; - virtual std::size_t dataSelectionSize() const = 0; - virtual bool isPlotGuessChecked() const = 0; - - virtual void hideMultipleDataSelection() = 0; - virtual void showMultipleDataSelection() = 0; - - virtual void setAvailableSpectra(std::size_t minimum, - std::size_t maximum) = 0; - virtual void - setAvailableSpectra(const std::vector<std::size_t>::const_iterator &from, - const std::vector<std::size_t>::const_iterator &to) = 0; - - virtual void setMinimumSpectrum(int minimum) = 0; - virtual void setMaximumSpectrum(int maximum) = 0; - virtual void setPlotSpectrum(int spectrum) = 0; - virtual void appendToDataSelection(const std::string &dataName) = 0; - virtual void setNameInDataSelection(const std::string &dataName, - std::size_t index) = 0; - virtual void clearDataSelection() = 0; - - virtual void plotInTopPreview(const QString &name, - Mantid::API::MatrixWorkspace_sptr workspace, - std::size_t spectrum, - Qt::GlobalColor colour) = 0; - virtual void plotInBottomPreview(const QString &name, - Mantid::API::MatrixWorkspace_sptr workspace, - std::size_t spectrum, - Qt::GlobalColor colour) = 0; - - virtual void removeFromTopPreview(const QString &name) = 0; - virtual void removeFromBottomPreview(const QString &name) = 0; - - virtual void enablePlotGuess(bool enable) = 0; - virtual void enableSpectrumSelection(bool enable) = 0; - virtual void enableFitRangeSelection(bool enable) = 0; - - virtual void setFitSingleSpectrumText(QString const &text) = 0; - virtual void setFitSingleSpectrumEnabled(bool enable) = 0; - - virtual void setBackgroundLevel(double value) = 0; - - virtual void setFitRange(double minimum, double maximum) = 0; - virtual void setFitRangeMinimum(double minimum) = 0; - virtual void setFitRangeMaximum(double maximum) = 0; - - virtual void setBackgroundRangeVisible(bool visible) = 0; - virtual void setHWHMRangeVisible(bool visible) = 0; - - virtual void displayMessage(const std::string &message) const = 0; - -public slots: - virtual void clearTopPreview() = 0; - virtual void clearBottomPreview() = 0; - virtual void clearPreviews() = 0; - virtual void setHWHMRange(double minimum, double maximum) = 0; - virtual void setHWHMMaximum(double minimum) = 0; - virtual void setHWHMMinimum(double maximum) = 0; - -signals: - void selectedFitDataChanged(std::size_t /*_t1*/); - void plotCurrentPreview(); - void plotSpectrumChanged(std::size_t /*_t1*/); - void plotGuessChanged(bool /*_t1*/); - void fitSelectedSpectrum(); - void startXChanged(double /*_t1*/); - void endXChanged(double /*_t1*/); - void hwhmMinimumChanged(double /*_t1*/); - void hwhmMaximumChanged(double /*_t1*/); - void hwhmChanged(double /*_t1*/, double /*_t2*/); - void backgroundChanged(double /*_t1*/); -}; -} // namespace IDA -} // namespace CustomInterfaces -} // namespace MantidQt diff --git a/qt/scientific_interfaces/Indirect/IndirectDataTablePresenterLegacy.cpp b/qt/scientific_interfaces/Indirect/IndirectDataTablePresenterLegacy.cpp deleted file mode 100644 index c14d6f4c6ec..00000000000 --- a/qt/scientific_interfaces/Indirect/IndirectDataTablePresenterLegacy.cpp +++ /dev/null @@ -1,604 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -#include "IndirectDataTablePresenterLegacy.h" - -#include "MantidQtWidgets/Common/SignalBlocker.h" - -#include <boost/numeric/conversion/cast.hpp> - -#include <QHeaderView> -#include <QItemDelegate> -#include <QLineEdit> -#include <QRegExpValidator> - -namespace { -using MantidQt::CustomInterfaces::IDA::DiscontinuousSpectra; -using MantidQt::CustomInterfaces::IDA::SpectraLegacy; - -namespace Regexes { -const QString EMPTY = "^$"; -const QString SPACE = "(\\s)*"; -const QString COMMA = SPACE + "," + SPACE; -const QString NATURAL_NUMBER = "(0|[1-9][0-9]*)"; -const QString REAL_NUMBER = "(-?" + NATURAL_NUMBER + "(\\.[0-9]*)?)"; -const QString REAL_RANGE = "(" + REAL_NUMBER + COMMA + REAL_NUMBER + ")"; -const QString MASK_LIST = - "(" + REAL_RANGE + "(" + COMMA + REAL_RANGE + ")*" + ")|" + EMPTY; -} // namespace Regexes - -class ExcludeRegionDelegate : public QItemDelegate { -public: - QWidget *createEditor(QWidget *parent, - const QStyleOptionViewItem & /*option*/, - const QModelIndex & /*index*/) const override { - auto lineEdit = std::make_unique<QLineEdit>(parent); - auto validator = - std::make_unique<QRegExpValidator>(QRegExp(Regexes::MASK_LIST), parent); - lineEdit->setValidator(validator.release()); - return lineEdit.release(); - } - - void setEditorData(QWidget *editor, const QModelIndex &index) const override { - const auto value = index.model()->data(index, Qt::EditRole).toString(); - static_cast<QLineEdit *>(editor)->setText(value); - } - - void setModelData(QWidget *editor, QAbstractItemModel *model, - const QModelIndex &index) const override { - auto *lineEdit = static_cast<QLineEdit *>(editor); - model->setData(index, lineEdit->text(), Qt::EditRole); - } - - void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, - const QModelIndex & /*index*/) const override { - editor->setGeometry(option.rect); - } -}; - -QStringList defaultHeaders() { - QStringList headers; - headers << "Workspace" - << "WS Index" - << "StartX" - << "EndX" - << "Mask X Range"; - return headers; -} - -QString makeNumber(double d) { return QString::number(d, 'g', 16); } - -std::string -pairsToString(const std::vector<std::pair<std::size_t, std::size_t>> &pairs) { - std::vector<std::string> pairStrings; - for (auto const &value : pairs) { - if (value.first == value.second) - pairStrings.emplace_back(std::to_string(value.first)); - else - pairStrings.emplace_back(std::to_string(value.first) + "-" + - std::to_string(value.second)); - } - return boost::algorithm::join(pairStrings, ","); -} - -boost::optional<SpectraLegacy> -pairsToSpectra(const std::vector<std::pair<std::size_t, std::size_t>> &pairs) { - if (pairs.empty()) - return boost::none; - else if (pairs.size() == 1) - return boost::optional<SpectraLegacy>(pairs[0]); - return boost::optional<SpectraLegacy>( - DiscontinuousSpectra<std::size_t>(pairsToString(pairs))); -} - -QVariant getVariant(std::size_t i) { - return QVariant::fromValue<qulonglong>(i); -} -} // namespace - -namespace MantidQt { -namespace CustomInterfaces { -namespace IDA { - -IndirectDataTablePresenterLegacy::IndirectDataTablePresenterLegacy( - IndirectFittingModelLegacy *model, QTableWidget *dataTable) - : IndirectDataTablePresenterLegacy(model, dataTable, defaultHeaders()) {} - -IndirectDataTablePresenterLegacy::IndirectDataTablePresenterLegacy( - IndirectFittingModelLegacy *model, QTableWidget *dataTable, - const QStringList &headers) - : m_model(model), m_dataTable(dataTable) { - setHorizontalHeaders(headers); - m_dataTable->setItemDelegateForColumn( - headers.size() - 1, std::make_unique<ExcludeRegionDelegate>().release()); - m_dataTable->verticalHeader()->setVisible(false); - - connect(m_dataTable, SIGNAL(cellChanged(int, int)), this, - SLOT(setModelFittingRange(int, int))); - connect(m_dataTable, SIGNAL(cellChanged(int, int)), this, - SLOT(updateAllFittingRangeFrom(int, int))); -} - -bool IndirectDataTablePresenterLegacy::tableDatasetsMatchModel() const { - if (m_dataPositions.size() != m_model->numberOfWorkspaces()) - return false; - - for (auto i = 0u; i < m_dataPositions.size(); ++i) { - if (m_model->getWorkspace(i)->getName() != - getWorkspaceName(m_dataPositions[i])) - return false; - } - return true; -} - -bool IndirectDataTablePresenterLegacy::isTableEmpty() const { - return m_dataPositions.empty(); -} - -int IndirectDataTablePresenterLegacy::workspaceIndexColumn() const { return 1; } - -int IndirectDataTablePresenterLegacy::startXColumn() const { return 2; } - -int IndirectDataTablePresenterLegacy::endXColumn() const { return 3; } - -int IndirectDataTablePresenterLegacy::excludeColumn() const { return 4; } - -double IndirectDataTablePresenterLegacy::startX(int row) const { - return getDouble(row, startXColumn()); -} - -double IndirectDataTablePresenterLegacy::endX(int row) const { - return getDouble(row, endXColumn()); -} - -std::string IndirectDataTablePresenterLegacy::getExcludeString(int row) const { - return getString(row, excludeColumn()); -} - -std::string IndirectDataTablePresenterLegacy::getWorkspaceName(int row) const { - return getString(row, 0); -} - -std::size_t IndirectDataTablePresenterLegacy::getWorkspaceIndex(int row) const { - const auto item = m_dataTable->item(row, workspaceIndexColumn()); - return static_cast<std::size_t>(item->text().toULongLong()); -} - -double IndirectDataTablePresenterLegacy::getDouble(int row, int column) const { - return getText(row, column).toDouble(); -} - -std::string IndirectDataTablePresenterLegacy::getString(int row, - int column) const { - return getText(row, column).toStdString(); -} - -QString IndirectDataTablePresenterLegacy::getText(int row, int column) const { - return m_dataTable->item(row, column)->text(); -} - -int IndirectDataTablePresenterLegacy::getNextPosition(std::size_t index) const { - if (m_dataPositions.size() > index + 1) - return m_dataPositions[index + 1]; - return m_dataTable->rowCount(); -} - -int IndirectDataTablePresenterLegacy::getFirstRow(std::size_t dataIndex) const { - if (m_dataPositions.size() > dataIndex) - return m_dataPositions[dataIndex]; - return -1; -} - -std::size_t IndirectDataTablePresenterLegacy::getDataIndex(int row) const { - return m_dataTable->item(row, 0)->data(Qt::UserRole).toULongLong(); -} - -boost::optional<SpectraLegacy> -IndirectDataTablePresenterLegacy::getSpectra(std::size_t dataIndex) const { - if (m_dataPositions.size() > dataIndex) - return getSpectra(m_dataPositions[dataIndex], getNextPosition(dataIndex)); - return boost::none; -} - -boost::optional<SpectraLegacy> -IndirectDataTablePresenterLegacy::getSpectra(int start, int end) const { - std::vector<std::pair<std::size_t, std::size_t>> spectraPairs; - while (start < end) { - std::size_t minimum = getWorkspaceIndex(start); - std::size_t maximum = minimum; - - while (++start < end && getWorkspaceIndex(start) == maximum + 1) - ++maximum; - spectraPairs.emplace_back(minimum, maximum); - } - return pairsToSpectra(spectraPairs); -} - -boost::optional<int> -IndirectDataTablePresenterLegacy::getRowIndex(std::size_t dataIndex, - int spectrumIndex) const { - const auto position = m_dataPositions[dataIndex] + spectrumIndex; - if (getNextPosition(dataIndex) > position) - return position; - return boost::none; -} - -void IndirectDataTablePresenterLegacy::setStartX(double startX, - std::size_t dataIndex, - int spectrumIndex) { - if (FittingModeLegacy::SEQUENTIAL == m_model->getFittingMode()) - setStartX(startX); - else if (auto row = getRowIndex(dataIndex, spectrumIndex)) - setStartX(startX, *row); -} - -void IndirectDataTablePresenterLegacy::setEndX(double endX, - std::size_t dataIndex, - int spectrumIndex) { - if (FittingModeLegacy::SEQUENTIAL == m_model->getFittingMode()) - setEndX(endX); - else if (auto row = getRowIndex(dataIndex, spectrumIndex)) - setEndX(endX, *row); -} - -void IndirectDataTablePresenterLegacy::setExclude(const std::string &exclude, - std::size_t dataIndex, - int spectrumIndex) { - if (FittingModeLegacy::SEQUENTIAL == m_model->getFittingMode()) - setExcludeRegion(exclude); - else if (auto row = getRowIndex(dataIndex, spectrumIndex)) - setExcludeRegion(exclude, *row); -} - -void IndirectDataTablePresenterLegacy::addData(std::size_t index) { - if (m_dataPositions.size() > index) - updateData(index); - else - addNewData(index); -} - -void IndirectDataTablePresenterLegacy::addNewData(std::size_t index) { - MantidQt::API::SignalBlocker blocker(m_dataTable); - const auto start = m_dataTable->rowCount(); - - const auto addRow = [&](std::size_t spectrum) { - addTableEntry(index, spectrum); - }; - m_model->applySpectra(index, addRow); - - if (m_model->numberOfWorkspaces() > m_dataPositions.size()) - m_dataPositions.emplace_back(start); -} - -void IndirectDataTablePresenterLegacy::updateData(std::size_t index) { - if (m_dataPositions.size() > index) - updateExistingData(index); - else - addNewData(index); -} - -void IndirectDataTablePresenterLegacy::updateExistingData(std::size_t index) { - MantidQt::API::SignalBlocker blocker(m_dataTable); - auto position = m_dataPositions[index]; - const auto nextPosition = getNextPosition(index); - const auto initialSize = nextPosition - position; - - const auto updateRow = [&](std::size_t spectrum) { - if (position < nextPosition) - updateTableEntry(index, spectrum, position++); - else - addTableEntry(index, spectrum, position++); - }; - m_model->applySpectra(index, updateRow); - - collapseData(position, nextPosition, initialSize, index); -} - -void IndirectDataTablePresenterLegacy::collapseData(int from, int to, - int initialSize, - std::size_t dataIndex) { - const auto shift = from - to; - if (shift != 0) { - for (auto i = from; i < to; ++i) - removeTableEntry(from); - - if (initialSize + shift == 0 && m_dataPositions.size() > dataIndex) { - m_dataPositions.erase(m_dataPositions.begin() + dataIndex); - shiftDataPositions(shift, dataIndex, m_dataPositions.size()); - updateDataPositionsInCells(dataIndex, m_dataPositions.size()); - } else - shiftDataPositions(shift, dataIndex + 1, m_dataPositions.size()); - } -} - -void IndirectDataTablePresenterLegacy::removeSelectedData() { - MantidQt::API::SignalBlocker blocker(m_dataTable); - auto selectedIndices = m_dataTable->selectionModel()->selectedIndexes(); - const auto modifiedIndicesAndCount = removeTableRows(selectedIndices); - const auto &modifiedCount = modifiedIndicesAndCount.second; - auto &modifiedIndices = modifiedIndicesAndCount.first; - - for (auto i = 0u; i < modifiedIndices.size(); ++i) - shiftDataPositions(-static_cast<int>(modifiedCount[i]), - modifiedIndices[i] + 1, m_dataPositions.size()); - - if (!modifiedIndices.empty()) { - updateFromRemovedIndices(modifiedIndices); - updateDataPositionsInCells( - modifiedIndices.back() > 0 ? modifiedIndices.back() - 1 : 0, - m_dataPositions.size()); - } -} - -void IndirectDataTablePresenterLegacy::updateFromRemovedIndices( - const std::vector<std::size_t> &indices) { - for (const auto &index : indices) { - const auto existingSpectra = getSpectra(index); - if (existingSpectra) - m_model->setSpectra(*existingSpectra, index); - else { - const auto originalNumberOfWorkspaces = m_model->numberOfWorkspaces(); - m_model->removeWorkspace(index); - m_dataPositions.erase(m_dataPositions.begin() + index); - - if (m_model->numberOfWorkspaces() == originalNumberOfWorkspaces - 2) - m_dataPositions.erase(m_dataPositions.begin() + index); - } - } -} - -std::pair<std::vector<std::size_t>, std::vector<std::size_t>> -IndirectDataTablePresenterLegacy::removeTableRows( - QModelIndexList &selectedRows) { - std::vector<std::size_t> modifiedIndices; - std::vector<std::size_t> modifiedCount; - int previous = -1; - - qSort(selectedRows); - for (auto i = selectedRows.count() - 1; i >= 0; --i) { - const auto current = selectedRows[i].row(); - if (current != previous) { - auto modifiedIndex = removeTableEntry(current); - - if (!modifiedIndices.empty() && modifiedIndices.back() == modifiedIndex) - ++modifiedCount.back(); - else { - modifiedIndices.emplace_back(modifiedIndex); - modifiedCount.emplace_back(1); - } - previous = current; - } - } - return {modifiedIndices, modifiedCount}; -} - -void IndirectDataTablePresenterLegacy::setModelFittingRange(int row, - int column) { - const auto workspaceIndex = getWorkspaceIndex(row); - const auto dataIndex = getDataIndex(row); - - if (startXColumn() == column) - setModelStartXAndEmit(getDouble(row, column), dataIndex, workspaceIndex); - else if (endXColumn() == column) - setModelEndXAndEmit(getDouble(row, column), dataIndex, workspaceIndex); - else if (excludeColumn() == column) - setModelExcludeAndEmit(getString(row, column), dataIndex, workspaceIndex); -} - -void IndirectDataTablePresenterLegacy::setModelStartXAndEmit( - double startX, std::size_t dataIndex, std::size_t workspaceIndex) { - m_model->setStartX(startX, dataIndex, workspaceIndex); - emit startXChanged(startX, dataIndex, workspaceIndex); -} - -void IndirectDataTablePresenterLegacy::setModelEndXAndEmit( - double endX, std::size_t dataIndex, std::size_t workspaceIndex) { - m_model->setEndX(endX, dataIndex, workspaceIndex); - emit endXChanged(endX, dataIndex, workspaceIndex); -} - -void IndirectDataTablePresenterLegacy::setModelExcludeAndEmit( - const std::string &exclude, std::size_t dataIndex, - std::size_t workspaceIndex) { - m_model->setExcludeRegion(exclude, dataIndex, workspaceIndex); - emit excludeRegionChanged(exclude, dataIndex, workspaceIndex); -} - -void IndirectDataTablePresenterLegacy::setGlobalFittingRange(bool global) { - if (global) - enableGlobalFittingRange(); - else - disableGlobalFittingRange(); -} - -void IndirectDataTablePresenterLegacy::updateAllFittingRangeFrom(int row, - int column) { - MantidQt::API::SignalBlocker blocker(m_dataTable); - if (startXColumn() == column) - setStartX(getDouble(row, column)); - else if (endXColumn() == column) - setEndX(getDouble(row, column)); - else if (excludeColumn() == column) - setExcludeRegion(getText(row, column)); -} - -void IndirectDataTablePresenterLegacy::enableGlobalFittingRange() { - MantidQt::API::SignalBlocker blocker(m_dataTable); - const auto range = m_model->getFittingRange(0, 0); - setStartX(range.first); - setEndX(range.second); - setExcludeRegion(m_model->getExcludeRegion(0, 0)); - connect(m_dataTable, SIGNAL(cellChanged(int, int)), this, - SLOT(updateAllFittingRangeFrom(int, int))); -} - -void IndirectDataTablePresenterLegacy::disableGlobalFittingRange() { - disconnect(m_dataTable, SIGNAL(cellChanged(int, int)), this, - SLOT(updateAllFittingRangeFrom(int, int))); -} - -void IndirectDataTablePresenterLegacy::enableTable() { - m_dataTable->setEnabled(true); -} - -void IndirectDataTablePresenterLegacy::disableTable() { - m_dataTable->setDisabled(true); -} - -void IndirectDataTablePresenterLegacy::clearTable() { - m_dataTable->setRowCount(0); - m_dataPositions.clear(); -} - -void IndirectDataTablePresenterLegacy::setStartX(double startX, int index) { - MantidQt::API::SignalBlocker blocker(m_dataTable); - if (FittingModeLegacy::SEQUENTIAL == m_model->getFittingMode()) - setStartX(startX); - else - m_dataTable->item(index, startXColumn())->setText(makeNumber(startX)); -} - -void IndirectDataTablePresenterLegacy::setEndX(double endX, int index) { - MantidQt::API::SignalBlocker blocker(m_dataTable); - if (FittingModeLegacy::SEQUENTIAL == m_model->getFittingMode()) - setEndX(endX); - else - m_dataTable->item(index, endXColumn())->setText(makeNumber(endX)); -} - -void IndirectDataTablePresenterLegacy::setExcludeRegion( - const std::string &exclude, int index) { - MantidQt::API::SignalBlocker blocker(m_dataTable); - if (FittingModeLegacy::SEQUENTIAL == m_model->getFittingMode()) - setExcludeRegion(exclude); - else - m_dataTable->item(index, excludeColumn()) - ->setText(QString::fromStdString(exclude)); -} - -void IndirectDataTablePresenterLegacy::setStartX(double startX) { - setColumnValues(startXColumn(), makeNumber(startX)); -} - -void IndirectDataTablePresenterLegacy::setEndX(double endX) { - setColumnValues(endXColumn(), makeNumber(endX)); -} - -void IndirectDataTablePresenterLegacy::setExcludeRegion( - const std::string &exclude) { - setExcludeRegion(QString::fromStdString(exclude)); -} - -void IndirectDataTablePresenterLegacy::setExcludeRegion( - const QString &exclude) { - setColumnValues(excludeColumn(), exclude); -} - -void IndirectDataTablePresenterLegacy::setColumnValues(int column, - const QString &value) { - MantidQt::API::SignalBlocker blocker(m_dataTable); - for (int i = 0; i < m_dataTable->rowCount(); ++i) - m_dataTable->item(i, column)->setText(value); -} - -void IndirectDataTablePresenterLegacy::setHorizontalHeaders( - const QStringList &headers) { - m_dataTable->setColumnCount(headers.size()); - m_dataTable->setHorizontalHeaderLabels(headers); - - auto header = m_dataTable->horizontalHeader(); -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - header->setResizeMode(0, QHeaderView::Stretch); -#elif QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) - header->setSectionResizeMode(0, QHeaderView::Stretch); -#endif -} - -void IndirectDataTablePresenterLegacy::addTableEntry(std::size_t dataIndex, - std::size_t spectrum) { - const auto row = m_dataTable->rowCount(); - addTableEntry(dataIndex, spectrum, row); - m_dataTable->item(row, 0)->setData(Qt::UserRole, getVariant(dataIndex)); -} - -void IndirectDataTablePresenterLegacy::addTableEntry(std::size_t dataIndex, - std::size_t spectrum, - int row) { - m_dataTable->insertRow(row); - - const auto &name = m_model->getWorkspace(dataIndex)->getName(); - auto cell = std::make_unique<QTableWidgetItem>(QString::fromStdString(name)); - auto flags = cell->flags(); - flags ^= Qt::ItemIsEditable; - cell->setFlags(flags); - setCell(std::move(cell), row, 0); - - cell = std::make_unique<QTableWidgetItem>(QString::number(spectrum)); - cell->setFlags(flags); - setCell(std::move(cell), row, workspaceIndexColumn()); - - const auto range = m_model->getFittingRange(dataIndex, spectrum); - cell = std::make_unique<QTableWidgetItem>(makeNumber(range.first)); - setCell(std::move(cell), row, startXColumn()); - - cell = std::make_unique<QTableWidgetItem>(makeNumber(range.second)); - setCell(std::move(cell), row, endXColumn()); - - const auto exclude = m_model->getExcludeRegion(dataIndex, spectrum); - cell = std::make_unique<QTableWidgetItem>(QString::fromStdString(exclude)); - setCell(std::move(cell), row, excludeColumn()); -} - -void IndirectDataTablePresenterLegacy::setCell( - std::unique_ptr<QTableWidgetItem> cell, int row, int column) { - m_dataTable->setItem(row, column, cell.release()); -} - -void IndirectDataTablePresenterLegacy::updateTableEntry(std::size_t dataIndex, - std::size_t spectrum, - int row) { - const auto &name = m_model->getWorkspace(dataIndex)->getName(); - setCellText(QString::fromStdString(name), row, 0); - setCellText(QString::number(spectrum), row, workspaceIndexColumn()); - - const auto range = m_model->getFittingRange(dataIndex, spectrum); - setCellText(makeNumber(range.first), row, startXColumn()); - setCellText(makeNumber(range.second), row, endXColumn()); - - const auto exclude = m_model->getExcludeRegion(dataIndex, spectrum); - setCellText(QString::fromStdString(exclude), row, excludeColumn()); -} - -void IndirectDataTablePresenterLegacy::setCellText(const QString &text, int row, - int column) { - m_dataTable->item(row, column)->setText(text); -} - -std::size_t IndirectDataTablePresenterLegacy::removeTableEntry(int row) { - const auto dataIndex = m_dataTable->item(row, 0)->data(Qt::UserRole); - m_dataTable->removeRow(row); - return dataIndex.toULongLong(); -} - -void IndirectDataTablePresenterLegacy::shiftDataPositions(int shift, - std::size_t from, - std::size_t to) { - for (auto i = from; i < to; ++i) - m_dataPositions[i] += shift; -} - -void IndirectDataTablePresenterLegacy::updateDataPositionsInCells( - std::size_t from, std::size_t to) { - for (auto i = from; i < to; ++i) { - const auto nextPosition = getNextPosition(i); - for (auto row = m_dataPositions[i]; row < nextPosition; ++row) - m_dataTable->item(row, 0)->setData(Qt::UserRole, getVariant(i)); - } -} - -} // namespace IDA -} // namespace CustomInterfaces -} // namespace MantidQt \ No newline at end of file diff --git a/qt/scientific_interfaces/Indirect/IndirectDataTablePresenterLegacy.h b/qt/scientific_interfaces/Indirect/IndirectDataTablePresenterLegacy.h deleted file mode 100644 index 8539047f340..00000000000 --- a/qt/scientific_interfaces/Indirect/IndirectDataTablePresenterLegacy.h +++ /dev/null @@ -1,128 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2015 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -#pragma once - -#include "IndirectFittingModelLegacy.h" - -#include <QTableWidget> - -#include <cstddef> -#include <unordered_map> - -namespace MantidQt { -namespace CustomInterfaces { -namespace IDA { - -/** - Presenter for a table of indirect fitting data. -*/ -class MANTIDQT_INDIRECT_DLL IndirectDataTablePresenterLegacy : public QObject { - Q_OBJECT -public: - IndirectDataTablePresenterLegacy(IndirectFittingModelLegacy *model, - QTableWidget *dataTable); - - IndirectDataTablePresenterLegacy(IndirectFittingModelLegacy *model, - QTableWidget *dataTable, - const QStringList &headers); - - bool tableDatasetsMatchModel() const; - bool isTableEmpty() const; - - void setStartX(double startX, std::size_t dataIndex, int spectrumIndex); - void setEndX(double endX, std::size_t dataIndex, int spectrumIndex); - void setExclude(const std::string &exclude, std::size_t dataIndex, - int spectrumIndex); - -signals: - void startXChanged(double /*_t1*/, std::size_t /*_t2*/, std::size_t /*_t3*/); - void endXChanged(double /*_t1*/, std::size_t /*_t2*/, std::size_t /*_t3*/); - void excludeRegionChanged(const std::string & /*_t1*/, std::size_t /*_t2*/, - std::size_t /*_t3*/); - -public slots: - void addData(std::size_t index); - void updateData(std::size_t index); - void removeSelectedData(); - void setStartX(double startX, int index); - void setEndX(double endX, int index); - void setExcludeRegion(const std::string &exclude, int index); - void setGlobalFittingRange(bool global); - void enableTable(); - void disableTable(); - void clearTable(); - -private slots: - void setModelFittingRange(int row, int column); - void updateAllFittingRangeFrom(int row, int column); - -protected: - int getFirstRow(std::size_t dataIndex) const; - std::string getString(int row, int column) const; - - virtual void addTableEntry(std::size_t dataIndex, std::size_t spectrum, - int row); - void setCell(std::unique_ptr<QTableWidgetItem> cell, int row, int column); - virtual void updateTableEntry(std::size_t dataIndex, std::size_t spectrum, - int row); - void setCellText(const QString &text, int row, int column); - -private: - virtual int workspaceIndexColumn() const; - virtual int startXColumn() const; - virtual int endXColumn() const; - virtual int excludeColumn() const; - double startX(int row) const; - double endX(int row) const; - std::string getExcludeString(int row) const; - std::string getWorkspaceName(int row) const; - std::size_t getWorkspaceIndex(int row) const; - double getDouble(int row, int column) const; - QString getText(int row, int column) const; - int getNextPosition(std::size_t index) const; - std::size_t getDataIndex(int row) const; - boost::optional<SpectraLegacy> getSpectra(std::size_t dataIndex) const; - boost::optional<SpectraLegacy> getSpectra(int start, int end) const; - boost::optional<int> getRowIndex(std::size_t dataIndex, - int spectrumIndex) const; - - void setModelStartXAndEmit(double startX, std::size_t dataIndex, - std::size_t workspaceIndex); - void setModelEndXAndEmit(double endX, std::size_t dataIndex, - std::size_t workspaceIndex); - void setModelExcludeAndEmit(const std::string &exclude, std::size_t dataIndex, - std::size_t workspaceIndex); - - void enableGlobalFittingRange(); - void disableGlobalFittingRange(); - - void updateExistingData(std::size_t index); - void addNewData(std::size_t index); - void addTableEntry(std::size_t dataIndex, std::size_t spectrum); - std::size_t removeTableEntry(int row); - std::pair<std::vector<std::size_t>, std::vector<std::size_t>> - removeTableRows(QModelIndexList &selectedRows); - void setStartX(double startX); - void setEndX(double endX); - void setExcludeRegion(const std::string &exclude); - void setExcludeRegion(const QString &exclude); - void setColumnValues(int column, const QString &value); - void setHorizontalHeaders(const QStringList &headers); - - void collapseData(int from, int to, int initialSize, std::size_t dataIndex); - void updateFromRemovedIndices(const std::vector<std::size_t> &indices); - void shiftDataPositions(int value, std::size_t from, std::size_t to); - void updateDataPositionsInCells(std::size_t from, std::size_t to); - - std::vector<int> m_dataPositions; - IndirectFittingModelLegacy *m_model; - QTableWidget *m_dataTable; -}; - -} // namespace IDA -} // namespace CustomInterfaces -} // namespace MantidQt diff --git a/qt/scientific_interfaces/Indirect/IndirectFitAnalysisTabLegacy.cpp b/qt/scientific_interfaces/Indirect/IndirectFitAnalysisTabLegacy.cpp deleted file mode 100644 index 02d0163c5e8..00000000000 --- a/qt/scientific_interfaces/Indirect/IndirectFitAnalysisTabLegacy.cpp +++ /dev/null @@ -1,1143 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -#include "IndirectFitAnalysisTabLegacy.h" -#include "ui_ConvFit.h" -#include "ui_IqtFit.h" -#include "ui_JumpFit.h" -#include "ui_MSDFit.h" - -#include "MantidAPI/FunctionFactory.h" -#include "MantidAPI/TextAxis.h" -#include "MantidAPI/WorkspaceFactory.h" - -#include "MantidQtWidgets/Common/PropertyHandler.h" -#include "MantidQtWidgets/Common/SignalBlocker.h" - -#include <QString> -#include <QtCore> - -#include <algorithm> -#include <utility> - -using namespace Mantid::API; - -namespace { -using namespace MantidQt::CustomInterfaces::IDA; - -bool doesExistInADS(std::string const &workspaceName) { - return AnalysisDataService::Instance().doesExist(workspaceName); -} - -WorkspaceGroup_sptr getADSGroupWorkspace(std::string const &workspaceName) { - return AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>( - workspaceName); -} - -void updateParameters( - const IFunction_sptr &function, - std::unordered_map<std::string, ParameterValueLegacy> const ¶meters) { - for (auto i = 0u; i < function->nParams(); ++i) { - auto const value = parameters.find(function->parameterName(i)); - if (value != parameters.end()) { - function->setParameter(i, value->second.value); - if (value->second.error) - function->setError(i, *value->second.error); - } - } -} - -void updateAttributes( - const IFunction_sptr &function, - std::vector<std::string> const &attributeNames, - std::unordered_map<std::string, IFunction::Attribute> const &attributes) { - for (const auto &attributeName : attributeNames) { - auto const value = attributes.find(attributeName); - if (value != attributes.end()) - function->setAttribute(attributeName, value->second); - } -} - -} // namespace - -namespace MantidQt { -namespace CustomInterfaces { -namespace IDA { - -IndirectFitAnalysisTabLegacy::IndirectFitAnalysisTabLegacy( - IndirectFittingModelLegacy *model, QWidget *parent) - : IndirectDataAnalysisTab(parent), m_fittingModel(model) {} - -void IndirectFitAnalysisTabLegacy::setup() { - setupFitTab(); - updateResultOptions(); - - connect(m_dataPresenter.get(), - SIGNAL(startXChanged(double, std::size_t, std::size_t)), this, - SLOT(tableStartXChanged(double, std::size_t, std::size_t))); - connect(m_dataPresenter.get(), - SIGNAL(endXChanged(double, std::size_t, std::size_t)), this, - SLOT(tableEndXChanged(double, std::size_t, std::size_t))); - connect( - m_dataPresenter.get(), - SIGNAL( - excludeRegionChanged(const std::string &, std::size_t, std::size_t)), - this, - SLOT(tableExcludeChanged(const std::string &, std::size_t, std::size_t))); - connect(m_dataPresenter.get(), SIGNAL(singleResolutionLoaded()), this, - SLOT(setModelFitFunction())); - - connect(m_fitPropertyBrowser, SIGNAL(fitScheduled()), this, - SLOT(singleFit())); - connect(m_fitPropertyBrowser, SIGNAL(sequentialFitScheduled()), this, - SLOT(executeFit())); - - connect(m_fitPropertyBrowser, SIGNAL(startXChanged(double)), this, - SLOT(setModelStartX(double))); - connect(m_fitPropertyBrowser, SIGNAL(endXChanged(double)), this, - SLOT(setModelEndX(double))); - - connect(m_fitPropertyBrowser, - SIGNAL(parameterChanged(const Mantid::API::IFunction *)), this, - SIGNAL(parameterChanged(const Mantid::API::IFunction *))); - - connect(m_fitPropertyBrowser, - SIGNAL(customBoolChanged(const QString &, bool)), this, - SIGNAL(customBoolChanged(const QString &, bool))); - - connect(m_fitPropertyBrowser, SIGNAL(functionChanged()), this, - SLOT(setModelFitFunction())); - connect(m_fitPropertyBrowser, SIGNAL(functionChanged()), this, - SIGNAL(functionChanged())); - connect(m_fitPropertyBrowser, SIGNAL(functionChanged()), this, - SLOT(updateResultOptions())); - connect(m_fitPropertyBrowser, SIGNAL(functionChanged()), this, - SLOT(updateParameterValues())); - - connect(m_fitPropertyBrowser, SIGNAL(functionChanged()), this, - SLOT(updatePlotGuess())); - connect(m_fitPropertyBrowser, SIGNAL(workspaceNameChanged(const QString &)), - this, SLOT(updatePlotGuess())); - - connect(m_plotPresenter.get(), - SIGNAL(fitSingleSpectrum(std::size_t, std::size_t)), this, - SLOT(singleFit(std::size_t, std::size_t))); - connect(m_plotPresenter.get(), - SIGNAL(runAsPythonScript(const QString &, bool)), this, - SIGNAL(runAsPythonScript(const QString &, bool))); - - connect(m_dataPresenter.get(), SIGNAL(dataChanged()), this, - SLOT(updateResultOptions())); - connect(m_dataPresenter.get(), SIGNAL(updateAvailableFitTypes()), this, - SIGNAL(updateAvailableFitTypes())); - - connect(m_outOptionsPresenter.get(), SIGNAL(plotSpectra()), this, - SLOT(plotSelectedSpectra())); - - connectDataAndSpectrumPresenters(); - connectDataAndPlotPresenters(); - connectDataAndFitBrowserPresenters(); - connectSpectrumAndPlotPresenters(); - connectFitBrowserAndPlotPresenter(); -} - -void IndirectFitAnalysisTabLegacy::connectDataAndPlotPresenters() { - connect(m_dataPresenter.get(), SIGNAL(multipleDataViewSelected()), - m_plotPresenter.get(), SLOT(showMultipleDataSelection())); - connect(m_dataPresenter.get(), SIGNAL(singleDataViewSelected()), - m_plotPresenter.get(), SLOT(hideMultipleDataSelection())); - - connect(m_dataPresenter.get(), SIGNAL(dataAdded()), m_plotPresenter.get(), - SLOT(appendLastDataToSelection())); - connect(m_dataPresenter.get(), SIGNAL(dataRemoved()), m_plotPresenter.get(), - SLOT(updateDataSelection())); - - connect(m_dataPresenter.get(), SIGNAL(dataChanged()), m_plotPresenter.get(), - SLOT(updateAvailableSpectra())); - connect(m_dataPresenter.get(), SIGNAL(dataChanged()), m_plotPresenter.get(), - SLOT(updatePlots())); - connect(m_dataPresenter.get(), SIGNAL(dataChanged()), m_plotPresenter.get(), - SLOT(updateGuessAvailability())); - - connect(m_dataPresenter.get(), SIGNAL(singleResolutionLoaded()), - m_plotPresenter.get(), SLOT(updatePlots())); - connect(m_dataPresenter.get(), SIGNAL(singleResolutionLoaded()), - m_plotPresenter.get(), SLOT(updateGuessAvailability())); - - connect(m_plotPresenter.get(), SIGNAL(startXChanged(double)), this, - SLOT(setDataTableStartX(double))); - connect(m_plotPresenter.get(), SIGNAL(endXChanged(double)), this, - SLOT(setDataTableEndX(double))); -} - -void IndirectFitAnalysisTabLegacy::connectSpectrumAndPlotPresenters() { - connect(m_plotPresenter.get(), SIGNAL(selectedFitDataChanged(std::size_t)), - m_spectrumPresenter.get(), SLOT(setActiveModelIndex(std::size_t))); - connect(m_plotPresenter.get(), SIGNAL(noFitDataSelected()), - m_spectrumPresenter.get(), SLOT(disableView())); - connect(m_spectrumPresenter.get(), SIGNAL(spectraChanged(std::size_t)), - m_plotPresenter.get(), SLOT(updateSelectedDataName())); - connect(m_spectrumPresenter.get(), SIGNAL(spectraChanged(std::size_t)), - m_plotPresenter.get(), SLOT(updateAvailableSpectra())); -} - -void IndirectFitAnalysisTabLegacy::connectFitBrowserAndPlotPresenter() { - connect(m_plotPresenter.get(), SIGNAL(selectedFitDataChanged(std::size_t)), - this, SLOT(setBrowserWorkspace(std::size_t))); - connect(m_fitPropertyBrowser, SIGNAL(functionChanged()), this, - SLOT(updateAttributeValues())); - connect(m_plotPresenter.get(), SIGNAL(selectedFitDataChanged(std::size_t)), - this, SLOT(updateAttributeValues())); - connect(m_plotPresenter.get(), SIGNAL(selectedFitDataChanged(std::size_t)), - this, SLOT(updateParameterValues())); - connect(m_plotPresenter.get(), SIGNAL(plotSpectrumChanged(std::size_t)), this, - SLOT(setBrowserWorkspaceIndex(std::size_t))); - // Update attributes before parameters as the parameters may depend on the - // attribute values - connect(m_plotPresenter.get(), SIGNAL(plotSpectrumChanged(std::size_t)), this, - SLOT(updateAttributeValues())); - connect(m_plotPresenter.get(), SIGNAL(plotSpectrumChanged(std::size_t)), this, - SLOT(updateParameterValues())); - - connect(m_fitPropertyBrowser, SIGNAL(startXChanged(double)), - m_plotPresenter.get(), SLOT(setStartX(double))); - connect(m_fitPropertyBrowser, SIGNAL(endXChanged(double)), - m_plotPresenter.get(), SLOT(setEndX(double))); - connect(m_fitPropertyBrowser, SIGNAL(updatePlotSpectrum(int)), - m_plotPresenter.get(), SLOT(updatePlotSpectrum(int))); - connect(m_fitPropertyBrowser, SIGNAL(workspaceIndexChanged(int)), this, - SLOT(setBrowserWorkspaceIndex(int))); - connect(m_fitPropertyBrowser, SIGNAL(workspaceIndexChanged(int)), this, - SLOT(updateAttributeValues())); - connect(m_fitPropertyBrowser, SIGNAL(workspaceIndexChanged(int)), this, - SLOT(updateParameterValues())); - - connect(m_plotPresenter.get(), SIGNAL(startXChanged(double)), this, - SLOT(setBrowserStartX(double))); - connect(m_plotPresenter.get(), SIGNAL(endXChanged(double)), this, - SLOT(setBrowserEndX(double))); - connect(m_plotPresenter.get(), SIGNAL(fwhmChanged(double)), this, - SLOT(updateFitBrowserParameterValues())); - connect(m_plotPresenter.get(), SIGNAL(backgroundChanged(double)), this, - SLOT(updateFitBrowserParameterValues())); - - connect(m_fitPropertyBrowser, SIGNAL(xRangeChanged(double, double)), - m_plotPresenter.get(), SLOT(updateGuess())); - connect(m_plotPresenter.get(), SIGNAL(fwhmChanged(double)), - m_plotPresenter.get(), SLOT(updateGuess())); - connect(m_plotPresenter.get(), SIGNAL(backgroundChanged(double)), - m_plotPresenter.get(), SLOT(updateGuess())); - - connect(m_fitPropertyBrowser, - SIGNAL(parameterChanged(const Mantid::API::IFunction *)), - m_plotPresenter.get(), SLOT(updateRangeSelectors())); - connect(m_fitPropertyBrowser, - SIGNAL(parameterChanged(const Mantid::API::IFunction *)), - m_plotPresenter.get(), SLOT(updateGuessAvailability())); - - connect(m_fitPropertyBrowser, SIGNAL(functionChanged()), - m_plotPresenter.get(), SLOT(updatePlots())); - connect(m_fitPropertyBrowser, SIGNAL(functionChanged()), - m_plotPresenter.get(), SLOT(updateGuessAvailability())); - - connect(m_fitPropertyBrowser, SIGNAL(plotGuess()), m_plotPresenter.get(), - SLOT(enablePlotGuessInSeparateWindow())); -} - -void IndirectFitAnalysisTabLegacy::connectDataAndSpectrumPresenters() { - connect(m_dataPresenter.get(), SIGNAL(singleDataViewSelected()), - m_spectrumPresenter.get(), SLOT(setActiveIndexToZero())); - connect(m_dataPresenter.get(), SIGNAL(dataChanged()), - m_spectrumPresenter.get(), SLOT(updateSpectra())); - connect(m_spectrumPresenter.get(), SIGNAL(spectraChanged(std::size_t)), - m_dataPresenter.get(), SLOT(updateSpectraInTable(std::size_t))); - connect(m_spectrumPresenter.get(), SIGNAL(maskChanged(const std::string &)), - this, SLOT(setDataTableExclude(const std::string &))); -} - -void IndirectFitAnalysisTabLegacy::connectDataAndFitBrowserPresenters() { - connect(m_dataPresenter.get(), SIGNAL(dataChanged()), this, - SLOT(updateBrowserFittingRange())); - connect(m_dataPresenter.get(), SIGNAL(dataChanged()), this, - SLOT(setBrowserWorkspace())); - connect(m_fitPropertyBrowser, SIGNAL(startXChanged(double)), this, - SLOT(setDataTableStartX(double))); - connect(m_fitPropertyBrowser, SIGNAL(endXChanged(double)), this, - SLOT(setDataTableEndX(double))); -} - -void IndirectFitAnalysisTabLegacy::setFitDataPresenter( - std::unique_ptr<IndirectFitDataPresenterLegacy> presenter) { - m_dataPresenter = std::move(presenter); -} - -void IndirectFitAnalysisTabLegacy::setPlotView( - IIndirectFitPlotViewLegacy *view) { - m_plotPresenter = std::make_unique<IndirectFitPlotPresenterLegacy>( - m_fittingModel.get(), view, this); -} - -void IndirectFitAnalysisTabLegacy::setSpectrumSelectionView( - IndirectSpectrumSelectionViewLegacy *view) { - m_spectrumPresenter = - std::make_unique<IndirectSpectrumSelectionPresenterLegacy>( - m_fittingModel.get(), view); -} - -void IndirectFitAnalysisTabLegacy::setOutputOptionsView( - IIndirectFitOutputOptionsView *view) { - m_outOptionsPresenter = - std::make_unique<IndirectFitOutputOptionsPresenter>(view); -} - -void IndirectFitAnalysisTabLegacy::setFitPropertyBrowser( - MantidWidgets::IndirectFitPropertyBrowserLegacy *browser) { - browser->init(); - m_fitPropertyBrowser = browser; -#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) - m_fitPropertyBrowser->setFeatures(QDockWidget::NoDockWidgetFeatures); -#endif -} - -void IndirectFitAnalysisTabLegacy::loadSettings(const QSettings &settings) { - m_dataPresenter->loadSettings(settings); -} - -void IndirectFitAnalysisTabLegacy::setFileExtensionsByName(bool filter) { - auto const tab = tabName(); - setSampleSuffixes(tab, filter); - if (hasResolution()) - setResolutionSuffixes(tab, filter); -} - -void IndirectFitAnalysisTabLegacy::setSampleSuffixes(std::string const &tab, - bool filter) { - QStringList const noSuffixes{""}; - setSampleWSSuffixes(filter ? getSampleWSSuffixes(tab) : noSuffixes); - setSampleFBSuffixes(filter ? getSampleFBSuffixes(tab) : getExtensions(tab)); - m_dataPresenter->setMultiInputSampleWSSuffixes(); - m_dataPresenter->setMultiInputSampleFBSuffixes(); -} - -void IndirectFitAnalysisTabLegacy::setResolutionSuffixes(std::string const &tab, - bool filter) { - QStringList const noSuffixes{""}; - setResolutionWSSuffixes(filter ? getResolutionWSSuffixes(tab) : noSuffixes); - setResolutionFBSuffixes(filter ? getResolutionFBSuffixes(tab) - : getExtensions(tab)); - m_dataPresenter->setMultiInputResolutionWSSuffixes(); - m_dataPresenter->setMultiInputResolutionFBSuffixes(); -} - -void IndirectFitAnalysisTabLegacy::setSampleWSSuffixes( - const QStringList &suffices) { - m_dataPresenter->setSampleWSSuffices(suffices); -} - -void IndirectFitAnalysisTabLegacy::setSampleFBSuffixes( - const QStringList &suffices) { - m_dataPresenter->setSampleFBSuffices(suffices); -} - -void IndirectFitAnalysisTabLegacy::setResolutionWSSuffixes( - const QStringList &suffices) { - m_dataPresenter->setResolutionWSSuffices(suffices); -} - -void IndirectFitAnalysisTabLegacy::setResolutionFBSuffixes( - const QStringList &suffices) { - m_dataPresenter->setResolutionFBSuffices(suffices); -} - -std::size_t IndirectFitAnalysisTabLegacy::getSelectedDataIndex() const { - return m_plotPresenter->getSelectedDataIndex(); -} - -std::size_t IndirectFitAnalysisTabLegacy::getSelectedSpectrum() const { - return m_plotPresenter->getSelectedSpectrum(); -} - -bool IndirectFitAnalysisTabLegacy::isRangeCurrentlySelected( - std::size_t dataIndex, std::size_t spectrum) const { - return FittingModeLegacy::SEQUENTIAL == m_fittingModel->getFittingMode() || - m_plotPresenter->isCurrentlySelected(dataIndex, spectrum); -} - -IndirectFittingModelLegacy *IndirectFitAnalysisTabLegacy::fittingModel() const { - return m_fittingModel.get(); -} - -/** - * @return The fit type selected in the custom functions combo box, in the fit - * property browser. - */ -QString IndirectFitAnalysisTabLegacy::selectedFitType() const { - return m_fitPropertyBrowser->selectedFitType(); -} - -/** - * @param functionName The name of the function. - * @return The number of custom functions, with the specified name, - * included in the selected model. - */ -size_t IndirectFitAnalysisTabLegacy::numberOfCustomFunctions( - const std::string &functionName) const { - return m_fitPropertyBrowser->numberOfCustomFunctions(functionName); -} - -void IndirectFitAnalysisTabLegacy::setModelFitFunction() { - try { - m_fittingModel->setFitFunction(m_fitPropertyBrowser->getFittingFunction()); - } catch (const std::out_of_range &) { - m_fittingModel->setFitFunction(m_fitPropertyBrowser->compositeFunction()); - } -} - -void IndirectFitAnalysisTabLegacy::setModelStartX(double startX) { - const auto dataIndex = getSelectedDataIndex(); - if (m_fittingModel->numberOfWorkspaces() > dataIndex) { - m_fittingModel->setStartX(startX, dataIndex, getSelectedSpectrum()); - } else { - setBrowserStartX(0); - setBrowserEndX(0); - } -} - -void IndirectFitAnalysisTabLegacy::setModelEndX(double endX) { - const auto dataIndex = getSelectedDataIndex(); - if (m_fittingModel->numberOfWorkspaces() > dataIndex) { - m_fittingModel->setEndX(endX, dataIndex, getSelectedSpectrum()); - } else { - setBrowserStartX(0); - setBrowserEndX(0); - } -} - -void IndirectFitAnalysisTabLegacy::setDataTableStartX(double startX) { - m_dataPresenter->setStartX(startX, m_plotPresenter->getSelectedDataIndex(), - m_plotPresenter->getSelectedSpectrumIndex()); -} - -void IndirectFitAnalysisTabLegacy::setDataTableEndX(double endX) { - m_dataPresenter->setEndX(endX, m_plotPresenter->getSelectedDataIndex(), - m_plotPresenter->getSelectedSpectrumIndex()); -} - -void IndirectFitAnalysisTabLegacy::setDataTableExclude( - const std::string &exclude) { - m_dataPresenter->setExclude(exclude, m_plotPresenter->getSelectedDataIndex(), - m_plotPresenter->getSelectedSpectrumIndex()); -} - -void IndirectFitAnalysisTabLegacy::setBrowserStartX(double startX) { - MantidQt::API::SignalBlocker blocker(m_fitPropertyBrowser); - m_fitPropertyBrowser->setStartX(startX); -} - -void IndirectFitAnalysisTabLegacy::setBrowserEndX(double endX) { - MantidQt::API::SignalBlocker blocker(m_fitPropertyBrowser); - m_fitPropertyBrowser->setEndX(endX); -} - -void IndirectFitAnalysisTabLegacy::updateBrowserFittingRange() { - const auto range = m_fittingModel->getFittingRange(getSelectedDataIndex(), - getSelectedSpectrum()); - setBrowserStartX(range.first); - setBrowserEndX(range.second); -} - -void IndirectFitAnalysisTabLegacy::setBrowserWorkspace() { - if (m_fittingModel->numberOfWorkspaces() > 0) { - auto const name = - m_fittingModel->getWorkspace(getSelectedDataIndex())->getName(); - m_fitPropertyBrowser->setWorkspaceName(QString::fromStdString(name)); - } -} - -void IndirectFitAnalysisTabLegacy::setBrowserWorkspace(std::size_t dataIndex) { - const auto name = m_fittingModel->getWorkspace(dataIndex)->getName(); - m_fitPropertyBrowser->setWorkspaceName(QString::fromStdString(name)); -} - -void IndirectFitAnalysisTabLegacy::setBrowserWorkspaceIndex( - std::size_t spectrum) { - setBrowserWorkspaceIndex(boost::numeric_cast<int>(spectrum)); -} - -void IndirectFitAnalysisTabLegacy::setBrowserWorkspaceIndex(int spectrum) { - m_fitPropertyBrowser->setWorkspaceIndex(spectrum); -} - -void IndirectFitAnalysisTabLegacy::tableStartXChanged(double startX, - std::size_t dataIndex, - std::size_t spectrum) { - if (isRangeCurrentlySelected(dataIndex, spectrum)) { - m_plotPresenter->setStartX(startX); - setBrowserStartX(startX); - } -} - -void IndirectFitAnalysisTabLegacy::tableEndXChanged(double endX, - std::size_t dataIndex, - std::size_t spectrum) { - if (isRangeCurrentlySelected(dataIndex, spectrum)) { - m_plotPresenter->setEndX(endX); - setBrowserEndX(endX); - } -} - -void IndirectFitAnalysisTabLegacy::tableExcludeChanged( - const std::string & /*unused*/, std::size_t dataIndex, - std::size_t spectrum) { - if (isRangeCurrentlySelected(dataIndex, spectrum)) - m_spectrumPresenter->displayBinMask(); -} - -/** - * Sets whether fit members should be convolved with the resolution after a fit. - * - * @param convolveMembers If true, members are to be convolved. - */ -void IndirectFitAnalysisTabLegacy::setConvolveMembers(bool convolveMembers) { - m_fitPropertyBrowser->setConvolveMembers(convolveMembers); -} - -/** - * Updates the ties displayed in the fit property browser, using - * the set fitting function. - */ -void IndirectFitAnalysisTabLegacy::updateTies() { - m_fitPropertyBrowser->updateTies(); -} - -/** - * Sets whether the custom setting with the specified name is enabled. - * - * @param settingName The name of the custom setting. - * @param enabled True if custom setting should be enabled, false otherwise. - */ -void IndirectFitAnalysisTabLegacy::setCustomSettingEnabled( - const QString &customName, bool enabled) { - m_fitPropertyBrowser->setCustomSettingEnabled(customName, enabled); -} - -/** - * Sets the value of the parameter with the specified name, in the function with - * the specified name. - * - * @param functionName The name of the function containing the parameter. - * @param parameterName The name of the parameter to set. - * @param value The value to set. - */ -void IndirectFitAnalysisTabLegacy::setParameterValue( - const std::string &functionName, const std::string ¶meterName, - double value) { - m_fitPropertyBrowser->setParameterValue(functionName, parameterName, value); -} - -/** - * Sets the default peak type for the indirect property browser. - * - * @param function The name of the default peak function to set. - */ -void IndirectFitAnalysisTabLegacy::setDefaultPeakType( - const std::string &function) { - m_fitPropertyBrowser->setDefaultPeakType(function); -} - -/** - * Adds a check-box with the specified name, to the fit property browser, which - * when checked adds the specified functions to the mode and when unchecked, - * removes them. - * - * @param groupName The name/label of the check-box to add. - * @param functions The functions to be added when the check-box is checked. - * @param defaultValue The default value of the check-box. - */ -void IndirectFitAnalysisTabLegacy::addCheckBoxFunctionGroup( - const QString &groupName, const std::vector<IFunction_sptr> &functions, - bool defaultValue) { - m_fitPropertyBrowser->addCheckBoxFunctionGroup(groupName, functions, - defaultValue); -} - -/** - * Adds a number spinner with the specified name, to the fit property browser, - * which specifies how many multiples of the specified functions should be added - * to the model. - * - * @param groupName The name/label of the spinner to add. - * @param functions The functions to be added. - * @param minimum The minimum value of the spinner. - * @param maximum The maximum value of the spinner. - * @param defaultValue The default value of the spinner. - */ -void IndirectFitAnalysisTabLegacy::addSpinnerFunctionGroup( - const QString &groupName, const std::vector<IFunction_sptr> &functions, - int minimum, int maximum, int defaultValue) { - m_fitPropertyBrowser->addSpinnerFunctionGroup(groupName, functions, minimum, - maximum, defaultValue); -} - -/** - * Adds an option with the specified name, to the fit type combo-box in the fit - * property browser, which adds the specified functions to the model. - * - * @param groupName The name of the option to be added to the fit type - * combo-box. - * @param functions The functions added by the option. - */ -void IndirectFitAnalysisTabLegacy::addComboBoxFunctionGroup( - const QString &groupName, const std::vector<IFunction_sptr> &functions) { - m_fitPropertyBrowser->addComboBoxFunctionGroup(groupName, functions); -} - -/** - * Removes all options from the Fit Type combo-box apart from the 'None' option - * - */ -void IndirectFitAnalysisTabLegacy::clearFitTypeComboBox() { - m_fitPropertyBrowser->clearFitTypeComboBox(); -} - -/** - * Sets the available background options in this fit analysis tab. - * - * @param backgrounds A list of the available backgrounds. - */ -void IndirectFitAnalysisTabLegacy::setBackgroundOptions( - const QStringList &backgrounds) { - m_fitPropertyBrowser->setBackgroundOptions(backgrounds); -} - -/** - * @param settingKey The key of the boolean setting whose value to retrieve. - * @return The value of the boolean setting with the specified key. - */ -bool IndirectFitAnalysisTabLegacy::boolSettingValue( - const QString &settingKey) const { - return m_fitPropertyBrowser->boolSettingValue(settingKey); -} - -/** - * Sets the value of the custom boolean setting, with the specified key, to the - * specified value. - * - * @param settingKey The key of the custom boolean setting. - * @param value The value to set the boolean custom setting to. - */ -void IndirectFitAnalysisTabLegacy::setCustomBoolSetting( - const QString &settingKey, bool value) { - m_fitPropertyBrowser->setCustomBoolSetting(settingKey, value); -} - -/** - * @param settingKey The key of the integer setting whose value to retrieve. - * @return The value of the integer setting with the specified key. - */ -int IndirectFitAnalysisTabLegacy::intSettingValue( - const QString &settingKey) const { - return m_fitPropertyBrowser->intSettingValue(settingKey); -} - -/** - * @param settingKey The key of the double setting whose value to retrieve. - * @return The value of the double setting with the specified key. - */ -double IndirectFitAnalysisTabLegacy::doubleSettingValue( - const QString &settingKey) const { - return m_fitPropertyBrowser->doubleSettingValue(settingKey); -} - -/** - * @param settingKey The key of the enum setting whose value to retrieve. - * @return The value of the enum setting with the specified key. - */ -QString IndirectFitAnalysisTabLegacy::enumSettingValue( - const QString &settingKey) const { - return m_fitPropertyBrowser->enumSettingValue(settingKey); -} - -/** - * Adds a boolean custom setting, with the specified key and display name. - * - * @param settingKey The key of the boolean setting to add. - * @param settingName The display name of the boolean setting to add. - * @param defaultValue The default value of the boolean setting. - */ -void IndirectFitAnalysisTabLegacy::addBoolCustomSetting( - const QString &settingKey, const QString &settingName, bool defaultValue) { - m_fitPropertyBrowser->addBoolCustomSetting(settingKey, settingName, - defaultValue); -} - -/** - * Adds a double custom setting, with the specified key and display name. - * - * @param settingKey The key of the double setting to add. - * @param settingName The display name of the double setting to add. - * @param defaultValue The default value of the double setting. - */ -void IndirectFitAnalysisTabLegacy::addDoubleCustomSetting( - const QString &settingKey, const QString &settingName, - double defaultValue) { - m_fitPropertyBrowser->addDoubleCustomSetting(settingKey, settingName, - defaultValue); -} - -/** - * Adds an integer custom setting, with the specified key and display name. - * - * @param settingKey The key of the integer setting to add. - * @param settingName The display name of the integer setting to add. - * @param defaultValue The default value of the integer setting. - */ -void IndirectFitAnalysisTabLegacy::addIntCustomSetting( - const QString &settingKey, const QString &settingName, int defaultValue) { - m_fitPropertyBrowser->addIntCustomSetting(settingKey, settingName, - defaultValue); -} - -/** - * Adds an enum custom setting, with the specified key and display name. - * - * @param settingKey The key of the enum setting to add. - * @param settingName The display name of the enum setting to add. - * @param defaultValue The default value of the enum setting. - */ -void IndirectFitAnalysisTabLegacy::addEnumCustomSetting( - const QString &settingKey, const QString &settingName, - const QStringList &options) { - m_fitPropertyBrowser->addEnumCustomSetting(settingKey, settingName, options); -} - -/** - * Adds an optional double custom setting, with the specified key and display - * name. - * - * @param settingKey The key of the optional double setting to add. - * @param settingName The display name of the optional double setting to add. - * @param optionKey The key of the setting specifying whether to use this - * this optional setting. - * @param optionName The display name of the setting specifying whether to - * use this optional setting. - * @param defaultValue The default value of the optional double setting. - */ -void IndirectFitAnalysisTabLegacy::addOptionalDoubleSetting( - const QString &settingKey, const QString &settingName, - const QString &optionKey, const QString &optionName, bool enabled, - double defaultValue) { - m_fitPropertyBrowser->addOptionalDoubleSetting( - settingKey, settingName, optionKey, optionName, enabled, defaultValue); -} - -/** - * Sets whether a setting with a specified key affects the fitting function. - * - * @param settingKey The key of the setting. - * @param changesFunction Boolean specifying whether the setting affects the - * fitting function. - */ -void IndirectFitAnalysisTabLegacy::setCustomSettingChangesFunction( - const QString &settingKey, bool changesFunction) { - m_fitPropertyBrowser->setCustomSettingChangesFunction(settingKey, - changesFunction); -} - -void IndirectFitAnalysisTabLegacy::updateFitOutput(bool error) { - disconnect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, - SLOT(updateFitOutput(bool))); - - if (error) - m_fittingModel->cleanFailedRun(m_fittingAlgorithm); - else - m_fittingModel->addOutput(m_fittingAlgorithm); -} - -void IndirectFitAnalysisTabLegacy::updateSingleFitOutput(bool error) { - disconnect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, - SLOT(updateSingleFitOutput(bool))); - - if (error) - m_fittingModel->cleanFailedSingleRun(m_fittingAlgorithm, 0); - else - m_fittingModel->addSingleFitOutput(m_fittingAlgorithm, 0); -} - -/** - * Performs necessary state changes when the fit algorithm was run - * and completed within this interface. - */ -void IndirectFitAnalysisTabLegacy::fitAlgorithmComplete(bool error) { - setRunIsRunning(false); - m_plotPresenter->watchADS(true); - m_plotPresenter->setFitSingleSpectrumIsFitting(false); - enableFitButtons(true); - enableOutputOptions(!error); - updateParameterValues(); - m_spectrumPresenter->enableView(); - m_plotPresenter->updatePlots(); - - connect(m_fitPropertyBrowser, - SIGNAL(parameterChanged(const Mantid::API::IFunction *)), - m_plotPresenter.get(), SLOT(updateGuessAvailability())); - disconnect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, - SLOT(fitAlgorithmComplete(bool))); -} - -/** - * Updates the attribute values which are dependent on which spectrum is - * selected. They are updated in the function and in the FitPropertyBrowser. - */ -void IndirectFitAnalysisTabLegacy::updateAttributeValues() { - auto const attributeNames = m_fittingModel->getSpectrumDependentAttributes(); - if (!attributeNames.empty()) { - for (auto i = 0; i < m_fitPropertyBrowser->count(); ++i) { - auto function = m_fitPropertyBrowser->getFunctionAtIndex(i); - updateAttributeValues(function, attributeNames); - } - } -} - -/** - * Updates the attribute values in the function provided and in the fit property - * browser. - * @param function The function containing the attributes - * @param attributeNames The attributes to update - */ -void IndirectFitAnalysisTabLegacy::updateAttributeValues( - const IFunction_sptr &function, - std::vector<std::string> const &attributeNames) { - auto const attributes = getAttributes(function, attributeNames); - if (!attributes.empty()) - updateAttributeValues(function, attributeNames, attributes); -} - -void IndirectFitAnalysisTabLegacy::updateAttributeValues( - const IFunction_sptr &fitFunction, - std::vector<std::string> const &attributeNames, - std::unordered_map<std::string, IFunction::Attribute> const &attributes) { - try { - updateAttributes(std::move(fitFunction), attributeNames, attributes); - updateFitBrowserAttributeValues(); - } catch (const std::runtime_error &) { - showMessageBox("An unexpected error occured:\n The setting of attribute " - "values failed."); - } -} - -/** - * Updates the attribute values in the the fit property browser. - */ -void IndirectFitAnalysisTabLegacy::updateFitBrowserAttributeValues() { - MantidQt::API::SignalBlocker blocker(m_fitPropertyBrowser); - m_fitPropertyBrowser->updateAttributes(); -} - -/** - * Gets the new attribute values to be updated in the function and in the fit - * property browser. - * @param function The function containing the attributes - * @param attributeNames The names of the attributes to update - */ -std::unordered_map<std::string, IFunction::Attribute> -IndirectFitAnalysisTabLegacy::getAttributes( - IFunction_sptr const &function, - std::vector<std::string> const &attributeNames) { - std::unordered_map<std::string, IFunction::Attribute> attributes; - for (auto const &name : attributeNames) - if (function->hasAttribute(name)) - attributes[name] = - name == "WorkspaceIndex" - ? IFunction::Attribute(m_fitPropertyBrowser->workspaceIndex()) - : function->getAttribute(name); - return attributes; -} - -/** - * Updates the parameter values and errors in the fit property browser. - */ -void IndirectFitAnalysisTabLegacy::updateParameterValues() { - updateParameterValues(m_fittingModel->getParameterValues( - getSelectedDataIndex(), getSelectedSpectrum())); -} - -/** - * Updates the parameter values and errors in the fit property browser. - * - * @param parameters The parameter values to update the browser with. - */ -void IndirectFitAnalysisTabLegacy::updateParameterValues( - const std::unordered_map<std::string, ParameterValueLegacy> ¶meters) { - try { - auto fitFunction = m_fitPropertyBrowser->getFittingFunction(); - updateParameters(fitFunction, parameters); - - updateFitBrowserParameterValues(); - - if (m_fittingModel->isPreviouslyFit(getSelectedDataIndex(), - getSelectedSpectrum())) - m_fitPropertyBrowser->updateErrors(); - else - m_fitPropertyBrowser->clearErrors(); - } catch (const std::out_of_range &) { - } -} - -void IndirectFitAnalysisTabLegacy::updateFitBrowserParameterValues() { - MantidQt::API::SignalBlocker blocker(m_fitPropertyBrowser); - m_fitPropertyBrowser->updateParameters(); -} - -/** - * Enables Plot Guess in the FitPropertyBrowser if a sample workspace is loaded - */ -void IndirectFitAnalysisTabLegacy::updatePlotGuess() { - auto const sampleWorkspace = - m_fittingModel->getWorkspace(getSelectedDataIndex()); - m_fitPropertyBrowser->updatePlotGuess(sampleWorkspace); -} - -/** - * Plots the spectra corresponding to the selected parameters - */ -void IndirectFitAnalysisTabLegacy::plotSelectedSpectra() { - enableFitButtons(false); - plotSelectedSpectra(m_outOptionsPresenter->getSpectraToPlot()); - enableFitButtons(true); - m_outOptionsPresenter->setPlotting(false); -} - -/** - * Plots the spectra corresponding to the selected parameters - * @param spectra :: a vector of spectra to plot from a group workspace - */ -void IndirectFitAnalysisTabLegacy::plotSelectedSpectra( - std::vector<SpectrumToPlot> const &spectra) { - for (auto const &spectrum : spectra) - plotSpectrum(spectrum.first, spectrum.second); - m_outOptionsPresenter->clearSpectraToPlot(); -} - -/** - * Plots a spectrum with the specified index in a workspace - * @workspaceName :: the workspace containing the spectrum to plot - * @index :: the index in the workspace - * @errorBars :: true if you want error bars to be plotted - */ -void IndirectFitAnalysisTabLegacy::plotSpectrum( - std::string const &workspaceName, std::size_t const &index) { - m_plotter->plotSpectra(workspaceName, std::to_string(index)); -} - -/** - * Gets the name used for the base of the result workspaces - */ -std::string IndirectFitAnalysisTabLegacy::getOutputBasename() const { - return m_fittingModel->getOutputBasename(); -} - -/** - * Gets the Result workspace from a fit - */ -WorkspaceGroup_sptr IndirectFitAnalysisTabLegacy::getResultWorkspace() const { - return m_fittingModel->getResultWorkspace(); -} - -/** - * Gets the names of the Fit Parameters - */ -std::vector<std::string> -IndirectFitAnalysisTabLegacy::getFitParameterNames() const { - return m_fittingModel->getFitParameterNames(); -} - -/** - * Executes the single fit algorithm defined in this indirect fit analysis tab. - */ -void IndirectFitAnalysisTabLegacy::singleFit() { - singleFit(getSelectedDataIndex(), getSelectedSpectrum()); -} - -void IndirectFitAnalysisTabLegacy::singleFit(std::size_t dataIndex, - std::size_t spectrum) { - if (validate()) { - m_plotPresenter->watchADS(false); - m_plotPresenter->setFitSingleSpectrumIsFitting(true); - enableFitButtons(false); - enableOutputOptions(false); - runSingleFit(m_fittingModel->getSingleFit(dataIndex, spectrum)); - } -} - -/** - * Executes the sequential fit algorithm defined in this indirect fit analysis - * tab. - */ -void IndirectFitAnalysisTabLegacy::executeFit() { - if (validate()) { - m_plotPresenter->watchADS(false); - setRunIsRunning(true); - enableFitButtons(false); - enableOutputOptions(false); - runFitAlgorithm(m_fittingModel->getFittingAlgorithm()); - } -} - -bool IndirectFitAnalysisTabLegacy::validate() { - UserInputValidator validator; - m_dataPresenter->validate(validator); - m_spectrumPresenter->validate(validator); - - const auto invalidFunction = m_fittingModel->isInvalidFunction(); - if (invalidFunction) - validator.addErrorMessage(QString::fromStdString(*invalidFunction)); - if (m_fittingModel->numberOfWorkspaces() == 0) - validator.addErrorMessage( - QString::fromStdString("No data has been selected for a fit.")); - - const auto error = validator.generateErrorMessage(); - emit showMessageBox(error); - return error.isEmpty(); -} - -/** - * Called when the 'Run' button is called in the IndirectTab. - */ -void IndirectFitAnalysisTabLegacy::run() { - setRunIsRunning(true); - enableFitButtons(false); - enableOutputOptions(false); - runFitAlgorithm(m_fittingModel->getFittingAlgorithm()); -} - -/** - * Enables or disables the 'Run', 'Fit Single Spectrum' and other related - * buttons - * @param enable :: true to enable buttons - */ -void IndirectFitAnalysisTabLegacy::enableFitButtons(bool enable) { - setRunEnabled(enable); - m_plotPresenter->setFitSingleSpectrumEnabled(enable); - m_fitPropertyBrowser->setFitEnabled(enable); -} - -/** - * Enables or disables the output options. It also sets the current result and - * PDF workspaces to be plotted - * @param enable :: true to enable buttons - */ -void IndirectFitAnalysisTabLegacy::enableOutputOptions(bool enable) { - if (enable) { - m_outOptionsPresenter->setResultWorkspace(getResultWorkspace()); - setPDFWorkspace(getOutputBasename() + "_PDFs"); - m_outOptionsPresenter->setPlotTypes("Result Group"); - } else - m_outOptionsPresenter->setMultiWorkspaceOptionsVisible(enable); - - m_outOptionsPresenter->setPlotEnabled( - enable && m_outOptionsPresenter->isSelectedGroupPlottable()); - m_outOptionsPresenter->setEditResultEnabled(enable); - m_outOptionsPresenter->setSaveEnabled(enable); -} - -/** - * Sets the active PDF workspace within the output options if one exists for the - * current run - * @param workspaceName :: the name of the PDF workspace if it exists - */ -void IndirectFitAnalysisTabLegacy::setPDFWorkspace( - std::string const &workspaceName) { - auto const fabMinimizer = m_fitPropertyBrowser->minimizer() == "FABADA"; - auto const enablePDFOptions = doesExistInADS(workspaceName) && fabMinimizer; - - if (enablePDFOptions) { - m_outOptionsPresenter->setPDFWorkspace(getADSGroupWorkspace(workspaceName)); - m_outOptionsPresenter->setPlotWorkspaces(); - } else - m_outOptionsPresenter->removePDFWorkspace(); - m_outOptionsPresenter->setMultiWorkspaceOptionsVisible(enablePDFOptions); -} - -/** - * Sets the visiblity of the output options Edit Result button - * @param visible :: true to make the edit result button visible - */ -void IndirectFitAnalysisTabLegacy::setEditResultVisible(bool visible) { - m_outOptionsPresenter->setEditResultVisible(visible); -} - -void IndirectFitAnalysisTabLegacy::setAlgorithmProperties( - const IAlgorithm_sptr &fitAlgorithm) const { - fitAlgorithm->setProperty("Minimizer", m_fitPropertyBrowser->minimizer(true)); - fitAlgorithm->setProperty("MaxIterations", - m_fitPropertyBrowser->maxIterations()); - fitAlgorithm->setProperty("ConvolveMembers", - m_fitPropertyBrowser->convolveMembers()); - fitAlgorithm->setProperty("PeakRadius", - m_fitPropertyBrowser->getPeakRadius()); - fitAlgorithm->setProperty("CostFunction", - m_fitPropertyBrowser->costFunction()); - fitAlgorithm->setProperty("IgnoreInvalidData", - m_fitPropertyBrowser->ignoreInvalidData()); - - if (m_fitPropertyBrowser->isHistogramFit()) - fitAlgorithm->setProperty("EvaluationType", "Histogram"); -} - -/* - * Runs the specified fit algorithm and calls the algorithmComplete - * method of this fit analysis tab once completed. - * - * @param fitAlgorithm The fit algorithm to run. - */ -void IndirectFitAnalysisTabLegacy::runFitAlgorithm( - IAlgorithm_sptr fitAlgorithm) { - connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, - SLOT(updateFitOutput(bool))); - setupFit(std::move(fitAlgorithm)); - m_batchAlgoRunner->executeBatchAsync(); -} - -void IndirectFitAnalysisTabLegacy::runSingleFit(IAlgorithm_sptr fitAlgorithm) { - connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, - SLOT(updateSingleFitOutput(bool))); - setupFit(std::move(fitAlgorithm)); - m_batchAlgoRunner->executeBatchAsync(); -} - -void IndirectFitAnalysisTabLegacy::setupFit(IAlgorithm_sptr fitAlgorithm) { - disconnect(m_fitPropertyBrowser, - SIGNAL(parameterChanged(const Mantid::API::IFunction *)), - m_plotPresenter.get(), SLOT(updateGuessAvailability())); - - setAlgorithmProperties(fitAlgorithm); - - m_fittingAlgorithm = fitAlgorithm; - m_spectrumPresenter->disableView(); - m_batchAlgoRunner->addAlgorithm(fitAlgorithm); - - connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, - SLOT(fitAlgorithmComplete(bool))); -} - -/** - * Updates whether the options for plotting and saving fit results are - * enabled/disabled. - */ -void IndirectFitAnalysisTabLegacy::updateResultOptions() { - const bool isFit = m_fittingModel->isPreviouslyFit(getSelectedDataIndex(), - getSelectedSpectrum()); - if (isFit) - m_outOptionsPresenter->setResultWorkspace(getResultWorkspace()); - m_outOptionsPresenter->setPlotEnabled(isFit); - m_outOptionsPresenter->setEditResultEnabled(isFit); - m_outOptionsPresenter->setSaveEnabled(isFit); -} - -} // namespace IDA -} // namespace CustomInterfaces -} // namespace MantidQt diff --git a/qt/scientific_interfaces/Indirect/IndirectFitAnalysisTabLegacy.h b/qt/scientific_interfaces/Indirect/IndirectFitAnalysisTabLegacy.h deleted file mode 100644 index 0deb72aedee..00000000000 --- a/qt/scientific_interfaces/Indirect/IndirectFitAnalysisTabLegacy.h +++ /dev/null @@ -1,242 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -#pragma once - -#include "IndirectDataAnalysisTab.h" -#include "IndirectFitDataPresenterLegacy.h" -#include "IndirectFitOutputOptionsPresenter.h" -#include "IndirectFitOutputOptionsView.h" -#include "IndirectFitPlotPresenterLegacy.h" -#include "IndirectFittingModelLegacy.h" -#include "IndirectSpectrumSelectionPresenterLegacy.h" -#include "IndirectSpectrumSelectionViewLegacy.h" - -#include "MantidQtWidgets/Common/IndirectFitPropertyBrowserLegacy.h" - -#include <boost/optional.hpp> - -#include <QtCore> - -#include <memory> -#include <type_traits> - -namespace MantidQt { -namespace CustomInterfaces { -namespace IDA { - -class DLLExport IndirectFitAnalysisTabLegacy : public IndirectDataAnalysisTab { - Q_OBJECT - -public: - IndirectFitAnalysisTabLegacy(IndirectFittingModelLegacy *model, - QWidget *parent = nullptr); - - void setFitDataPresenter( - std::unique_ptr<IndirectFitDataPresenterLegacy> presenter); - void setPlotView(IIndirectFitPlotViewLegacy *view); - void setSpectrumSelectionView(IndirectSpectrumSelectionViewLegacy *view); - void setOutputOptionsView(IIndirectFitOutputOptionsView *view); - void setFitPropertyBrowser( - MantidWidgets::IndirectFitPropertyBrowserLegacy *browser); - - virtual std::string tabName() const = 0; - - virtual bool hasResolution() const = 0; - - std::size_t getSelectedDataIndex() const; - std::size_t getSelectedSpectrum() const; - bool isRangeCurrentlySelected(std::size_t dataIndex, - std::size_t spectrum) const; - - QString selectedFitType() const; - - size_t numberOfCustomFunctions(const std::string &functionName) const; - - void setConvolveMembers(bool convolveMembers); - - void updateTies(); - - void setCustomSettingEnabled(const QString &customName, bool enabled); - - void setParameterValue(const std::string &functionName, - const std::string ¶meterName, double value); - - void setDefaultPeakType(const std::string &function); - - void addCheckBoxFunctionGroup( - const QString &groupName, - const std::vector<Mantid::API::IFunction_sptr> &functions, - bool defaultValue = false); - - void addSpinnerFunctionGroup( - const QString &groupName, - const std::vector<Mantid::API::IFunction_sptr> &functions, - int minimum = 0, int maximum = 10, int defaultValue = 0); - - void addComboBoxFunctionGroup( - const QString &groupName, - const std::vector<Mantid::API::IFunction_sptr> &functions); - void clearFitTypeComboBox(); - - void setBackgroundOptions(const QStringList &backgrounds); - - bool boolSettingValue(const QString &settingKey) const; - - void setCustomBoolSetting(const QString &settingKey, bool value); - - int intSettingValue(const QString &settingKey) const; - - double doubleSettingValue(const QString &settingKey) const; - - QString enumSettingValue(const QString &settingKey) const; - - void addBoolCustomSetting(const QString &settingKey, - const QString &settingName, - bool defaultValue = false); - - void addDoubleCustomSetting(const QString &settingKey, - const QString &settingName, - double defaultValue = 0); - - void addIntCustomSetting(const QString &settingKey, - const QString &settingName, int defaultValue = 0); - - void addEnumCustomSetting(const QString &settingKey, - const QString &settingName, - const QStringList &options); - - void addOptionalDoubleSetting(const QString &settingKey, - const QString &settingName, - const QString &optionKey, - const QString &optionName, bool enabled = false, - double defaultValue = 0); - - void setCustomSettingChangesFunction(const QString &settingKey, - bool changesFunction); - -public slots: - void setBrowserWorkspace() override; - -protected: - IndirectFittingModelLegacy *fittingModel() const; - - void run() override; - - void setSampleWSSuffixes(const QStringList &suffices); - void setSampleFBSuffixes(const QStringList &suffices); - void setResolutionWSSuffixes(const QStringList &suffices); - void setResolutionFBSuffixes(const QStringList &suffices); - - void setAlgorithmProperties( - const Mantid::API::IAlgorithm_sptr &fitAlgorithm) const; - void runFitAlgorithm(Mantid::API::IAlgorithm_sptr fitAlgorithm); - void runSingleFit(Mantid::API::IAlgorithm_sptr fitAlgorithm); - virtual void setupFit(Mantid::API::IAlgorithm_sptr fitAlgorithm); - - virtual void setRunIsRunning(bool running) = 0; - virtual void setRunEnabled(bool enable) = 0; - void setEditResultVisible(bool visible); - -signals: - void functionChanged(); - void parameterChanged(const Mantid::API::IFunction * /*_t1*/); - void customBoolChanged(const QString &key, bool value); - void updateAvailableFitTypes(); - -protected slots: - - void setModelFitFunction(); - void setModelStartX(double startX); - void setModelEndX(double startX); - void setDataTableStartX(double startX); - void setDataTableEndX(double endX); - void setDataTableExclude(const std::string &exclude); - void setBrowserStartX(double startX); - void setBrowserEndX(double endX); - void updateBrowserFittingRange(); - void setBrowserWorkspace(std::size_t dataIndex); - void setBrowserWorkspaceIndex(std::size_t spectrum); - void setBrowserWorkspaceIndex(int spectrum); - void tableStartXChanged(double startX, std::size_t dataIndex, - std::size_t spectrum); - void tableEndXChanged(double endX, std::size_t dataIndex, - std::size_t spectrum); - void tableExcludeChanged(const std::string &exclude, std::size_t dataIndex, - std::size_t spectrum); - - void updateFitOutput(bool error); - void updateSingleFitOutput(bool error); - void fitAlgorithmComplete(bool error); - - void singleFit(); - void singleFit(std::size_t dataIndex, std::size_t spectrum); - void executeFit(); - - void updateAttributeValues(); - void updateAttributeValues(const Mantid::API::IFunction_sptr &function, - std::vector<std::string> const &attributeNames); - void updateAttributeValues( - const Mantid::API::IFunction_sptr &function, - std::vector<std::string> const &attributeNames, - std::unordered_map<std::string, Mantid::API::IFunction::Attribute> const - &attributes); - void updateFitBrowserAttributeValues(); - std::unordered_map<std::string, Mantid::API::IFunction::Attribute> - getAttributes(Mantid::API::IFunction_sptr const &function, - std::vector<std::string> const &attributeNames); - void updateParameterValues(); - void updateParameterValues( - const std::unordered_map<std::string, ParameterValueLegacy> ¶meters); - void updateFitBrowserParameterValues(); - - void updateResultOptions(); - -private slots: - void updatePlotGuess(); - void plotSelectedSpectra(); - -private: - /// Overidden by child class. - void setup() override; - void loadSettings(const QSettings &settings) override; - virtual void setupFitTab() = 0; - bool validate() override; - - void setFileExtensionsByName(bool filter) override; - void setSampleSuffixes(std::string const &tab, bool filter); - void setResolutionSuffixes(std::string const &tab, bool filter); - - void connectDataAndPlotPresenters(); - void connectSpectrumAndPlotPresenters(); - void connectFitBrowserAndPlotPresenter(); - void connectDataAndSpectrumPresenters(); - void connectDataAndFitBrowserPresenters(); - - void plotSelectedSpectra(std::vector<SpectrumToPlot> const &spectra); - void plotSpectrum(std::string const &workspaceName, std::size_t const &index); - - std::string getOutputBasename() const; - Mantid::API::WorkspaceGroup_sptr getResultWorkspace() const; - std::vector<std::string> getFitParameterNames() const; - - void enableFitButtons(bool enable); - void enableOutputOptions(bool enable); - void setPDFWorkspace(std::string const &workspaceName); - - std::unique_ptr<IndirectFittingModelLegacy> m_fittingModel; - MantidWidgets::IndirectFitPropertyBrowserLegacy *m_fitPropertyBrowser; - std::unique_ptr<IndirectFitDataPresenterLegacy> m_dataPresenter; - std::unique_ptr<IndirectFitPlotPresenterLegacy> m_plotPresenter; - std::unique_ptr<IndirectSpectrumSelectionPresenterLegacy> m_spectrumPresenter; - std::unique_ptr<IndirectFitOutputOptionsPresenter> m_outOptionsPresenter; - - Mantid::API::IAlgorithm_sptr m_fittingAlgorithm; -}; - -} // namespace IDA -} // namespace CustomInterfaces -} // namespace MantidQt diff --git a/qt/scientific_interfaces/Indirect/IndirectFitDataLegacy.cpp b/qt/scientific_interfaces/Indirect/IndirectFitDataLegacy.cpp deleted file mode 100644 index f54ed01a18d..00000000000 --- a/qt/scientific_interfaces/Indirect/IndirectFitDataLegacy.cpp +++ /dev/null @@ -1,435 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -#include "IndirectFitDataLegacy.h" - -#include "MantidKernel/Strings.h" - -#include <boost/algorithm/string.hpp> -#include <boost/format.hpp> - -#include <sstream> -#include <utility> - -using namespace Mantid::API; - -namespace { -using namespace MantidQt::CustomInterfaces::IDA; -using namespace Mantid::Kernel::Strings; - -std::string rangeToString(const std::pair<std::size_t, std::size_t> &range, - const std::string &delimiter = "-") { - if (range.first != range.second) - return std::to_string(range.first) + delimiter + - std::to_string(range.second); - return std::to_string(range.first); -} - -template <template <typename...> class Vector, typename T, typename... Ts> -std::vector<T> outOfRange(const Vector<T, Ts...> &values, const T &minimum, - const T &maximum) { - std::vector<T> result; - std::copy_if(values.begin(), values.end(), std::back_inserter(result), - [&minimum, &maximum](const auto &value) { - return value < minimum || value > maximum; - }); - return result; -} - -template <typename T> -struct SpectraOutOfRange : boost::static_visitor<std::vector<T>> { - SpectraOutOfRange(const T &minimum, const T &maximum) - : m_minimum(minimum), m_maximum(maximum) {} - - std::vector<T> operator()(const std::pair<T, T> &range) const { - std::vector<T> notInRange; - if (range.first < m_minimum) - notInRange.emplace_back(m_minimum); - if (range.second > m_maximum) - notInRange.emplace_back(m_maximum); - return notInRange; - } - - std::vector<T> operator()(const DiscontinuousSpectra<T> &spectra) const { - return outOfRange(spectra, m_minimum, m_maximum); - } - -private: - const T m_minimum, m_maximum; -}; - -struct CheckZeroSpectrum : boost::static_visitor<bool> { - bool - operator()(const std::pair<std::size_t, std::size_t> & /*unused*/) const { - return false; - } - bool operator()(const DiscontinuousSpectra<std::size_t> &spectra) const { - return spectra.empty(); - } -}; - -struct NumberOfSpectra : boost::static_visitor<std::size_t> { - std::size_t - operator()(const std::pair<std::size_t, std::size_t> &spectra) const { - return 1 + (spectra.second - spectra.first); - } - - std::size_t - operator()(const DiscontinuousSpectra<std::size_t> &spectra) const { - return spectra.size(); - } -}; - -struct SpectraToString : boost::static_visitor<std::string> { - explicit SpectraToString(const std::string &rangeDelimiter = "-") - : m_rangeDelimiter(rangeDelimiter) {} - - std::string - operator()(const DiscontinuousSpectra<std::size_t> &spectra) const { - return spectra.getString(); - } - - std::string - operator()(const std::pair<std::size_t, std::size_t> &spectra) const { - return rangeToString(spectra, m_rangeDelimiter); - } - -private: - const std::string m_rangeDelimiter; -}; - -std::string constructSpectraString(std::vector<int> const &spectras) { - return joinCompress(spectras.begin(), spectras.end()); -} - -template <typename T, typename Predicate> -void removeElementsIf(T &iterable, Predicate const &filter) { - auto const iter = std::remove_if(iterable.begin(), iterable.end(), filter); - if (iter != iterable.end()) - iterable.erase(iter, iterable.end()); -} - -std::vector<std::string> splitStringBy(std::string const &str, - std::string const &delimiter) { - std::vector<std::string> subStrings; - boost::split(subStrings, str, boost::is_any_of(delimiter)); - removeElementsIf(subStrings, [](std::string const &subString) { - return subString.empty(); - }); - return subStrings; -} - -std::string getSpectraRange(std::string const &string) { - auto const bounds = splitStringBy(string, "-"); - return std::stoull(bounds[0]) > std::stoull(bounds[1]) - ? bounds[1] + "-" + bounds[0] - : string; -} - -std::string rearrangeSpectraSubString(std::string const &string) { - return string.find("-") != std::string::npos ? getSpectraRange(string) - : string; -} - -// Swaps the two numbers in a spectra range if they go from large to small -std::string rearrangeSpectraRangeStrings(std::string const &string) { - std::string spectraString; - std::vector<std::string> subStrings = splitStringBy(string, ","); - for (auto it = subStrings.begin(); it < subStrings.end(); ++it) { - spectraString += rearrangeSpectraSubString(*it); - spectraString += it != subStrings.end() ? "," : ""; - } - return spectraString; -} - -std::string createSpectraString(std::string string) { - removeElementsIf(string, isspace); - std::vector<int> spectras = parseRange(rearrangeSpectraRangeStrings(string)); - std::sort(spectras.begin(), spectras.end()); - // Remove duplicate entries - spectras.erase(std::unique(spectras.begin(), spectras.end()), spectras.end()); - return constructSpectraString(spectras); -} - -struct CombineSpectra : boost::static_visitor<SpectraLegacy> { - SpectraLegacy - operator()(const std::pair<std::size_t, std::size_t> &spectra1, - const std::pair<std::size_t, std::size_t> &spectra2) const { - if (spectra1.second + 1 == spectra2.first) - return std::make_pair(spectra1.first, spectra2.second); - else if (spectra2.second + 1 == spectra1.first) - return std::make_pair(spectra2.first, spectra1.second); - else { - return DiscontinuousSpectra<std::size_t>(createSpectraString( - rangeToString(spectra1) + "," + rangeToString(spectra2))); - } - } - - SpectraLegacy operator()(const SpectraLegacy &spectra1, - const SpectraLegacy &spectra2) const { - return DiscontinuousSpectra<std::size_t>(createSpectraString( - boost::apply_visitor(SpectraToString(), spectra1) + "," + - boost::apply_visitor(SpectraToString(), spectra2))); - } -}; - -struct GetSpectrum : boost::static_visitor<std::size_t> { - explicit GetSpectrum(std::size_t index) : m_index(index) {} - - std::size_t - operator()(const std::pair<std::size_t, std::size_t> &spectra) const { - return spectra.first + m_index; - } - - std::size_t - operator()(const DiscontinuousSpectra<std::size_t> &spectra) const { - return spectra[m_index]; - } - -private: - std::size_t m_index; -}; - -template <typename T> -std::string join(const std::vector<T> &values, const char *delimiter) { - if (values.empty()) - return ""; - - std::stringstream stream; - stream << values.front(); - for (auto i = 1u; i < values.size(); ++i) - stream << delimiter << values[i]; - return stream.str(); -} - -template <typename T, typename... Ts> -std::vector<T, Ts...> subvector(const std::vector<T, Ts...> vec, - std::size_t start, std::size_t end) { - return std::vector<T, Ts...>(vec.begin() + start, vec.begin() + end); -} - -std::string cutLastOf(const std::string &str, const std::string &delimiter) { - const auto cutIndex = str.rfind(delimiter); - if (cutIndex != std::string::npos) - return str.substr(0, cutIndex); - return str; -} - -boost::basic_format<char> & -tryPassFormatArgument(boost::basic_format<char> &formatString, - const std::string &arg) { - try { - return formatString % arg; - } catch (const boost::io::too_many_args &) { - return formatString; - } -} - -std::pair<double, double> getBinRange(const MatrixWorkspace_sptr &workspace) { - return std::make_pair(workspace->x(0).front(), workspace->x(0).back()); -} - -double convertBoundToDoubleAndFormat(std::string const &str) { - return std::round(std::stod(str) * 1000) / 1000; -} - -std::string constructExcludeRegionString(std::vector<double> const &bounds) { - std::string excludeRegion; - for (auto it = bounds.begin(); it < bounds.end(); ++it) { - auto const splitDouble = splitStringBy(std::to_string(*it), "."); - excludeRegion += splitDouble[0] + "." + splitDouble[1].substr(0, 3); - excludeRegion += it == bounds.end() - 1 ? "" : ","; - } - return excludeRegion; -} - -std::string orderExcludeRegionString(std::vector<double> &bounds) { - for (auto it = bounds.begin(); it < bounds.end() - 1; it += 2) - if (*it > *(it + 1)) - std::iter_swap(it, it + 1); - return constructExcludeRegionString(bounds); -} - -std::vector<double> -getBoundsAsDoubleVector(std::vector<std::string> const &boundStrings) { - std::vector<double> bounds; - bounds.reserve(boundStrings.size()); - for (auto bound : boundStrings) - bounds.emplace_back(convertBoundToDoubleAndFormat(bound)); - return bounds; -} - -std::string createExcludeRegionString(std::string regionString) { - removeElementsIf(regionString, isspace); - auto bounds = getBoundsAsDoubleVector(splitStringBy(regionString, ",")); - return orderExcludeRegionString(bounds); -} - -} // namespace - -namespace MantidQt { -namespace CustomInterfaces { -namespace IDA { - -IndirectFitDataLegacy::IndirectFitDataLegacy(MatrixWorkspace_sptr workspace, - const SpectraLegacy &spectra) - : m_workspace(std::move(workspace)), - m_spectra(DiscontinuousSpectra<std::size_t>("")) { - setSpectra(spectra); -} - -std::string -IndirectFitDataLegacy::displayName(const std::string &formatString, - const std::string &rangeDelimiter) const { - const auto workspaceName = getBasename(); - const auto spectraString = - boost::apply_visitor(SpectraToString(rangeDelimiter), m_spectra); - - auto formatted = boost::format(formatString); - formatted = tryPassFormatArgument(formatted, workspaceName); - formatted = tryPassFormatArgument(formatted, spectraString); - - auto name = formatted.str(); - std::replace(name.begin(), name.end(), ',', '+'); - return name; -} - -std::string IndirectFitDataLegacy::displayName(const std::string &formatString, - std::size_t spectrum) const { - const auto workspaceName = getBasename(); - - auto formatted = boost::format(formatString); - formatted = tryPassFormatArgument(formatted, workspaceName); - formatted = tryPassFormatArgument(formatted, std::to_string(spectrum)); - return formatted.str(); -} - -std::string IndirectFitDataLegacy::getBasename() const { - return cutLastOf(workspace()->getName(), "_red"); -} - -Mantid::API::MatrixWorkspace_sptr IndirectFitDataLegacy::workspace() const { - return m_workspace; -} - -const SpectraLegacy &IndirectFitDataLegacy::spectra() const { - return m_spectra; -} - -std::size_t IndirectFitDataLegacy::getSpectrum(std::size_t index) const { - return boost::apply_visitor(GetSpectrum(index), m_spectra); -} - -std::size_t IndirectFitDataLegacy::numberOfSpectra() const { - return boost::apply_visitor(NumberOfSpectra(), m_spectra); -} - -bool IndirectFitDataLegacy::zeroSpectra() const { - if (m_workspace->getNumberHistograms()) - return boost::apply_visitor(CheckZeroSpectrum(), m_spectra); - return true; -} - -std::pair<double, double> -IndirectFitDataLegacy::getRange(std::size_t spectrum) const { - const auto range = m_ranges.find(spectrum); - if (range != m_ranges.end()) - return range->second; - return getBinRange(m_workspace); -} - -std::string -IndirectFitDataLegacy::getExcludeRegion(std::size_t spectrum) const { - const auto region = m_excludeRegions.find(spectrum); - if (region != m_excludeRegions.end()) - return region->second; - return ""; -} - -std::vector<double> -IndirectFitDataLegacy::excludeRegionsVector(std::size_t spectrum) const { - return vectorFromStringLegacy<double>(getExcludeRegion(spectrum)); -} - -void IndirectFitDataLegacy::setSpectra(std::string const &spectra) { - try { - const SpectraLegacy spec = - DiscontinuousSpectra<std::size_t>(createSpectraString(spectra)); - setSpectra(spec); - } catch (std::exception &ex) { - throw std::runtime_error("Spectra too large for cast: " + - std::string(ex.what())); - } -} - -void IndirectFitDataLegacy::setSpectra(SpectraLegacy &&spectra) { - validateSpectra(spectra); - m_spectra = std::move(spectra); -} - -void IndirectFitDataLegacy::setSpectra(SpectraLegacy const &spectra) { - validateSpectra(spectra); - m_spectra = spectra; -} - -void IndirectFitDataLegacy::validateSpectra(SpectraLegacy const &spectra) { - const auto visitor = - SpectraOutOfRange<std::size_t>(0, workspace()->getNumberHistograms() - 1); - auto notInRange = boost::apply_visitor(visitor, spectra); - if (!notInRange.empty()) { - if (notInRange.size() > 5) - throw std::runtime_error("SpectraLegacy out of range: " + - join(subvector(notInRange, 0, 5), ",") + "..."); - throw std::runtime_error("SpectraLegacy out of range: " + - join(notInRange, ",")); - } -} - -void IndirectFitDataLegacy::setStartX(double const &startX, - std::size_t const &spectrum) { - const auto range = m_ranges.find(spectrum); - if (range != m_ranges.end()) - range->second.first = startX; - else if (m_workspace) - m_ranges[spectrum] = std::make_pair(startX, m_workspace->x(0).back()); - else - throw std::runtime_error( - "Unable to set StartX: Workspace no longer exists."); -} - -void IndirectFitDataLegacy::setEndX(double const &endX, - std::size_t const &spectrum) { - const auto range = m_ranges.find(spectrum); - if (range != m_ranges.end()) - range->second.second = endX; - else if (m_workspace) - m_ranges[spectrum] = std::make_pair(m_workspace->x(0).front(), endX); - else - throw std::runtime_error("Unable to set EndX: Workspace no longer exists."); -} - -void IndirectFitDataLegacy::setExcludeRegionString( - std::string const &excludeRegionString, std::size_t const &spectrum) { - if (!excludeRegionString.empty()) - m_excludeRegions[spectrum] = createExcludeRegionString(excludeRegionString); - else - m_excludeRegions[spectrum] = excludeRegionString; -} - -IndirectFitDataLegacy & -IndirectFitDataLegacy::combine(IndirectFitDataLegacy const &fitData) { - m_workspace = fitData.m_workspace; - setSpectra( - boost::apply_visitor(CombineSpectra(), m_spectra, fitData.m_spectra)); - m_excludeRegions.insert(std::begin(fitData.m_excludeRegions), - std::end(fitData.m_excludeRegions)); - m_ranges.insert(std::begin(fitData.m_ranges), std::end(fitData.m_ranges)); - return *this; -} - -} // namespace IDA -} // namespace CustomInterfaces -} // namespace MantidQt diff --git a/qt/scientific_interfaces/Indirect/IndirectFitDataLegacy.h b/qt/scientific_interfaces/Indirect/IndirectFitDataLegacy.h deleted file mode 100644 index 67bae2c8232..00000000000 --- a/qt/scientific_interfaces/Indirect/IndirectFitDataLegacy.h +++ /dev/null @@ -1,198 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2007 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -#pragma once - -#include "DllConfig.h" -#include "MantidAPI/MatrixWorkspace.h" -#include "MantidKernel/ArrayProperty.h" - -#include <boost/optional.hpp> -#include <boost/variant.hpp> -#include <boost/variant/static_visitor.hpp> -#include <memory> - -#include <cctype> - -namespace MantidQt { -namespace CustomInterfaces { -namespace IDA { - -template <typename T> -std::vector<T> vectorFromStringLegacy(const std::string &listString) { - try { - return Mantid::Kernel::ArrayProperty<T>("vector", listString); - } catch (const std::runtime_error &) { - return std::vector<T>(); - } -} - -/* - * Representation of a discontinuous spectra range. - * Can be used in a vector-like manner. - * - * Holds a string and vector representation. - */ -template <typename T> class DiscontinuousSpectra { -public: - explicit DiscontinuousSpectra(const std::string &str) - : m_str(str), m_vec(vectorFromStringLegacy<T>(str)) { - m_str.erase(std::remove_if(m_str.begin(), m_str.end(), - static_cast<int (*)(int)>(std::isspace)), - m_str.end()); - } - DiscontinuousSpectra(const DiscontinuousSpectra &vec) - : m_str(vec.m_str), m_vec(vec.m_vec) {} - DiscontinuousSpectra(DiscontinuousSpectra &&vec) - : m_str(std::move(vec.m_str)), m_vec(std::move(vec.m_vec)) {} - - DiscontinuousSpectra &operator=(const DiscontinuousSpectra &vec) { - m_str = vec.m_str; - m_vec = vec.m_vec; - return *this; - } - - DiscontinuousSpectra &operator=(DiscontinuousSpectra &&vec) { - m_str = std::move(vec.m_str); - m_vec = std::move(vec.m_vec); - return *this; - } - - bool empty() const { return m_vec.empty(); } - std::size_t size() const { return m_vec.size(); } - const std::string &getString() const { return m_str; } - typename std::vector<T>::iterator begin() { return m_vec.begin(); } - typename std::vector<T>::iterator end() { return m_vec.end(); } - typename std::vector<T>::const_iterator begin() const { - return m_vec.begin(); - } - typename std::vector<T>::const_iterator end() const { return m_vec.end(); } - const T &operator[](std::size_t index) const { return m_vec[index]; } - bool operator==(DiscontinuousSpectra<std::size_t> const &spec) const { - return this->getString() == spec.getString(); - } - -private: - std::string m_str; - std::vector<T> m_vec; -}; - -/* - * Spectra can either be specified as: - * - * Continuous Range - Represented as a pair of the minimum and maximum spectrum. - * Discontinuous Range - Represented by a DiscontinuousSpectra object. - * - * A variant is used, such that faster operations can be employed when using - * a continuous range. - */ -using SpectraLegacy = boost::variant<DiscontinuousSpectra<std::size_t>, - std::pair<std::size_t, std::size_t>>; - -template <typename F> struct ApplySpectraLegacy : boost::static_visitor<> { - explicit ApplySpectraLegacy(F &&functor) - : m_functor(std::forward<F>(functor)) {} - - void operator()(const std::pair<std::size_t, std::size_t> &spectra) const { - for (auto spectrum = spectra.first; spectrum <= spectra.second; ++spectrum) - m_functor(spectrum); - } - - void operator()(const DiscontinuousSpectra<std::size_t> &spectra) const { - for (const auto &spectrum : spectra) - m_functor(spectrum); - } - -private: - F m_functor; -}; - -template <typename F> -struct ApplyEnumeratedSpectraLegacy : boost::static_visitor<std::size_t> { - ApplyEnumeratedSpectraLegacy(F &&functor, std::size_t start = 0) - : m_start(start), m_functor(std::forward<F>(functor)) {} - - std::size_t - operator()(const std::pair<std::size_t, std::size_t> &spectra) const { - auto i = m_start; - for (auto spectrum = spectra.first; spectrum <= spectra.second; ++spectrum) - m_functor(i++, spectrum); - return i; - } - - std::size_t - operator()(const DiscontinuousSpectra<std::size_t> &spectra) const { - auto i = m_start; - for (const auto &spectrum : spectra) - m_functor(i++, spectrum); - return i; - } - -private: - std::size_t m_start; - F m_functor; -}; - -/* - IndirectFitDataLegacy - Stores the data to be fit; workspace, spectra, - fitting range and exclude regions. Provides methods for accessing - and applying the fitting data. -*/ -class MANTIDQT_INDIRECT_DLL IndirectFitDataLegacy { -public: - IndirectFitDataLegacy(Mantid::API::MatrixWorkspace_sptr workspace, - const SpectraLegacy &spectra); - - std::string displayName(const std::string &formatString, - const std::string &rangeDelimiter) const; - std::string displayName(const std::string &formatString, - std::size_t spectrum) const; - std::string getBasename() const; - - Mantid::API::MatrixWorkspace_sptr workspace() const; - const SpectraLegacy &spectra() const; - std::size_t getSpectrum(std::size_t index) const; - std::size_t numberOfSpectra() const; - bool zeroSpectra() const; - std::pair<double, double> getRange(std::size_t spectrum) const; - std::string getExcludeRegion(std::size_t spectrum) const; - IndirectFitDataLegacy &combine(IndirectFitDataLegacy const &fitData); - - std::vector<double> excludeRegionsVector(std::size_t spectrum) const; - - template <typename F> void applySpectra(F &&functor) const { - boost::apply_visitor(ApplySpectraLegacy<F>(std::forward<F>(functor)), - m_spectra); - } - - template <typename F> - std::size_t applyEnumeratedSpectraLegacy(F &&functor, - std::size_t start = 0) const { - return boost::apply_visitor( - ApplyEnumeratedSpectraLegacy<F>(std::forward<F>(functor), start), - m_spectra); - } - - void setSpectra(std::string const &spectra); - void setSpectra(SpectraLegacy &&spectra); - void setSpectra(SpectraLegacy const &spectra); - void setStartX(double const &startX, std::size_t const &index); - void setEndX(double const &endX, std::size_t const &spectrum); - void setExcludeRegionString(std::string const &excludeRegion, - std::size_t const &spectrum); - -private: - void validateSpectra(SpectraLegacy const &spectra); - - Mantid::API::MatrixWorkspace_sptr m_workspace; - SpectraLegacy m_spectra; - std::unordered_map<std::size_t, std::string> m_excludeRegions; - std::unordered_map<std::size_t, std::pair<double, double>> m_ranges; -}; - -} // namespace IDA -} // namespace CustomInterfaces -} // namespace MantidQt diff --git a/qt/scientific_interfaces/Indirect/IndirectFitDataPresenterLegacy.cpp b/qt/scientific_interfaces/Indirect/IndirectFitDataPresenterLegacy.cpp deleted file mode 100644 index c5fcc17795d..00000000000 --- a/qt/scientific_interfaces/Indirect/IndirectFitDataPresenterLegacy.cpp +++ /dev/null @@ -1,275 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -#include "IndirectFitDataPresenterLegacy.h" -#include "IndirectAddWorkspaceDialog.h" - -namespace MantidQt { -namespace CustomInterfaces { -namespace IDA { - -IndirectFitDataPresenterLegacy::IndirectFitDataPresenterLegacy( - IndirectFittingModelLegacy *model, IIndirectFitDataViewLegacy *view) - : IndirectFitDataPresenterLegacy( - model, view, - std::make_unique<IndirectDataTablePresenterLegacy>( - model, view->getDataTable())) {} - -IndirectFitDataPresenterLegacy::IndirectFitDataPresenterLegacy( - IndirectFittingModelLegacy *model, IIndirectFitDataViewLegacy *view, - std::unique_ptr<IndirectDataTablePresenterLegacy> tablePresenter) - : m_model(model), m_view(view), - m_tablePresenter(std::move(tablePresenter)) { - observeReplace(true); - - connect(m_view, SIGNAL(singleDataViewSelected()), this, - SLOT(setModelFromSingleData())); - connect(m_view, SIGNAL(multipleDataViewSelected()), this, - SLOT(setModelFromMultipleData())); - - connect(m_view, SIGNAL(singleDataViewSelected()), this, - SIGNAL(singleDataViewSelected())); - connect(m_view, SIGNAL(multipleDataViewSelected()), this, - SIGNAL(multipleDataViewSelected())); - - connect(m_view, SIGNAL(sampleLoaded(const QString &)), this, - SLOT(setModelWorkspace(const QString &))); - connect(m_view, SIGNAL(sampleLoaded(const QString &)), this, - SIGNAL(dataChanged())); - - connect(m_view, SIGNAL(addClicked()), this, - SIGNAL(requestedAddWorkspaceDialog())); - connect(m_view, SIGNAL(addClicked()), this, SLOT(showAddWorkspaceDialog())); - - connect(m_view, SIGNAL(removeClicked()), m_tablePresenter.get(), - SLOT(removeSelectedData())); - connect(m_view, SIGNAL(removeClicked()), this, SIGNAL(dataRemoved())); - connect(m_view, SIGNAL(removeClicked()), this, SIGNAL(dataChanged())); - - connect(m_tablePresenter.get(), - SIGNAL(startXChanged(double, std::size_t, std::size_t)), this, - SIGNAL(startXChanged(double, std::size_t, std::size_t))); - connect(m_tablePresenter.get(), - SIGNAL(endXChanged(double, std::size_t, std::size_t)), this, - SIGNAL(endXChanged(double, std::size_t, std::size_t))); - connect(m_tablePresenter.get(), - SIGNAL(excludeRegionChanged(const std::string &, std::size_t, - std::size_t)), - this, - SIGNAL(excludeRegionChanged(const std::string &, std::size_t, - std::size_t))); -} - -IndirectFitDataPresenterLegacy::~IndirectFitDataPresenterLegacy() { - observeReplace(false); -} - -IIndirectFitDataViewLegacy const * -IndirectFitDataPresenterLegacy::getView() const { - return m_view; -} - -void IndirectFitDataPresenterLegacy::setSampleWSSuffices( - const QStringList &suffices) { - m_view->setSampleWSSuffices(suffices); -} - -void IndirectFitDataPresenterLegacy::setSampleFBSuffices( - const QStringList &suffices) { - m_view->setSampleFBSuffices(suffices); -} - -void IndirectFitDataPresenterLegacy::setResolutionWSSuffices( - const QStringList &suffices) { - m_view->setResolutionWSSuffices(suffices); -} - -void IndirectFitDataPresenterLegacy::setResolutionFBSuffices( - const QStringList &suffices) { - m_view->setResolutionFBSuffices(suffices); -} - -void IndirectFitDataPresenterLegacy::setMultiInputSampleWSSuffixes() { - if (m_addWorkspaceDialog) - m_addWorkspaceDialog->setWSSuffices(m_view->getSampleWSSuffices()); -} - -void IndirectFitDataPresenterLegacy::setMultiInputSampleFBSuffixes() { - if (m_addWorkspaceDialog) - m_addWorkspaceDialog->setFBSuffices(m_view->getSampleFBSuffices()); -} - -void IndirectFitDataPresenterLegacy::setMultiInputResolutionWSSuffixes() { - if (m_addWorkspaceDialog) - setMultiInputResolutionWSSuffixes(m_addWorkspaceDialog.get()); -} - -void IndirectFitDataPresenterLegacy::setMultiInputResolutionFBSuffixes() { - if (m_addWorkspaceDialog) - setMultiInputResolutionFBSuffixes(m_addWorkspaceDialog.get()); -} - -void IndirectFitDataPresenterLegacy::setMultiInputResolutionFBSuffixes( - IAddWorkspaceDialog *dialog) { - UNUSED_ARG(dialog); -} - -void IndirectFitDataPresenterLegacy::setMultiInputResolutionWSSuffixes( - IAddWorkspaceDialog *dialog) { - UNUSED_ARG(dialog); -} - -void IndirectFitDataPresenterLegacy::setStartX(double startX, - std::size_t dataIndex, - int spectrumIndex) { - m_tablePresenter->setStartX(startX, dataIndex, spectrumIndex); -} - -void IndirectFitDataPresenterLegacy::setEndX(double endX, std::size_t dataIndex, - int spectrumIndex) { - m_tablePresenter->setEndX(endX, dataIndex, spectrumIndex); -} - -void IndirectFitDataPresenterLegacy::setExclude(const std::string &exclude, - std::size_t dataIndex, - int spectrumIndex) { - m_tablePresenter->setExclude(exclude, dataIndex, spectrumIndex); -} - -void IndirectFitDataPresenterLegacy::setModelFromSingleData() { - m_multipleData = m_model->clearWorkspaces(); - m_model->setFittingData(std::move(m_singleData)); - emit dataChanged(); -} - -void IndirectFitDataPresenterLegacy::setModelFromMultipleData() { - m_singleData = m_model->clearWorkspaces(); - m_model->setFittingData(std::move(m_multipleData)); - emit dataChanged(); -} - -void IndirectFitDataPresenterLegacy::updateSpectraInTable( - std::size_t dataIndex) { - if (m_view->isMultipleDataTabSelected()) - m_tablePresenter->updateData(dataIndex); -} - -void IndirectFitDataPresenterLegacy::updateDataInTable(std::size_t dataIndex) { - if (m_tablePresenter->isTableEmpty()) - m_tablePresenter->addData(dataIndex); - else - m_tablePresenter->updateData(dataIndex); -} - -void IndirectFitDataPresenterLegacy::setResolutionHidden(bool hide) { - m_view->setResolutionHidden(hide); -} - -void IndirectFitDataPresenterLegacy::setModelWorkspace(const QString &name) { - observeReplace(false); - setSingleModelData(name.toStdString()); - observeReplace(true); -} - -void IndirectFitDataPresenterLegacy::loadSettings(const QSettings &settings) { - m_view->readSettings(settings); -} - -void IndirectFitDataPresenterLegacy::replaceHandle( - const std::string &workspaceName, const Workspace_sptr &workspace) { - UNUSED_ARG(workspace) - if (m_model->hasWorkspace(workspaceName) && - !m_view->isMultipleDataTabSelected()) - selectReplacedWorkspace(QString::fromStdString(workspaceName)); -} - -void IndirectFitDataPresenterLegacy::selectReplacedWorkspace( - const QString &workspaceName) { - if (m_view->isSampleWorkspaceSelectorVisible()) { - setModelWorkspace(workspaceName); - emit dataChanged(); - } else - m_view->setSampleWorkspaceSelectorIndex(workspaceName); -} - -UserInputValidator & -IndirectFitDataPresenterLegacy::validate(UserInputValidator &validator) { - return m_view->validate(validator); -} - -void IndirectFitDataPresenterLegacy::showAddWorkspaceDialog() { - if (!m_addWorkspaceDialog) - m_addWorkspaceDialog = getAddWorkspaceDialog(m_view->parentWidget()); - m_addWorkspaceDialog->updateSelectedSpectra(); - setMultiInputSampleWSSuffixes(); - setMultiInputSampleFBSuffixes(); - m_addWorkspaceDialog->show(); - connect(m_addWorkspaceDialog.get(), SIGNAL(addData()), this, SLOT(addData())); - connect(m_addWorkspaceDialog.get(), SIGNAL(closeDialog()), this, - SLOT(closeDialog())); -} - -std::unique_ptr<IAddWorkspaceDialog> -IndirectFitDataPresenterLegacy::getAddWorkspaceDialog(QWidget *parent) const { - return std::make_unique<AddWorkspaceDialog>(parent); -} - -void IndirectFitDataPresenterLegacy::addData() { - addData(m_addWorkspaceDialog.get()); -} - -void IndirectFitDataPresenterLegacy::closeDialog() { - disconnect(m_addWorkspaceDialog.get(), SIGNAL(addData()), this, - SLOT(addData())); - disconnect(m_addWorkspaceDialog.get(), SIGNAL(closeDialog()), this, - SLOT(closeDialog())); - m_addWorkspaceDialog->close(); -} - -void IndirectFitDataPresenterLegacy::addData( - IAddWorkspaceDialog const *dialog) { - try { - addDataToModel(dialog); - m_tablePresenter->addData(m_model->numberOfWorkspaces() - 1); - emit dataAdded(); - emit dataChanged(); - } catch (const std::runtime_error &ex) { - displayWarning(ex.what()); - } -} - -void IndirectFitDataPresenterLegacy::addDataToModel( - IAddWorkspaceDialog const *dialog) { - if (const auto indirectDialog = - dynamic_cast<AddWorkspaceDialog const *>(dialog)) - m_model->addWorkspace(indirectDialog->workspaceName(), - indirectDialog->workspaceIndices()); -} - -void IndirectFitDataPresenterLegacy::setSingleModelData( - const std::string &name) { - m_model->clearWorkspaces(); - addModelData(name); -} - -void IndirectFitDataPresenterLegacy::addModelData(const std::string &name) { - try { - m_model->addWorkspace(name); - } catch (const std::runtime_error &ex) { - displayWarning("Unable to load workspace:\n" + std::string(ex.what())); - } catch (const std::invalid_argument &ex) { - displayWarning("Invalid workspace:\n" + std::string(ex.what())); - } -} - -void IndirectFitDataPresenterLegacy::displayWarning( - const std::string &warning) { - m_view->displayWarning(warning); -} - -} // namespace IDA -} // namespace CustomInterfaces -} // namespace MantidQt diff --git a/qt/scientific_interfaces/Indirect/IndirectFitDataPresenterLegacy.h b/qt/scientific_interfaces/Indirect/IndirectFitDataPresenterLegacy.h deleted file mode 100644 index d85474399d5..00000000000 --- a/qt/scientific_interfaces/Indirect/IndirectFitDataPresenterLegacy.h +++ /dev/null @@ -1,113 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2015 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -#pragma once - -#include "IAddWorkspaceDialog.h" -#include "IIndirectFitDataViewLegacy.h" -#include "IndirectDataTablePresenterLegacy.h" -#include "IndirectFittingModelLegacy.h" - -#include "DllConfig.h" -#include "MantidAPI/AnalysisDataServiceObserver.h" -#include "MantidAPI/MatrixWorkspace.h" - -#include <QObject> - -namespace MantidQt { -namespace CustomInterfaces { -namespace IDA { - -class MANTIDQT_INDIRECT_DLL IndirectFitDataPresenterLegacy - : public QObject, - public AnalysisDataServiceObserver { - Q_OBJECT -public: - IndirectFitDataPresenterLegacy(IndirectFittingModelLegacy *model, - IIndirectFitDataViewLegacy *view); - IndirectFitDataPresenterLegacy( - IndirectFittingModelLegacy *model, IIndirectFitDataViewLegacy *view, - std::unique_ptr<IndirectDataTablePresenterLegacy> tablePresenter); - ~IndirectFitDataPresenterLegacy(); - - void setSampleWSSuffices(const QStringList &suffices); - void setSampleFBSuffices(const QStringList &suffices); - void setResolutionWSSuffices(const QStringList &suffices); - void setResolutionFBSuffices(const QStringList &suffices); - void setMultiInputSampleWSSuffixes(); - void setMultiInputSampleFBSuffixes(); - void setMultiInputResolutionWSSuffixes(); - void setMultiInputResolutionFBSuffixes(); - - void setStartX(double startX, std::size_t dataIndex, int spectrumIndex); - void setEndX(double endX, std::size_t dataIndex, int spectrumIndex); - void setExclude(const std::string &exclude, std::size_t dataIndex, - int spectrumIndex); - - void loadSettings(const QSettings &settings); - UserInputValidator &validate(UserInputValidator &validator); - - void replaceHandle(const std::string &workspaceName, - const Workspace_sptr &workspace) override; - -public slots: - void updateSpectraInTable(std::size_t dataIndex); - -protected slots: - void setModelWorkspace(const QString &name); - void setModelFromSingleData(); - void setModelFromMultipleData(); - void showAddWorkspaceDialog(); - - virtual void closeDialog(); - -signals: - void singleResolutionLoaded(); - void dataAdded(); - void dataRemoved(); - void dataChanged(); - void startXChanged(double /*_t1*/, std::size_t /*_t2*/, std::size_t /*_t3*/); - void endXChanged(double /*_t1*/, std::size_t /*_t2*/, std::size_t /*_t3*/); - void excludeRegionChanged(const std::string & /*_t1*/, std::size_t /*_t2*/, - std::size_t /*_t3*/); - void multipleDataViewSelected(); - void singleDataViewSelected(); - void requestedAddWorkspaceDialog(); - void updateAvailableFitTypes(); - -protected: - IIndirectFitDataViewLegacy const *getView() const; - void addData(IAddWorkspaceDialog const *dialog); - virtual void addDataToModel(IAddWorkspaceDialog const *dialog); - void setSingleModelData(const std::string &name); - virtual void addModelData(const std::string &name); - void setResolutionHidden(bool hide); - void displayWarning(const std::string &warning); - -private slots: - void addData(); - -private: - virtual std::unique_ptr<IAddWorkspaceDialog> - getAddWorkspaceDialog(QWidget *parent) const; - void updateDataInTable(std::size_t dataIndex); - - void selectReplacedWorkspace(const QString &workspaceName); - - virtual void setMultiInputResolutionFBSuffixes(IAddWorkspaceDialog *dialog); - virtual void setMultiInputResolutionWSSuffixes(IAddWorkspaceDialog *dialog); - - std::unique_ptr<IAddWorkspaceDialog> m_addWorkspaceDialog; - IndirectFittingModelLegacy *m_model; - PrivateFittingDataLegacy m_singleData; - PrivateFittingDataLegacy m_multipleData; - IIndirectFitDataViewLegacy *m_view; - std::unique_ptr<IndirectDataTablePresenterLegacy> m_tablePresenter; -}; - -} // namespace IDA -} // namespace CustomInterfaces -} // namespace MantidQt diff --git a/qt/scientific_interfaces/Indirect/IndirectFitDataViewLegacy.cpp b/qt/scientific_interfaces/Indirect/IndirectFitDataViewLegacy.cpp deleted file mode 100644 index b316a64356a..00000000000 --- a/qt/scientific_interfaces/Indirect/IndirectFitDataViewLegacy.cpp +++ /dev/null @@ -1,187 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -#include "IndirectFitDataViewLegacy.h" - -using namespace Mantid::API; - -namespace { - -bool isWorkspaceLoaded(std::string const &workspaceName) { - return AnalysisDataService::Instance().doesExist(workspaceName); -} - -} // namespace - -namespace MantidQt { -namespace CustomInterfaces { -namespace IDA { - -IndirectFitDataViewLegacy::IndirectFitDataViewLegacy(QWidget *parent) - : IIndirectFitDataViewLegacy(parent), - m_dataForm(new Ui::IndirectFitDataForm) { - m_dataForm->setupUi(this); - m_dataForm->dsResolution->hide(); - m_dataForm->lbResolution->hide(); - m_dataForm->wgtStartEnd->hide(); - - connect(m_dataForm->dsSample, SIGNAL(dataReady(const QString &)), this, - SIGNAL(sampleLoaded(const QString &))); - connect(m_dataForm->dsResolution, SIGNAL(dataReady(const QString &)), this, - SIGNAL(resolutionLoaded(const QString &))); - connect(m_dataForm->pbAdd, SIGNAL(clicked()), this, SIGNAL(addClicked())); - connect(m_dataForm->pbRemove, SIGNAL(clicked()), this, - SIGNAL(removeClicked())); - - connect(this, SIGNAL(currentChanged(int)), this, SLOT(emitViewSelected(int))); - - m_dataForm->dsSample->isOptional(true); - m_dataForm->dsResolution->isOptional(true); -} - -QTableWidget *IndirectFitDataViewLegacy::getDataTable() const { - return m_dataForm->tbFitData; -} - -bool IndirectFitDataViewLegacy::isMultipleDataTabSelected() const { - return currentIndex() == 1; -} - -bool IndirectFitDataViewLegacy::isResolutionHidden() const { - return m_dataForm->dsResolution->isHidden(); -} - -std::string IndirectFitDataViewLegacy::getSelectedSample() const { - return m_dataForm->dsSample->getCurrentDataName().toStdString(); -} - -std::string IndirectFitDataViewLegacy::getSelectedResolution() const { - return m_dataForm->dsResolution->getCurrentDataName().toStdString(); -} - -void IndirectFitDataViewLegacy::readSettings(const QSettings &settings) { - const auto group = settings.group(); - m_dataForm->dsSample->readSettings(group); - m_dataForm->dsResolution->readSettings(group); -} - -void IndirectFitDataViewLegacy::disableMultipleDataTab() { - setTabEnabled(1, false); -} - -QStringList IndirectFitDataViewLegacy::getSampleWSSuffices() const { - return m_dataForm->dsSample->getWSSuffixes(); -} - -QStringList IndirectFitDataViewLegacy::getSampleFBSuffices() const { - return m_dataForm->dsSample->getFBSuffixes(); -} - -QStringList IndirectFitDataViewLegacy::getResolutionWSSuffices() const { - return m_dataForm->dsResolution->getWSSuffixes(); -} - -QStringList IndirectFitDataViewLegacy::getResolutionFBSuffices() const { - return m_dataForm->dsResolution->getFBSuffixes(); -} - -void IndirectFitDataViewLegacy::setSampleWSSuffices( - const QStringList &suffices) { - m_dataForm->dsSample->setWSSuffixes(suffices); -} - -void IndirectFitDataViewLegacy::setSampleFBSuffices( - const QStringList &suffices) { - m_dataForm->dsSample->setFBSuffixes(suffices); -} - -void IndirectFitDataViewLegacy::setResolutionWSSuffices( - const QStringList &suffices) { - m_dataForm->dsResolution->setWSSuffixes(suffices); -} - -void IndirectFitDataViewLegacy::setResolutionFBSuffices( - const QStringList &suffices) { - m_dataForm->dsResolution->setFBSuffixes(suffices); -} - -bool IndirectFitDataViewLegacy::isSampleWorkspaceSelectorVisible() const { - return m_dataForm->dsSample->isWorkspaceSelectorVisible(); -} - -void IndirectFitDataViewLegacy::setSampleWorkspaceSelectorIndex( - const QString &workspaceName) { - m_dataForm->dsSample->setWorkspaceSelectorIndex(workspaceName); - m_dataForm->dsSample->setSelectorIndex(1); -} - -UserInputValidator & -IndirectFitDataViewLegacy::validate(UserInputValidator &validator) { - if (currentIndex() == 0) - return validateSingleData(validator); - return validateMultipleData(validator); -} - -UserInputValidator & -IndirectFitDataViewLegacy::validateMultipleData(UserInputValidator &validator) { - if (m_dataForm->tbFitData->rowCount() == 0) - validator.addErrorMessage("No input data has been provided."); - return validator; -} - -UserInputValidator & -IndirectFitDataViewLegacy::validateSingleData(UserInputValidator &validator) { - validator = validateSample(validator); - if (!isResolutionHidden()) - validator = validateResolution(validator); - return validator; -} - -UserInputValidator & -IndirectFitDataViewLegacy::validateSample(UserInputValidator &validator) { - const auto sampleIsLoaded = isWorkspaceLoaded(getSelectedSample()); - validator.checkDataSelectorIsValid("Sample Input", m_dataForm->dsSample); - - if (!sampleIsLoaded) - emit sampleLoaded(QString::fromStdString(getSelectedSample())); - return validator; -} - -UserInputValidator & -IndirectFitDataViewLegacy::validateResolution(UserInputValidator &validator) { - const auto resolutionIsLoaded = isWorkspaceLoaded(getSelectedResolution()); - validator.checkDataSelectorIsValid("Resolution Input", - m_dataForm->dsResolution); - - if (!resolutionIsLoaded) - emit resolutionLoaded(QString::fromStdString(getSelectedResolution())); - return validator; -} - -void IndirectFitDataViewLegacy::displayWarning(const std::string &warning) { - QMessageBox::warning(parentWidget(), "MantidPlot - Warning", - QString::fromStdString(warning)); -} - -void IndirectFitDataViewLegacy::setResolutionHidden(bool hide) { - m_dataForm->lbResolution->setHidden(hide); - m_dataForm->dsResolution->setHidden(hide); -} - -void IndirectFitDataViewLegacy::emitViewSelected(int index) { - if (index == 0) - emit singleDataViewSelected(); - else - emit multipleDataViewSelected(); -} - -void IndirectFitDataViewLegacy::setStartAndEndHidden(bool hidden) { - m_dataForm->wgtStartEnd->setHidden(hidden); -} - -} // namespace IDA -} // namespace CustomInterfaces -} // namespace MantidQt diff --git a/qt/scientific_interfaces/Indirect/IndirectFitDataViewLegacy.h b/qt/scientific_interfaces/Indirect/IndirectFitDataViewLegacy.h deleted file mode 100644 index 0b6c16f8c3b..00000000000 --- a/qt/scientific_interfaces/Indirect/IndirectFitDataViewLegacy.h +++ /dev/null @@ -1,72 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2015 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -#pragma once - -#include "ui_IndirectFitDataView.h" - -#include "IIndirectFitDataViewLegacy.h" - -#include "DllConfig.h" -#include "MantidQtWidgets/Common/UserInputValidator.h" - -#include <QTabWidget> - -namespace MantidQt { -namespace CustomInterfaces { -namespace IDA { - -class MANTIDQT_INDIRECT_DLL IndirectFitDataViewLegacy - : public IIndirectFitDataViewLegacy { - Q_OBJECT -public: - IndirectFitDataViewLegacy(QWidget *parent = nullptr); - ~IndirectFitDataViewLegacy() override = default; - - QTableWidget *getDataTable() const override; - virtual bool isMultipleDataTabSelected() const override; - bool isResolutionHidden() const override; - void setResolutionHidden(bool hide) override; - void setStartAndEndHidden(bool hidden) override; - void disableMultipleDataTab() override; - - virtual std::string getSelectedSample() const override; - std::string getSelectedResolution() const override; - - virtual QStringList getSampleWSSuffices() const override; - virtual QStringList getSampleFBSuffices() const override; - QStringList getResolutionWSSuffices() const override; - QStringList getResolutionFBSuffices() const override; - - virtual void setSampleWSSuffices(const QStringList &suffices) override; - virtual void setSampleFBSuffices(const QStringList &suffices) override; - virtual void setResolutionWSSuffices(const QStringList &suffices) override; - virtual void setResolutionFBSuffices(const QStringList &suffices) override; - - bool isSampleWorkspaceSelectorVisible() const override; - void setSampleWorkspaceSelectorIndex(const QString &workspaceName) override; - - void readSettings(const QSettings &settings) override; - UserInputValidator &validate(UserInputValidator &validator) override; - -public slots: - void displayWarning(const std::string &warning) override; - -protected slots: - void emitViewSelected(int index); - -private: - UserInputValidator &validateMultipleData(UserInputValidator &validator); - UserInputValidator &validateSingleData(UserInputValidator &validator); - UserInputValidator &validateSample(UserInputValidator &validator); - UserInputValidator &validateResolution(UserInputValidator &validator); - - std::unique_ptr<Ui::IndirectFitDataForm> m_dataForm; -}; - -} // namespace IDA -} // namespace CustomInterfaces -} // namespace MantidQt diff --git a/qt/scientific_interfaces/Indirect/IndirectFitDataViewLegacy.ui b/qt/scientific_interfaces/Indirect/IndirectFitDataViewLegacy.ui deleted file mode 100644 index 882a1463e4d..00000000000 --- a/qt/scientific_interfaces/Indirect/IndirectFitDataViewLegacy.ui +++ /dev/null @@ -1,129 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>IndirectFitDataForm</class> - <widget class="QTabWidget" name="IndirectFitDataForm"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>654</width> - <height>222</height> - </rect> - </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> - <horstretch>0</horstretch> - <verstretch>1</verstretch> - </sizepolicy> - </property> - <property name="windowTitle"> - <string>TabWidget</string> - </property> - <property name="tabPosition"> - <enum>QTabWidget::North</enum> - </property> - <property name="tabShape"> - <enum>QTabWidget::Rounded</enum> - </property> - <property name="currentIndex"> - <number>0</number> - </property> - <property name="elideMode"> - <enum>Qt::ElideLeft</enum> - </property> - <widget class="QWidget" name="loSingleInput"> - <attribute name="title"> - <string>Single Input</string> - </attribute> - <layout class="QGridLayout" name="gridLayout" columnstretch="0,1"> - <item row="0" column="0"> - <widget class="QLabel" name="lbSample"> - <property name="text"> - <string>Sample</string> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="lbResolution"> - <property name="text"> - <string>Resolution</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="MantidQt::MantidWidgets::DataSelector" name="dsSample" native="true"> - <property name="autoLoad" stdset="0"> - <bool>true</bool> - </property> - <property name="ShowGroups" stdset="0"> - <bool>false</bool> - </property> - <property name="showLoad" stdset="0"> - <bool>false</bool> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="MantidQt::MantidWidgets::DataSelector" name="dsResolution" native="true"> - <property name="autoLoad" stdset="0"> - <bool>true</bool> - </property> - <property name="ShowGroups" stdset="0"> - <bool>false</bool> - </property> - <property name="showLoad" stdset="0"> - <bool>false</bool> - </property> - </widget> - </item> - </layout> - </widget> - <widget class="QWidget" name="tab"> - <attribute name="title"> - <string>Multiple Input</string> - </attribute> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <widget class="QTableWidget" name="tbFitData"> - <property name="minimumSize"> - <size> - <width>0</width> - <height>0</height> - </size> - </property> - </widget> - </item> - <item> - <layout class="QVBoxLayout" name="loDataControl"> - <property name="rightMargin"> - <number>0</number> - </property> - <item> - <widget class="QPushButton" name="pbAdd"> - <property name="text"> - <string>Add Workspace</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="pbRemove"> - <property name="text"> - <string>Remove</string> - </property> - </widget> - </item> - </layout> - </item> - </layout> - </widget> - </widget> - <customwidgets> - <customwidget> - <class>MantidQt::MantidWidgets::DataSelector</class> - <extends>QWidget</extends> - <header>MantidQtWidgets/Common/DataSelector.h</header> - </customwidget> - </customwidgets> - <resources/> - <connections/> -</ui> diff --git a/qt/scientific_interfaces/Indirect/IndirectFitOutputLegacy.cpp b/qt/scientific_interfaces/Indirect/IndirectFitOutputLegacy.cpp deleted file mode 100644 index ec0a7e188f3..00000000000 --- a/qt/scientific_interfaces/Indirect/IndirectFitOutputLegacy.cpp +++ /dev/null @@ -1,433 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -#include "IndirectFitOutputLegacy.h" - -#include "MantidAPI/AlgorithmManager.h" -#include "MantidAPI/AnalysisDataService.h" -#include "MantidAPI/TableRow.h" -#include "MantidAPI/TextAxis.h" - -#include <boost/functional/hash.hpp> - -#include <unordered_set> -#include <utility> - -using namespace Mantid::API; - -namespace { -using namespace MantidQt::CustomInterfaces::IDA; - -struct TableRowExtractor { - explicit TableRowExtractor(ITableWorkspace_sptr table) - : m_table(std::move(table)), m_columns(m_table->getColumnNames()) { - m_chiIndex = std::find(m_columns.begin(), m_columns.end(), "Chi_squared") - - m_columns.begin(); - } - - std::unordered_map<std::string, ParameterValueLegacy> - operator()(std::size_t index) { - TableRow row = m_table->getRow(index); - std::unordered_map<std::string, ParameterValueLegacy> parameters; - - for (auto i = 1u; i < m_chiIndex; i += 2) { - const auto &columnName = m_columns[i]; - parameters[columnName] = - ParameterValueLegacy(row.Double(i), row.Double(i + 1)); - } - return parameters; - } - -private: - ITableWorkspace_sptr m_table; - const std::vector<std::string> m_columns; - std::size_t m_chiIndex; -}; - -template <typename Map, typename Key> -typename Map::mapped_type &extractOrAddDefault(Map &map, const Key &key) { - auto values = map.find(key); - if (values != map.end()) - return values->second; - return map[key] = typename Map::mapped_type(); -} - -template <typename F> -void applyEnumeratedData(F &&functor, const FitDataIteratorLegacy &fitDataBegin, - const FitDataIteratorLegacy &fitDataEnd) { - std::size_t start = 0; - for (auto it = fitDataBegin; it < fitDataEnd; ++it) - start = (*it)->applyEnumeratedSpectraLegacy(functor(it->get()), start); -} - -template <typename F> -void applyData(F &&functor, const FitDataIteratorLegacy &fitDataBegin, - const FitDataIteratorLegacy &fitDataEnd) { - for (auto it = fitDataBegin; it < fitDataEnd; ++it) - (*it)->applySpectra(functor(it->get())); -} - -void extractParametersFromTable( - ITableWorkspace_sptr tableWs, const FitDataIteratorLegacy &fitDataBegin, - const FitDataIteratorLegacy &fitDataEnd, - std::unordered_map<IndirectFitDataLegacy const *, ParameterValues> - ¶meters) { - TableRowExtractor extractRowFromTable(std::move(tableWs)); - auto extract = [&](IndirectFitDataLegacy const *inputData) { - auto &values = extractOrAddDefault(parameters, inputData); - return [&](std::size_t index, std::size_t spectrum) { - values[spectrum] = extractRowFromTable(index); - }; - }; - applyEnumeratedData(extract, fitDataBegin, fitDataEnd); -} - -template <typename Map, typename Value, typename Key> -Value getValueOr(const Map &map, const Value &defaultValue, const Key &key) { - const auto value = map.find(key); - if (value != map.end()) - return value->second; - return defaultValue; -} - -template <typename MapND, typename Value, typename Key, typename... Keys> -Value getValueOr(const MapND &map, const Value &defaultValue, const Key &key, - const Keys &... keys) { - const auto values = map.find(key); - if (values != map.end()) - return getValueOr(values->second, defaultValue, keys...); - return defaultValue; -} - -template <typename Map, typename KeyMap> -Map mapKeys(const Map &map, const KeyMap &keyMap) { - Map newMap; - - for (const auto unmapped : map) { - const auto mapping = keyMap.find(unmapped.first); - if (mapping != keyMap.end()) - newMap[mapping->second] = unmapped.second; - else - newMap[unmapped.first] = unmapped.second; - } - return newMap; -} - -MatrixWorkspace_sptr -getMatrixWorkspaceFromGroup(const WorkspaceGroup_sptr &group, - std::size_t index) { - if (group->size() > index) - return std::dynamic_pointer_cast<MatrixWorkspace>(group->getItem(index)); - return nullptr; -} - -std::vector<std::string> getAxisLabels(TextAxis const *axis) { - std::vector<std::string> labels; - labels.reserve(axis->length()); - for (auto i = 0u; i < axis->length(); ++i) - labels.emplace_back(axis->label(i)); - return labels; -} - -std::vector<std::string> getAxisLabels(const MatrixWorkspace_sptr &workspace, - std::size_t index) { - auto axis = dynamic_cast<TextAxis *>(workspace->getAxis(index)); - if (axis) - return getAxisLabels(axis); - return std::vector<std::string>(); -} - -std::string cutLastOf(const std::string &str, const std::string &delimiter) { - const auto cutIndex = str.rfind(delimiter); - if (cutIndex != std::string::npos) - return str.substr(0, cutIndex); - return str; -} - -bool containsMultipleData(const std::string &name) { - return name.substr(0, 5) == "Multi"; -} - -std::string constructResultName(const std::string &name, - IndirectFitDataLegacy const *fitData) { - if (containsMultipleData(name)) { - const auto formatString = cutLastOf(name, "_Results") + "_%1%_s%2%_Result"; - return fitData->displayName(formatString, "_to_"); - } else - return cutLastOf(name, "s_1"); -} - -void renameWorkspace(std::string const &name, std::string const &newName) { - auto renamer = AlgorithmManager::Instance().create("RenameWorkspace"); - renamer->setProperty("InputWorkspace", name); - renamer->setProperty("OutputWorkspace", newName); - renamer->execute(); -} - -void renameResult(const Workspace_sptr &resultWorkspace, - const std::string &workspaceName) { - renameWorkspace(resultWorkspace->getName(), workspaceName + "_Result"); -} - -void renameResult(const Workspace_sptr &resultWorkspace, - IndirectFitDataLegacy const *fitData) { - const auto name = resultWorkspace->getName(); - const auto newName = constructResultName(name, fitData); - if (newName != name) - renameWorkspace(name, newName); -} - -void renameResult(const WorkspaceGroup_sptr &resultWorkspace, - IndirectFitDataLegacy const *fitData) { - for (auto const &workspace : *resultWorkspace) - renameResult(workspace, fitData); -} - -void renameResultWithoutSpectra(const WorkspaceGroup_sptr &resultWorkspace, - const FitDataIteratorLegacy &fitDataBegin, - const FitDataIteratorLegacy &fitDataEnd) { - std::size_t index = 0; - MatrixWorkspace const *previous = nullptr; - - for (auto it = fitDataBegin; it < fitDataEnd; ++it) { - auto workspace = (*it)->workspace().get(); - if (workspace != previous) { - renameResult(resultWorkspace->getItem(index++), workspace->getName()); - previous = workspace; - } - } -} - -void renameResultWithSpectra(const WorkspaceGroup_sptr &resultWorkspace, - const FitDataIteratorLegacy &fitDataBegin, - const FitDataIteratorLegacy &fitDataEnd) { - std::size_t index = 0; - for (auto it = fitDataBegin; it < fitDataEnd; ++it) - renameResult(resultWorkspace->getItem(index++), it->get()); -} - -void renameResult(const WorkspaceGroup_sptr &resultWorkspace, - const FitDataIteratorLegacy &fitDataBegin, - const FitDataIteratorLegacy &fitDataEnd) { - if (static_cast<int>(resultWorkspace->size()) >= fitDataEnd - fitDataBegin) - renameResultWithSpectra(resultWorkspace, fitDataBegin, fitDataEnd); - else - renameResultWithoutSpectra(resultWorkspace, fitDataBegin, fitDataEnd); -} - -template <typename Map, typename Key> -typename Map::mapped_type &findOrCreateDefaultInMap(Map &map, const Key &key) { - auto valueIt = map.find(key); - if (valueIt != map.end()) - return valueIt->second; - return map[key] = typename Map::mapped_type(); -} - -struct UnstructuredResultAdder { -public: - UnstructuredResultAdder( - WorkspaceGroup_sptr resultGroup, ResultLocations &locations, - std::unordered_map<std::size_t, std::size_t> &defaultPositions, - std::size_t &index) - : m_resultGroup(std::move(resultGroup)), m_locations(locations), - m_defaultPositions(defaultPositions), m_index(index) {} - - void operator()(std::size_t spectrum) const { - auto defaultIt = m_defaultPositions.find(spectrum); - if (defaultIt != m_defaultPositions.end()) - m_locations[spectrum] = ResultLocation(m_resultGroup, defaultIt->second); - else if (m_resultGroup->size() > m_index) { - m_locations[spectrum] = ResultLocation(m_resultGroup, m_index); - m_defaultPositions[spectrum] = m_index++; - } - } - -private: - WorkspaceGroup_sptr m_resultGroup; - ResultLocations &m_locations; - std::unordered_map<std::size_t, std::size_t> &m_defaultPositions; - std::size_t &m_index; -}; - -std::size_t numberOfSpectraIn(const FitDataIteratorLegacy &fitDataBegin, - const FitDataIteratorLegacy &fitDataEnd) { - std::size_t spectra = 0; - for (auto it = fitDataBegin; it < fitDataEnd; ++it) - spectra += (*it)->numberOfSpectra(); - return spectra; -} -} // namespace - -namespace MantidQt { -namespace CustomInterfaces { -namespace IDA { - -IndirectFitOutputLegacy::IndirectFitOutputLegacy( - const WorkspaceGroup_sptr &resultGroup, ITableWorkspace_sptr parameterTable, - const WorkspaceGroup_sptr &resultWorkspace, - const FitDataIteratorLegacy &fitDataBegin, - const FitDataIteratorLegacy &fitDataEnd) - : m_resultGroup(resultGroup), m_resultWorkspace(resultWorkspace), - m_parameters(), m_outputResultLocations() { - addOutput(resultGroup, std::move(parameterTable), resultWorkspace, - fitDataBegin, fitDataEnd); -} - -IndirectFitOutputLegacy::IndirectFitOutputLegacy( - const WorkspaceGroup_sptr &resultGroup, ITableWorkspace_sptr parameterTable, - const WorkspaceGroup_sptr &resultWorkspace, - IndirectFitDataLegacy const *fitData, std::size_t spectrum) { - m_parameters[fitData] = ParameterValues(); - m_outputResultLocations[fitData] = ResultLocations(); - addOutput(std::move(resultGroup), std::move(parameterTable), - std::move(resultWorkspace), fitData, spectrum); -} - -bool IndirectFitOutputLegacy::isSpectrumFit( - IndirectFitDataLegacy const *fitData, std::size_t spectrum) const { - auto values = m_parameters.find(fitData); - return values != m_parameters.end() && - values->second.find(spectrum) != values->second.end(); -} - -std::unordered_map<std::string, ParameterValueLegacy> -IndirectFitOutputLegacy::getParameters(IndirectFitDataLegacy const *fitData, - std::size_t spectrum) const { - return getValueOr(m_parameters, - std::unordered_map<std::string, ParameterValueLegacy>(), - fitData, spectrum); -} - -boost::optional<ResultLocation> -IndirectFitOutputLegacy::getResultLocation(IndirectFitDataLegacy const *fitData, - std::size_t spectrum) const { - return getValueOr(m_outputResultLocations, - boost::optional<ResultLocation>(boost::none), fitData, - spectrum); -} - -std::vector<std::string> -IndirectFitOutputLegacy::getResultParameterNames() const { - if (auto resultWorkspace = getLastResultWorkspace()) - if (auto workspace = getMatrixWorkspaceFromGroup(resultWorkspace, 0)) - return getAxisLabels(workspace, 1); - return std::vector<std::string>(); -} - -WorkspaceGroup_sptr IndirectFitOutputLegacy::getLastResultWorkspace() const { - return m_resultWorkspace.lock(); -} - -WorkspaceGroup_sptr IndirectFitOutputLegacy::getLastResultGroup() const { - return m_resultGroup.lock(); -} - -void IndirectFitOutputLegacy::mapParameterNames( - const std::unordered_map<std::string, std::string> ¶meterNameChanges, - const FitDataIteratorLegacy &fitDataBegin, - const FitDataIteratorLegacy &fitDataEnd) { - for (auto it = fitDataBegin; it < fitDataEnd; ++it) - mapParameterNames(parameterNameChanges, it->get()); -} - -void IndirectFitOutputLegacy::mapParameterNames( - const std::unordered_map<std::string, std::string> ¶meterNameChanges, - IndirectFitDataLegacy const *fitData) { - const auto parameterIt = m_parameters.find(fitData); - if (parameterIt != m_parameters.end()) { - for (const auto &values : parameterIt->second) - parameterIt->second[values.first] = - mapKeys(values.second, parameterNameChanges); - } -} - -void IndirectFitOutputLegacy::mapParameterNames( - const std::unordered_map<std::string, std::string> ¶meterNameChanges, - IndirectFitDataLegacy const *fitData, std::size_t spectrum) { - auto ¶meters = m_parameters[fitData][spectrum]; - parameters = mapKeys(parameters, parameterNameChanges); -} - -void IndirectFitOutputLegacy::addOutput( - const WorkspaceGroup_sptr &resultGroup, ITableWorkspace_sptr parameterTable, - const WorkspaceGroup_sptr &resultWorkspace, - const FitDataIteratorLegacy &fitDataBegin, - const FitDataIteratorLegacy &fitDataEnd) { - updateParameters(std::move(parameterTable), fitDataBegin, fitDataEnd); - updateFitResults(resultGroup, fitDataBegin, fitDataEnd); - renameResult(resultWorkspace, fitDataBegin, fitDataEnd); - m_resultWorkspace = resultWorkspace; - m_resultGroup = resultGroup; -} - -void IndirectFitOutputLegacy::addOutput( - const WorkspaceGroup_sptr &resultGroup, ITableWorkspace_sptr parameterTable, - const WorkspaceGroup_sptr &resultWorkspace, - IndirectFitDataLegacy const *fitData, std::size_t spectrum) { - TableRowExtractor extractRowFromTable(std::move(parameterTable)); - m_parameters[fitData][spectrum] = extractRowFromTable(0); - m_outputResultLocations[fitData][spectrum] = ResultLocation(resultGroup, 0); - renameResult(resultWorkspace, fitData); - m_resultWorkspace = resultWorkspace; - m_resultGroup = resultGroup; -} - -void IndirectFitOutputLegacy::removeOutput( - IndirectFitDataLegacy const *fitData) { - m_parameters.erase(fitData); - m_outputResultLocations.erase(fitData); -} - -void IndirectFitOutputLegacy::updateFitResults( - const WorkspaceGroup_sptr &resultGroup, - const FitDataIteratorLegacy &fitDataBegin, - const FitDataIteratorLegacy &fitDataEnd) { - if (numberOfSpectraIn(fitDataBegin, fitDataEnd) <= resultGroup->size()) - updateFitResultsFromStructured(resultGroup, fitDataBegin, fitDataEnd); - else - updateFitResultsFromUnstructured(resultGroup, fitDataBegin, fitDataEnd); -} - -void IndirectFitOutputLegacy::updateParameters( - ITableWorkspace_sptr parameterTable, - const FitDataIteratorLegacy &fitDataBegin, - const FitDataIteratorLegacy &fitDataEnd) { - extractParametersFromTable(std::move(parameterTable), fitDataBegin, - fitDataEnd, m_parameters); -} - -void IndirectFitOutputLegacy::updateFitResultsFromUnstructured( - WorkspaceGroup_sptr resultGroup, const FitDataIteratorLegacy &fitDataBegin, - const FitDataIteratorLegacy &fitDataEnd) { - std::unordered_map<MatrixWorkspace *, - std::unordered_map<std::size_t, std::size_t>> - resultIndices; - std::size_t index = 0; - - auto update = [&](IndirectFitDataLegacy const *inputData) { - auto &fitResults = extractOrAddDefault(m_outputResultLocations, inputData); - auto ws = inputData->workspace().get(); - auto &indices = findOrCreateDefaultInMap(resultIndices, ws); - return UnstructuredResultAdder(resultGroup, fitResults, indices, index); - }; - applyData(update, fitDataBegin, fitDataEnd); -} - -void IndirectFitOutputLegacy::updateFitResultsFromStructured( - WorkspaceGroup_sptr resultGroup, const FitDataIteratorLegacy &fitDataBegin, - const FitDataIteratorLegacy &fitDataEnd) { - auto update = [&](IndirectFitDataLegacy const *inputData) { - auto &fitResults = extractOrAddDefault(m_outputResultLocations, inputData); - return [&](std::size_t index, std::size_t spectrum) { - fitResults[spectrum] = ResultLocation(resultGroup, index); - }; - }; - applyEnumeratedData(update, fitDataBegin, fitDataEnd); -} - -} // namespace IDA -} // namespace CustomInterfaces -} // namespace MantidQt diff --git a/qt/scientific_interfaces/Indirect/IndirectFitOutputLegacy.h b/qt/scientific_interfaces/Indirect/IndirectFitOutputLegacy.h deleted file mode 100644 index 6a8fc3f5ec4..00000000000 --- a/qt/scientific_interfaces/Indirect/IndirectFitOutputLegacy.h +++ /dev/null @@ -1,130 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2007 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -#pragma once - -#include "IndirectFitDataLegacy.h" - -#include "DllConfig.h" -#include "MantidAPI/ITableWorkspace.h" -#include "MantidAPI/WorkspaceGroup.h" - -#include <boost/optional.hpp> - -#include <unordered_map> - -namespace MantidQt { -namespace CustomInterfaces { -namespace IDA { - -struct ParameterValueLegacy { - ParameterValueLegacy() : value(0) {} - explicit ParameterValueLegacy(double val) : value(val) {} - ParameterValueLegacy(double val, double err) : value(val), error(err) {} - double value; - boost::optional<double> error; -}; - -struct ResultLocation { - ResultLocation() : result(), index(0) {} - ResultLocation(const Mantid::API::WorkspaceGroup_sptr &group, std::size_t i) - : result(group), index(i) {} - std::weak_ptr<Mantid::API::WorkspaceGroup> result; - std::size_t index; -}; - -using ParameterValues = - std::unordered_map<std::size_t, - std::unordered_map<std::string, ParameterValueLegacy>>; - -using ResultLocations = std::unordered_map<std::size_t, ResultLocation>; - -using FitDataIteratorLegacy = - std::vector<std::unique_ptr<IndirectFitDataLegacy>>::const_iterator; - -/* - IndirectFitOutputLegacy - Stores the output of a QENS fit and provides - convenient access to the output parameters. -*/ -class MANTIDQT_INDIRECT_DLL IndirectFitOutputLegacy { -public: - IndirectFitOutputLegacy( - const Mantid::API::WorkspaceGroup_sptr &resultGroup, - Mantid::API::ITableWorkspace_sptr parameterTable, - const Mantid::API::WorkspaceGroup_sptr &resultWorkspace, - const FitDataIteratorLegacy &fitDataBegin, - const FitDataIteratorLegacy &fitDataEnd); - - IndirectFitOutputLegacy( - const Mantid::API::WorkspaceGroup_sptr &resultGroup, - Mantid::API::ITableWorkspace_sptr parameterTable, - const Mantid::API::WorkspaceGroup_sptr &resultWorkspace, - IndirectFitDataLegacy const *fitData, std::size_t spectrum); - - bool isSpectrumFit(IndirectFitDataLegacy const *fitData, - std::size_t spectrum) const; - - std::unordered_map<std::string, ParameterValueLegacy> - getParameters(IndirectFitDataLegacy const *fitData, - std::size_t spectrum) const; - - boost::optional<ResultLocation> - getResultLocation(IndirectFitDataLegacy const *fitData, - std::size_t spectrum) const; - std::vector<std::string> getResultParameterNames() const; - Mantid::API::WorkspaceGroup_sptr getLastResultWorkspace() const; - Mantid::API::WorkspaceGroup_sptr getLastResultGroup() const; - - void mapParameterNames( - const std::unordered_map<std::string, std::string> ¶meterNameChanges, - const FitDataIteratorLegacy &fitDataBegin, - const FitDataIteratorLegacy &fitDataEnd); - void mapParameterNames( - const std::unordered_map<std::string, std::string> ¶meterNameChanges, - IndirectFitDataLegacy const *fitData); - void mapParameterNames( - const std::unordered_map<std::string, std::string> ¶meterNameChanges, - IndirectFitDataLegacy const *fitData, std::size_t spectrum); - - void addOutput(const Mantid::API::WorkspaceGroup_sptr &resultGroup, - Mantid::API::ITableWorkspace_sptr parameterTable, - const Mantid::API::WorkspaceGroup_sptr &resultWorkspace, - const FitDataIteratorLegacy &fitDataBegin, - const FitDataIteratorLegacy &fitDataEnd); - void addOutput(const Mantid::API::WorkspaceGroup_sptr &resultGroup, - Mantid::API::ITableWorkspace_sptr parameterTable, - const Mantid::API::WorkspaceGroup_sptr &resultWorkspace, - IndirectFitDataLegacy const *fitData, std::size_t spectrum); - - void removeOutput(IndirectFitDataLegacy const *fitData); - -private: - void updateFitResults(const Mantid::API::WorkspaceGroup_sptr &resultGroup, - const FitDataIteratorLegacy &fitDataBegin, - const FitDataIteratorLegacy &fitDataEnd); - void updateParameters(Mantid::API::ITableWorkspace_sptr parameterTable, - const FitDataIteratorLegacy &fitDataBegin, - const FitDataIteratorLegacy &fitDataEnd); - void - updateFitResultsFromUnstructured(Mantid::API::WorkspaceGroup_sptr resultGroup, - const FitDataIteratorLegacy &fitDataBegin, - const FitDataIteratorLegacy &fitDataEnd); - void - updateFitResultsFromStructured(Mantid::API::WorkspaceGroup_sptr resultGroup, - const FitDataIteratorLegacy &fitDataBegin, - const FitDataIteratorLegacy &fitDataEnd); - - std::weak_ptr<Mantid::API::WorkspaceGroup> m_resultGroup; - std::weak_ptr<Mantid::API::WorkspaceGroup> m_resultWorkspace; - std::unordered_map<IndirectFitDataLegacy const *, ParameterValues> - m_parameters; - std::unordered_map<IndirectFitDataLegacy const *, ResultLocations> - m_outputResultLocations; -}; - -} // namespace IDA -} // namespace CustomInterfaces -} // namespace MantidQt diff --git a/qt/scientific_interfaces/Indirect/IndirectFitPlotModelLegacy.cpp b/qt/scientific_interfaces/Indirect/IndirectFitPlotModelLegacy.cpp deleted file mode 100644 index f30a01e7627..00000000000 --- a/qt/scientific_interfaces/Indirect/IndirectFitPlotModelLegacy.cpp +++ /dev/null @@ -1,421 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -#include "IndirectFitPlotModelLegacy.h" - -#include <utility> - -#include "MantidAPI/AlgorithmManager.h" -#include "MantidAPI/AnalysisDataService.h" -#include "MantidAPI/CompositeFunction.h" -#include "MantidAPI/FunctionDomain1D.h" -#include "MantidAPI/TextAxis.h" -#include "MantidAPI/WorkspaceFactory.h" -#include "MantidAPI/Workspace_fwd.h" - -namespace { -using namespace Mantid::API; - -// The name of the conjoined input and guess workspaces -- required for -// creating an external guess plot. -const std::string INPUT_AND_GUESS_NAME = "__QENSInputAndGuess"; - -IFunction_sptr firstFunctionWithParameter(IFunction_sptr function, - const std::string &category, - const std::string ¶meterName); - -IFunction_sptr -firstFunctionWithParameter(const CompositeFunction_sptr &composite, - const std::string &category, - const std::string ¶meterName) { - for (auto i = 0u; i < composite->nFunctions(); ++i) { - const auto value = firstFunctionWithParameter(composite->getFunction(i), - category, parameterName); - if (value) - return value; - } - return nullptr; -} - -IFunction_sptr firstFunctionWithParameter(IFunction_sptr function, - const std::string &category, - const std::string ¶meterName) { - if (function->category() == category && function->hasParameter(parameterName)) - return function; - - const auto composite = std::dynamic_pointer_cast<CompositeFunction>(function); - if (composite) - return firstFunctionWithParameter(composite, category, parameterName); - return nullptr; -} - -boost::optional<double> firstParameterValue(const IFunction_sptr &function, - const std::string &category, - const std::string ¶meterName) { - if (!function) - return boost::none; - - const auto functionWithParameter = - firstFunctionWithParameter(function, category, parameterName); - if (functionWithParameter) - return functionWithParameter->getParameter(parameterName); - return boost::none; -} - -boost::optional<double> findFirstPeakCentre(const IFunction_sptr &function) { - return firstParameterValue(std::move(function), "Peak", "PeakCentre"); -} - -boost::optional<double> findFirstFWHM(const IFunction_sptr &function) { - return firstParameterValue(std::move(function), "Peak", "FWHM"); -} - -boost::optional<double> -findFirstBackgroundLevel(const IFunction_sptr &function) { - return firstParameterValue(std::move(function), "Background", "A0"); -} - -void setFunctionParameters(const IFunction_sptr &function, - const std::string &category, - const std::string ¶meterName, double value); - -void setFunctionParameters(const CompositeFunction_sptr &composite, - const std::string &category, - const std::string ¶meterName, double value) { - for (auto i = 0u; i < composite->nFunctions(); ++i) - setFunctionParameters(composite->getFunction(i), category, parameterName, - value); -} - -void setFunctionParameters(const IFunction_sptr &function, - const std::string &category, - const std::string ¶meterName, double value) { - if (function->category() == category && function->hasParameter(parameterName)) - function->setParameter(parameterName, value); - - auto composite = std::dynamic_pointer_cast<CompositeFunction>(function); - if (composite) - setFunctionParameters(composite, category, parameterName, value); -} - -void setFirstBackground(IFunction_sptr function, double value) { - firstFunctionWithParameter(std::move(function), "Background", "A0") - ->setParameter("A0", value); -} - -MatrixWorkspace_sptr castToMatrixWorkspace(const Workspace_sptr &workspace) { - return std::dynamic_pointer_cast<MatrixWorkspace>(workspace); -} - -} // namespace - -namespace MantidQt { -namespace CustomInterfaces { -namespace IDA { - -using namespace Mantid::API; - -IndirectFitPlotModelLegacy::IndirectFitPlotModelLegacy( - IndirectFittingModelLegacy *fittingModel) - : m_fittingModel(fittingModel), m_activeIndex(0), m_activeSpectrum(0) {} - -IndirectFitPlotModelLegacy::~IndirectFitPlotModelLegacy() { - deleteExternalGuessWorkspace(); -} - -void IndirectFitPlotModelLegacy::setActiveIndex(std::size_t index) { - m_activeIndex = index; -} - -void IndirectFitPlotModelLegacy::setActiveSpectrum(std::size_t spectrum) { - m_activeSpectrum = spectrum; -} - -void IndirectFitPlotModelLegacy::setStartX(double startX) { - if (getRange().second > startX) - m_fittingModel->setStartX(startX, m_activeIndex, m_activeSpectrum); -} - -void IndirectFitPlotModelLegacy::setEndX(double endX) { - if (getRange().first < endX) - m_fittingModel->setEndX(endX, m_activeIndex, m_activeSpectrum); -} - -void IndirectFitPlotModelLegacy::setFWHM(double fwhm) { - m_fittingModel->setDefaultParameterValue("FWHM", fwhm, m_activeIndex); - setFunctionParameters(m_fittingModel->getFittingFunction(), "Peak", "FWHM", - fwhm); -} - -void IndirectFitPlotModelLegacy::setBackground(double background) { - m_fittingModel->setDefaultParameterValue("A0", background, m_activeIndex); - setFirstBackground(m_fittingModel->getFittingFunction(), background); -} - -void IndirectFitPlotModelLegacy::deleteExternalGuessWorkspace() { - if (AnalysisDataService::Instance().doesExist(INPUT_AND_GUESS_NAME)) - deleteWorkspace(INPUT_AND_GUESS_NAME); -} - -MatrixWorkspace_sptr IndirectFitPlotModelLegacy::getWorkspace() const { - return m_fittingModel->getWorkspace(m_activeIndex); -} - -SpectraLegacy IndirectFitPlotModelLegacy::getSpectra() const { - return m_fittingModel->getSpectra(m_activeIndex); -} - -std::pair<double, double> IndirectFitPlotModelLegacy::getRange() const { - return m_fittingModel->getFittingRange(m_activeIndex, m_activeSpectrum); -} - -std::pair<double, double> -IndirectFitPlotModelLegacy::getWorkspaceRange() const { - const auto xValues = getWorkspace()->x(0); - return {xValues.front(), xValues.back()}; -} - -std::pair<double, double> IndirectFitPlotModelLegacy::getResultRange() const { - const auto xValues = getResultWorkspace()->x(0); - return {xValues.front(), xValues.back()}; -} - -std::size_t IndirectFitPlotModelLegacy::getActiveDataIndex() const { - return m_activeIndex; -} - -std::size_t IndirectFitPlotModelLegacy::getActiveSpectrum() const { - return m_activeSpectrum; -} - -std::size_t IndirectFitPlotModelLegacy::numberOfWorkspaces() const { - return m_fittingModel->numberOfWorkspaces(); -} - -std::string -IndirectFitPlotModelLegacy::getFitDataName(std::size_t index) const { - if (m_fittingModel->getWorkspace(index)) - return m_fittingModel->createDisplayName("%1% (%2%)", "-", index); - return ""; -} - -std::string IndirectFitPlotModelLegacy::getFitDataName() const { - return getFitDataName(m_activeIndex); -} - -std::string IndirectFitPlotModelLegacy::getLastFitDataName() const { - auto const workspaceCount = m_fittingModel->numberOfWorkspaces(); - if (workspaceCount > 0) - return getFitDataName(workspaceCount - 1); - return ""; -} - -boost::optional<double> IndirectFitPlotModelLegacy::getFirstHWHM() const { - auto fwhm = findFirstFWHM(m_fittingModel->getFittingFunction()); - if (fwhm) - return *fwhm / 2.0; - return boost::none; -} - -boost::optional<double> IndirectFitPlotModelLegacy::getFirstPeakCentre() const { - return findFirstPeakCentre(m_fittingModel->getFittingFunction()); -} - -boost::optional<double> -IndirectFitPlotModelLegacy::getFirstBackgroundLevel() const { - return findFirstBackgroundLevel(m_fittingModel->getFittingFunction()); -} - -double IndirectFitPlotModelLegacy::calculateHWHMMaximum(double minimum) const { - const auto peakCentre = getFirstPeakCentre().get_value_or(0.); - return peakCentre + (peakCentre - minimum); -} - -double IndirectFitPlotModelLegacy::calculateHWHMMinimum(double maximum) const { - const auto peakCentre = getFirstPeakCentre().get_value_or(0.); - return peakCentre - (maximum - peakCentre); -} - -bool IndirectFitPlotModelLegacy::canCalculateGuess() const { - const auto function = m_fittingModel->getFittingFunction(); - if (!function) - return false; - - const auto composite = std::dynamic_pointer_cast<CompositeFunction>(function); - const auto isEmptyModel = composite && composite->nFunctions() == 0; - return getWorkspace() && !isEmptyModel; -} - -MatrixWorkspace_sptr IndirectFitPlotModelLegacy::getResultWorkspace() const { - const auto location = - m_fittingModel->getResultLocation(m_activeIndex, m_activeSpectrum); - - if (location) { - const auto group = location->result.lock(); - if (group) - return castToMatrixWorkspace(group->getItem(location->index)); - } - return nullptr; -} - -MatrixWorkspace_sptr IndirectFitPlotModelLegacy::getGuessWorkspace() const { - const auto range = getGuessRange(); - return createGuessWorkspace(getWorkspace(), - m_fittingModel->getFittingFunction(), range.first, - range.second); -} - -MatrixWorkspace_sptr IndirectFitPlotModelLegacy::appendGuessToInput( - const MatrixWorkspace_sptr &guessWorkspace) const { - const auto range = getGuessRange(); - return createInputAndGuessWorkspace( - getWorkspace(), std::move(guessWorkspace), - boost::numeric_cast<int>(m_activeSpectrum), range.first, range.second); -} - -std::pair<double, double> IndirectFitPlotModelLegacy::getGuessRange() const { - if (getResultWorkspace()) - return getResultRange(); - return getRange(); -} - -MatrixWorkspace_sptr IndirectFitPlotModelLegacy::createInputAndGuessWorkspace( - const MatrixWorkspace_sptr &inputWS, - const MatrixWorkspace_sptr &guessWorkspace, int spectrum, double startX, - double endX) const { - guessWorkspace->setInstrument(inputWS->getInstrument()); - guessWorkspace->replaceAxis( - 0, - std::unique_ptr<Axis>(inputWS->getAxis(0)->clone(guessWorkspace.get()))); - guessWorkspace->setDistribution(inputWS->isDistribution()); - - auto extracted = extractSpectra(inputWS, spectrum, spectrum, startX, endX); - auto inputAndGuess = appendSpectra(extracted, guessWorkspace); - AnalysisDataService::Instance().addOrReplace(INPUT_AND_GUESS_NAME, - inputAndGuess); - - auto axis = std::make_unique<TextAxis>(2); - axis->setLabel(0, "Sample"); - axis->setLabel(1, "Guess"); - inputAndGuess->replaceAxis(1, std::move(axis)); - return inputAndGuess; -} - -MatrixWorkspace_sptr IndirectFitPlotModelLegacy::createGuessWorkspace( - const MatrixWorkspace_sptr &inputWorkspace, - const IFunction_const_sptr &func, double startX, double endX) const { - IAlgorithm_sptr createWsAlg = - AlgorithmManager::Instance().create("EvaluateFunction"); - createWsAlg->initialize(); - createWsAlg->setChild(true); - createWsAlg->setLogging(false); - createWsAlg->setProperty("Function", func->asString()); - createWsAlg->setProperty("InputWorkspace", inputWorkspace); - createWsAlg->setProperty("OutputWorkspace", "__QENSGuess"); - createWsAlg->setProperty("StartX", startX); - createWsAlg->setProperty("EndX", endX); - createWsAlg->execute(); - Workspace_sptr outputWorkspace = createWsAlg->getProperty("OutputWorkspace"); - return extractSpectra( - std::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>(outputWorkspace), - 1, 1, startX, endX); -} - -std::vector<double> IndirectFitPlotModelLegacy::computeOutput( - const IFunction_const_sptr &func, const std::vector<double> &dataX) const { - if (dataX.empty()) - return std::vector<double>(); - - FunctionDomain1DVector domain(dataX); - FunctionValues outputData(domain); - func->function(domain, outputData); - - std::vector<double> dataY(dataX.size()); - for (auto i = 0u; i < dataX.size(); ++i) - dataY[i] = outputData.getCalculated(i); - return dataY; -} - -IAlgorithm_sptr IndirectFitPlotModelLegacy::createWorkspaceAlgorithm( - std::size_t numberOfSpectra, const std::vector<double> &dataX, - const std::vector<double> &dataY) const { - IAlgorithm_sptr createWsAlg = - AlgorithmManager::Instance().create("CreateWorkspace"); - createWsAlg->initialize(); - createWsAlg->setChild(true); - createWsAlg->setLogging(false); - createWsAlg->setProperty("OutputWorkspace", "__QENSGuess"); - createWsAlg->setProperty("NSpec", boost::numeric_cast<int>(numberOfSpectra)); - createWsAlg->setProperty("DataX", dataX); - createWsAlg->setProperty("DataY", dataY); - return createWsAlg; -} - -MatrixWorkspace_sptr -IndirectFitPlotModelLegacy::extractSpectra(const MatrixWorkspace_sptr &inputWS, - int startIndex, int endIndex, - double startX, double endX) const { - auto extractSpectraAlg = - AlgorithmManager::Instance().create("ExtractSpectra"); - extractSpectraAlg->initialize(); - extractSpectraAlg->setChild(true); - extractSpectraAlg->setLogging(false); - extractSpectraAlg->setProperty("InputWorkspace", inputWS); - extractSpectraAlg->setProperty("StartWorkspaceIndex", startIndex); - extractSpectraAlg->setProperty("XMin", startX); - extractSpectraAlg->setProperty("XMax", endX); - extractSpectraAlg->setProperty("EndWorkspaceIndex", endIndex); - extractSpectraAlg->setProperty("OutputWorkspace", "__extracted"); - extractSpectraAlg->execute(); - return extractSpectraAlg->getProperty("OutputWorkspace"); -} - -MatrixWorkspace_sptr IndirectFitPlotModelLegacy::appendSpectra( - const MatrixWorkspace_sptr &inputWS, - const MatrixWorkspace_sptr &spectraWS) const { - auto appendSpectraAlg = AlgorithmManager::Instance().create("AppendSpectra"); - appendSpectraAlg->initialize(); - appendSpectraAlg->setChild(true); - appendSpectraAlg->setLogging(false); - appendSpectraAlg->setProperty("InputWorkspace1", inputWS); - appendSpectraAlg->setProperty("InputWorkspace2", spectraWS); - appendSpectraAlg->setProperty("OutputWorkspace", "__appended"); - appendSpectraAlg->execute(); - return appendSpectraAlg->getProperty("OutputWorkspace"); -} - -MatrixWorkspace_sptr -IndirectFitPlotModelLegacy::cropWorkspace(const MatrixWorkspace_sptr &inputWS, - double startX, double endX, - int startIndex, int endIndex) const { - const auto cropAlg = AlgorithmManager::Instance().create("CropWorkspace"); - cropAlg->initialize(); - cropAlg->setChild(true); - cropAlg->setLogging(false); - cropAlg->setProperty("InputWorkspace", inputWS); - cropAlg->setProperty("XMin", startX); - cropAlg->setProperty("XMax", endX); - cropAlg->setProperty("StartWorkspaceIndex", startIndex); - cropAlg->setProperty("EndWorkspaceIndex", endIndex); - cropAlg->setProperty("OutputWorkspace", "__cropped"); - cropAlg->execute(); - return cropAlg->getProperty("OutputWorkspace"); -} - -void IndirectFitPlotModelLegacy::deleteWorkspace( - const std::string &name) const { - auto deleteWorkspaceAlg = - AlgorithmManager::Instance().create("DeleteWorkspace"); - deleteWorkspaceAlg->initialize(); - deleteWorkspaceAlg->setChild(true); - deleteWorkspaceAlg->setLogging(false); - deleteWorkspaceAlg->setProperty("Workspace", name); - deleteWorkspaceAlg->execute(); -} - -} // namespace IDA -} // namespace CustomInterfaces -} // namespace MantidQt diff --git a/qt/scientific_interfaces/Indirect/IndirectFitPlotModelLegacy.h b/qt/scientific_interfaces/Indirect/IndirectFitPlotModelLegacy.h deleted file mode 100644 index afa24ea6a6a..00000000000 --- a/qt/scientific_interfaces/Indirect/IndirectFitPlotModelLegacy.h +++ /dev/null @@ -1,104 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -#pragma once - -#include "IndirectFittingModelLegacy.h" - -#include "MantidAPI/IAlgorithm.h" -#include "MantidAPI/IFunction.h" -#include "MantidAPI/MatrixWorkspace.h" - -#include <boost/optional.hpp> -#include <memory> - -namespace MantidQt { -namespace CustomInterfaces { -namespace IDA { - -class DLLExport IndirectFitPlotModelLegacy { -public: - IndirectFitPlotModelLegacy(IndirectFittingModelLegacy *fittingModel); - ~IndirectFitPlotModelLegacy(); - - Mantid::API::MatrixWorkspace_sptr getWorkspace() const; - Mantid::API::MatrixWorkspace_sptr getResultWorkspace() const; - Mantid::API::MatrixWorkspace_sptr getGuessWorkspace() const; - SpectraLegacy getSpectra() const; - - Mantid::API::MatrixWorkspace_sptr appendGuessToInput( - const Mantid::API::MatrixWorkspace_sptr &guessWorkspace) const; - - std::size_t getActiveDataIndex() const; - std::size_t getActiveSpectrum() const; - std::size_t numberOfWorkspaces() const; - std::string getFitDataName(std::size_t index) const; - std::string getFitDataName() const; - std::string getLastFitDataName() const; - std::pair<double, double> getRange() const; - std::pair<double, double> getWorkspaceRange() const; - std::pair<double, double> getResultRange() const; - boost::optional<double> getFirstHWHM() const; - boost::optional<double> getFirstPeakCentre() const; - boost::optional<double> getFirstBackgroundLevel() const; - double calculateHWHMMaximum(double minimum) const; - double calculateHWHMMinimum(double maximum) const; - bool canCalculateGuess() const; - - void setActiveIndex(std::size_t index); - void setActiveSpectrum(std::size_t spectrum); - void setStartX(double startX); - void setEndX(double endX); - void setFWHM(double fwhm); - void setBackground(double background); - - void deleteExternalGuessWorkspace(); - -private: - std::pair<double, double> getGuessRange() const; - - Mantid::API::MatrixWorkspace_sptr createInputAndGuessWorkspace( - const Mantid::API::MatrixWorkspace_sptr &inputWS, - const Mantid::API::MatrixWorkspace_sptr &guessWorkspace, int spectrum, - double startX, double endX) const; - - Mantid::API::MatrixWorkspace_sptr - createGuessWorkspace(const Mantid::API::MatrixWorkspace_sptr &inputWorkspace, - const Mantid::API::IFunction_const_sptr &func, - double startX, double endX) const; - - std::vector<double> - computeOutput(const Mantid::API::IFunction_const_sptr &func, - const std::vector<double> &dataX) const; - - Mantid::API::IAlgorithm_sptr - createWorkspaceAlgorithm(std::size_t numberOfSpectra, - const std::vector<double> &dataX, - const std::vector<double> &dataY) const; - - Mantid::API::MatrixWorkspace_sptr - extractSpectra(const Mantid::API::MatrixWorkspace_sptr &inputWS, - int startIndex, int endIndex, double startX, - double endX) const; - - Mantid::API::MatrixWorkspace_sptr - appendSpectra(const Mantid::API::MatrixWorkspace_sptr &inputWS, - const Mantid::API::MatrixWorkspace_sptr &spectraWS) const; - - Mantid::API::MatrixWorkspace_sptr - cropWorkspace(const Mantid::API::MatrixWorkspace_sptr &inputWS, double startX, - double endX, int startIndex, int endIndex) const; - - void deleteWorkspace(const std::string &name) const; - - IndirectFittingModelLegacy *m_fittingModel; - std::size_t m_activeIndex; - std::size_t m_activeSpectrum; -}; - -} // namespace IDA -} // namespace CustomInterfaces -} // namespace MantidQt diff --git a/qt/scientific_interfaces/Indirect/IndirectFitPlotPresenterLegacy.cpp b/qt/scientific_interfaces/Indirect/IndirectFitPlotPresenterLegacy.cpp deleted file mode 100644 index 1039289f86d..00000000000 --- a/qt/scientific_interfaces/Indirect/IndirectFitPlotPresenterLegacy.cpp +++ /dev/null @@ -1,414 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -#include "IndirectFitPlotPresenterLegacy.h" - -#include "MantidQtWidgets/Common/SignalBlocker.h" - -#include <QTimer> -#include <utility> - -namespace { -using MantidQt::CustomInterfaces::IDA::DiscontinuousSpectra; -using MantidQt::CustomInterfaces::IDA::IIndirectFitPlotViewLegacy; - -struct UpdateAvailableSpectra : public boost::static_visitor<> { -public: - explicit UpdateAvailableSpectra(IIndirectFitPlotViewLegacy *view) - : m_view(view) {} - - void operator()(const std::pair<std::size_t, std::size_t> &spectra) { - m_view->setAvailableSpectra(spectra.first, spectra.second); - } - - void operator()(const DiscontinuousSpectra<std::size_t> &spectra) { - m_view->setAvailableSpectra(spectra.begin(), spectra.end()); - } - -private: - IIndirectFitPlotViewLegacy *m_view; -}; -} // namespace - -namespace MantidQt { -namespace CustomInterfaces { -namespace IDA { - -using namespace Mantid::API; - -IndirectFitPlotPresenterLegacy::IndirectFitPlotPresenterLegacy( - IndirectFittingModelLegacy *model, IIndirectFitPlotViewLegacy *view, - IPyRunner *pythonRunner) - : m_model(new IndirectFitPlotModelLegacy(model)), m_view(view), - m_plotGuessInSeparateWindow(false), - m_plotter(std::make_unique<IndirectPlotter>(pythonRunner)) { - connect(m_view, SIGNAL(selectedFitDataChanged(std::size_t)), this, - SLOT(setActiveIndex(std::size_t))); - connect(m_view, SIGNAL(selectedFitDataChanged(std::size_t)), this, - SLOT(updateAvailableSpectra())); - connect(m_view, SIGNAL(selectedFitDataChanged(std::size_t)), this, - SLOT(updatePlots())); - connect(m_view, SIGNAL(selectedFitDataChanged(std::size_t)), this, - SIGNAL(selectedFitDataChanged(std::size_t))); - - connect(m_view, SIGNAL(plotSpectrumChanged(std::size_t)), this, - SLOT(setActiveSpectrum(std::size_t))); - connect(m_view, SIGNAL(plotSpectrumChanged(std::size_t)), this, - SLOT(updatePlots())); - connect(m_view, SIGNAL(plotSpectrumChanged(std::size_t)), this, - SIGNAL(plotSpectrumChanged(std::size_t))); - - connect(m_view, SIGNAL(plotCurrentPreview()), this, - SLOT(plotCurrentPreview())); - - connect(m_view, SIGNAL(fitSelectedSpectrum()), this, - SLOT(emitFitSingleSpectrum())); - - connect(m_view, SIGNAL(plotGuessChanged(bool)), this, SLOT(plotGuess(bool))); - - connect(m_view, SIGNAL(startXChanged(double)), this, - SLOT(setModelStartX(double))); - connect(m_view, SIGNAL(endXChanged(double)), this, - SLOT(setModelEndX(double))); - - connect(m_view, SIGNAL(startXChanged(double)), this, - SIGNAL(startXChanged(double))); - connect(m_view, SIGNAL(endXChanged(double)), this, - SIGNAL(endXChanged(double))); - - connect(m_view, SIGNAL(hwhmMaximumChanged(double)), this, - SLOT(setHWHMMinimum(double))); - connect(m_view, SIGNAL(hwhmMinimumChanged(double)), this, - SLOT(setHWHMMaximum(double))); - connect(m_view, SIGNAL(hwhmChanged(double, double)), this, - SLOT(setModelHWHM(double, double))); - connect(m_view, SIGNAL(hwhmChanged(double, double)), this, - SLOT(emitFWHMChanged(double, double))); - - connect(m_view, SIGNAL(backgroundChanged(double)), this, - SLOT(setModelBackground(double))); - connect(m_view, SIGNAL(backgroundChanged(double)), this, - SIGNAL(backgroundChanged(double))); - - updateRangeSelectors(); - updateAvailableSpectra(); -} - -void IndirectFitPlotPresenterLegacy::watchADS(bool watch) { - m_view->watchADS(watch); -} - -std::size_t IndirectFitPlotPresenterLegacy::getSelectedDataIndex() const { - return m_model->getActiveDataIndex(); -} - -std::size_t IndirectFitPlotPresenterLegacy::getSelectedSpectrum() const { - return m_model->getActiveSpectrum(); -} - -int IndirectFitPlotPresenterLegacy::getSelectedSpectrumIndex() const { - return m_view->getSelectedSpectrumIndex(); -} - -bool IndirectFitPlotPresenterLegacy::isCurrentlySelected( - std::size_t dataIndex, std::size_t spectrum) const { - return getSelectedDataIndex() == dataIndex && - getSelectedSpectrum() == spectrum; -} - -void IndirectFitPlotPresenterLegacy::setActiveIndex(std::size_t index) { - m_model->setActiveIndex(index); -} - -void IndirectFitPlotPresenterLegacy::setActiveSpectrum(std::size_t spectrum) { - m_model->setActiveSpectrum(spectrum); -} - -void IndirectFitPlotPresenterLegacy::setModelStartX(double startX) { - m_model->setStartX(startX); -} - -void IndirectFitPlotPresenterLegacy::setModelEndX(double endX) { - m_model->setEndX(endX); -} - -void IndirectFitPlotPresenterLegacy::setModelHWHM(double minimum, - double maximum) { - m_model->setFWHM(maximum - minimum); -} - -void IndirectFitPlotPresenterLegacy::setModelBackground(double background) { - m_model->setBackground(background); -} - -void IndirectFitPlotPresenterLegacy::hideMultipleDataSelection() { - m_view->hideMultipleDataSelection(); -} - -void IndirectFitPlotPresenterLegacy::showMultipleDataSelection() { - m_view->showMultipleDataSelection(); -} - -void IndirectFitPlotPresenterLegacy::setStartX(double startX) { - m_view->setFitRangeMinimum(startX); -} - -void IndirectFitPlotPresenterLegacy::setEndX(double endX) { - m_view->setFitRangeMaximum(endX); -} - -void IndirectFitPlotPresenterLegacy::updatePlotSpectrum(int spectrum) { - m_view->setPlotSpectrum(spectrum); - setActiveSpectrum(static_cast<std::size_t>(spectrum)); - updatePlots(); -} - -void IndirectFitPlotPresenterLegacy::updateRangeSelectors() { - updateBackgroundSelector(); - updateHWHMSelector(); -} - -void IndirectFitPlotPresenterLegacy::setHWHMMaximum(double minimum) { - m_view->setHWHMMaximum(m_model->calculateHWHMMaximum(minimum)); -} - -void IndirectFitPlotPresenterLegacy::setHWHMMinimum(double maximum) { - m_view->setHWHMMinimum(m_model->calculateHWHMMinimum(maximum)); -} - -void IndirectFitPlotPresenterLegacy::enablePlotGuessInSeparateWindow() { - m_plotGuessInSeparateWindow = true; - const auto inputAndGuess = - m_model->appendGuessToInput(m_model->getGuessWorkspace()); - m_plotter->plotSpectra(inputAndGuess->getName(), "0-1"); -} - -void IndirectFitPlotPresenterLegacy::disablePlotGuessInSeparateWindow() { - m_plotGuessInSeparateWindow = false; - m_model->deleteExternalGuessWorkspace(); -} - -void IndirectFitPlotPresenterLegacy::appendLastDataToSelection() { - const auto workspaceCount = m_model->numberOfWorkspaces(); - if (m_view->dataSelectionSize() == workspaceCount) - m_view->setNameInDataSelection(m_model->getLastFitDataName(), - workspaceCount - 1); - else - m_view->appendToDataSelection(m_model->getLastFitDataName()); -} - -void IndirectFitPlotPresenterLegacy::updateSelectedDataName() { - m_view->setNameInDataSelection(m_model->getFitDataName(), - m_model->getActiveDataIndex()); -} - -void IndirectFitPlotPresenterLegacy::updateDataSelection() { - MantidQt::API::SignalBlocker blocker(m_view); - m_view->clearDataSelection(); - for (auto i = 0u; i < m_model->numberOfWorkspaces(); ++i) - m_view->appendToDataSelection(m_model->getFitDataName(i)); - setActiveIndex(0); - updateAvailableSpectra(); - emitSelectedFitDataChanged(); -} - -void IndirectFitPlotPresenterLegacy::updateAvailableSpectra() { - if (m_model->getWorkspace()) { - enableAllDataSelection(); - auto updateSpectra = UpdateAvailableSpectra(m_view); - m_model->getSpectra().apply_visitor(updateSpectra); - setActiveSpectrum(m_view->getSelectedSpectrum()); - } else - disableAllDataSelection(); -} - -void IndirectFitPlotPresenterLegacy::disableAllDataSelection() { - m_view->enableSpectrumSelection(false); - m_view->enableFitRangeSelection(false); -} - -void IndirectFitPlotPresenterLegacy::enableAllDataSelection() { - m_view->enableSpectrumSelection(true); - m_view->enableFitRangeSelection(true); -} - -void IndirectFitPlotPresenterLegacy::setFitSingleSpectrumIsFitting( - bool fitting) { - m_view->setFitSingleSpectrumText(fitting ? "Fitting..." - : "Fit Single Spectrum"); -} - -void IndirectFitPlotPresenterLegacy::setFitSingleSpectrumEnabled(bool enable) { - m_view->setFitSingleSpectrumEnabled(enable); -} - -void IndirectFitPlotPresenterLegacy::updatePlots() { - m_view->clearPreviews(); - - plotLines(); - - updateRangeSelectors(); - updateFitRangeSelector(); -} - -void IndirectFitPlotPresenterLegacy::plotLines() { - if (auto const resultWorkspace = m_model->getResultWorkspace()) { - plotFit(resultWorkspace); - updatePlotRange(m_model->getResultRange()); - } else if (auto const inputWorkspace = m_model->getWorkspace()) { - plotInput(inputWorkspace); - updatePlotRange(m_model->getWorkspaceRange()); - } -} - -void IndirectFitPlotPresenterLegacy::plotInput(MatrixWorkspace_sptr workspace) { - plotInput(std::move(workspace), m_model->getActiveSpectrum()); - if (auto doGuess = m_view->isPlotGuessChecked()) - plotGuess(doGuess); -} - -void IndirectFitPlotPresenterLegacy::plotInput(MatrixWorkspace_sptr workspace, - std::size_t spectrum) { - m_view->plotInTopPreview("Sample", std::move(workspace), spectrum, Qt::black); -} - -void IndirectFitPlotPresenterLegacy::plotFit( - const MatrixWorkspace_sptr &workspace) { - plotInput(workspace, 0); - if (auto doGuess = m_view->isPlotGuessChecked()) - plotGuess(doGuess); - plotFit(workspace, 1); - plotDifference(workspace, 2); -} - -void IndirectFitPlotPresenterLegacy::plotFit(MatrixWorkspace_sptr workspace, - std::size_t spectrum) { - m_view->plotInTopPreview("Fit", std::move(workspace), spectrum, Qt::red); -} - -void IndirectFitPlotPresenterLegacy::plotDifference( - MatrixWorkspace_sptr workspace, std::size_t spectrum) { - m_view->plotInBottomPreview("Difference", std::move(workspace), spectrum, - Qt::blue); -} - -void IndirectFitPlotPresenterLegacy::updatePlotRange( - const std::pair<double, double> &range) { - MantidQt::API::SignalBlocker blocker(m_view); - m_view->setFitRange(range.first, range.second); - m_view->setHWHMRange(range.first, range.second); -} - -void IndirectFitPlotPresenterLegacy::updateFitRangeSelector() { - const auto range = m_model->getRange(); - m_view->setFitRangeMinimum(range.first); - m_view->setFitRangeMaximum(range.second); -} - -void IndirectFitPlotPresenterLegacy::plotCurrentPreview() { - const auto inputWorkspace = m_model->getWorkspace(); - if (inputWorkspace && !inputWorkspace->getName().empty()) { - plotSpectrum(m_model->getActiveSpectrum()); - } else - m_view->displayMessage("Workspace not found - data may not be loaded."); -} - -void IndirectFitPlotPresenterLegacy::updateGuess() { - if (m_model->canCalculateGuess()) { - m_view->enablePlotGuess(true); - plotGuess(m_view->isPlotGuessChecked()); - } else { - m_view->enablePlotGuess(false); - clearGuess(); - } -} - -void IndirectFitPlotPresenterLegacy::updateGuessAvailability() { - if (m_model->canCalculateGuess()) - m_view->enablePlotGuess(true); - else - m_view->enablePlotGuess(false); -} - -void IndirectFitPlotPresenterLegacy::plotGuess(bool doPlotGuess) { - if (doPlotGuess) { - const auto guessWorkspace = m_model->getGuessWorkspace(); - if (guessWorkspace->x(0).size() >= 2) { - plotGuess(guessWorkspace); - if (m_plotGuessInSeparateWindow) - plotGuessInSeparateWindow(guessWorkspace); - } - } else if (m_plotGuessInSeparateWindow) - plotGuessInSeparateWindow(m_model->getGuessWorkspace()); - else - clearGuess(); -} - -void IndirectFitPlotPresenterLegacy::plotGuess( - Mantid::API::MatrixWorkspace_sptr workspace) { - m_view->plotInTopPreview("Guess", std::move(workspace), 0, Qt::green); -} - -void IndirectFitPlotPresenterLegacy::plotGuessInSeparateWindow( - const Mantid::API::MatrixWorkspace_sptr &workspace) { - m_plotExternalGuessRunner.addCallback( - [this, workspace]() { m_model->appendGuessToInput(workspace); }); -} - -void IndirectFitPlotPresenterLegacy::clearGuess() { updatePlots(); } - -void IndirectFitPlotPresenterLegacy::updateHWHMSelector() { - const auto hwhm = m_model->getFirstHWHM(); - m_view->setHWHMRangeVisible(hwhm ? true : false); - - if (hwhm) - setHWHM(*hwhm); -} - -void IndirectFitPlotPresenterLegacy::setHWHM(double hwhm) { - const auto centre = m_model->getFirstPeakCentre().get_value_or(0.); - m_view->setHWHMMaximum(centre + hwhm); - m_view->setHWHMMinimum(centre - hwhm); -} - -void IndirectFitPlotPresenterLegacy::updateBackgroundSelector() { - const auto background = m_model->getFirstBackgroundLevel(); - m_view->setBackgroundRangeVisible(background ? true : false); - - if (background) - m_view->setBackgroundLevel(*background); -} - -void IndirectFitPlotPresenterLegacy::plotSpectrum(std::size_t spectrum) const { - const auto resultWs = m_model->getResultWorkspace(); - if (resultWs) - m_plotter->plotSpectra(resultWs->getName(), "0-2"); - else - m_plotter->plotSpectra(m_model->getWorkspace()->getName(), - std::to_string(spectrum)); -} - -void IndirectFitPlotPresenterLegacy::emitFitSingleSpectrum() { - emit fitSingleSpectrum(m_model->getActiveDataIndex(), - m_model->getActiveSpectrum()); -} - -void IndirectFitPlotPresenterLegacy::emitFWHMChanged(double minimum, - double maximum) { - emit fwhmChanged(maximum - minimum); -} - -void IndirectFitPlotPresenterLegacy::emitSelectedFitDataChanged() { - const auto index = m_view->getSelectedDataIndex(); - if (index >= 0) - emit selectedFitDataChanged(static_cast<std::size_t>(index)); - else - emit noFitDataSelected(); -} - -} // namespace IDA -} // namespace CustomInterfaces -} // namespace MantidQt \ No newline at end of file diff --git a/qt/scientific_interfaces/Indirect/IndirectFitPlotPresenterLegacy.h b/qt/scientific_interfaces/Indirect/IndirectFitPlotPresenterLegacy.h deleted file mode 100644 index b893ba19b8a..00000000000 --- a/qt/scientific_interfaces/Indirect/IndirectFitPlotPresenterLegacy.h +++ /dev/null @@ -1,116 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -#pragma once - -#include "DllConfig.h" - -#include "IndirectFitPlotModelLegacy.h" -#include "IndirectPlotter.h" - -#include "IIndirectFitPlotViewLegacy.h" -#include "LazyAsyncRunner.h" - -namespace MantidQt { -namespace CustomInterfaces { -namespace IDA { - -class MANTIDQT_INDIRECT_DLL IndirectFitPlotPresenterLegacy : public QObject { - Q_OBJECT - -public: - IndirectFitPlotPresenterLegacy(IndirectFittingModelLegacy *model, - IIndirectFitPlotViewLegacy *view, - IPyRunner *pythonRunner = nullptr); - - void watchADS(bool watch); - - std::size_t getSelectedDataIndex() const; - std::size_t getSelectedSpectrum() const; - int getSelectedSpectrumIndex() const; - bool isCurrentlySelected(std::size_t dataIndex, std::size_t spectrum) const; - - void setFitSingleSpectrumIsFitting(bool fitting); - void setFitSingleSpectrumEnabled(bool enable); - -public slots: - void setStartX(double /*startX*/); - void setEndX(double /*endX*/); - void updatePlotSpectrum(int spectrum); - void hideMultipleDataSelection(); - void showMultipleDataSelection(); - void updateRangeSelectors(); - void appendLastDataToSelection(); - void updateSelectedDataName(); - void updateDataSelection(); - void updateAvailableSpectra(); - void updatePlots(); - void updateGuess(); - void updateGuessAvailability(); - void enablePlotGuessInSeparateWindow(); - void disablePlotGuessInSeparateWindow(); - -signals: - void selectedFitDataChanged(std::size_t /*_t1*/); - void noFitDataSelected(); - void plotSpectrumChanged(std::size_t /*_t1*/); - void fitSingleSpectrum(std::size_t /*_t1*/, std::size_t /*_t2*/); - void startXChanged(double /*_t1*/); - void endXChanged(double /*_t1*/); - void fwhmChanged(double /*_t1*/); - void backgroundChanged(double /*_t1*/); - void runAsPythonScript(const QString &code, bool noOutput = false); - -private slots: - void setModelStartX(double value); - void setModelEndX(double value); - void setModelHWHM(double minimum, double maximum); - void setModelBackground(double background); - void setActiveIndex(std::size_t index); - void setActiveSpectrum(std::size_t spectrum); - void setHWHMMaximum(double minimum); - void setHWHMMinimum(double maximum); - void plotGuess(bool doPlotGuess); - void updateFitRangeSelector(); - void plotCurrentPreview(); - void emitFitSingleSpectrum(); - void emitFWHMChanged(double minimum, double maximum); - -private: - void disableAllDataSelection(); - void enableAllDataSelection(); - void plotInput(Mantid::API::MatrixWorkspace_sptr workspace); - void plotInput(Mantid::API::MatrixWorkspace_sptr workspace, - std::size_t spectrum); - void plotFit(const Mantid::API::MatrixWorkspace_sptr &workspace); - void plotFit(Mantid::API::MatrixWorkspace_sptr workspace, - std::size_t spectrum); - void plotDifference(Mantid::API::MatrixWorkspace_sptr workspace, - std::size_t spectrum); - void plotGuess(Mantid::API::MatrixWorkspace_sptr workspace); - void - plotGuessInSeparateWindow(const Mantid::API::MatrixWorkspace_sptr &workspace); - void plotLines(); - void updatePlotRange(const std::pair<double, double> &range); - void clearGuess(); - void updateHWHMSelector(); - void setHWHM(double value); - void updateBackgroundSelector(); - void emitSelectedFitDataChanged(); - - void plotSpectrum(std::size_t spectrum) const; - - std::unique_ptr<IndirectFitPlotModelLegacy> m_model; - IIndirectFitPlotViewLegacy *m_view; - - bool m_plotGuessInSeparateWindow; - QtLazyAsyncRunner<std::function<void()>> m_plotExternalGuessRunner; - std::unique_ptr<IndirectPlotter> m_plotter; -}; - -} // namespace IDA -} // namespace CustomInterfaces -} // namespace MantidQt diff --git a/qt/scientific_interfaces/Indirect/IndirectFitPlotViewLegacy.cpp b/qt/scientific_interfaces/Indirect/IndirectFitPlotViewLegacy.cpp deleted file mode 100644 index 4497328aa23..00000000000 --- a/qt/scientific_interfaces/Indirect/IndirectFitPlotViewLegacy.cpp +++ /dev/null @@ -1,406 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -#include "IndirectFitPlotViewLegacy.h" - -#include "MantidQtWidgets/Common/SignalBlocker.h" - -#include <boost/numeric/conversion/cast.hpp> - -#include <QMessageBox> -#include <QTimer> - -#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) -#include "MantidQtIcons/Icon.h" - -namespace { - -QHash<QString, QVariant> tightLayoutKwargs() { - QHash<QString, QVariant> kwargs; - kwargs.insert("pad", 0); - return kwargs; -} - -} // namespace - -#endif - -namespace MantidQt { -namespace CustomInterfaces { -namespace IDA { - -using namespace MantidWidgets; - -IndirectFitPlotViewLegacy::IndirectFitPlotViewLegacy(QWidget *parent) - : IIndirectFitPlotViewLegacy(parent), - m_plotForm(new Ui::IndirectFitPreviewPlot) { - m_plotForm->setupUi(this); - - connect(m_plotForm->cbDataSelection, SIGNAL(currentIndexChanged(int)), this, - SLOT(emitSelectedFitDataChanged(int))); - connect(m_plotForm->spPlotSpectrum, SIGNAL(valueChanged(int)), this, - SLOT(emitDelayedPlotSpectrumChanged())); - - connect(m_plotForm->cbPlotSpectrum, - SIGNAL(currentIndexChanged(const QString &)), this, - SLOT(emitPlotSpectrumChanged(const QString &))); - connect(m_plotForm->ckPlotGuess, SIGNAL(stateChanged(int)), this, - SLOT(emitPlotGuessChanged(int))); - connect(m_plotForm->pbPlotPreview, SIGNAL(clicked()), this, - SIGNAL(plotCurrentPreview())); - connect(m_plotForm->pbFitSingle, SIGNAL(clicked()), this, - SIGNAL(fitSelectedSpectrum())); - - // Create a Splitter and place two plots within the splitter layout - createSplitterWithPlots(); - - // Avoids squished plots for >qt5 -#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) - char const *const overrideLabel = ""; - m_topPlot->setOverrideAxisLabel(AxisID::XBottom, overrideLabel); - m_bottomPlot->setOverrideAxisLabel(AxisID::YLeft, overrideLabel); - m_plotForm->dwMiniPlots->setFeatures(QDockWidget::NoDockWidgetFeatures); -#endif - - m_plotForm->cbDataSelection->hide(); - addFitRangeSelector(); - addBackgroundRangeSelector(); - addHWHMRangeSelector(); -} - -void IndirectFitPlotViewLegacy::createSplitterWithPlots() { - createSplitter(); - m_splitter->addWidget(createTopPlot()); - m_splitter->addWidget(createBottomPlot()); - - m_plotForm->gridLayout->addWidget(m_splitter.get(), 0, 0, 1, 1); -} - -void IndirectFitPlotViewLegacy::createSplitter() { -#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) - auto const dragIcon = Icons::getIcon("mdi.dots-horizontal"); - m_splitter = std::make_unique<SplitterLegacy>(dragIcon, m_plotForm->dwLayout); -#else - m_splitter = std::make_unique<QSplitter>(m_plotForm->dwLayout); -#endif - m_splitter->setOrientation(Qt::Vertical); - m_splitter->setStyleSheet( - "QSplitter::handle { background-color: transparent; }"); -} - -PreviewPlot *IndirectFitPlotViewLegacy::createTopPlot() { - m_topPlot = std::make_unique<PreviewPlot>(m_splitter.get()); - return createPlot(m_topPlot.get(), QSize(0, 125), 0, 10); -} - -PreviewPlot *IndirectFitPlotViewLegacy::createBottomPlot() { - m_bottomPlot = std::make_unique<PreviewPlot>(m_splitter.get()); - return createPlot(m_bottomPlot.get(), QSize(0, 75), 0, 6); -} - -PreviewPlot *IndirectFitPlotViewLegacy::createPlot( - PreviewPlot *plot, QSize const &minimumSize, - unsigned char horizontalStretch, unsigned char verticalStretch) const { - setPlotSizePolicy(plot, horizontalStretch, verticalStretch); - - plot->setMinimumSize(minimumSize); - plot->setProperty("showLegend", QVariant(true)); - plot->setProperty("canvasColour", QVariant(QColor(255, 255, 255))); - - // Avoids squished plots for >qt5 -#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) - plot->setTightLayout(tightLayoutKwargs()); -#endif - - return plot; -} - -void IndirectFitPlotViewLegacy::setPlotSizePolicy( - PreviewPlot *plot, unsigned char horizontalStretch, - unsigned char verticalStretch) const { - QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); - sizePolicy.setHorizontalStretch(horizontalStretch); - sizePolicy.setVerticalStretch(verticalStretch); - sizePolicy.setHeightForWidth(plot->sizePolicy().hasHeightForWidth()); - plot->setSizePolicy(sizePolicy); -} - -IndirectFitPlotViewLegacy::~IndirectFitPlotViewLegacy() { - m_topPlot.reset(); - m_bottomPlot.reset(); - m_splitter.reset(); -} - -void IndirectFitPlotViewLegacy::watchADS(bool watch) { - m_topPlot->watchADS(watch); - m_bottomPlot->watchADS(watch); -} - -std::string IndirectFitPlotViewLegacy::getSpectrumText() const { - return m_plotForm->cbPlotSpectrum->currentText().toStdString(); -} - -std::size_t IndirectFitPlotViewLegacy::getSelectedSpectrum() const { - if (m_plotForm->swPlotSpectrum->currentIndex() == 0) - return m_plotForm->spPlotSpectrum->value(); - else if (m_plotForm->cbPlotSpectrum->count() != 0) - return std::stoull(getSpectrumText()); - return 0; -} - -int IndirectFitPlotViewLegacy::getSelectedSpectrumIndex() const { - if (m_plotForm->swPlotSpectrum->currentIndex() == 0) - return m_plotForm->spPlotSpectrum->value() - - m_plotForm->spPlotSpectrum->minimum(); - return m_plotForm->cbPlotSpectrum->currentIndex(); -} - -int IndirectFitPlotViewLegacy::getSelectedDataIndex() const { - return m_plotForm->cbDataSelection->currentIndex(); -} - -std::size_t IndirectFitPlotViewLegacy::dataSelectionSize() const { - return boost::numeric_cast<std::size_t>(m_plotForm->cbDataSelection->count()); -} - -bool IndirectFitPlotViewLegacy::isPlotGuessChecked() const { - return m_plotForm->ckPlotGuess->isChecked(); -} - -void IndirectFitPlotViewLegacy::hideMultipleDataSelection() { - m_plotForm->cbDataSelection->hide(); -} - -void IndirectFitPlotViewLegacy::showMultipleDataSelection() { - m_plotForm->cbDataSelection->show(); -} - -void IndirectFitPlotViewLegacy::setAvailableSpectra(std::size_t minimum, - std::size_t maximum) { - m_plotForm->swPlotSpectrum->setCurrentIndex(0); - m_plotForm->spPlotSpectrum->setMinimum(boost::numeric_cast<int>(minimum)); - m_plotForm->spPlotSpectrum->setMaximum(boost::numeric_cast<int>(maximum)); -} - -void IndirectFitPlotViewLegacy::setAvailableSpectra( - const std::vector<std::size_t>::const_iterator &from, - const std::vector<std::size_t>::const_iterator &to) { - m_plotForm->swPlotSpectrum->setCurrentIndex(1); - m_plotForm->cbPlotSpectrum->clear(); - - for (auto spectrum = from; spectrum < to; ++spectrum) - m_plotForm->cbPlotSpectrum->addItem(QString::number(*spectrum)); -} - -void IndirectFitPlotViewLegacy::setMinimumSpectrum(int minimum) { - m_plotForm->spPlotSpectrum->setMinimum(minimum); -} - -void IndirectFitPlotViewLegacy::setMaximumSpectrum(int maximum) { - m_plotForm->spPlotSpectrum->setMaximum(maximum); -} - -void IndirectFitPlotViewLegacy::setPlotSpectrum(int spectrum) { - MantidQt::API::SignalBlocker blocker(m_plotForm->spPlotSpectrum); - m_plotForm->spPlotSpectrum->setValue(spectrum); -} - -void IndirectFitPlotViewLegacy::setBackgroundLevel(double value) { - auto selector = m_topPlot->getSingleSelector("Background"); - MantidQt::API::SignalBlocker blocker(selector); - selector->setPosition(value); -} - -void IndirectFitPlotViewLegacy::setFitRange(double minimum, double maximum) { - auto selector = m_topPlot->getRangeSelector("FitRange"); - MantidQt::API::SignalBlocker blocker(selector); - selector->setRange(minimum, maximum); -} - -void IndirectFitPlotViewLegacy::setFitRangeMinimum(double minimum) { - auto selector = m_topPlot->getRangeSelector("FitRange"); - MantidQt::API::SignalBlocker blocker(selector); - selector->setMinimum(minimum); -} - -void IndirectFitPlotViewLegacy::setFitRangeMaximum(double maximum) { - auto selector = m_topPlot->getRangeSelector("FitRange"); - MantidQt::API::SignalBlocker blocker(selector); - selector->setMaximum(maximum); -} - -void IndirectFitPlotViewLegacy::appendToDataSelection( - const std::string &dataName) { - MantidQt::API::SignalBlocker blocker(m_plotForm->cbDataSelection); - m_plotForm->cbDataSelection->addItem(QString::fromStdString(dataName)); -} - -void IndirectFitPlotViewLegacy::setNameInDataSelection( - const std::string &dataName, std::size_t index) { - m_plotForm->cbDataSelection->setItemText(boost::numeric_cast<int>(index), - QString::fromStdString(dataName)); -} - -void IndirectFitPlotViewLegacy::clearDataSelection() { - m_plotForm->cbDataSelection->clear(); -} - -void IndirectFitPlotViewLegacy::plotInTopPreview( - const QString &name, Mantid::API::MatrixWorkspace_sptr workspace, - std::size_t spectrum, Qt::GlobalColor colour) { - m_topPlot->addSpectrum(name, workspace, spectrum, colour); -} - -void IndirectFitPlotViewLegacy::plotInBottomPreview( - const QString &name, Mantid::API::MatrixWorkspace_sptr workspace, - std::size_t spectrum, Qt::GlobalColor colour) { - m_bottomPlot->addSpectrum(name, workspace, spectrum, colour); -} - -void IndirectFitPlotViewLegacy::removeFromTopPreview(const QString &name) { - m_topPlot->removeSpectrum(name); -} - -void IndirectFitPlotViewLegacy::removeFromBottomPreview(const QString &name) { - m_bottomPlot->removeSpectrum(name); -} - -void IndirectFitPlotViewLegacy::enablePlotGuess(bool enable) { - if (!enable) - m_plotForm->ckPlotGuess->setChecked(enable); - m_plotForm->ckPlotGuess->setEnabled(enable); -} - -void IndirectFitPlotViewLegacy::enableSpectrumSelection(bool enable) { - if (!enable) - m_plotForm->spPlotSpectrum->setValue(0); - m_plotForm->spPlotSpectrum->setEnabled(enable); -} - -void IndirectFitPlotViewLegacy::enableFitRangeSelection(bool enable) { - m_topPlot->getRangeSelector("FitRange")->setVisible(enable); -} - -void IndirectFitPlotViewLegacy::setFitSingleSpectrumText(QString const &text) { - m_plotForm->pbFitSingle->setText(text); -} - -void IndirectFitPlotViewLegacy::setFitSingleSpectrumEnabled(bool enable) { - m_plotForm->pbFitSingle->setEnabled(enable); -} - -void IndirectFitPlotViewLegacy::clearTopPreview() { m_topPlot->clear(); } - -void IndirectFitPlotViewLegacy::clearBottomPreview() { m_bottomPlot->clear(); } - -void IndirectFitPlotViewLegacy::clearPreviews() { - clearTopPreview(); - clearBottomPreview(); -} - -void IndirectFitPlotViewLegacy::setHWHMRange(double minimum, double maximum) { - auto selector = m_topPlot->getRangeSelector("HWHM"); - MantidQt::API::SignalBlocker blocker(selector); - selector->setRange(minimum, maximum); -} - -void IndirectFitPlotViewLegacy::setHWHMMaximum(double minimum) { - auto selector = m_topPlot->getRangeSelector("HWHM"); - MantidQt::API::SignalBlocker blocker(selector); - selector->setMaximum(minimum); -} - -void IndirectFitPlotViewLegacy::setHWHMMinimum(double maximum) { - auto selector = m_topPlot->getRangeSelector("HWHM"); - MantidQt::API::SignalBlocker blocker(selector); - selector->setMinimum(maximum); -} - -void IndirectFitPlotViewLegacy::addFitRangeSelector() { - auto fitRangeSelector = m_topPlot->addRangeSelector("FitRange"); - - connect(fitRangeSelector, SIGNAL(minValueChanged(double)), this, - SIGNAL(startXChanged(double))); - connect(fitRangeSelector, SIGNAL(maxValueChanged(double)), this, - SIGNAL(endXChanged(double))); -} - -void IndirectFitPlotViewLegacy::addBackgroundRangeSelector() { - auto backRangeSelector = - m_topPlot->addSingleSelector("Background", SingleSelector::YSINGLE); - backRangeSelector->setVisible(false); - backRangeSelector->setColour(Qt::darkGreen); - backRangeSelector->setLowerBound(0.0); - - connect(backRangeSelector, SIGNAL(valueChanged(double)), this, - SIGNAL(backgroundChanged(double))); -#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) - connect(backRangeSelector, SIGNAL(resetScientificBounds()), this, - SLOT(setBackgroundBounds())); -#endif -} - -void IndirectFitPlotViewLegacy::setBackgroundBounds() { - auto backRangeSelector = m_topPlot->getSingleSelector("Background"); - backRangeSelector->setLowerBound(0.0); -} - -void IndirectFitPlotViewLegacy::addHWHMRangeSelector() { - auto hwhmRangeSelector = m_topPlot->addRangeSelector("HWHM"); - hwhmRangeSelector->setColour(Qt::red); - hwhmRangeSelector->setRange(0.0, 0.0); - hwhmRangeSelector->setVisible(false); - - connect(hwhmRangeSelector, SIGNAL(minValueChanged(double)), this, - SIGNAL(hwhmMinimumChanged(double))); - connect(hwhmRangeSelector, SIGNAL(maxValueChanged(double)), this, - SIGNAL(hwhmMaximumChanged(double))); - connect(hwhmRangeSelector, SIGNAL(selectionChanged(double, double)), this, - SIGNAL(hwhmChanged(double, double))); -} - -void IndirectFitPlotViewLegacy::setBackgroundRangeVisible(bool visible) { - m_topPlot->getSingleSelector("Background")->setVisible(visible); -} - -void IndirectFitPlotViewLegacy::setHWHMRangeVisible(bool visible) { - m_topPlot->getRangeSelector("HWHM")->setVisible(visible); -} - -void IndirectFitPlotViewLegacy::displayMessage( - const std::string &message) const { - QMessageBox::information(parentWidget(), "MantidPlot - Warning", - QString::fromStdString(message)); -} - -void IndirectFitPlotViewLegacy::emitSelectedFitDataChanged(int index) { - if (index >= 0) - emit selectedFitDataChanged(boost::numeric_cast<std::size_t>(index)); -} - -// Required due to a bug in qt causing the valueChanged signal to be emitted -// twice due to the long amount of time taken to complete the necessary actions -void IndirectFitPlotViewLegacy::emitDelayedPlotSpectrumChanged() { - QTimer::singleShot(150, this, SLOT(emitPlotSpectrumChanged())); -} - -void IndirectFitPlotViewLegacy::emitPlotSpectrumChanged() { - emit plotSpectrumChanged( - boost::numeric_cast<std::size_t>(m_plotForm->spPlotSpectrum->value())); -} - -void IndirectFitPlotViewLegacy::emitPlotSpectrumChanged( - const QString &spectrum) { - emit plotSpectrumChanged(spectrum.toULongLong()); -} - -void IndirectFitPlotViewLegacy::emitPlotGuessChanged(int doPlotGuess) { - emit plotGuessChanged(doPlotGuess == Qt::Checked); -} - -} // namespace IDA -} // namespace CustomInterfaces -} // namespace MantidQt diff --git a/qt/scientific_interfaces/Indirect/IndirectFitPlotViewLegacy.h b/qt/scientific_interfaces/Indirect/IndirectFitPlotViewLegacy.h deleted file mode 100644 index 541d4947303..00000000000 --- a/qt/scientific_interfaces/Indirect/IndirectFitPlotViewLegacy.h +++ /dev/null @@ -1,167 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -#pragma once - -#include "ui_IndirectFitPreviewPlot.h" - -#include "DllConfig.h" -#include "IIndirectFitPlotViewLegacy.h" -#include "MantidAPI/MatrixWorkspace.h" -#include "MantidQtWidgets/Plotting/PreviewPlot.h" - -#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) -#include <QIcon> -#include <QPainter> -#include <QSplitterHandle> -#endif -#include <QSplitter> -#include <utility> - -namespace MantidQt { -namespace CustomInterfaces { -namespace IDA { - -// Used for painting an Icon onto the handle of the splitter on workbench -#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) -class SplitterHandleLegacy : public QSplitterHandle { -public: - SplitterHandleLegacy(QIcon icon, Qt::Orientation orientation, - QSplitter *parent = nullptr) - : QSplitterHandle(orientation, parent), m_icon(std::move(icon)) {} - - void paintEvent(QPaintEvent *e) override { - QSplitterHandle::paintEvent(e); - - QPainter painter(this); - auto const xPos = static_cast<int>(std::round(this->size().width() / 2)); - m_icon.paint(&painter, xPos, -9, 24, 24); - } - -private: - QIcon m_icon; -}; - -class SplitterLegacy : public QSplitter { -public: - SplitterLegacy(QIcon icon, QWidget *parent = nullptr) - : QSplitter(parent), m_icon(std::move(icon)) {} - - QSplitterHandle *createHandle() override { - return new SplitterHandleLegacy(m_icon, Qt::Vertical, this); - } - -private: - QIcon m_icon; -}; -#endif - -class MANTIDQT_INDIRECT_DLL IndirectFitPlotViewLegacy - : public IIndirectFitPlotViewLegacy { - Q_OBJECT - -public: - IndirectFitPlotViewLegacy(QWidget *parent = nullptr); - virtual ~IndirectFitPlotViewLegacy() override; - - void watchADS(bool watch) override; - - std::size_t getSelectedSpectrum() const override; - int getSelectedSpectrumIndex() const override; - int getSelectedDataIndex() const override; - std::size_t dataSelectionSize() const override; - bool isPlotGuessChecked() const override; - - void hideMultipleDataSelection() override; - void showMultipleDataSelection() override; - - void setAvailableSpectra(std::size_t minimum, std::size_t maximum) override; - void setAvailableSpectra( - const std::vector<std::size_t>::const_iterator &from, - const std::vector<std::size_t>::const_iterator &to) override; - - void setMinimumSpectrum(int minimum) override; - void setMaximumSpectrum(int maximum) override; - void setPlotSpectrum(int spectrum) override; - void appendToDataSelection(const std::string &dataName) override; - void setNameInDataSelection(const std::string &dataName, - std::size_t index) override; - void clearDataSelection() override; - - void plotInTopPreview(const QString &name, - Mantid::API::MatrixWorkspace_sptr workspace, - std::size_t spectrum, Qt::GlobalColor colour) override; - void plotInBottomPreview(const QString &name, - Mantid::API::MatrixWorkspace_sptr workspace, - std::size_t spectrum, - Qt::GlobalColor colour) override; - - void removeFromTopPreview(const QString &name) override; - void removeFromBottomPreview(const QString &name) override; - - void enablePlotGuess(bool enable) override; - void enableSpectrumSelection(bool enable) override; - void enableFitRangeSelection(bool enable) override; - - void setFitSingleSpectrumText(QString const &text) override; - void setFitSingleSpectrumEnabled(bool enable) override; - - void setBackgroundLevel(double value) override; - - void setFitRange(double minimum, double maximum) override; - void setFitRangeMinimum(double minimum) override; - void setFitRangeMaximum(double maximum) override; - - void setBackgroundRangeVisible(bool visible) override; - void setHWHMRangeVisible(bool visible) override; - - void displayMessage(const std::string &message) const override; - -public slots: - void clearTopPreview() override; - void clearBottomPreview() override; - void clearPreviews() override; - void setHWHMRange(double minimum, double maximum) override; - void setHWHMMaximum(double minimum) override; - void setHWHMMinimum(double maximum) override; - -private slots: - void setBackgroundBounds(); - - void emitDelayedPlotSpectrumChanged(); - void emitPlotSpectrumChanged(); - void emitPlotSpectrumChanged(const QString &spectrum); - void emitSelectedFitDataChanged(int /*index*/); - void emitPlotGuessChanged(int /*doPlotGuess*/); - -private: - void createSplitterWithPlots(); - void createSplitter(); - MantidWidgets::PreviewPlot *createTopPlot(); - MantidWidgets::PreviewPlot *createBottomPlot(); - MantidWidgets::PreviewPlot * - createPlot(MantidQt::MantidWidgets::PreviewPlot *plot, - QSize const &minimumSize, unsigned char horizontalStretch, - unsigned char verticalStretch) const; - void setPlotSizePolicy(MantidQt::MantidWidgets::PreviewPlot *plot, - unsigned char horizontalStretch, - unsigned char verticalStretch) const; - - std::string getSpectrumText() const; - - void addFitRangeSelector(); - void addBackgroundRangeSelector(); - void addHWHMRangeSelector(); - - std::unique_ptr<Ui::IndirectFitPreviewPlot> m_plotForm; - std::unique_ptr<MantidQt::MantidWidgets::PreviewPlot> m_topPlot; - std::unique_ptr<MantidQt::MantidWidgets::PreviewPlot> m_bottomPlot; - std::unique_ptr<QSplitter> m_splitter; -}; - -} // namespace IDA -} // namespace CustomInterfaces -} // namespace MantidQt \ No newline at end of file diff --git a/qt/scientific_interfaces/Indirect/IndirectFittingModel.cpp b/qt/scientific_interfaces/Indirect/IndirectFittingModel.cpp index ec89b3e5be4..dda3e9b1b0e 100644 --- a/qt/scientific_interfaces/Indirect/IndirectFittingModel.cpp +++ b/qt/scientific_interfaces/Indirect/IndirectFittingModel.cpp @@ -776,8 +776,8 @@ IndirectFittingModel::mapDefaultParameterNames() const { } std::unordered_map<std::string, ParameterValue> - IndirectFittingModel::createDefaultParameters( - TableDatasetIndex /*unused*/) const { +IndirectFittingModel::createDefaultParameters( + TableDatasetIndex /*unused*/) const { return std::unordered_map<std::string, ParameterValue>(); } diff --git a/qt/scientific_interfaces/Indirect/IndirectFittingModelLegacy.cpp b/qt/scientific_interfaces/Indirect/IndirectFittingModelLegacy.cpp deleted file mode 100644 index 13ae54b6d2a..00000000000 --- a/qt/scientific_interfaces/Indirect/IndirectFittingModelLegacy.cpp +++ /dev/null @@ -1,908 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -#include "IndirectFittingModelLegacy.h" - -#include "MantidAPI/AlgorithmManager.h" -#include "MantidAPI/AnalysisDataService.h" -#include "MantidAPI/CompositeFunction.h" -#include "MantidAPI/FunctionFactory.h" -#include "MantidAPI/ITableWorkspace.h" -#include "MantidAPI/MultiDomainFunction.h" -#include "MantidAPI/TableRow.h" - -#include <algorithm> -#include <numeric> -#include <set> - -#include <boost/algorithm/string.hpp> -#include <utility> - -using namespace Mantid::API; - -namespace { -using namespace MantidQt::CustomInterfaces::IDA; - -bool doesExistInADS(std::string const &workspaceName) { - return AnalysisDataService::Instance().doesExist(workspaceName); -} - -std::string cutLastOf(std::string const &str, std::string const &delimiter) { - auto const cutIndex = str.rfind(delimiter); - if (cutIndex != std::string::npos) - return str.substr(0, cutIndex); - return str; -} - -bool equivalentWorkspaces(const MatrixWorkspace_const_sptr &lhs, - const MatrixWorkspace_const_sptr &rhs) { - if (!lhs || !rhs) - return false; - else if (lhs->getName() == "" && rhs->getName() == "") - return lhs == rhs; - return lhs->getName() == rhs->getName(); -} - -/** - * @return True if the first function precedes the second when ordering by - * name. - */ -bool functionNameComparator(const IFunction_const_sptr &first, - const IFunction_const_sptr &second) { - return first->name() < second->name(); -} - -/** - * Extracts the functions from a composite function into a vector. - * - * @param composite The composite function. - * @return A vector of the functions in the specified composite - * function. - */ -std::vector<IFunction_const_sptr> -extractFunctions(const CompositeFunction &composite) { - std::vector<IFunction_const_sptr> functions; - functions.reserve(composite.nFunctions()); - - for (auto i = 0u; i < composite.nFunctions(); ++i) - functions.emplace_back(composite.getFunction(i)); - return functions; -} - -bool equivalentFunctions(const IFunction_const_sptr &func1, - const IFunction_const_sptr &func2); - -/* - * Checks whether the specified composite functions have the same composition. - * - * @param composite1 Function to compare. - * @param composite2 Function to compare. - * @return True if the specified functions have the same composition, - * False otherwise. - */ -bool equivalentComposites(const CompositeFunction &composite1, - const CompositeFunction &composite2) { - - if (composite1.nFunctions() != composite2.nFunctions() || - composite1.nParams() != composite2.nParams()) { - return false; - } else { - auto functions1 = extractFunctions(composite1); - auto functions2 = extractFunctions(composite2); - std::sort(functions1.begin(), functions1.end(), functionNameComparator); - std::sort(functions2.begin(), functions2.end(), functionNameComparator); - - for (auto i = 0u; i < functions1.size(); ++i) { - if (!equivalentFunctions(functions1[i], functions2[i])) - return false; - } - return true; - } -} - -/* - * Checks whether the specified functions have the same composition. - * - * @param func1 Function to compare. - * @param func2 Function to compare. - * @return True if the specified functions have the same composition, - * False otherwise. - */ -bool equivalentFunctions(const IFunction_const_sptr &func1, - const IFunction_const_sptr &func2) { - const auto composite1 = - std::dynamic_pointer_cast<const CompositeFunction>(func1); - const auto composite2 = - std::dynamic_pointer_cast<const CompositeFunction>(func2); - - if (composite1 && composite2) - return equivalentComposites(*composite1, *composite2); - else if (func1 && func2 && !composite1 && !composite2) - return func1->name() == func2->name(); - return false; -} - -std::ostringstream &addInputString(IndirectFitDataLegacy *fitData, - std::ostringstream &stream) { - const auto &name = fitData->workspace()->getName(); - if (!name.empty()) { - auto addToStream = [&](std::size_t spectrum) { - stream << name << ",i" << spectrum << ";"; - }; - fitData->applySpectra(addToStream); - return stream; - } else - throw std::runtime_error( - "Workspace name is empty. The sample workspace may not be loaded."); -} - -std::string constructInputString( - const std::vector<std::unique_ptr<IndirectFitDataLegacy>> &fittingData) { - std::ostringstream input; - for (const auto &fitData : fittingData) - addInputString(fitData.get(), input); - return input.str(); -} - -void addInputDataToSimultaneousFit(const IAlgorithm_sptr &fitAlgorithm, - const MatrixWorkspace_sptr &workspace, - std::size_t spectrum, - const std::pair<double, double> &xRange, - const std::vector<double> &excludeRegions, - const std::string &suffix) { - fitAlgorithm->setProperty("InputWorkspace" + suffix, workspace); - fitAlgorithm->setProperty("StartX" + suffix, xRange.first); - fitAlgorithm->setProperty("EndX" + suffix, xRange.second); - fitAlgorithm->setProperty("WorkspaceIndex" + suffix, - boost::numeric_cast<int>(spectrum)); - - if (!excludeRegions.empty()) - fitAlgorithm->setProperty("Exclude" + suffix, excludeRegions); -} - -void addInputDataToSimultaneousFit( - IAlgorithm_sptr fitAlgorithm, - const std::unique_ptr<IndirectFitDataLegacy> &fitData, - std::size_t &counter) { - const auto workspace = fitData->workspace(); - const auto addData = [&](std::size_t spectrum) { - const auto suffix = counter == 0 ? "" : "_" + std::to_string(counter); - addInputDataToSimultaneousFit( - fitAlgorithm, workspace, spectrum, fitData->getRange(spectrum), - fitData->excludeRegionsVector(spectrum), suffix); - counter += 1; - }; - fitData->applySpectra(addData); -} - -void addInputDataToSimultaneousFit( - IAlgorithm_sptr fitAlgorithm, - const std::unique_ptr<IndirectFitDataLegacy> &fitData, - const std::pair<double, double> &range, const std::vector<double> &exclude, - std::size_t &counter) { - const auto workspace = fitData->workspace(); - const auto addData = [&](std::size_t spectrum) { - const auto suffix = counter == 0 ? "" : "_" + std::to_string(counter); - addInputDataToSimultaneousFit(fitAlgorithm, workspace, spectrum, range, - exclude, suffix); - counter += 1; - }; - fitData->applySpectra(addData); -} - -void addInputDataToSimultaneousFit( - const IAlgorithm_sptr &fitAlgorithm, - const std::vector<std::unique_ptr<IndirectFitDataLegacy>> &fittingData) { - std::size_t counter = 0; - for (const auto &data : fittingData) - addInputDataToSimultaneousFit(fitAlgorithm, data, counter); -} - -void addInputDataToSimultaneousFit( - const IAlgorithm_sptr &fitAlgorithm, - const std::vector<std::unique_ptr<IndirectFitDataLegacy>> &fittingData, - const std::pair<double, double> &range, - const std::vector<double> &exclude) { - std::size_t counter = 0; - for (const auto &data : fittingData) - addInputDataToSimultaneousFit(fitAlgorithm, data, range, exclude, counter); -} - -template <typename Map> Map combine(const Map &mapA, const Map &mapB) { - Map newMap(mapA); - newMap.insert(std::begin(mapB), std::end(mapB)); - return newMap; -} - -std::unordered_map<std::string, std::string> -shortToLongParameterNames(const IFunction_sptr &function) { - std::unordered_map<std::string, std::string> shortToLong; - for (const auto &name : function->getParameterNames()) - shortToLong[name.substr(name.rfind(".") + 1)] = name; - return shortToLong; -} - -template <typename Map, typename KeyMap> -Map mapKeys(const Map &map, const KeyMap &mapping) { - Map mapped; - for (const auto value : map) { - auto it = mapping.find(value.first); - if (it != mapping.end()) - mapped[it->second] = value.second; - } - return mapped; -} - -void removeFromADSIfExists(const std::string &name) { - if (AnalysisDataService::Instance().doesExist(name)) - AnalysisDataService::Instance().remove(name); -} - -void cleanTemporaries(const std::string &base) { - removeFromADSIfExists(base + "_Parameters"); - removeFromADSIfExists(base + "_Workspace"); - removeFromADSIfExists(base + "_NormalisedCovarianceMatrix"); -} - -void cleanTemporaries(const std::string &base, - const std::unique_ptr<IndirectFitDataLegacy> &fitData) { - removeFromADSIfExists(base); - - const auto clean = [&](std::size_t index, std::size_t /*unused*/) { - cleanTemporaries(base + "_" + std::to_string(index)); - }; - fitData->applyEnumeratedSpectraLegacy(clean); -} - -void cleanTemporaries( - const std::string &algorithmName, - const std::vector<std::unique_ptr<IndirectFitDataLegacy>> &fittingData) { - const auto prefix = "__" + algorithmName + "_ws"; - for (auto i = 0u; i < fittingData.size(); ++i) - cleanTemporaries(prefix + std::to_string(i + 1), fittingData[i]); -} - -CompositeFunction_sptr createMultiDomainFunction(const IFunction_sptr &function, - std::size_t numberOfDomains) { - auto multiDomainFunction = std::make_shared<MultiDomainFunction>(); - - for (auto i = 0u; i < numberOfDomains; ++i) { - multiDomainFunction->addFunction(function); - multiDomainFunction->setDomainIndex(i, i); - } - return multiDomainFunction; -} - -IFunction_sptr extractFirstInnerFunction(IFunction_sptr function) { - if (const auto multiDomain = - std::dynamic_pointer_cast<MultiDomainFunction>(function)) { - if (multiDomain->nFunctions() > 0) - return multiDomain->getFunction(0); - } - return function; -} - -IFunction_sptr extractFirstInnerFunction(const std::string &function) { - return extractFirstInnerFunction( - FunctionFactory::Instance().createInitialized(function)); -} - -template <typename WorkspaceType> -std::shared_ptr<WorkspaceType> -getWorkspaceOutput(const IAlgorithm_sptr &algorithm, - const std::string &propertyName) { - return AnalysisDataService::Instance().retrieveWS<WorkspaceType>( - algorithm->getProperty(propertyName)); -} - -WorkspaceGroup_sptr getOutputResult(const IAlgorithm_sptr &algorithm) { - return getWorkspaceOutput<WorkspaceGroup>(std::move(algorithm), - "OutputWorkspace"); -} - -ITableWorkspace_sptr getOutputParameters(const IAlgorithm_sptr &algorithm) { - return getWorkspaceOutput<ITableWorkspace>(std::move(algorithm), - "OutputParameterWorkspace"); -} - -WorkspaceGroup_sptr getOutputGroup(const IAlgorithm_sptr &algorithm) { - return getWorkspaceOutput<WorkspaceGroup>(std::move(algorithm), - "OutputWorkspaceGroup"); -} - -void addFitProperties(Mantid::API::IAlgorithm &algorithm, - const Mantid::API::IFunction_sptr &function, - std::string const &xAxisUnit) { - algorithm.setProperty("Function", function); - algorithm.setProperty("ResultXAxisUnit", xAxisUnit); -} -} // namespace - -namespace MantidQt { -namespace CustomInterfaces { -namespace IDA { - -PrivateFittingDataLegacy::PrivateFittingDataLegacy() : m_data() {} - -PrivateFittingDataLegacy::PrivateFittingDataLegacy( - PrivateFittingDataLegacy &&privateData) - : m_data(std::move(privateData.m_data)) {} - -PrivateFittingDataLegacy::PrivateFittingDataLegacy( - std::vector<std::unique_ptr<IndirectFitDataLegacy>> &&data) - : m_data(std::move(data)) {} - -PrivateFittingDataLegacy &PrivateFittingDataLegacy:: -operator=(PrivateFittingDataLegacy &&fittingData) { - m_data = std::move(fittingData.m_data); - return *this; -} - -IndirectFittingModelLegacy::IndirectFittingModelLegacy() - : m_previousModelSelected(false), - m_fittingMode(FittingModeLegacy::SEQUENTIAL) {} - -bool IndirectFittingModelLegacy::hasWorkspace( - std::string const &workspaceName) const { - auto const names = getWorkspaceNames(); - auto const iter = std::find(names.begin(), names.end(), workspaceName); - return iter != names.end(); -} - -MatrixWorkspace_sptr -IndirectFittingModelLegacy::getWorkspace(std::size_t index) const { - if (index < m_fittingData.size()) - return m_fittingData[index]->workspace(); - return nullptr; -} - -std::vector<std::string> IndirectFittingModelLegacy::getWorkspaceNames() const { - std::vector<std::string> names; - names.reserve(m_fittingData.size()); - for (auto i = 0u; i < m_fittingData.size(); ++i) - names.emplace_back(m_fittingData[i]->workspace()->getName()); - return names; -} - -SpectraLegacy IndirectFittingModelLegacy::getSpectra(std::size_t index) const { - if (index < m_fittingData.size()) - return m_fittingData[index]->spectra(); - return DiscontinuousSpectra<std::size_t>(""); -} - -std::pair<double, double> -IndirectFittingModelLegacy::getFittingRange(std::size_t dataIndex, - std::size_t spectrum) const { - if (dataIndex < m_fittingData.size() && - !m_fittingData[dataIndex]->zeroSpectra()) { - if (FittingModeLegacy::SEQUENTIAL == m_fittingMode) - return m_fittingData.front()->getRange(0); - return m_fittingData[dataIndex]->getRange(spectrum); - } - return std::make_pair(0., 0.); -} - -std::string -IndirectFittingModelLegacy::getExcludeRegion(std::size_t dataIndex, - std::size_t spectrum) const { - if (dataIndex < m_fittingData.size() && - !m_fittingData[dataIndex]->zeroSpectra()) { - if (FittingModeLegacy::SEQUENTIAL == m_fittingMode) - return m_fittingData.back()->getExcludeRegion(0); - return m_fittingData[dataIndex]->getExcludeRegion(spectrum); - } - return ""; -} - -std::string -IndirectFittingModelLegacy::createDisplayName(const std::string &formatString, - const std::string &rangeDelimiter, - std::size_t dataIndex) const { - if (m_fittingData.size() > dataIndex) - return m_fittingData[dataIndex]->displayName(formatString, rangeDelimiter); - else - throw std::runtime_error("Cannot create a display name for a workspace: " - "the workspace index provided is too large."); -} - -std::string -IndirectFittingModelLegacy::createOutputName(const std::string &formatString, - const std::string &rangeDelimiter, - std::size_t dataIndex) const { - return createDisplayName(formatString, rangeDelimiter, dataIndex) + - "_Results"; -} - -bool IndirectFittingModelLegacy::isMultiFit() const { - return numberOfWorkspaces() > 1; -} - -bool IndirectFittingModelLegacy::isPreviouslyFit(std::size_t dataIndex, - std::size_t spectrum) const { - if (!m_previousModelSelected || !m_fitOutput || - m_fittingData.size() <= dataIndex) - return false; - const auto fitData = m_fittingData[dataIndex].get(); - return m_fitOutput->isSpectrumFit(fitData, spectrum); -} - -bool IndirectFittingModelLegacy::hasZeroSpectra(std::size_t dataIndex) const { - if (m_fittingData.size() > dataIndex) - return m_fittingData[dataIndex]->zeroSpectra(); - return true; -} - -boost::optional<std::string> -IndirectFittingModelLegacy::isInvalidFunction() const { - if (!m_activeFunction) - return std::string("No fit function has been defined"); - - const auto composite = - std::dynamic_pointer_cast<CompositeFunction>(m_activeFunction); - if (composite && (composite->nFunctions() == 0 || composite->nParams() == 0)) - return std::string("No fitting functions have been defined."); - return boost::none; -} - -std::size_t IndirectFittingModelLegacy::numberOfWorkspaces() const { - return m_fittingData.size(); -} - -std::size_t -IndirectFittingModelLegacy::getNumberOfSpectra(std::size_t index) const { - if (index < m_fittingData.size()) - return m_fittingData[index]->numberOfSpectra(); - else - throw std::runtime_error( - "Cannot find the number of spectra for a workspace: the workspace " - "index provided is too large."); -} - -std::vector<std::string> -IndirectFittingModelLegacy::getFitParameterNames() const { - if (m_fitOutput) - return m_fitOutput->getResultParameterNames(); - return std::vector<std::string>(); -} - -Mantid::API::IFunction_sptr -IndirectFittingModelLegacy::getFittingFunction() const { - return m_activeFunction; -} - -void IndirectFittingModelLegacy::setFittingData( - PrivateFittingDataLegacy &&fittingData) { - m_fittingData = std::move(fittingData.m_data); -} - -void IndirectFittingModelLegacy::setSpectra(const std::string &spectra, - std::size_t dataIndex) { - setSpectra(DiscontinuousSpectra<std::size_t>(spectra), dataIndex); -} - -void IndirectFittingModelLegacy::setSpectra(SpectraLegacy &&spectra, - std::size_t dataIndex) { - m_fittingData[dataIndex]->setSpectra(std::forward<SpectraLegacy>(spectra)); -} - -void IndirectFittingModelLegacy::setSpectra(const SpectraLegacy &spectra, - std::size_t dataIndex) { - m_fittingData[dataIndex]->setSpectra(spectra); -} - -void IndirectFittingModelLegacy::setStartX(double startX, std::size_t dataIndex, - std::size_t spectrum) { - if (FittingModeLegacy::SEQUENTIAL == m_fittingMode) - m_fittingData.front()->setStartX(startX, 0); - else - m_fittingData[dataIndex]->setStartX(startX, spectrum); -} - -void IndirectFittingModelLegacy::setEndX(double endX, std::size_t dataIndex, - std::size_t spectrum) { - if (FittingModeLegacy::SEQUENTIAL == m_fittingMode) - m_fittingData.front()->setEndX(endX, 0); - else - m_fittingData[dataIndex]->setEndX(endX, spectrum); -} - -void IndirectFittingModelLegacy::setExcludeRegion(const std::string &exclude, - std::size_t dataIndex, - std::size_t spectrum) { - if (FittingModeLegacy::SEQUENTIAL == m_fittingMode) - m_fittingData.front()->setExcludeRegionString(exclude, 0); - else - m_fittingData[dataIndex]->setExcludeRegionString(exclude, spectrum); -} - -void IndirectFittingModelLegacy::addWorkspace( - const std::string &workspaceName) { - auto ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>( - workspaceName); - addWorkspace(ws, std::make_pair(0u, ws->getNumberHistograms() - 1)); -} - -void IndirectFittingModelLegacy::addWorkspace(const std::string &workspaceName, - const std::string &spectra) { - if (spectra.empty()) - throw std::runtime_error( - "Fitting Data must consist of one or more spectra."); - if (workspaceName.empty() || !doesExistInADS(workspaceName)) - throw std::runtime_error("A valid sample file needs to be selected."); - - addWorkspace(workspaceName, DiscontinuousSpectra<std::size_t>(spectra)); -} - -void IndirectFittingModelLegacy::addWorkspace(const std::string &workspaceName, - const SpectraLegacy &spectra) { - auto ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>( - workspaceName); - addWorkspace(ws, spectra); -} - -void IndirectFittingModelLegacy::addWorkspace(MatrixWorkspace_sptr workspace, - const SpectraLegacy &spectra) { - if (!m_fittingData.empty() && - equivalentWorkspaces(workspace, m_fittingData.back()->workspace())) - m_fittingData.back()->combine(IndirectFitDataLegacy(workspace, spectra)); - else - addNewWorkspace(workspace, spectra); -} - -void IndirectFittingModelLegacy::addNewWorkspace(MatrixWorkspace_sptr workspace, - const SpectraLegacy &spectra) { - m_fittingData.emplace_back( - new IndirectFitDataLegacy(std::move(workspace), spectra)); - m_defaultParameters.emplace_back( - createDefaultParameters(m_fittingData.size() - 1)); -} - -void IndirectFittingModelLegacy::removeWorkspaceFromFittingData( - std::size_t const &index) { - if (m_fittingData.size() > index) - removeFittingData(index); - else - throw std::runtime_error("Cannot remove a workspace from the fitting data: " - "the workspace index provided is too large."); -} - -void IndirectFittingModelLegacy::removeWorkspace(std::size_t index) { - removeWorkspaceFromFittingData(index); - - if (index > 0 && m_fittingData.size() > index) { - const auto previousWS = m_fittingData[index - 1]->workspace(); - const auto subsequentWS = m_fittingData[index]->workspace(); - - if (equivalentWorkspaces(previousWS, subsequentWS)) { - m_fittingData[index - 1]->combine(*m_fittingData[index]); - m_fittingData.erase(m_fittingData.begin() + index); - } - } -} - -void IndirectFittingModelLegacy::removeFittingData(std::size_t index) { - if (m_fitOutput) - m_fitOutput->removeOutput(m_fittingData[index].get()); - m_fittingData.erase(m_fittingData.begin() + index); - if (m_defaultParameters.size() > index) - m_defaultParameters.erase(m_defaultParameters.begin() + index); -} - -PrivateFittingDataLegacy IndirectFittingModelLegacy::clearWorkspaces() { - m_fitOutput.reset(); - return std::move(m_fittingData); -} - -void IndirectFittingModelLegacy::setFittingMode(FittingModeLegacy mode) { - m_fittingMode = mode; -} - -void IndirectFittingModelLegacy::setFitFunction(IFunction_sptr function) { - m_activeFunction = std::move(function); - m_previousModelSelected = isPreviousModelSelected(); -} - -void IndirectFittingModelLegacy::setDefaultParameterValue( - const std::string &name, double value, std::size_t dataIndex) { - if (m_defaultParameters.size() > dataIndex) - m_defaultParameters[dataIndex][name] = ParameterValueLegacy(value); -} - -void IndirectFittingModelLegacy::addOutput(IAlgorithm_sptr fitAlgorithm) { - addOutput(std::move(fitAlgorithm), m_fittingData.begin(), - m_fittingData.end()); -} - -void IndirectFittingModelLegacy::addOutput( - const IAlgorithm_sptr &fitAlgorithm, - const FitDataIteratorLegacy &fitDataBegin, - const FitDataIteratorLegacy &fitDataEnd) { - auto group = getOutputGroup(fitAlgorithm); - auto parameters = getOutputParameters(fitAlgorithm); - auto result = getOutputResult(fitAlgorithm); - m_fitFunction = - extractFirstInnerFunction(fitAlgorithm->getPropertyValue("Function")); - addOutput(group, parameters, result, fitDataBegin, fitDataEnd); -} - -void IndirectFittingModelLegacy::addSingleFitOutput( - const IAlgorithm_sptr &fitAlgorithm, std::size_t index) { - auto group = getOutputGroup(fitAlgorithm); - auto parameters = getOutputParameters(fitAlgorithm); - auto result = getOutputResult(fitAlgorithm); - int spectrum = fitAlgorithm->getProperty("WorkspaceIndex"); - m_fitFunction = FunctionFactory::Instance().createInitialized( - fitAlgorithm->getPropertyValue("Function")); - addOutput(group, parameters, result, m_fittingData[index].get(), - boost::numeric_cast<std::size_t>(spectrum)); -} - -void IndirectFittingModelLegacy::addOutput( - const WorkspaceGroup_sptr &resultGroup, - const ITableWorkspace_sptr ¶meterTable, - const WorkspaceGroup_sptr &resultWorkspace, - const FitDataIteratorLegacy &fitDataBegin, - const FitDataIteratorLegacy &fitDataEnd) { - if (m_previousModelSelected && m_fitOutput) - addOutput(m_fitOutput.get(), resultGroup, parameterTable, resultWorkspace, - fitDataBegin, fitDataEnd); - else - m_fitOutput = std::make_unique<IndirectFitOutputLegacy>( - createFitOutput(resultGroup, parameterTable, resultWorkspace, - fitDataBegin, fitDataEnd)); - m_previousModelSelected = isPreviousModelSelected(); -} - -void IndirectFittingModelLegacy::addOutput( - const WorkspaceGroup_sptr &resultGroup, - const ITableWorkspace_sptr ¶meterTable, - const WorkspaceGroup_sptr &resultWorkspace, IndirectFitDataLegacy *fitData, - std::size_t spectrum) { - if (m_previousModelSelected && m_fitOutput) - addOutput(m_fitOutput.get(), resultGroup, parameterTable, resultWorkspace, - fitData, spectrum); - else - m_fitOutput = std::make_unique<IndirectFitOutputLegacy>(createFitOutput( - resultGroup, parameterTable, resultWorkspace, fitData, spectrum)); - m_previousModelSelected = isPreviousModelSelected(); -} - -IndirectFitOutputLegacy IndirectFittingModelLegacy::createFitOutput( - WorkspaceGroup_sptr resultGroup, ITableWorkspace_sptr parameterTable, - WorkspaceGroup_sptr resultWorkspace, - const FitDataIteratorLegacy &fitDataBegin, - const FitDataIteratorLegacy &fitDataEnd) const { - return IndirectFitOutputLegacy( - std::move(resultGroup), std::move(parameterTable), - std::move(resultWorkspace), fitDataBegin, fitDataEnd); -} - -IndirectFitOutputLegacy IndirectFittingModelLegacy::createFitOutput( - Mantid::API::WorkspaceGroup_sptr resultGroup, - Mantid::API::ITableWorkspace_sptr parameterTable, - Mantid::API::WorkspaceGroup_sptr resultWorkspace, - IndirectFitDataLegacy *fitData, std::size_t spectrum) const { - return IndirectFitOutputLegacy(std::move(resultGroup), - std::move(parameterTable), - std::move(resultWorkspace), fitData, spectrum); -} - -void IndirectFittingModelLegacy::addOutput( - IndirectFitOutputLegacy *fitOutput, WorkspaceGroup_sptr resultGroup, - ITableWorkspace_sptr parameterTable, WorkspaceGroup_sptr resultWorkspace, - const FitDataIteratorLegacy &fitDataBegin, - const FitDataIteratorLegacy &fitDataEnd) const { - fitOutput->addOutput(std::move(resultGroup), std::move(parameterTable), - std::move(resultWorkspace), fitDataBegin, fitDataEnd); -} - -void IndirectFittingModelLegacy::addOutput( - IndirectFitOutputLegacy *fitOutput, - Mantid::API::WorkspaceGroup_sptr resultGroup, - Mantid::API::ITableWorkspace_sptr parameterTable, - Mantid::API::WorkspaceGroup_sptr resultWorkspace, - IndirectFitDataLegacy *fitData, std::size_t spectrum) const { - fitOutput->addOutput(std::move(resultGroup), std::move(parameterTable), - std::move(resultWorkspace), fitData, spectrum); -} - -FittingModeLegacy IndirectFittingModelLegacy::getFittingMode() const { - return m_fittingMode; -} - -std::unordered_map<std::string, ParameterValueLegacy> -IndirectFittingModelLegacy::getParameterValues(std::size_t index, - std::size_t spectrum) const { - if (m_fittingData.size() > index) { - const auto parameters = getFitParameters(index, spectrum); - if (m_previousModelSelected) - return parameters; - else if (parameters.empty()) - return getDefaultParameters(index); - return combine(getDefaultParameters(index), parameters); - } - return std::unordered_map<std::string, ParameterValueLegacy>(); -} - -std::unordered_map<std::string, ParameterValueLegacy> -IndirectFittingModelLegacy::getFitParameters(std::size_t index, - std::size_t spectrum) const { - if (m_fitOutput) - return m_fitOutput->getParameters(m_fittingData[index].get(), spectrum); - return std::unordered_map<std::string, ParameterValueLegacy>(); -} - -std::unordered_map<std::string, ParameterValueLegacy> -IndirectFittingModelLegacy::getDefaultParameters(std::size_t index) const { - if (index < m_defaultParameters.size()) - return mapKeys(m_defaultParameters[index], mapDefaultParameterNames()); - return std::unordered_map<std::string, ParameterValueLegacy>(); -} - -std::unordered_map<std::string, std::string> -IndirectFittingModelLegacy::mapDefaultParameterNames() const { - if (m_activeFunction) - return shortToLongParameterNames(getFittingFunction()); - return std::unordered_map<std::string, std::string>(); -} - -std::unordered_map<std::string, ParameterValueLegacy> -IndirectFittingModelLegacy::createDefaultParameters( - std::size_t /*unused*/) const { - return std::unordered_map<std::string, ParameterValueLegacy>(); -} - -std::string IndirectFittingModelLegacy::getResultXAxisUnit() const { - return "MomentumTransfer"; -} - -std::string IndirectFittingModelLegacy::getResultLogName() const { - return "axis-1"; -} - -boost::optional<ResultLocation> -IndirectFittingModelLegacy::getResultLocation(std::size_t index, - std::size_t spectrum) const { - if (m_previousModelSelected && m_fitOutput && m_fittingData.size() > index) - return m_fitOutput->getResultLocation(m_fittingData[index].get(), spectrum); - return boost::none; -} - -WorkspaceGroup_sptr IndirectFittingModelLegacy::getResultWorkspace() const { - return m_fitOutput->getLastResultWorkspace(); -} - -WorkspaceGroup_sptr IndirectFittingModelLegacy::getResultGroup() const { - return m_fitOutput->getLastResultGroup(); -} - -bool IndirectFittingModelLegacy::isPreviousModelSelected() const { - return m_fitFunction && - equivalentFunctions(getFittingFunction(), m_fitFunction); -} - -CompositeFunction_sptr -IndirectFittingModelLegacy::getMultiDomainFunction() const { - return createMultiDomainFunction(getFittingFunction(), numberOfWorkspaces()); -} - -IAlgorithm_sptr IndirectFittingModelLegacy::getFittingAlgorithm() const { - return getFittingAlgorithm(m_fittingMode); -} - -IAlgorithm_sptr -IndirectFittingModelLegacy::getFittingAlgorithm(FittingModeLegacy mode) const { - if (mode == FittingModeLegacy::SEQUENTIAL) - return createSequentialFit(getFittingFunction()); - else - return createSimultaneousFit(getMultiDomainFunction()); -} - -IAlgorithm_sptr -IndirectFittingModelLegacy::getSingleFit(std::size_t dataIndex, - std::size_t spectrum) const { - const auto &fitData = m_fittingData[dataIndex]; - const auto ws = fitData->workspace(); - const auto range = fitData->getRange(spectrum); - const auto exclude = fitData->excludeRegionsVector(spectrum); - - auto fitAlgorithm = simultaneousFitAlgorithm(); - addFitProperties(*fitAlgorithm, getFittingFunction(), getResultXAxisUnit()); - addInputDataToSimultaneousFit(fitAlgorithm, ws, spectrum, range, exclude, ""); - fitAlgorithm->setProperty("OutputWorkspace", - singleFitOutputName(dataIndex, spectrum)); - return fitAlgorithm; -} - -Mantid::API::IAlgorithm_sptr -IndirectFittingModelLegacy::sequentialFitAlgorithm() const { - return AlgorithmManager::Instance().create("QENSFitSequential"); -} - -Mantid::API::IAlgorithm_sptr -IndirectFittingModelLegacy::simultaneousFitAlgorithm() const { - return AlgorithmManager::Instance().create("QENSFitSimultaneous"); -} - -IAlgorithm_sptr -IndirectFittingModelLegacy::createSequentialFit(IFunction_sptr function) const { - const auto input = constructInputString(m_fittingData); - return createSequentialFit(std::move(function), input, - m_fittingData.front().get()); -} - -IAlgorithm_sptr IndirectFittingModelLegacy::createSequentialFit( - const IFunction_sptr &function, const std::string &input, - IndirectFitDataLegacy *initialFitData) const { - auto fitAlgorithm = sequentialFitAlgorithm(); - addFitProperties(*fitAlgorithm, std::move(function), getResultXAxisUnit()); - fitAlgorithm->setProperty("Input", input); - fitAlgorithm->setProperty("OutputWorkspace", sequentialFitOutputName()); - fitAlgorithm->setProperty("PassWSIndexToFunction", true); - fitAlgorithm->setProperty("LogName", getResultLogName()); - - const auto range = initialFitData->getRange(0); - fitAlgorithm->setProperty("StartX", range.first); - fitAlgorithm->setProperty("EndX", range.second); - - auto excludeRegion = initialFitData->excludeRegionsVector(0); - if (!excludeRegion.empty()) - fitAlgorithm->setProperty("Exclude", excludeRegion); - - return fitAlgorithm; -} - -IAlgorithm_sptr IndirectFittingModelLegacy::createSimultaneousFit( - const IFunction_sptr &function) const { - auto fitAlgorithm = simultaneousFitAlgorithm(); - addFitProperties(*fitAlgorithm, std::move(function), getResultXAxisUnit()); - addInputDataToSimultaneousFit(fitAlgorithm, m_fittingData); - fitAlgorithm->setProperty("OutputWorkspace", simultaneousFitOutputName()); - return fitAlgorithm; -} - -IAlgorithm_sptr IndirectFittingModelLegacy::createSimultaneousFitWithEqualRange( - const IFunction_sptr &function) const { - auto fitAlgorithm = simultaneousFitAlgorithm(); - addFitProperties(*fitAlgorithm, std::move(function), getResultXAxisUnit()); - - auto exclude = vectorFromStringLegacy<double>(getExcludeRegion(0, 0)); - addInputDataToSimultaneousFit(fitAlgorithm, m_fittingData, - getFittingRange(0, 0), exclude); - fitAlgorithm->setProperty("OutputWorkspace", simultaneousFitOutputName()); - return fitAlgorithm; -} - -std::string IndirectFittingModelLegacy::createSingleFitOutputName( - const std::string &formatString, std::size_t index, - std::size_t spectrum) const { - if (m_fittingData.size() > index) - return m_fittingData[index]->displayName(formatString, spectrum); - else - throw std::runtime_error("Cannot create a display name for a workspace: " - "the workspace index provided is too large."); -} - -std::string IndirectFittingModelLegacy::getOutputBasename() const { - return cutLastOf(sequentialFitOutputName(), "_Results"); -} - -void IndirectFittingModelLegacy::cleanFailedRun( - const IAlgorithm_sptr &fittingAlgorithm) { - cleanTemporaries(fittingAlgorithm->name(), m_fittingData); -} - -void IndirectFittingModelLegacy::cleanFailedSingleRun( - const IAlgorithm_sptr &fittingAlgorithm, std::size_t index) { - const auto base = - "__" + fittingAlgorithm->name() + "_ws" + std::to_string(index + 1); - removeFromADSIfExists(base); - cleanTemporaries(base + "_0"); -} - -} // namespace IDA -} // namespace CustomInterfaces -} // namespace MantidQt diff --git a/qt/scientific_interfaces/Indirect/IndirectFittingModelLegacy.h b/qt/scientific_interfaces/Indirect/IndirectFittingModelLegacy.h deleted file mode 100644 index d87fee500ee..00000000000 --- a/qt/scientific_interfaces/Indirect/IndirectFittingModelLegacy.h +++ /dev/null @@ -1,226 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2007 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -#pragma once - -#include "IndirectFitDataLegacy.h" -#include "IndirectFitOutputLegacy.h" - -#include "DllConfig.h" -#include "MantidAPI/CompositeFunction.h" -#include "MantidAPI/IAlgorithm.h" - -#include <boost/optional.hpp> -#include <boost/variant.hpp> - -namespace MantidQt { -namespace CustomInterfaces { -namespace IDA { - -enum class FittingModeLegacy { SEQUENTIAL, SIMULTANEOUS }; - -class IndirectFittingModelLegacy; - -struct PrivateFittingDataLegacy { - friend class IndirectFittingModelLegacy; - -public: - PrivateFittingDataLegacy(); - PrivateFittingDataLegacy &operator=(PrivateFittingDataLegacy &&fittingData); - -private: - PrivateFittingDataLegacy(PrivateFittingDataLegacy &&privateData); - PrivateFittingDataLegacy( - std::vector<std::unique_ptr<IndirectFitDataLegacy>> &&data); - std::vector<std::unique_ptr<IndirectFitDataLegacy>> m_data; -}; - -/* - IndirectFittingModelLegacy - Provides methods for specifying and - performing a QENS fit, as well as accessing the results of the fit. -*/ -class MANTIDQT_INDIRECT_DLL IndirectFittingModelLegacy { -public: - IndirectFittingModelLegacy(); - virtual ~IndirectFittingModelLegacy() = default; - - virtual bool hasWorkspace(std::string const &workspaceName) const; - virtual Mantid::API::MatrixWorkspace_sptr - getWorkspace(std::size_t index) const; - SpectraLegacy getSpectra(std::size_t index) const; - virtual std::pair<double, double> getFittingRange(std::size_t dataIndex, - std::size_t spectrum) const; - virtual std::string getExcludeRegion(std::size_t dataIndex, - std::size_t index) const; - virtual std::string createDisplayName(const std::string &formatString, - const std::string &rangeDelimiter, - std::size_t dataIndex) const; - std::string createOutputName(const std::string &formatString, - const std::string &rangeDelimiter, - std::size_t dataIndex) const; - virtual bool isMultiFit() const; - bool isPreviouslyFit(std::size_t dataIndex, std::size_t spectrum) const; - bool hasZeroSpectra(std::size_t dataIndex) const; - virtual boost::optional<std::string> isInvalidFunction() const; - virtual std::size_t numberOfWorkspaces() const; - std::size_t getNumberOfSpectra(std::size_t index) const; - std::vector<std::string> getFitParameterNames() const; - virtual Mantid::API::IFunction_sptr getFittingFunction() const; - - virtual std::vector<std::string> getSpectrumDependentAttributes() const = 0; - - void setFittingData(PrivateFittingDataLegacy &&fittingData); - void setSpectra(const std::string &spectra, std::size_t dataIndex); - void setSpectra(SpectraLegacy &&spectra, std::size_t dataIndex); - void setSpectra(const SpectraLegacy &spectra, std::size_t dataIndex); - virtual void setStartX(double startX, std::size_t dataIndex, - std::size_t spectrum); - virtual void setEndX(double endX, std::size_t dataIndex, - std::size_t spectrum); - virtual void setExcludeRegion(const std::string &exclude, - std::size_t dataIndex, std::size_t spectrum); - - virtual void addWorkspace(const std::string &workspaceName); - void addWorkspace(const std::string &workspaceName, - const std::string &spectra); - void addWorkspace(const std::string &workspaceName, - const SpectraLegacy &spectra); - virtual void addWorkspace(Mantid::API::MatrixWorkspace_sptr workspace, - const SpectraLegacy &spectra); - virtual void removeWorkspace(std::size_t index); - virtual PrivateFittingDataLegacy clearWorkspaces(); - void setFittingMode(FittingModeLegacy mode); - virtual void setFitFunction(Mantid::API::IFunction_sptr function); - virtual void setDefaultParameterValue(const std::string &name, double value, - std::size_t dataIndex); - void addSingleFitOutput(const Mantid::API::IAlgorithm_sptr &fitAlgorithm, - std::size_t index); - virtual void addOutput(Mantid::API::IAlgorithm_sptr fitAlgorithm); - - template <typename F> - void applySpectra(std::size_t index, const F &functor) const; - - FittingModeLegacy getFittingMode() const; - std::unordered_map<std::string, ParameterValueLegacy> - getParameterValues(std::size_t dataIndex, std::size_t spectrum) const; - std::unordered_map<std::string, ParameterValueLegacy> - getFitParameters(std::size_t dataIndex, std::size_t spectrum) const; - std::unordered_map<std::string, ParameterValueLegacy> - getDefaultParameters(std::size_t dataIndex) const; - boost::optional<ResultLocation> getResultLocation(std::size_t dataIndex, - std::size_t spectrum) const; - Mantid::API::WorkspaceGroup_sptr getResultWorkspace() const; - Mantid::API::WorkspaceGroup_sptr getResultGroup() const; - virtual Mantid::API::IAlgorithm_sptr getFittingAlgorithm() const; - Mantid::API::IAlgorithm_sptr getSingleFit(std::size_t dataIndex, - std::size_t spectrum) const; - std::string getOutputBasename() const; - - void cleanFailedRun(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm); - void - cleanFailedSingleRun(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm, - std::size_t index); - -protected: - Mantid::API::IAlgorithm_sptr - getFittingAlgorithm(FittingModeLegacy mode) const; - Mantid::API::IAlgorithm_sptr - createSequentialFit(Mantid::API::IFunction_sptr function) const; - Mantid::API::IAlgorithm_sptr - createSimultaneousFit(const Mantid::API::IFunction_sptr &function) const; - Mantid::API::IAlgorithm_sptr createSimultaneousFitWithEqualRange( - const Mantid::API::IFunction_sptr &function) const; - virtual Mantid::API::CompositeFunction_sptr getMultiDomainFunction() const; - virtual std::unordered_map<std::string, std::string> - mapDefaultParameterNames() const; - std::string createSingleFitOutputName(const std::string &formatString, - std::size_t index, - std::size_t spectrum) const; - void addNewWorkspace(Mantid::API::MatrixWorkspace_sptr workspace, - const SpectraLegacy &spectra); - void removeFittingData(std::size_t index); - -private: - std::vector<std::string> getWorkspaceNames() const; - - void removeWorkspaceFromFittingData(std::size_t const &index); - - Mantid::API::IAlgorithm_sptr - createSequentialFit(const Mantid::API::IFunction_sptr &function, - const std::string &input, - IndirectFitDataLegacy *initialFitData) const; - virtual Mantid::API::IAlgorithm_sptr sequentialFitAlgorithm() const; - virtual Mantid::API::IAlgorithm_sptr simultaneousFitAlgorithm() const; - virtual std::string sequentialFitOutputName() const = 0; - virtual std::string simultaneousFitOutputName() const = 0; - virtual std::string singleFitOutputName(std::size_t index, - std::size_t spectrum) const = 0; - virtual std::unordered_map<std::string, ParameterValueLegacy> - createDefaultParameters(std::size_t index) const; - - virtual std::string getResultXAxisUnit() const; - virtual std::string getResultLogName() const; - - bool isPreviousModelSelected() const; - - virtual IndirectFitOutputLegacy - createFitOutput(Mantid::API::WorkspaceGroup_sptr resultGroup, - Mantid::API::ITableWorkspace_sptr parameterTable, - Mantid::API::WorkspaceGroup_sptr resultWorkspace, - const FitDataIteratorLegacy &fitDataBegin, - const FitDataIteratorLegacy &fitDataEnd) const; - virtual IndirectFitOutputLegacy - createFitOutput(Mantid::API::WorkspaceGroup_sptr resultGroup, - Mantid::API::ITableWorkspace_sptr parameterTable, - Mantid::API::WorkspaceGroup_sptr resultWorkspace, - IndirectFitDataLegacy *fitData, std::size_t spectrum) const; - - void addOutput(const Mantid::API::IAlgorithm_sptr &fitAlgorithm, - const FitDataIteratorLegacy &fitDataBegin, - const FitDataIteratorLegacy &fitDataEnd); - void addOutput(const Mantid::API::WorkspaceGroup_sptr &resultGroup, - const Mantid::API::ITableWorkspace_sptr ¶meterTable, - const Mantid::API::WorkspaceGroup_sptr &resultWorkspace, - const FitDataIteratorLegacy &fitDataBegin, - const FitDataIteratorLegacy &fitDataEnd); - void addOutput(const Mantid::API::WorkspaceGroup_sptr &resultGroup, - const Mantid::API::ITableWorkspace_sptr ¶meterTable, - const Mantid::API::WorkspaceGroup_sptr &resultWorkspace, - IndirectFitDataLegacy *fitData, std::size_t spectrum); - - virtual void addOutput(IndirectFitOutputLegacy *fitOutput, - Mantid::API::WorkspaceGroup_sptr resultGroup, - Mantid::API::ITableWorkspace_sptr parameterTable, - Mantid::API::WorkspaceGroup_sptr resultWorkspace, - const FitDataIteratorLegacy &fitDataBegin, - const FitDataIteratorLegacy &fitDataEnd) const; - virtual void addOutput(IndirectFitOutputLegacy *fitOutput, - Mantid::API::WorkspaceGroup_sptr resultGroup, - Mantid::API::ITableWorkspace_sptr parameterTable, - Mantid::API::WorkspaceGroup_sptr resultWorkspace, - IndirectFitDataLegacy *fitData, - std::size_t spectrum) const; - - std::unique_ptr<IndirectFitOutputLegacy> m_fitOutput; - std::vector<std::unique_ptr<IndirectFitDataLegacy>> m_fittingData; - Mantid::API::IFunction_sptr m_activeFunction; - Mantid::API::IFunction_sptr m_fitFunction; - std::vector<std::unordered_map<std::string, ParameterValueLegacy>> - m_defaultParameters; - bool m_previousModelSelected; - FittingModeLegacy m_fittingMode; -}; - -template <typename F> -void IndirectFittingModelLegacy::applySpectra(std::size_t index, - const F &functor) const { - if (m_fittingData.size() > 0) - m_fittingData[index]->applySpectra(functor); -} - -} // namespace IDA -} // namespace CustomInterfaces -} // namespace MantidQt diff --git a/qt/scientific_interfaces/Indirect/IndirectSpectrumSelectionPresenterLegacy.cpp b/qt/scientific_interfaces/Indirect/IndirectSpectrumSelectionPresenterLegacy.cpp deleted file mode 100644 index 38dec56d705..00000000000 --- a/qt/scientific_interfaces/Indirect/IndirectSpectrumSelectionPresenterLegacy.cpp +++ /dev/null @@ -1,286 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -#include "IndirectSpectrumSelectionPresenterLegacy.h" - -#include "MantidKernel/ArrayProperty.h" -#include "MantidKernel/Strings.h" -#include "MantidQtWidgets/Common/SignalBlocker.h" - -#include <algorithm> -#include <iterator> -#include <sstream> - -#include <boost/numeric/conversion/cast.hpp> - -namespace { -using namespace MantidQt::CustomInterfaces::IDA; -using namespace Mantid::Kernel::Strings; - -struct SetViewSpectra : boost::static_visitor<> { - explicit SetViewSpectra(IndirectSpectrumSelectionViewLegacy *view) - : m_view(view) {} - - void operator()(const std::pair<std::size_t, std::size_t> &spectra) const { - m_view->displaySpectra(static_cast<int>(spectra.first), - static_cast<int>(spectra.second)); - } - - void operator()(const DiscontinuousSpectra<std::size_t> &spectra) const { - m_view->displaySpectra(spectra.getString()); - } - -private: - IndirectSpectrumSelectionViewLegacy *m_view; -}; - -std::string OR(const std::string &lhs, const std::string &rhs) { - return "(" + lhs + "|" + rhs + ")"; -} - -std::string NATURAL_NUMBER(std::size_t digits) { - return OR("0", "[1-9][0-9]{," + std::to_string(digits - 1) + "}"); -} - -std::string constructSpectraString(std::vector<int> const &spectras) { - return joinCompress(spectras.begin(), spectras.end()); -} - -std::vector<std::string> splitStringBy(std::string const &str, - std::string const &delimiter) { - std::vector<std::string> subStrings; - boost::split(subStrings, str, boost::is_any_of(delimiter)); - subStrings.erase(std::remove_if(subStrings.begin(), subStrings.end(), - [](std::string const &subString) { - return subString.empty(); - }), - subStrings.end()); - return subStrings; -} - -std::string getSpectraRange(std::string const &string) { - auto const bounds = splitStringBy(string, "-"); - return std::stoull(bounds[0]) > std::stoull(bounds[1]) - ? bounds[1] + "-" + bounds[0] - : string; -} - -std::string rearrangeSpectraSubString(std::string const &string) { - return string.find("-") != std::string::npos ? getSpectraRange(string) - : string; -} - -// Swaps the two numbers in a spectra range if they go from large to small -std::string rearrangeSpectraRangeStrings(std::string const &string) { - std::string spectraString; - std::vector<std::string> subStrings = splitStringBy(string, ","); - for (auto it = subStrings.begin(); it < subStrings.end(); ++it) { - spectraString += rearrangeSpectraSubString(*it); - spectraString += it != subStrings.end() ? "," : ""; - } - return spectraString; -} - -std::string createSpectraString(std::string string) { - string.erase(std::remove_if(string.begin(), string.end(), isspace), - string.end()); - std::vector<int> spectras = parseRange(rearrangeSpectraRangeStrings(string)); - std::sort(spectras.begin(), spectras.end()); - // Remove duplicate entries - spectras.erase(std::unique(spectras.begin(), spectras.end()), spectras.end()); - return constructSpectraString(spectras); -} - -namespace Regexes { -const std::string EMPTY = "^$"; -const std::string SPACE = "[ ]*"; -const std::string COMMA = SPACE + "," + SPACE; -const std::string MINUS = "\\-"; - -const std::string NUMBER = NATURAL_NUMBER(4); -const std::string NATURAL_RANGE = "(" + NUMBER + MINUS + NUMBER + ")"; -const std::string NATURAL_OR_RANGE = OR(NATURAL_RANGE, NUMBER); -const std::string SPECTRA_LIST = - "(" + NATURAL_OR_RANGE + "(" + COMMA + NATURAL_OR_RANGE + ")*)"; - -const std::string REAL_NUMBER = "(-?" + NUMBER + "(\\.[0-9]*)?)"; -const std::string REAL_RANGE = "(" + REAL_NUMBER + COMMA + REAL_NUMBER + ")"; -const std::string MASK_LIST = - "(" + REAL_RANGE + "(" + COMMA + REAL_RANGE + ")*" + ")|" + EMPTY; -} // namespace Regexes -} // namespace - -namespace MantidQt { -namespace CustomInterfaces { -namespace IDA { - -IndirectSpectrumSelectionPresenterLegacy:: - IndirectSpectrumSelectionPresenterLegacy( - IndirectFittingModelLegacy *model, - IndirectSpectrumSelectionViewLegacy *view) - : QObject(nullptr), m_model(model), m_view(view), m_activeIndex(0), - m_maskIndex(0) { - connect(m_view.get(), SIGNAL(selectedSpectraChanged(const std::string &)), - this, SLOT(updateSpectraList(const std::string &))); - connect(m_view.get(), SIGNAL(selectedSpectraChanged(const std::string &)), - this, SLOT(setMaskSpectraList(const std::string &))); - connect(m_view.get(), - SIGNAL(selectedSpectraChanged(std::size_t, std::size_t)), this, - SLOT(updateSpectraRange(std::size_t, std::size_t))); - connect(m_view.get(), SIGNAL(selectedSpectraChanged(const std::string &)), - this, SLOT(displaySpectraList(const std::string &))); - - connect(m_view.get(), SIGNAL(maskSpectrumChanged(int)), this, - SLOT(setMaskIndex(int))); - connect(m_view.get(), SIGNAL(maskSpectrumChanged(int)), this, - SLOT(displayBinMask())); - connect(m_view.get(), SIGNAL(maskChanged(const std::string &)), this, - SLOT(setBinMask(const std::string &))); - connect(m_view.get(), SIGNAL(maskChanged(const std::string &)), this, - SLOT(displayBinMask())); - connect(m_view.get(), SIGNAL(maskChanged(const std::string &)), this, - SIGNAL(maskChanged(const std::string &))); - - m_view->setSpectraRegex(Regexes::SPECTRA_LIST); - m_view->setMaskBinsRegex(Regexes::MASK_LIST); - m_view->setEnabled(false); -} - -IndirectSpectrumSelectionPresenterLegacy:: - ~IndirectSpectrumSelectionPresenterLegacy() {} - -void IndirectSpectrumSelectionPresenterLegacy::disableView() { - MantidQt::API::SignalBlocker blocker(m_view.get()); - m_view->setDisabled(true); -} - -void IndirectSpectrumSelectionPresenterLegacy::enableView() { - m_view->setEnabled(true); -} - -void IndirectSpectrumSelectionPresenterLegacy::setActiveIndexToZero() { - setActiveModelIndex(0); -} - -void IndirectSpectrumSelectionPresenterLegacy::updateSpectra() { - const auto ws = m_model->getWorkspace(m_activeIndex); - if (ws) { - setSpectraRange(0, ws->getNumberHistograms() - 1); - const auto activeSpectra = m_model->getSpectra(m_activeIndex); - boost::apply_visitor(SetViewSpectra(m_view.get()), activeSpectra); - enableView(); - } else { - m_view->clear(); - disableView(); - } -} - -void IndirectSpectrumSelectionPresenterLegacy::setActiveModelIndex( - std::size_t index) { - m_activeIndex = index; - updateSpectra(); -} - -void IndirectSpectrumSelectionPresenterLegacy::setSpectraRange( - std::size_t minimum, std::size_t maximum) { - int minimumInt = boost::numeric_cast<int>(minimum); - int maximumInt = boost::numeric_cast<int>(maximum); - m_view->setSpectraRange(minimumInt, maximumInt); -} - -void IndirectSpectrumSelectionPresenterLegacy::setModelSpectra( - SpectraLegacy const &spectra) { - try { - m_model->setSpectra(spectra, m_activeIndex); - m_spectraError.clear(); - m_view->hideSpectraErrorLabel(); - m_view->setMaskSelectionEnabled(true); - } catch (const std::runtime_error &ex) { - m_spectraError = ex.what(); - m_view->showSpectraErrorLabel(); - m_view->setMaskSelectionEnabled(false); - } -} - -void IndirectSpectrumSelectionPresenterLegacy::updateSpectraList( - std::string const &spectraList) { - setModelSpectra( - DiscontinuousSpectra<std::size_t>(createSpectraString(spectraList))); - emit spectraChanged(m_activeIndex); -} - -void IndirectSpectrumSelectionPresenterLegacy::updateSpectraRange( - std::size_t minimum, std::size_t maximum) { - setModelSpectra(std::make_pair(minimum, maximum)); - emit spectraChanged(m_activeIndex); -} - -void IndirectSpectrumSelectionPresenterLegacy::setMaskSpectraList( - std::string const &spectra) { - if (m_spectraError.empty()) - m_view->setMaskSpectraList(vectorFromStringLegacy<std::size_t>(spectra)); - else - m_view->setMaskSpectraList({}); -} - -void IndirectSpectrumSelectionPresenterLegacy::displaySpectraList( - std::string const &spectra) { - m_view->displaySpectra(createSpectraString(spectra)); -} - -void IndirectSpectrumSelectionPresenterLegacy::setBinMask( - std::string const &maskString) { - auto validator = validateMaskBinsString(); - - if (validator.isAllInputValid()) { - m_model->setExcludeRegion(maskString, m_activeIndex, m_maskIndex); - m_view->hideMaskBinErrorLabel(); - } else { - m_view->showMaskBinErrorLabel(); - emit invalidMaskBinsString(validator.generateErrorMessage()); - } -} - -void IndirectSpectrumSelectionPresenterLegacy::setMaskIndex(int index) { - if (index >= 0) - m_maskIndex = boost::numeric_cast<std::size_t>(index); -} - -void IndirectSpectrumSelectionPresenterLegacy::displayBinMask() { - m_view->setMaskString(m_model->getExcludeRegion(m_activeIndex, m_maskIndex)); -} - -UserInputValidator &IndirectSpectrumSelectionPresenterLegacy::validate( - UserInputValidator &validator) { - validator = validateSpectraString(validator); - return m_view->validateMaskBinsString(validator); -} - -UserInputValidator -IndirectSpectrumSelectionPresenterLegacy::validateSpectraString() { - UserInputValidator validator; - return validateSpectraString(validator); -} - -UserInputValidator & -IndirectSpectrumSelectionPresenterLegacy::validateSpectraString( - UserInputValidator &validator) { - validator = m_view->validateSpectraString(validator); - - if (!m_spectraError.empty()) - validator.addErrorMessage(QString::fromStdString(m_spectraError)); - return validator; -} - -UserInputValidator -IndirectSpectrumSelectionPresenterLegacy::validateMaskBinsString() { - UserInputValidator uiv; - return m_view->validateMaskBinsString(uiv); -} - -} // namespace IDA -} // namespace CustomInterfaces -} // namespace MantidQt diff --git a/qt/scientific_interfaces/Indirect/IndirectSpectrumSelectionPresenterLegacy.h b/qt/scientific_interfaces/Indirect/IndirectSpectrumSelectionPresenterLegacy.h deleted file mode 100644 index cebb27e3dc3..00000000000 --- a/qt/scientific_interfaces/Indirect/IndirectSpectrumSelectionPresenterLegacy.h +++ /dev/null @@ -1,74 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2013 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -#pragma once - -#include "IndirectFittingModelLegacy.h" -#include "IndirectSpectrumSelectionViewLegacy.h" - -#include "DllConfig.h" -#include "MantidQtWidgets/Common/UserInputValidator.h" - -#include <boost/optional.hpp> -#include <boost/variant.hpp> - -#include <unordered_map> -#include <vector> - -namespace MantidQt { -namespace CustomInterfaces { -namespace IDA { - -class MANTIDQT_INDIRECT_DLL IndirectSpectrumSelectionPresenterLegacy - : public QObject { - Q_OBJECT -public: - IndirectSpectrumSelectionPresenterLegacy( - IndirectFittingModelLegacy *model, - IndirectSpectrumSelectionViewLegacy *view); - ~IndirectSpectrumSelectionPresenterLegacy() override; - UserInputValidator &validate(UserInputValidator &validator); - -signals: - void spectraChanged(std::size_t /*_t1*/); - void maskChanged(std::string const & /*_t1*/); - void invalidSpectraString(QString const &errorMessage); - void invalidMaskBinsString(QString const &errorMessage); - -public slots: - void setActiveModelIndex(std::size_t index); - void setActiveIndexToZero(); - void updateSpectra(); - void displayBinMask(); - void disableView(); - void enableView(); - -private slots: - void setBinMask(std::string const &maskString); - void setMaskSpectraList(std::string const &spectraList); - void updateSpectraList(std::string const &spectraList); - void updateSpectraRange(std::size_t minimum, std::size_t maximum); - void displaySpectraList(std::string const &spectra); - void setMaskIndex(int index); - -private: - void setSpectraRange(std::size_t minimum, std::size_t maximum); - void setModelSpectra(SpectraLegacy const &spectra); - - UserInputValidator validateSpectraString(); - UserInputValidator &validateSpectraString(UserInputValidator &validator); - UserInputValidator validateMaskBinsString(); - - IndirectFittingModelLegacy *m_model; - std::unique_ptr<IndirectSpectrumSelectionViewLegacy> m_view; - std::size_t m_activeIndex; - std::size_t m_maskIndex; - std::string m_spectraError; -}; - -} // namespace IDA -} // namespace CustomInterfaces -} // namespace MantidQt diff --git a/qt/scientific_interfaces/Indirect/IndirectSpectrumSelectionViewLegacy.cpp b/qt/scientific_interfaces/Indirect/IndirectSpectrumSelectionViewLegacy.cpp deleted file mode 100644 index f756eebb155..00000000000 --- a/qt/scientific_interfaces/Indirect/IndirectSpectrumSelectionViewLegacy.cpp +++ /dev/null @@ -1,285 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -#include "IndirectSpectrumSelectionViewLegacy.h" - -#include "MantidQtWidgets/Common/SignalBlocker.h" - -#include <QRegExpValidator> - -#include <boost/numeric/conversion/cast.hpp> - -namespace MantidQt { -namespace CustomInterfaces { -namespace IDA { - -IndirectSpectrumSelectionViewLegacy::IndirectSpectrumSelectionViewLegacy( - QWidget *parent) - : API::MantidWidget(parent), m_selector(new Ui::IndirectSpectrumSelector) { - m_selector->setupUi(this); - - connect(m_selector->cbMaskSpectrum, SIGNAL(currentIndexChanged(int)), this, - SLOT(enableMaskLineEdit(int))); - - connect(m_selector->spMaximumSpectrum, SIGNAL(valueChanged(int)), this, - SLOT(setSpectraRangeMaxiMin(int))); - connect(m_selector->spMinimumSpectrum, SIGNAL(valueChanged(int)), this, - SLOT(setSpectraRangeMiniMax(int))); - - connect(m_selector->spMaximumSpectrum, SIGNAL(valueChanged(int)), this, - SLOT(emitSpectraRangeChanged())); - connect(m_selector->spMinimumSpectrum, SIGNAL(valueChanged(int)), this, - SLOT(emitSpectraRangeChanged())); - connect(m_selector->leSpectra, SIGNAL(editingFinished()), this, - SLOT(emitSpectraStringChanged())); - - connect(m_selector->spMaskSpectrum, SIGNAL(valueChanged(int)), this, - SIGNAL(maskSpectrumChanged(int))); - connect(m_selector->cbMaskSpectrum, - SIGNAL(currentIndexChanged(const QString &)), this, - SLOT(emitMaskSpectrumChanged(const QString &))); - connect(m_selector->leMaskBins, SIGNAL(editingFinished()), this, - SLOT(emitMaskChanged())); - - connect(m_selector->cbSelectionMode, SIGNAL(currentIndexChanged(int)), this, - SLOT(emitSpectraChanged(int))); - connect(m_selector->cbSelectionMode, SIGNAL(currentIndexChanged(int)), this, - SLOT(clearMaskString())); -} - -IndirectSpectrumSelectionViewLegacy::~IndirectSpectrumSelectionViewLegacy() {} - -SpectrumSelectionModeLegacy -IndirectSpectrumSelectionViewLegacy::selectionMode() const { - return static_cast<SpectrumSelectionModeLegacy>( - m_selector->swSpectraSelection->currentIndex()); -} - -std::size_t IndirectSpectrumSelectionViewLegacy::minimumSpectrum() const { - return boost::numeric_cast<std::size_t>( - m_selector->spMinimumSpectrum->value()); -} - -std::size_t IndirectSpectrumSelectionViewLegacy::maximumSpectrum() const { - return boost::numeric_cast<std::size_t>( - m_selector->spMaximumSpectrum->value()); -} - -std::string IndirectSpectrumSelectionViewLegacy::spectraString() const { - return m_selector->leSpectra->text().toStdString(); -} - -std::string IndirectSpectrumSelectionViewLegacy::maskString() const { - return m_selector->leMaskBins->text().toStdString(); -} - -void IndirectSpectrumSelectionViewLegacy::displaySpectra( - const std::string &spectraString) { - setSpectraString(spectraString); - m_selector->cbSelectionMode->setCurrentIndex( - static_cast<int>(SpectrumSelectionModeLegacy::STRING)); -} - -void IndirectSpectrumSelectionViewLegacy::displaySpectra(int minimum, - int maximum) { - setMinimumSpectrum(minimum); - setMaximumSpectrum(maximum); - m_selector->cbSelectionMode->setCurrentIndex( - static_cast<int>(SpectrumSelectionModeLegacy::RANGE)); -} - -void IndirectSpectrumSelectionViewLegacy::setSpectraRange(int minimum, - int maximum) { - setSpectraRangeMinimum(minimum); - setSpectraRangeMaximum(maximum); -} - -void IndirectSpectrumSelectionViewLegacy::setSpectraRangeMinimum(int minimum) { - MantidQt::API::SignalBlocker blocker(m_selector->spMinimumSpectrum); - m_selector->spMinimumSpectrum->setMinimum(minimum); - setSpectraRangeMiniMax(minimum); -} - -void IndirectSpectrumSelectionViewLegacy::setSpectraRangeMaximum(int maximum) { - MantidQt::API::SignalBlocker blocker(m_selector->spMaximumSpectrum); - m_selector->spMaximumSpectrum->setMaximum(maximum); - setSpectraRangeMaxiMin(maximum); -} - -void IndirectSpectrumSelectionViewLegacy::setMaskSpectraList( - const std::vector<std::size_t> &spectra) { - m_selector->cbMaskSpectrum->clear(); - for (const auto &spectrum : spectra) - m_selector->cbMaskSpectrum->addItem(QString::number(spectrum)); -} - -void IndirectSpectrumSelectionViewLegacy::setMaskSelectionEnabled( - bool enabled) { - m_selector->cbMaskSpectrum->setEnabled(enabled); - m_selector->lbMaskSpectrum->setEnabled(enabled); - m_selector->leMaskBins->setEnabled(enabled); -} - -void IndirectSpectrumSelectionViewLegacy::clear() { - m_selector->leSpectra->clear(); - m_selector->leMaskBins->clear(); - m_selector->cbMaskSpectrum->clear(); - setSpectraRange(0, 0); -} - -void IndirectSpectrumSelectionViewLegacy::setSpectraRegex( - const std::string ®ex) { - m_selector->leSpectra->setValidator( - createValidator(QString::fromStdString(regex))); -} - -void IndirectSpectrumSelectionViewLegacy::setMaskBinsRegex( - const std::string ®ex) { - m_selector->leMaskBins->setValidator( - createValidator(QString::fromStdString(regex))); -} - -void IndirectSpectrumSelectionViewLegacy::setMinimumSpectrum( - std::size_t spectrum) { - MantidQt::API::SignalBlocker blocker(m_selector->spMinimumSpectrum); - m_selector->spMinimumSpectrum->setValue(boost::numeric_cast<int>(spectrum)); -} - -void IndirectSpectrumSelectionViewLegacy::setMaximumSpectrum( - std::size_t spectrum) { - MantidQt::API::SignalBlocker blocker(m_selector->spMaximumSpectrum); - m_selector->spMaximumSpectrum->setValue(boost::numeric_cast<int>(spectrum)); -} - -void IndirectSpectrumSelectionViewLegacy::setMaskSpectrum( - std::size_t spectrum) { - MantidQt::API::SignalBlocker blocker(m_selector->spMaskSpectrum); - m_selector->spMaskSpectrum->setValue(boost::numeric_cast<int>(spectrum)); -} - -void IndirectSpectrumSelectionViewLegacy::setSpectraString( - const std::string &spectraString) { - MantidQt::API::SignalBlocker blocker(m_selector->leSpectra); - m_selector->leSpectra->setText(QString::fromStdString(spectraString)); -} - -void IndirectSpectrumSelectionViewLegacy::setMaskString( - const std::string &maskString) { - MantidQt::API::SignalBlocker blocker(m_selector->leMaskBins); - m_selector->leMaskBins->setText(QString::fromStdString(maskString)); -} - -void IndirectSpectrumSelectionViewLegacy::setSpectraRangeMaxiMin(int value) { - MantidQt::API::SignalBlocker blocker(m_selector->spMinimumSpectrum); - m_selector->spMinimumSpectrum->setMaximum(value); - m_selector->spMaskSpectrum->setMaximum(value); -} - -void IndirectSpectrumSelectionViewLegacy::setSpectraRangeMiniMax(int value) { - MantidQt::API::SignalBlocker blocker(m_selector->spMaximumSpectrum); - m_selector->spMaximumSpectrum->setMinimum(value); - m_selector->spMaskSpectrum->setMinimum(value); -} - -void IndirectSpectrumSelectionViewLegacy::showSpectraErrorLabel() { - UserInputValidator().setErrorLabel(m_selector->lbSpectraError, false); -} - -void IndirectSpectrumSelectionViewLegacy::showMaskBinErrorLabel() { - UserInputValidator().setErrorLabel(m_selector->lbMaskBinsError, false); -} - -void IndirectSpectrumSelectionViewLegacy::hideSpectraErrorLabel() { - m_selector->lbSpectraError->setText(""); - m_selector->lbSpectraError->setVisible(false); -} - -void IndirectSpectrumSelectionViewLegacy::hideMaskBinErrorLabel() { - m_selector->lbMaskBinsError->setText(""); - m_selector->lbMaskBinsError->setVisible(false); -} - -QValidator * -IndirectSpectrumSelectionViewLegacy::createValidator(const QString ®ex) { - return new QRegExpValidator(QRegExp(regex), this); -} - -UserInputValidator &IndirectSpectrumSelectionViewLegacy::validateSpectraString( - UserInputValidator &uiv) const { - if (selectionMode() == SpectrumSelectionModeLegacy::STRING) - uiv.checkFieldIsValid("Spectra", m_selector->leSpectra, - m_selector->lbSpectraError); - return uiv; -} - -UserInputValidator &IndirectSpectrumSelectionViewLegacy::validateMaskBinsString( - UserInputValidator &uiv) const { - uiv.checkFieldIsValid("Mask Bins", m_selector->leMaskBins, - m_selector->lbMaskBinsError); - return uiv; -} - -void IndirectSpectrumSelectionViewLegacy::hideSpectrumSelector() { - m_selector->lbSelectionMode->hide(); - m_selector->cbSelectionMode->hide(); - m_selector->swSpectraSelection->hide(); - m_selector->lbColon->hide(); -} - -void IndirectSpectrumSelectionViewLegacy::showSpectrumSelector() { - m_selector->lbSelectionMode->show(); - m_selector->cbSelectionMode->show(); - m_selector->swSpectraSelection->show(); - m_selector->lbColon->show(); -} - -void IndirectSpectrumSelectionViewLegacy::hideMaskSpectrumSelector() { - m_selector->swMaskSpectrumSelection->hide(); -} - -void IndirectSpectrumSelectionViewLegacy::showMaskSpectrumSelector() { - m_selector->swMaskSpectrumSelection->show(); -} - -void IndirectSpectrumSelectionViewLegacy::clearMaskString() { - m_selector->leMaskBins->clear(); -} - -void IndirectSpectrumSelectionViewLegacy::enableMaskLineEdit(int doEnable) { - if (doEnable >= 0 || selectionMode() == SpectrumSelectionModeLegacy::RANGE) - m_selector->leMaskBins->setEnabled(true); - else - m_selector->leMaskBins->setEnabled(false); -} - -void IndirectSpectrumSelectionViewLegacy::emitSpectraChanged(int modeIndex) { - const auto mode = static_cast<SpectrumSelectionModeLegacy>(modeIndex); - if (mode == SpectrumSelectionModeLegacy::RANGE) - emitSpectraRangeChanged(); - else - emitSpectraStringChanged(); -} - -void IndirectSpectrumSelectionViewLegacy::emitSpectraRangeChanged() { - emit selectedSpectraChanged(minimumSpectrum(), maximumSpectrum()); -} - -void IndirectSpectrumSelectionViewLegacy::emitSpectraStringChanged() { - emit selectedSpectraChanged(m_selector->leSpectra->text().toStdString()); -} - -void IndirectSpectrumSelectionViewLegacy::emitMaskChanged() { - emit maskChanged(m_selector->leMaskBins->text().toStdString()); -} - -void IndirectSpectrumSelectionViewLegacy::emitMaskSpectrumChanged( - const QString &spectrum) { - emit maskSpectrumChanged(spectrum.toInt()); -} - -} // namespace IDA -} // namespace CustomInterfaces -} // namespace MantidQt diff --git a/qt/scientific_interfaces/Indirect/IndirectSpectrumSelectionViewLegacy.h b/qt/scientific_interfaces/Indirect/IndirectSpectrumSelectionViewLegacy.h deleted file mode 100644 index 32dcbf9301c..00000000000 --- a/qt/scientific_interfaces/Indirect/IndirectSpectrumSelectionViewLegacy.h +++ /dev/null @@ -1,102 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2013 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -#pragma once - -#include "ui_IndirectSpectrumSelector.h" - -#include "DllConfig.h" -#include "MantidKernel/System.h" -#include "MantidQtWidgets/Common/MantidWidget.h" -#include "MantidQtWidgets/Common/UserInputValidator.h" - -#include <cstddef> - -namespace MantidQt { -namespace CustomInterfaces { -namespace IDA { - -enum class SpectrumSelectionModeLegacy { RANGE, STRING }; - -class MANTIDQT_INDIRECT_DLL IndirectSpectrumSelectionViewLegacy - : public API::MantidWidget { - Q_OBJECT - -public: - IndirectSpectrumSelectionViewLegacy(QWidget *parent = nullptr); - virtual ~IndirectSpectrumSelectionViewLegacy() override; - - SpectrumSelectionModeLegacy selectionMode() const; - - virtual std::size_t minimumSpectrum() const; - virtual std::size_t maximumSpectrum() const; - - virtual std::string spectraString() const; - virtual std::string maskString() const; - - virtual void displaySpectra(const std::string &spectraString); - virtual void displaySpectra(int minimum, int maximum); - - virtual void setSpectraRange(int minimum, int maximum); - - void setSpectraRegex(const std::string ®ex); - void setMaskBinsRegex(const std::string ®ex); - - UserInputValidator &validateSpectraString(UserInputValidator &uiv) const; - UserInputValidator &validateMaskBinsString(UserInputValidator &uiv) const; - - virtual void showSpectraErrorLabel(); - void showMaskBinErrorLabel(); - virtual void hideSpectraErrorLabel(); - void hideMaskBinErrorLabel(); - - virtual void setMaskSelectionEnabled(bool enabled); - virtual void clear(); - -public slots: - virtual void setMinimumSpectrum(std::size_t spectrum); - virtual void setMaximumSpectrum(std::size_t spectrum); - void setMaskSpectrum(std::size_t spectrum); - - virtual void setSpectraString(const std::string &spectraString); - virtual void setMaskString(const std::string &maskString); - void setMaskSpectraList(const std::vector<std::size_t> &maskSpectra); - - void hideSpectrumSelector(); - void showSpectrumSelector(); - void hideMaskSpectrumSelector(); - void showMaskSpectrumSelector(); - - void clearMaskString(); - -signals: - void selectedSpectraChanged(const std::string & /*_t1*/); - void selectedSpectraChanged(std::size_t /*_t1*/, std::size_t /*_t2*/); - void maskSpectrumChanged(int /*_t1*/); - void maskChanged(const std::string & /*_t1*/); - -private slots: - void emitMaskChanged(); - void emitMaskSpectrumChanged(const QString &spectrum); - void emitSpectraChanged(int modeIndex); - void emitSpectraStringChanged(); - void emitSpectraRangeChanged(); - void setSpectraRangeMiniMax(int value); - void setSpectraRangeMaxiMin(int value); - void enableMaskLineEdit(int doEnable); - -private: - void setSpectraRangeMinimum(int minimum); - void setSpectraRangeMaximum(int maximum); - void displaySpectraList(); - QValidator *createValidator(const QString ®ex); - - std::unique_ptr<Ui::IndirectSpectrumSelector> m_selector; -}; - -} // namespace IDA -} // namespace CustomInterfaces -} // namespace MantidQt diff --git a/qt/scientific_interfaces/Indirect/test/IndirectFitOutputTest.h b/qt/scientific_interfaces/Indirect/test/IndirectFitOutputTest.h index 6f85e114e5f..ab822538260 100644 --- a/qt/scientific_interfaces/Indirect/test/IndirectFitOutputTest.h +++ b/qt/scientific_interfaces/Indirect/test/IndirectFitOutputTest.h @@ -90,7 +90,7 @@ std::unique_ptr<IndirectFitOutput> createFitOutput(const WorkspaceGroup_sptr &resultGroup, const ITableWorkspace_sptr ¶meterTable, const WorkspaceGroup_sptr &resultWorkspace, - IndirectFitDataLegacy *fitData, std::size_t spectrum) { + IndirectFitData *fitData, std::size_t spectrum) { return std::make_unique<IndirectFitOutput>( resultGroup, parameterTable, resultWorkspace, fitData, spectrum); } diff --git a/qt/scientific_interfaces/Indirect/test/IndirectFitPlotModelTest.h b/qt/scientific_interfaces/Indirect/test/IndirectFitPlotModelTest.h index 554f781f58f..d8519f58a8a 100644 --- a/qt/scientific_interfaces/Indirect/test/IndirectFitPlotModelTest.h +++ b/qt/scientific_interfaces/Indirect/test/IndirectFitPlotModelTest.h @@ -139,52 +139,42 @@ IAlgorithm_sptr setupFitAlgorithm(const MatrixWorkspace_sptr &workspace, return alg; } -<<<<<<< HEAD -IAlgorithm_sptr getSetupFitAlgorithm(IndirectFittingModelLegacy *model, +IAlgorithm_sptr getSetupFitAlgorithm(IndirectFittingModel *model, const MatrixWorkspace_sptr &workspace, std::string const &workspaceName) { - setFittingFunction(model, getFittingFunctionString(workspaceName), true); + setFittingFunction(model, getFittingFunctionString(workspaceName), true, 20); auto alg = setupFitAlgorithm(std::move(workspace), getFittingFunctionString(workspaceName)); - == == == = IAlgorithm_sptr getSetupFitAlgorithm( - IndirectFittingModel * model, MatrixWorkspace_sptr workspace, - std::string const &workspaceName) { - setFittingFunction(model, getFittingFunctionString(workspaceName), true, - 20); - auto alg = - setupFitAlgorithm(workspace, getFittingFunctionString(workspaceName)); ->>>>>>> Updated IndirectFitPlotModelTest to work with new base classes Re #28057 - return alg; - } + return alg; +} - IAlgorithm_sptr getExecutedFitAlgorithm(IndirectFittingModel * model, - MatrixWorkspace_sptr workspace, - std::string const &workspaceName) { - auto const alg = - getSetupFitAlgorithm(model, std::move(workspace), workspaceName); - alg->execute(); - return alg; - } +IAlgorithm_sptr getExecutedFitAlgorithm(IndirectFittingModel *model, + MatrixWorkspace_sptr workspace, + std::string const &workspaceName) { + auto const alg = + getSetupFitAlgorithm(model, std::move(workspace), workspaceName); + alg->execute(); + return alg; +} - IndirectFittingModel *getModelWithFitOutputData() { - auto model = createModelWithSingleInstrumentWorkspace("__ConvFit", 6, 5); - auto const modelWorkspace = model->getWorkspace(TableDatasetIndex{0}); +IndirectFittingModel *getModelWithFitOutputData() { + auto model = createModelWithSingleInstrumentWorkspace("__ConvFit", 6, 5); + auto const modelWorkspace = model->getWorkspace(TableDatasetIndex{0}); - auto const alg = - getExecutedFitAlgorithm(model, modelWorkspace, "__ConvFit"); - model->addOutput(alg); - return model; - } + auto const alg = getExecutedFitAlgorithm(model, modelWorkspace, "__ConvFit"); + model->addOutput(alg); + return model; +} - IndirectFitPlotModel getFitPlotModel(bool setFitFunction = true) { - return IndirectFitPlotModel(createModelWithMultipleWorkspaces( - 10, setFitFunction, - std::vector<std::string>({"Workspace1", "Workspace2"}))); - } +IndirectFitPlotModel getFitPlotModel(bool setFitFunction = true) { + return IndirectFitPlotModel(createModelWithMultipleWorkspaces( + 10, setFitFunction, + std::vector<std::string>({"Workspace1", "Workspace2"}))); +} - IndirectFitPlotModel getFitPlotModelWithFitData() { - return IndirectFitPlotModel(getModelWithFitOutputData()); - } +IndirectFitPlotModel getFitPlotModelWithFitData() { + return IndirectFitPlotModel(getModelWithFitOutputData()); +} } // namespace diff --git a/qt/scientific_interfaces/Indirect/test/IndirectFitPlotPresenterTest.h b/qt/scientific_interfaces/Indirect/test/IndirectFitPlotPresenterTest.h index 7faa1c74fee..327acc9080c 100644 --- a/qt/scientific_interfaces/Indirect/test/IndirectFitPlotPresenterTest.h +++ b/qt/scientific_interfaces/Indirect/test/IndirectFitPlotPresenterTest.h @@ -38,9 +38,10 @@ getFunctionWithWorkspaceName(std::string const &workspaceName) { "name=LinearBackground,A0=0,A1=0,ties=(A0=0.000000,A1=0.0);" "(composite=Convolution,FixResolution=true,NumDeriv=true;" "name=Resolution,Workspace=" + - workspaceName + ",WorkspaceIndex=0;((composite=ProductFunction,NumDeriv=" - "false;name=Lorentzian,Amplitude=1,PeakCentre=0,FWHM=0." - "0175)))"; + workspaceName + + ",WorkspaceIndex=0;((composite=ProductFunction,NumDeriv=" + "false;name=Lorentzian,Amplitude=1,PeakCentre=0,FWHM=0." + "0175)))"; return getFunction(functionString); } diff --git a/qt/scientific_interfaces/Indirect/test/IndirectSpectrumSelectionPresenterTest.h b/qt/scientific_interfaces/Indirect/test/IndirectSpectrumSelectionPresenterTest.h index 0c83fe194b1..d7e254baa3b 100644 --- a/qt/scientific_interfaces/Indirect/test/IndirectSpectrumSelectionPresenterTest.h +++ b/qt/scientific_interfaces/Indirect/test/IndirectSpectrumSelectionPresenterTest.h @@ -72,7 +72,8 @@ public: MOCK_CONST_METHOD0(maskString, std::string()); MOCK_METHOD1(displaySpectra, void(std::string const &spectraString)); - MOCK_METHOD1(displaySpectra, void(std::pair<IDA::WorkspaceIndex, IDA::WorkspaceIndex>)); + MOCK_METHOD1(displaySpectra, + void(std::pair<IDA::WorkspaceIndex, IDA::WorkspaceIndex>)); MOCK_METHOD2(setSpectraRange, void(IDA::WorkspaceIndex minimum, IDA::WorkspaceIndex maximum)); @@ -97,8 +98,8 @@ public: class MockIndirectSpectrumSelectionModel : public IndirectFittingModel { public: /// Public methods - MOCK_CONST_METHOD2(getExcludeRegion, - std::string(TableDatasetIndex dataIndex, IDA::WorkspaceIndex index)); + MOCK_CONST_METHOD2(getExcludeRegion, std::string(TableDatasetIndex dataIndex, + IDA::WorkspaceIndex index)); MOCK_CONST_METHOD0(isMultiFit, bool()); private: @@ -175,14 +176,15 @@ public: test_that_invoking_a_presenter_method_will_call_the_relevant_methods_in_the_model_and_view() { std::string const excludeRegion("0-1"); - ON_CALL(*m_model, getExcludeRegion(TableDatasetIndex(0), IDA::WorkspaceIndex(0))) + ON_CALL(*m_model, + getExcludeRegion(TableDatasetIndex(0), IDA::WorkspaceIndex(0))) .WillByDefault(Return(excludeRegion)); Expectation getMask = EXPECT_CALL(*m_model, getExcludeRegion(TableDatasetIndex(0), IDA::WorkspaceIndex(0))) - .Times(1) - .WillOnce(Return(excludeRegion)); + .Times(1) + .WillOnce(Return(excludeRegion)); EXPECT_CALL(*m_view, setMaskString(excludeRegion)).Times(1).After(getMask); m_presenter->displayBinMask(); @@ -229,7 +231,8 @@ public: IDA::WorkspaceIndex const maskSpectrum(0); Expectation getMask = - EXPECT_CALL(*m_model, getExcludeRegion(TableDatasetIndex(0), maskSpectrum)) + EXPECT_CALL(*m_model, + getExcludeRegion(TableDatasetIndex(0), maskSpectrum)) .Times(1) .WillOnce(Return("0")); EXPECT_CALL(*m_view, setMaskString("0")).Times(1).After(getMask); @@ -317,11 +320,12 @@ public: IDA::WorkspaceIndex const minSpectrum(2); IDA::WorkspaceIndex const maxSpectrum(5); - EXPECT_CALL(*m_view, displaySpectra(std::make_pair(minSpectrum, maxSpectrum))).Times(1); + EXPECT_CALL(*m_view, + displaySpectra(std::make_pair(minSpectrum, maxSpectrum))) + .Times(1); EXPECT_CALL(*m_view, spectraString()).Times(1).WillOnce(Return("2-5")); - m_view->displaySpectra( - std::make_pair(minSpectrum, maxSpectrum)); + m_view->displaySpectra(std::make_pair(minSpectrum, maxSpectrum)); m_view->spectraString(); } -- GitLab