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
13
17
18class QLineEdit;
19class QLabel;
20class QString;
21class QStringList;
22
23namespace MantidQt {
24namespace CustomInterfaces {
35public:
38
40 bool checkFieldIsNotEmpty(const QString &name, QLineEdit *field, QLabel *errorLabel = nullptr);
43 bool checkFieldIsValid(const QString &errorMessage, QLineEdit *field, QLabel *errorLabel = nullptr);
45 bool checkWorkspaceSelectorIsNotEmpty(const QString &name, WorkspaceSelector *workspaceSelector);
47 bool checkFileFinderWidgetIsValid(const QString &name, FileFinderWidget *widget);
49 bool checkDataSelectorIsValid(const QString &name, DataSelector *widget, bool silent = false);
51 bool checkValidRange(const QString &name, std::pair<double, double> range);
53 bool checkRangesDontOverlap(std::pair<double, double> rangeA, std::pair<double, double> rangeB);
56 bool checkRangeIsEnclosed(const QString &outerName, std::pair<double, double> outer, const QString &innerName,
57 std::pair<double, double> inner);
60 bool checkBins(double lower, double binWidth, double upper, double tolerance = 0.00000001);
62 bool checkNotEqual(const QString &name, double x, double y = 0.0, double tolerance = 0.00000001);
63
65 template <typename T = Mantid::API::MatrixWorkspace>
66 bool checkWorkspaceType(QString const &workspaceName, QString const &inputType, QString const &validType,
67 bool silent = false);
69 bool checkWorkspaceExists(QString const &workspaceName, bool silent = false);
71 bool checkWorkspaceNumberOfHistograms(QString const &workspaceName, std::size_t const &validSize);
72 bool checkWorkspaceNumberOfHistograms(const Mantid::API::MatrixWorkspace_sptr &, std::size_t const &validSize);
74 bool checkWorkspaceNumberOfBins(QString const &workspaceName, std::size_t const &validSize);
75 bool checkWorkspaceNumberOfBins(const Mantid::API::MatrixWorkspace_sptr &, std::size_t const &validSize);
77 bool checkWorkspaceGroupIsValid(QString const &groupName, QString const &inputType, bool silent = false);
78
80 void addErrorMessage(const QString &message, bool silent = false);
81
83 void setErrorLabel(QLabel *errorLabel, bool valid);
84
87 QString generateErrorMessage();
89 bool isAllInputValid();
90
91private:
93 template <typename T = Mantid::API::MatrixWorkspace>
94 std::shared_ptr<T> getADSWorkspace(std::string const &workspaceName);
95
97 QStringList m_errorMessages;
99 bool m_error;
100};
101
111template <typename T>
112bool UserInputValidator::checkWorkspaceType(QString const &workspaceName, QString const &inputType,
113 QString const &validType, bool silent) {
114 if (checkWorkspaceExists(workspaceName, silent)) {
115 if (!getADSWorkspace<T>(workspaceName.toStdString())) {
116 addErrorMessage("The " + inputType + " workspace is not a " + validType + ".", silent);
117 return false;
118 } else
119 return true;
120 }
121 return false;
122}
123
130template <typename T> std::shared_ptr<T> UserInputValidator::getADSWorkspace(std::string const &workspaceName) {
131 return Mantid::API::AnalysisDataService::Instance().retrieveWS<T>(workspaceName);
132}
133
134} // namespace CustomInterfaces
135} // namespace MantidQt
double tolerance
#define DLLExport
Definitions of the DLLImport compiler directives for MSVC.
Definition: System.h:53
double lower
lower and upper bounds on the multiplier, if known
double upper
This class defines a widget for file searching.
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.
bool checkWorkspaceExists(QString const &workspaceName, bool silent=false)
Checks that a workspace exists in the ADS.
std::shared_ptr< T > getADSWorkspace(std::string const &workspaceName)
Gets a workspace from the ADS.
void addErrorMessage(const QString &message, bool silent=false)
Add a custom error message to the list.
bool checkWorkspaceType(QString const &workspaceName, QString const &inputType, QString const &validType, bool silent=false)
Checks that a workspace has the correct workspace type.
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...
Definition: DataSelector.h:35
This class defines a widget for selecting a workspace present in the AnalysisDataService.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
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