Mantid
Loading...
Searching...
No Matches
UserInputValidator.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2007 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
14
18
19class QLineEdit;
20class QLabel;
21class QString;
22class QStringList;
23
24namespace MantidQt {
25namespace CustomInterfaces {
26
28public:
29 virtual ~IUserInputValidator() = default;
30
31 virtual bool checkFieldIsNotEmpty(const QString &name, QLineEdit *field, QLabel *errorLabel = nullptr) = 0;
32 virtual bool checkFieldIsValid(const QString &errorMessage, QLineEdit *field, QLabel *errorLabel = nullptr) = 0;
33 virtual bool checkWorkspaceSelectorIsNotEmpty(const QString &name, WorkspaceSelector *workspaceSelector) = 0;
34 virtual bool checkFileFinderWidgetIsValid(const QString &name, const FileFinderWidget *widget) = 0;
35 virtual bool checkDataSelectorIsValid(const QString &name, DataSelector *widget, bool const silent = false,
36 bool const autoLoad = true) = 0;
37 virtual bool checkWorkspaceGroupIsValid(QString const &groupName, QString const &inputType, bool silent = false) = 0;
38 virtual bool checkWorkspaceExists(QString const &workspaceName, bool silent = false) = 0;
39 virtual bool checkValidRange(const QString &name, std::pair<double, double> range) = 0;
40 virtual bool checkRangesDontOverlap(std::pair<double, double> rangeA, std::pair<double, double> rangeB) = 0;
41 virtual bool checkRangeIsEnclosed(const QString &outerName, std::pair<double, double> outer, const QString &innerName,
42 std::pair<double, double> inner) = 0;
43 virtual bool checkBins(double lower, double binWidth, double upper, double tolerance = 0.00000001) = 0;
44 template <typename T = Mantid::API::MatrixWorkspace>
45 bool checkWorkspaceType(QString const &workspaceName, QString const &inputType, QString const &validType,
46 bool silent = false);
47
48 virtual void setErrorLabel(QLabel *errorLabel, bool valid) = 0;
49
50 virtual void addErrorMessage(const std::string &message, bool const silent = false) = 0;
51
52 virtual std::string generateErrorMessage() const = 0;
53 virtual bool isAllInputValid() const = 0;
54};
55
66public:
70
72 bool checkFieldIsNotEmpty(const QString &name, QLineEdit *field, QLabel *errorLabel = nullptr) override;
74 bool checkFieldIsValid(const QString &errorMessage, QLineEdit *field, QLabel *errorLabel = nullptr) override;
76 bool checkWorkspaceSelectorIsNotEmpty(const QString &name, WorkspaceSelector *workspaceSelector) override;
78 bool checkFileFinderWidgetIsValid(const QString &name, const FileFinderWidget *widget) override;
80 bool checkDataSelectorIsValid(const QString &name, DataSelector *widget, bool const silent = false,
81 bool const autoLoad = true) override;
83 bool checkValidRange(const QString &name, std::pair<double, double> range) override;
85 bool checkRangesDontOverlap(std::pair<double, double> rangeA, std::pair<double, double> rangeB) override;
87 bool checkRangeIsEnclosed(const QString &outerName, std::pair<double, double> outer, const QString &innerName,
88 std::pair<double, double> inner) override;
90 bool checkBins(double lower, double binWidth, double upper, double tolerance = 0.00000001) override;
92 bool checkNotEqual(const QString &name, double x, double y = 0.0, double tolerance = 0.00000001);
93
95 bool checkWorkspaceExists(QString const &workspaceName, bool silent = false) override;
97 bool checkWorkspaceNumberOfHistograms(QString const &workspaceName, std::size_t const &validSize);
98 bool checkWorkspaceNumberOfHistograms(const Mantid::API::MatrixWorkspace_sptr &, std::size_t const &validSize);
100 bool checkWorkspaceNumberOfBins(QString const &workspaceName, std::size_t const &validSize);
101 bool checkWorkspaceNumberOfBins(const Mantid::API::MatrixWorkspace_sptr &, std::size_t const &validSize);
103 bool checkWorkspaceGroupIsValid(QString const &groupName, QString const &inputType, bool silent = false) override;
104
106 void addErrorMessage(const std::string &message, bool const silent = false) override;
107
109 void setErrorLabel(QLabel *errorLabel, bool valid) override;
110
113 std::string generateErrorMessage() const override;
115 bool isAllInputValid() const override;
116
117private:
119 QStringList m_errorMessages;
122};
123
133template <typename T>
134bool IUserInputValidator::checkWorkspaceType(QString const &workspaceName, QString const &inputType,
135 QString const &validType, bool silent) {
136 if (!checkWorkspaceExists(workspaceName, silent)) {
137 return false;
138 }
139
140 if (!MantidWidgets::WorkspaceUtils::getADSWorkspace<T>(workspaceName.toStdString())) {
141 addErrorMessage("The " + inputType.toStdString() + " workspace is not a " + validType.toStdString() + ".", silent);
142 return false;
143 }
144 return true;
145}
146
147} // namespace CustomInterfaces
148} // namespace MantidQt
std::string name
Definition Run.cpp:60
double tolerance
#define DLLExport
Definitions of the DLLImport compiler directives for MSVC.
Definition System.h:37
double lower
lower and upper bounds on the multiplier, if known
double upper
This class defines a widget for file searching.
virtual bool checkWorkspaceExists(QString const &workspaceName, bool silent=false)=0
virtual bool checkWorkspaceSelectorIsNotEmpty(const QString &name, WorkspaceSelector *workspaceSelector)=0
virtual bool checkFieldIsNotEmpty(const QString &name, QLineEdit *field, QLabel *errorLabel=nullptr)=0
virtual void addErrorMessage(const std::string &message, bool const silent=false)=0
virtual bool checkRangeIsEnclosed(const QString &outerName, std::pair< double, double > outer, const QString &innerName, std::pair< double, double > inner)=0
virtual bool checkDataSelectorIsValid(const QString &name, DataSelector *widget, bool const silent=false, bool const autoLoad=true)=0
virtual bool checkFieldIsValid(const QString &errorMessage, QLineEdit *field, QLabel *errorLabel=nullptr)=0
bool checkWorkspaceType(QString const &workspaceName, QString const &inputType, QString const &validType, bool silent=false)
Checks if the workspace has the correct type.
virtual bool checkFileFinderWidgetIsValid(const QString &name, const FileFinderWidget *widget)=0
virtual bool checkWorkspaceGroupIsValid(QString const &groupName, QString const &inputType, bool silent=false)=0
virtual bool checkValidRange(const QString &name, std::pair< double, double > range)=0
virtual bool checkRangesDontOverlap(std::pair< double, double > rangeA, std::pair< double, double > rangeB)=0
virtual bool checkBins(double lower, double binWidth, double upper, double tolerance=0.00000001)=0
virtual std::string generateErrorMessage() const =0
virtual void setErrorLabel(QLabel *errorLabel, bool valid)=0
A class to try and get rid of some of the boiler-plate code surrounding input validation,...
bool m_error
True if there has been an error.
QStringList m_errorMessages
Any raised error messages.
This class defines a widget for selecting a workspace of file path by using a combination of two chil...
This class defines a widget for selecting a workspace present in the AnalysisDataService.
The AlgorithmProgressDialogPresenter keeps track of the running algorithms and displays a progress ba...
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class