From 84cf1a2499ecd6d43a5501f9cc0c98704b1062de Mon Sep 17 00:00:00 2001 From: Applin Date: Fri, 20 Sep 2024 10:17:44 +0100 Subject: [PATCH 1/5] Move ADS instantiation to annonymous namespace --- .../Inelastic/Processor/SymmetrisePresenter.cpp | 7 ++++--- .../Inelastic/Processor/SymmetrisePresenter.h | 1 - qt/widgets/common/src/DataSelector.cpp | 15 +++++---------- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/qt/scientific_interfaces/Inelastic/Processor/SymmetrisePresenter.cpp b/qt/scientific_interfaces/Inelastic/Processor/SymmetrisePresenter.cpp index 153fbf3f1eb6..907fb89120db 100644 --- a/qt/scientific_interfaces/Inelastic/Processor/SymmetrisePresenter.cpp +++ b/qt/scientific_interfaces/Inelastic/Processor/SymmetrisePresenter.cpp @@ -18,6 +18,8 @@ using namespace MantidQt::CustomInterfaces::InterfaceUtils; namespace { Mantid::Kernel::Logger g_log("SymmetrisePresenter"); + +auto &ads = Mantid::API::AnalysisDataService::Instance(); } // namespace namespace MantidQt { @@ -29,8 +31,7 @@ namespace CustomInterfaces { SymmetrisePresenter::SymmetrisePresenter(QWidget *parent, std::unique_ptr algorithmRunner, ISymmetriseView *view, std::unique_ptr model) - : DataProcessor(parent, std::move(algorithmRunner)), m_adsInstance(Mantid::API::AnalysisDataService::Instance()), - m_view(view), m_model(std::move(model)), m_isPreview(false) { + : DataProcessor(parent, std::move(algorithmRunner)), m_view(view), m_model(std::move(model)), m_isPreview(false) { m_view->subscribePresenter(this); setRunWidgetPresenter(std::make_unique(this, m_view->getRunView())); setOutputPlotOptionsPresenter( @@ -57,7 +58,7 @@ void SymmetrisePresenter::handleRun() { // Return if no data has been loaded auto const dataWorkspaceName = m_view->getDataName(); - if (dataWorkspaceName.empty()) + if (!ads.doesExist(dataWorkspaceName)) return; // Return if E range is incorrect if (!m_view->verifyERange(dataWorkspaceName)) diff --git a/qt/scientific_interfaces/Inelastic/Processor/SymmetrisePresenter.h b/qt/scientific_interfaces/Inelastic/Processor/SymmetrisePresenter.h index 5d0ff0e50380..c25e2435a5b7 100644 --- a/qt/scientific_interfaces/Inelastic/Processor/SymmetrisePresenter.h +++ b/qt/scientific_interfaces/Inelastic/Processor/SymmetrisePresenter.h @@ -78,7 +78,6 @@ class MANTIDQT_INELASTIC_DLL SymmetrisePresenter : public DataProcessor, void setFileExtensionsByName(bool filter) override; void setLoadHistory(bool doLoadHistory) override; - Mantid::API::AnalysisDataServiceImpl &m_adsInstance; ISymmetriseView *m_view; std::unique_ptr m_model; // wether batch algorunner is running preview or run buttons diff --git a/qt/widgets/common/src/DataSelector.cpp b/qt/widgets/common/src/DataSelector.cpp index fbe8a57143bb..818678211b7d 100644 --- a/qt/widgets/common/src/DataSelector.cpp +++ b/qt/widgets/common/src/DataSelector.cpp @@ -23,10 +23,7 @@ using namespace Mantid::API; namespace { - -bool doesExistInADS(std::string const &workspaceName) { - return AnalysisDataService::Instance().doesExist(workspaceName); -} +auto &ads = AnalysisDataService::Instance(); std::string cutLastOf(const std::string &str, const std::string &delimiter) { const auto cutIndex = str.rfind(delimiter); @@ -50,7 +47,6 @@ std::string loadAlgName(const std::string &filePath) { } void makeGroup(std::string const &workspaceName) { - auto const &ads = AnalysisDataService::Instance(); if (!ads.retrieveWS(workspaceName)) { const auto groupAlg = AlgorithmManager::Instance().createUnmanaged("GroupWorkspaces"); groupAlg->initialize(); @@ -167,14 +163,14 @@ bool DataSelector::isValid() { auto const wsName = getCurrentDataName().toStdString(); isValid = !wsName.empty(); - if (isValid && !doesExistInADS(wsName)) { + if (isValid && !ads.doesExist(wsName)) { // attempt to reload if we can // don't use algorithm runner because we need to know instantly. auto const filepath = m_uiForm.rfFileInput->getUserInput().toString().toStdString(); if (!filepath.empty()) executeLoadAlgorithm(filepath, wsName); - isValid = doesExistInADS(wsName); + isValid = ads.doesExist(wsName); if (!isValid) { m_uiForm.rfFileInput->setFileProblem("The specified workspace is " @@ -182,7 +178,6 @@ bool DataSelector::isValid() { "service"); } } else { - auto &ads = AnalysisDataService::Instance(); if (!ads.doesExist(wsName)) { return isValid; } @@ -457,7 +452,7 @@ void DataSelector::dropEvent(QDropEvent *de) { auto const dragData = mimeData->text().toStdString(); - if (de->mimeData() && doesExistInADS(dragData)) { + if (de->mimeData() && ads.doesExist(dragData)) { m_uiForm.wsWorkspaceInput->dropEvent(de); if (de->dropAction() == before_action) { setWorkspaceSelectorIndex(mimeData->text()); @@ -473,7 +468,7 @@ void DataSelector::dropEvent(QDropEvent *de) { } auto const filepath = m_uiForm.rfFileInput->getText().toStdString(); - if (de->mimeData() && !doesExistInADS(dragData) && !filepath.empty()) { + if (de->mimeData() && !ads.doesExist(dragData) && !filepath.empty()) { auto const file = extractLastOf(filepath, "/"); if (fileFound(file)) { auto const workspaceName = cutLastOf(file, "."); From 459972833d7efbc2ca7e0c1f919492a58b5c07ba Mon Sep 17 00:00:00 2001 From: Applin Date: Fri, 20 Sep 2024 11:56:57 +0100 Subject: [PATCH 2/5] Set file problem to empty string if loading successful --- qt/widgets/common/src/DataSelector.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/qt/widgets/common/src/DataSelector.cpp b/qt/widgets/common/src/DataSelector.cpp index 818678211b7d..d44dd016dec9 100644 --- a/qt/widgets/common/src/DataSelector.cpp +++ b/qt/widgets/common/src/DataSelector.cpp @@ -263,16 +263,15 @@ void DataSelector::setLoadProperty(std::string const &propertyName, bool const v * @param error :: Whether loading completed without error */ void DataSelector::handleAutoLoadComplete(bool error) { - if (!error) { - if (m_alwaysLoadAsGroup) { - makeGroup(getWsNameFromFiles().toStdString()); - } + m_uiForm.rfFileInput->setFileProblem(error ? "Could not load file. See log for details." : ""); - // emit that we got a valid workspace/file to work with - emit dataReady(getWsNameFromFiles()); - } else { - m_uiForm.rfFileInput->setFileProblem("Could not load file. See log for details."); + if (error) { + return; + } + if (m_alwaysLoadAsGroup) { + makeGroup(getWsNameFromFiles().toStdString()); } + emit dataReady(getWsNameFromFiles()); } /** From 271c2a4f1169541d029d979073ba810514662904 Mon Sep 17 00:00:00 2001 From: Applin Date: Fri, 20 Sep 2024 12:29:58 +0100 Subject: [PATCH 3/5] Remove m_autoLoad as member variable from DataSelector Removes this member variable because it is never set to false anywhere else in the code. It means this class can be simplified slightly. --- .../inc/MantidQtWidgets/Common/DataSelector.h | 11 +----- qt/widgets/common/src/DataSelector.cpp | 39 +++++-------------- 2 files changed, 11 insertions(+), 39 deletions(-) diff --git a/qt/widgets/common/inc/MantidQtWidgets/Common/DataSelector.h b/qt/widgets/common/inc/MantidQtWidgets/Common/DataSelector.h index 4fea55cf64ef..db98300c3ffa 100644 --- a/qt/widgets/common/inc/MantidQtWidgets/Common/DataSelector.h +++ b/qt/widgets/common/inc/MantidQtWidgets/Common/DataSelector.h @@ -61,7 +61,6 @@ class EXPORT_OPT_MANTIDQT_COMMON DataSelector : public API::MantidWidget { // These are global properties of data selector Q_PROPERTY(bool optional READ isOptional WRITE isOptional) - Q_PROPERTY(bool autoLoad READ willAutoLoad WRITE setAutoLoad) Q_PROPERTY(QString loadLabelText READ getLoadBtnText WRITE setLoadBtnText) public: @@ -73,7 +72,7 @@ class EXPORT_OPT_MANTIDQT_COMMON DataSelector : public API::MantidWidget { /// Get the workspace name from the list of files QString getWsNameFromFiles() const; /// Get the currently available file or workspace name - virtual QString getCurrentDataName() const; + virtual QString getCurrentDataName(bool const autoLoad = true) const; /// Sets which selector (file or workspace) is visible void setSelectorIndex(int index); /// Sets if the option to choose selector is visible @@ -85,7 +84,7 @@ class EXPORT_OPT_MANTIDQT_COMMON DataSelector : public API::MantidWidget { /// Get whether the workspace selector is currently being shown bool isWorkspaceSelectorVisible() const; /// Checks if widget is in a valid state - virtual bool isValid(); + virtual bool isValid(bool const autoLoad = true); /// Get file problem, empty string means no error. QString getProblem() const; /// Read settings from the given group @@ -96,10 +95,6 @@ class EXPORT_OPT_MANTIDQT_COMMON DataSelector : public API::MantidWidget { bool isOptional() const; /// Sets if optional void isOptional(bool /*optional*/); - /// Gets will auto load - bool willAutoLoad() const; - /// Sets will auto load - void setAutoLoad(bool /*load*/); /// Check if the widget will show the load button bool willShowLoad(); /// Set if the load button should be shown @@ -376,8 +371,6 @@ private slots: Mantid::API::AlgorithmRuntimeProps m_loadProperties; /// Algorithm Runner used to run the load algorithm MantidQt::API::QtAlgorithmRunner m_algRunner; - /// Flag to enable auto loading. By default this is set to true. - bool m_autoLoad; /// Flag to show or hide the load button. By default this is set to true. bool m_showLoad; /// Flag if optional diff --git a/qt/widgets/common/src/DataSelector.cpp b/qt/widgets/common/src/DataSelector.cpp index d44dd016dec9..0e61a68bedd2 100644 --- a/qt/widgets/common/src/DataSelector.cpp +++ b/qt/widgets/common/src/DataSelector.cpp @@ -61,8 +61,7 @@ void makeGroup(std::string const &workspaceName) { namespace MantidQt::MantidWidgets { DataSelector::DataSelector(QWidget *parent) - : API::MantidWidget(parent), m_loadProperties(), m_algRunner(), m_autoLoad(true), m_showLoad(true), - m_alwaysLoadAsGroup(false) { + : API::MantidWidget(parent), m_loadProperties(), m_algRunner(), m_showLoad(true), m_alwaysLoadAsGroup(false) { m_uiForm.setupUi(this); connect(m_uiForm.cbInputType, SIGNAL(currentIndexChanged(int)), this, SLOT(handleViewChanged(int))); connect(m_uiForm.pbLoadFile, SIGNAL(clicked()), this, SIGNAL(loadClicked())); @@ -106,14 +105,8 @@ void DataSelector::handleFileInput() { return; } - // attempt to load the file - if (m_autoLoad) { - emit filesAutoLoaded(); - autoLoadFile(filename); - } else { - // files were found - emit filesFound(); - } + emit filesAutoLoaded(); + autoLoadFile(filename); } /** @@ -148,10 +141,10 @@ bool DataSelector::isWorkspaceSelectorVisible() const { return !isFileSelectorVi * * Checks using the relvant widgets isValid method depending * on what view is currently being shown - * + * @param autoLoad :: Whether to automatically load the data if it is not found in the ADS. * @return :: If the data selector is valid */ -bool DataSelector::isValid() { +bool DataSelector::isValid(bool const autoLoad) { bool isValid = false; if (isFileSelectorVisible()) { @@ -159,7 +152,7 @@ bool DataSelector::isValid() { // check to make sure the user hasn't deleted the auto-loaded file // since choosing it. - if (isValid && m_autoLoad) { + if (isValid && autoLoad) { auto const wsName = getCurrentDataName().toStdString(); isValid = !wsName.empty(); @@ -344,10 +337,10 @@ QString DataSelector::getWsNameFromFiles() const { * If multiple files are allowed, and auto-loading is off, it will return the * full user input. * If there is no valid input the method returns an empty string. - * + * @param autoLoad :: Whether or not autoload is turned on. * @return The name of the current data item */ -QString DataSelector::getCurrentDataName() const { +QString DataSelector::getCurrentDataName(bool const autoLoad) const { QString filename(""); int index = m_uiForm.stackedDataSelect->currentIndex(); @@ -356,7 +349,7 @@ QString DataSelector::getCurrentDataName() const { case 0: // the file selector is visible if (m_uiForm.rfFileInput->isValid()) { - if (m_uiForm.rfFileInput->allowMultipleFiles() && !m_autoLoad) { + if (m_uiForm.rfFileInput->allowMultipleFiles() && !autoLoad) { // if multiple files are allowed, auto-loading is not on, return the // full user input filename = getFullFilePath(); @@ -374,20 +367,6 @@ QString DataSelector::getCurrentDataName() const { return filename; } -/** - * Gets whether the widget will attempt to auto load files - * - * @return Whether the widget will auto load - */ -bool DataSelector::willAutoLoad() const { return m_autoLoad; } - -/** - * Sets whether the widget will attempt to auto load files. - * - * @param load :: Whether the widget will auto load - */ -void DataSelector::setAutoLoad(bool load) { m_autoLoad = load; } - /** * Gets the text displayed on the load button * From 71301ea8c9039bdf783756ad4c11bbb96e12daa4 Mon Sep 17 00:00:00 2001 From: Applin Date: Fri, 20 Sep 2024 12:45:32 +0100 Subject: [PATCH 4/5] Avoid auto loading when validating on Symmetrise tab --- .../Processor/SymmetrisePresenter.cpp | 2 +- .../Common/MockUserInputValidator.h | 3 +- .../Common/UserInputValidator.h | 6 ++-- qt/widgets/common/src/UserInputValidator.cpp | 5 +-- .../Spectroscopy/DataValidationHelper.h | 17 ++++++---- .../spectroscopy/src/DataValidationHelper.cpp | 34 ++++++++++--------- 6 files changed, 39 insertions(+), 28 deletions(-) diff --git a/qt/scientific_interfaces/Inelastic/Processor/SymmetrisePresenter.cpp b/qt/scientific_interfaces/Inelastic/Processor/SymmetrisePresenter.cpp index 907fb89120db..f8746d3cab93 100644 --- a/qt/scientific_interfaces/Inelastic/Processor/SymmetrisePresenter.cpp +++ b/qt/scientific_interfaces/Inelastic/Processor/SymmetrisePresenter.cpp @@ -44,7 +44,7 @@ SymmetrisePresenter::SymmetrisePresenter(QWidget *parent, SymmetrisePresenter::~SymmetrisePresenter() { m_propTrees["SymmPropTree"]->unsetFactoryForManager(m_dblManager); } void SymmetrisePresenter::handleValidation(IUserInputValidator *validator) const { - validateDataIsOfType(validator, m_view->getDataSelector(), "Sample", DataType::Red); + validateDataIsOfType(validator, m_view->getDataSelector(), "Sample", DataType::Red, false, false); } void SymmetrisePresenter::handleRun() { diff --git a/qt/widgets/common/inc/MantidQtWidgets/Common/MockUserInputValidator.h b/qt/widgets/common/inc/MantidQtWidgets/Common/MockUserInputValidator.h index ba809af3c96f..5b8116a1b23a 100644 --- a/qt/widgets/common/inc/MantidQtWidgets/Common/MockUserInputValidator.h +++ b/qt/widgets/common/inc/MantidQtWidgets/Common/MockUserInputValidator.h @@ -23,7 +23,8 @@ class MockUserInputValidator : public MantidQt::CustomInterfaces::IUserInputVali MOCK_METHOD3(checkFieldIsValid, bool(const QString &errorMessage, QLineEdit *field, QLabel *errorLabel)); MOCK_METHOD2(checkWorkspaceSelectorIsNotEmpty, bool(const QString &name, WorkspaceSelector *workspaceSelector)); MOCK_METHOD2(checkFileFinderWidgetIsValid, bool(const QString &name, const FileFinderWidget *widget)); - MOCK_METHOD3(checkDataSelectorIsValid, bool(const QString &name, DataSelector *widget, bool silent)); + MOCK_METHOD4(checkDataSelectorIsValid, + bool(const QString &name, DataSelector *widget, bool const silent, bool const autoLoad)); MOCK_METHOD3(checkWorkspaceGroupIsValid, bool(QString const &groupName, QString const &inputType, bool silent)); MOCK_METHOD2(checkWorkspaceExists, bool(QString const &workspaceName, bool silent)); MOCK_METHOD2(checkValidRange, bool(QString const &name, std::pair range)); diff --git a/qt/widgets/common/inc/MantidQtWidgets/Common/UserInputValidator.h b/qt/widgets/common/inc/MantidQtWidgets/Common/UserInputValidator.h index cf0577ef1836..895c9adf2a56 100644 --- a/qt/widgets/common/inc/MantidQtWidgets/Common/UserInputValidator.h +++ b/qt/widgets/common/inc/MantidQtWidgets/Common/UserInputValidator.h @@ -32,7 +32,8 @@ class DLLExport IUserInputValidator { virtual bool checkFieldIsValid(const QString &errorMessage, QLineEdit *field, QLabel *errorLabel = nullptr) = 0; virtual bool checkWorkspaceSelectorIsNotEmpty(const QString &name, WorkspaceSelector *workspaceSelector) = 0; virtual bool checkFileFinderWidgetIsValid(const QString &name, const FileFinderWidget *widget) = 0; - virtual bool checkDataSelectorIsValid(const QString &name, DataSelector *widget, bool silent = false) = 0; + virtual bool checkDataSelectorIsValid(const QString &name, DataSelector *widget, bool const silent = false, + bool const autoLoad = true) = 0; virtual bool checkWorkspaceGroupIsValid(QString const &groupName, QString const &inputType, bool silent = false) = 0; virtual bool checkWorkspaceExists(QString const &workspaceName, bool silent = false) = 0; virtual bool checkValidRange(const QString &name, std::pair range) = 0; @@ -76,7 +77,8 @@ class DLLExport UserInputValidator final : public IUserInputValidator { /// Check that the given FileFinderWidget widget has valid files. bool checkFileFinderWidgetIsValid(const QString &name, const FileFinderWidget *widget) override; /// Check that the given DataSelector widget has valid input. - bool checkDataSelectorIsValid(const QString &name, DataSelector *widget, bool silent = false) override; + bool checkDataSelectorIsValid(const QString &name, DataSelector *widget, bool const silent = false, + bool const autoLoad = true) override; /// Check that the given start and end range is valid. bool checkValidRange(const QString &name, std::pair range) override; /// Check that the given ranges dont overlap. diff --git a/qt/widgets/common/src/UserInputValidator.cpp b/qt/widgets/common/src/UserInputValidator.cpp index 96b86f59c177..b42be880d393 100644 --- a/qt/widgets/common/src/UserInputValidator.cpp +++ b/qt/widgets/common/src/UserInputValidator.cpp @@ -141,8 +141,9 @@ bool UserInputValidator::checkFileFinderWidgetIsValid(const QString &name, const * @param silent True if an error should not be added to the validator. * @returns True if the input was valid */ -bool UserInputValidator::checkDataSelectorIsValid(const QString &name, DataSelector *widget, bool silent) { - if (!widget->isValid()) { +bool UserInputValidator::checkDataSelectorIsValid(const QString &name, DataSelector *widget, bool const silent, + bool const autoLoad) { + if (!widget->isValid(autoLoad)) { addErrorMessage(name.toStdString() + " error: " + widget->getProblem().toStdString(), silent); return false; } diff --git a/qt/widgets/spectroscopy/inc/MantidQtWidgets/Spectroscopy/DataValidationHelper.h b/qt/widgets/spectroscopy/inc/MantidQtWidgets/Spectroscopy/DataValidationHelper.h index 9fca849efa5c..a0705805c4fa 100644 --- a/qt/widgets/spectroscopy/inc/MantidQtWidgets/Spectroscopy/DataValidationHelper.h +++ b/qt/widgets/spectroscopy/inc/MantidQtWidgets/Spectroscopy/DataValidationHelper.h @@ -16,27 +16,32 @@ enum DataType { Red, Sqw, Calib, Corrections }; MANTID_SPECTROSCOPY_DLL bool validateDataIsOneOf(MantidQt::CustomInterfaces::IUserInputValidator *uiv, MantidQt::MantidWidgets::DataSelector *dataSelector, std::string const &inputType, DataType const &primaryType, - std::vector const &otherTypes, bool silent = false); + std::vector const &otherTypes, bool const silent = false, + bool const autoLoad = true); MANTID_SPECTROSCOPY_DLL bool validateDataIsOfType(MantidQt::CustomInterfaces::IUserInputValidator *uiv, MantidQt::MantidWidgets::DataSelector *dataSelector, std::string const &inputType, DataType const &type, - bool silent = false); + bool const silent = false, bool const autoLoad = true); MANTID_SPECTROSCOPY_DLL bool validateDataIsAReducedFile(MantidQt::CustomInterfaces::IUserInputValidator *uiv, MantidQt::MantidWidgets::DataSelector *dataSelector, - std::string const &inputType, bool silent = false); + std::string const &inputType, bool const silent = false, + bool const autoLoad = true); MANTID_SPECTROSCOPY_DLL bool validateDataIsASqwFile(MantidQt::CustomInterfaces::IUserInputValidator *uiv, MantidQt::MantidWidgets::DataSelector *dataSelector, - std::string const &inputType, bool silent = false); + std::string const &inputType, bool const silent = false, + bool const autoLoad = true); MANTID_SPECTROSCOPY_DLL bool validateDataIsACalibrationFile(MantidQt::CustomInterfaces::IUserInputValidator *uiv, MantidQt::MantidWidgets::DataSelector *dataSelector, - std::string const &inputType, bool silent = false); + std::string const &inputType, bool const silent = false, + bool const autoLoad = true); MANTID_SPECTROSCOPY_DLL bool validateDataIsACorrectionsFile(MantidQt::CustomInterfaces::IUserInputValidator *uiv, MantidQt::MantidWidgets::DataSelector *dataSelector, - std::string const &inputType, bool silent = false); + std::string const &inputType, bool const silent = false, + bool const autoLoad = true); } // namespace DataValidationHelper diff --git a/qt/widgets/spectroscopy/src/DataValidationHelper.cpp b/qt/widgets/spectroscopy/src/DataValidationHelper.cpp index c8d4b9b8b73e..63d281c399ba 100644 --- a/qt/widgets/spectroscopy/src/DataValidationHelper.cpp +++ b/qt/widgets/spectroscopy/src/DataValidationHelper.cpp @@ -28,9 +28,11 @@ namespace DataValidationHelper { * @return True if the data is valid. */ bool validateDataIsOneOf(IUserInputValidator *uiv, DataSelector *dataSelector, std::string const &inputType, - DataType const &primaryType, std::vector const &otherTypes, bool silent) { - if (std::any_of(otherTypes.cbegin(), otherTypes.cend(), - [&](auto const &type) { return validateDataIsOfType(uiv, dataSelector, inputType, type, true); })) { + DataType const &primaryType, std::vector const &otherTypes, bool const silent, + bool const autoLoad) { + if (std::any_of(otherTypes.cbegin(), otherTypes.cend(), [&](auto const &type) { + return validateDataIsOfType(uiv, dataSelector, inputType, type, true, autoLoad); + })) { return true; } @@ -47,16 +49,16 @@ bool validateDataIsOneOf(IUserInputValidator *uiv, DataSelector *dataSelector, s * @return True if the data is valid. */ bool validateDataIsOfType(IUserInputValidator *uiv, DataSelector *dataSelector, std::string const &inputType, - DataType const &type, bool silent) { + DataType const &type, bool const silent, bool const autoLoad) { switch (type) { case DataType::Red: - return validateDataIsAReducedFile(uiv, dataSelector, inputType, silent); + return validateDataIsAReducedFile(uiv, dataSelector, inputType, silent, autoLoad); case DataType::Sqw: - return validateDataIsASqwFile(uiv, dataSelector, inputType, silent); + return validateDataIsASqwFile(uiv, dataSelector, inputType, silent, autoLoad); case DataType::Calib: - return validateDataIsACalibrationFile(uiv, dataSelector, inputType, silent); + return validateDataIsACalibrationFile(uiv, dataSelector, inputType, silent, autoLoad); case DataType::Corrections: - return validateDataIsACorrectionsFile(uiv, dataSelector, inputType, silent); + return validateDataIsACorrectionsFile(uiv, dataSelector, inputType, silent, autoLoad); default: return false; } @@ -73,9 +75,9 @@ bool validateDataIsOfType(IUserInputValidator *uiv, DataSelector *dataSelector, * @return True if the data is valid. */ bool validateDataIsAReducedFile(IUserInputValidator *uiv, DataSelector *dataSelector, std::string const &inputType, - bool silent) { + bool const silent, bool const autoLoad) { auto const dataName = dataSelector->getCurrentDataName(); - uiv->checkDataSelectorIsValid(QString::fromStdString(inputType), dataSelector, silent); + uiv->checkDataSelectorIsValid(QString::fromStdString(inputType), dataSelector, silent, autoLoad); uiv->checkWorkspaceType(dataName, QString::fromStdString(inputType), "MatrixWorkspace", silent); // TODO :: check the axis labels for the data units return uiv->isAllInputValid(); @@ -90,9 +92,9 @@ bool validateDataIsAReducedFile(IUserInputValidator *uiv, DataSelector *dataSele * @return True if the data is valid. */ bool validateDataIsASqwFile(IUserInputValidator *uiv, DataSelector *dataSelector, std::string const &inputType, - bool silent) { + bool const silent, bool const autoLoad) { auto const dataName = dataSelector->getCurrentDataName(); - uiv->checkDataSelectorIsValid(QString::fromStdString(inputType), dataSelector, silent); + uiv->checkDataSelectorIsValid(QString::fromStdString(inputType), dataSelector, silent, autoLoad); uiv->checkWorkspaceType(dataName, QString::fromStdString(inputType), "MatrixWorkspace", silent); // TODO :: check the axis labels for the data units return uiv->isAllInputValid(); @@ -107,9 +109,9 @@ bool validateDataIsASqwFile(IUserInputValidator *uiv, DataSelector *dataSelector * @return True if the data is valid. */ bool validateDataIsACalibrationFile(IUserInputValidator *uiv, DataSelector *dataSelector, std::string const &inputType, - bool silent) { + bool const silent, bool const autoLoad) { auto const dataName = dataSelector->getCurrentDataName(); - uiv->checkDataSelectorIsValid(QString::fromStdString(inputType), dataSelector, silent); + uiv->checkDataSelectorIsValid(QString::fromStdString(inputType), dataSelector, silent, autoLoad); uiv->checkWorkspaceType(dataName, QString::fromStdString(inputType), "MatrixWorkspace", silent); // TODO :: check the axis labels for the data units return uiv->isAllInputValid(); @@ -124,9 +126,9 @@ bool validateDataIsACalibrationFile(IUserInputValidator *uiv, DataSelector *data * @return True if the data is valid. */ bool validateDataIsACorrectionsFile(IUserInputValidator *uiv, DataSelector *dataSelector, std::string const &inputType, - bool silent) { + bool const silent, bool const autoLoad) { auto const dataName = dataSelector->getCurrentDataName(); - uiv->checkDataSelectorIsValid(QString::fromStdString(inputType), dataSelector, silent); + uiv->checkDataSelectorIsValid(QString::fromStdString(inputType), dataSelector, silent, autoLoad); uiv->checkWorkspaceType(dataName, QString::fromStdString(inputType), "WorkspaceGroup", silent); uiv->checkWorkspaceGroupIsValid(dataName, QString::fromStdString(inputType), silent); // TODO :: check the axis labels for the data units From 74a8a673cb1b2bcff0ffe0acadcad122e4be086e Mon Sep 17 00:00:00 2001 From: Applin Date: Fri, 20 Sep 2024 13:27:01 +0100 Subject: [PATCH 5/5] Update Spectroscopy test suites --- qt/widgets/common/src/UserInputValidator.cpp | 1 + .../test/DataValidationHelperTest.h | 42 +++++++++---------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/qt/widgets/common/src/UserInputValidator.cpp b/qt/widgets/common/src/UserInputValidator.cpp index b42be880d393..2db5df7772bf 100644 --- a/qt/widgets/common/src/UserInputValidator.cpp +++ b/qt/widgets/common/src/UserInputValidator.cpp @@ -139,6 +139,7 @@ bool UserInputValidator::checkFileFinderWidgetIsValid(const QString &name, const * @param name :: the "name" of the widget so as to be recognised by the user. * @param widget :: the widget to check * @param silent True if an error should not be added to the validator. + * @param autoLoad True if the data should be reloaded if it is not in the ADS. * @returns True if the input was valid */ bool UserInputValidator::checkDataSelectorIsValid(const QString &name, DataSelector *widget, bool const silent, diff --git a/qt/widgets/spectroscopy/test/DataValidationHelperTest.h b/qt/widgets/spectroscopy/test/DataValidationHelperTest.h index cc148f2b2b6b..46d5ff96a40a 100644 --- a/qt/widgets/spectroscopy/test/DataValidationHelperTest.h +++ b/qt/widgets/spectroscopy/test/DataValidationHelperTest.h @@ -61,8 +61,8 @@ GNU_DIAG_OFF_SUGGEST_OVERRIDE class MockDataSelector : public DataSelector { public: /// Public Methods - MOCK_CONST_METHOD0(getCurrentDataName, QString()); - MOCK_METHOD0(isValid, bool()); + MOCK_CONST_METHOD1(getCurrentDataName, QString(bool const)); + MOCK_METHOD1(isValid, bool(bool const)); }; GNU_DIAG_ON_SUGGEST_OVERRIDE @@ -193,54 +193,54 @@ class DataValidationHelperTest : public CxxTest::TestSuite { private: template void assertTheDataIsCheckedOneTime(Functor const &functor, DataType const &primaryType) { - ON_CALL(*m_dataSelector, getCurrentDataName()).WillByDefault(Return(QString::fromStdString(WORKSPACE_NAME))); - ON_CALL(*m_dataSelector, isValid()).WillByDefault(Return(true)); + ON_CALL(*m_dataSelector, getCurrentDataName(true)).WillByDefault(Return(QString::fromStdString(WORKSPACE_NAME))); + ON_CALL(*m_dataSelector, isValid(true)).WillByDefault(Return(true)); - EXPECT_CALL(*m_dataSelector, getCurrentDataName()).Times(1); - EXPECT_CALL(*m_dataSelector, isValid()).Times(1); + EXPECT_CALL(*m_dataSelector, getCurrentDataName(true)).Times(1); + EXPECT_CALL(*m_dataSelector, isValid(true)).Times(1); - (void)functor(m_uiv.get(), m_dataSelector.get(), ERROR_LABEL, primaryType, false); + (void)functor(m_uiv.get(), m_dataSelector.get(), ERROR_LABEL, primaryType, false, true); } template void assertTheDataIsCheckedNTimes(Functor const &functor, int nTimes, DataType const &primaryType, std::vector const &otherTypes) { - ON_CALL(*m_dataSelector, getCurrentDataName()).WillByDefault(Return(QString::fromStdString(WORKSPACE_NAME))); - ON_CALL(*m_dataSelector, isValid()).WillByDefault(Return(true)); + ON_CALL(*m_dataSelector, getCurrentDataName(true)).WillByDefault(Return(QString::fromStdString(WORKSPACE_NAME))); + ON_CALL(*m_dataSelector, isValid(true)).WillByDefault(Return(true)); - EXPECT_CALL(*m_dataSelector, getCurrentDataName()).Times(nTimes); - EXPECT_CALL(*m_dataSelector, isValid()).Times(nTimes); + EXPECT_CALL(*m_dataSelector, getCurrentDataName(true)).Times(nTimes); + EXPECT_CALL(*m_dataSelector, isValid(true)).Times(nTimes); - (void)functor(m_uiv.get(), m_dataSelector.get(), ERROR_LABEL, primaryType, otherTypes, false); + (void)functor(m_uiv.get(), m_dataSelector.get(), ERROR_LABEL, primaryType, otherTypes, false, true); } template void assertThatTheDataIsValid(std::string const &workspaceName, std::string const &errorLabel, Functor const &functor) { - ON_CALL(*m_dataSelector, getCurrentDataName()).WillByDefault(Return(QString::fromStdString(workspaceName))); - ON_CALL(*m_dataSelector, isValid()).WillByDefault(Return(true)); + ON_CALL(*m_dataSelector, getCurrentDataName(true)).WillByDefault(Return(QString::fromStdString(workspaceName))); + ON_CALL(*m_dataSelector, isValid(true)).WillByDefault(Return(true)); - TS_ASSERT(functor(m_uiv.get(), m_dataSelector.get(), errorLabel, false)); + TS_ASSERT(functor(m_uiv.get(), m_dataSelector.get(), errorLabel, false, true)); TS_ASSERT(m_uiv->generateErrorMessage().empty()); } template void assertThatTheDataIsInvalid(std::string const &workspaceName, std::string const &errorLabel, Functor const &functor) { - ON_CALL(*m_dataSelector, getCurrentDataName()).WillByDefault(Return(QString::fromStdString(workspaceName))); - ON_CALL(*m_dataSelector, isValid()).WillByDefault(Return(true)); + ON_CALL(*m_dataSelector, getCurrentDataName(true)).WillByDefault(Return(QString::fromStdString(workspaceName))); + ON_CALL(*m_dataSelector, isValid(true)).WillByDefault(Return(true)); - TS_ASSERT(!functor(m_uiv.get(), m_dataSelector.get(), errorLabel, false)); + TS_ASSERT(!functor(m_uiv.get(), m_dataSelector.get(), errorLabel, false, true)); TS_ASSERT(!m_uiv->generateErrorMessage().empty()); } template void assertErrorMessage(std::string const &workspaceName, std::string const &errorLabel, Functor const &functor, std::string const &errorMessage) { - ON_CALL(*m_dataSelector, getCurrentDataName()).WillByDefault(Return(QString::fromStdString(workspaceName))); - ON_CALL(*m_dataSelector, isValid()).WillByDefault(Return(true)); + ON_CALL(*m_dataSelector, getCurrentDataName(true)).WillByDefault(Return(QString::fromStdString(workspaceName))); + ON_CALL(*m_dataSelector, isValid(true)).WillByDefault(Return(true)); - (void)functor(m_uiv.get(), m_dataSelector.get(), errorLabel, false); + (void)functor(m_uiv.get(), m_dataSelector.get(), errorLabel, false, true); TS_ASSERT_EQUALS(m_uiv->generateErrorMessage(), errorMessage); }