|
Mantid
|
A class to try and get rid of some of the boiler-plate code surrounding input validation, and hopefully as a result make it more readable. More...
#include <UserInputValidator.h>
Public Member Functions | |
| void | addErrorMessage (const std::string &message, bool const silent=false) override |
| Add a custom error message to the list. | |
| bool | checkBins (double lower, double binWidth, double upper, double tolerance=0.00000001) override |
| Check that the given range can be split evenly into bins of the given width. | |
| bool | checkDataSelectorIsValid (const QString &name, DataSelector *widget, bool const silent=false, bool const autoLoad=true) override |
| Check that the given DataSelector widget has valid input. | |
| bool | checkFieldIsNotEmpty (const QString &name, QLineEdit *field, QLabel *errorLabel=nullptr) override |
| Check that the given QLineEdit field is not empty. | |
| bool | checkFieldIsValid (const QString &errorMessage, QLineEdit *field, QLabel *errorLabel=nullptr) override |
| Check that the given QLineEdit field is valid as per any validators it might have. | |
| bool | checkFileFinderWidgetIsValid (const QString &name, const FileFinderWidget *widget) override |
| Check that the given FileFinderWidget widget has valid files. | |
| bool | checkNotEqual (const QString &name, double x, double y=0.0, double tolerance=0.00000001) |
| Checks two values are not equal. | |
| bool | checkRangeIsEnclosed (const QString &outerName, std::pair< double, double > outer, const QString &innerName, std::pair< double, double > inner) override |
| Check that the given "outer" range completely encloses the given "inner" range. | |
| bool | checkRangesDontOverlap (std::pair< double, double > rangeA, std::pair< double, double > rangeB) override |
| Check that the given ranges dont overlap. | |
| bool | checkValidRange (const QString &name, std::pair< double, double > range) override |
| Check that the given start and end range is valid. | |
| bool | checkWorkspaceExists (QString const &workspaceName, bool silent=false) override |
| Checks that a workspace exists in the ADS. | |
| bool | checkWorkspaceGroupIsValid (QString const &groupName, QString const &inputType, bool silent=false) override |
| Checks that a workspace group contains valid matrix workspace's. | |
| bool | checkWorkspaceNumberOfBins (const Mantid::API::MatrixWorkspace_sptr &, std::size_t const &validSize) |
| Checks that a workspaces has a valid number of bins. | |
| bool | checkWorkspaceNumberOfBins (QString const &workspaceName, std::size_t const &validSize) |
| Checks the number of bins in a workspace. | |
| bool | checkWorkspaceNumberOfHistograms (const Mantid::API::MatrixWorkspace_sptr &, std::size_t const &validSize) |
| Checks that a workspaces has a valid number of histograms. | |
| bool | checkWorkspaceNumberOfHistograms (QString const &workspaceName, std::size_t const &validSize) |
| Checks the number of histograms in a workspace. | |
| bool | checkWorkspaceSelectorIsNotEmpty (const QString &name, WorkspaceSelector *workspaceSelector) override |
| Check that the given WorkspaceSelector is not empty. | |
| std::string | generateErrorMessage () const override |
| Returns an error message which contains all the error messages raised by the check functions. | |
| bool | isAllInputValid () const override |
| Checks to see if all input is valid. | |
| void | setErrorLabel (QLabel *errorLabel, bool valid) override |
| Sets a validation label. | |
| UserInputValidator () | |
| Default Constructor. | |
| ~UserInputValidator () override | |
Public Member Functions inherited from MantidQt::CustomInterfaces::IUserInputValidator | |
| template<typename T = Mantid::API::MatrixWorkspace> | |
| bool | checkWorkspaceType (QString const &workspaceName, QString const &inputType, QString const &validType, bool silent=false) |
| Checks if the workspace has the correct type. | |
| virtual | ~IUserInputValidator ()=default |
Private Attributes | |
| bool | m_error |
| True if there has been an error. | |
| QStringList | m_errorMessages |
| Any raised error messages. | |
A class to try and get rid of some of the boiler-plate code surrounding input validation, and hopefully as a result make it more readable.
It has as its state a QStringList, which are the accumulated error messages after multiple calls to its "check[...]" member-functions.
Definition at line 65 of file UserInputValidator.h.
| MantidQt::CustomInterfaces::UserInputValidator::UserInputValidator | ( | ) |
Default Constructor.
Definition at line 52 of file UserInputValidator.cpp.
|
overridedefault |
|
overridevirtual |
Add a custom error message to the list.
| message | :: the message to add to the list |
| silent | True if an error should not be added to the validator. |
Implements MantidQt::CustomInterfaces::IUserInputValidator.
Definition at line 394 of file UserInputValidator.cpp.
References m_error, and m_errorMessages.
Referenced by checkBins(), checkDataSelectorIsValid(), checkFieldIsNotEmpty(), checkFieldIsValid(), checkFileFinderWidgetIsValid(), checkNotEqual(), checkRangeIsEnclosed(), checkRangesDontOverlap(), checkValidRange(), checkWorkspaceExists(), checkWorkspaceGroupIsValid(), checkWorkspaceNumberOfBins(), checkWorkspaceNumberOfHistograms(), and checkWorkspaceSelectorIsNotEmpty().
|
overridevirtual |
Check that the given range can be split evenly into bins of the given width.
Given a range defined by lower and upper bounds, checks to see if it can be divided evenly into bins of a given width.
Due to the nature of doubles, we use a tolerance value.
| lower | :: the lower bound of the range |
| binWidth | :: the wdith of the bin |
| upper | :: the upper bound of the range |
| tolerance | :: the tolerance with which to judge range / bin suitablility |
Implements MantidQt::CustomInterfaces::IUserInputValidator.
Definition at line 235 of file UserInputValidator.cpp.
References addErrorMessage(), lower, tolerance, and upper.
|
overridevirtual |
Check that the given DataSelector widget has valid input.
Check that the given DataSelector widget has valid files.
| name | :: the "name" of the widget so as to be recognised by the user. |
| widget | :: the widget to check |
| silent | True if an error should not be added to the validator. |
| autoLoad | True if the data should be reloaded if it is not in the ADS. |
Implements MantidQt::CustomInterfaces::IUserInputValidator.
Definition at line 145 of file UserInputValidator.cpp.
References addErrorMessage(), MantidQt::MantidWidgets::DataSelector::getProblem(), MantidQt::MantidWidgets::DataSelector::isValid(), and name.
|
overridevirtual |
Check that the given QLineEdit field is not empty.
Check that a given QLineEdit field (with given name) is not empty.
If it is empty then the given QLabel will be set to "*" and an error will be added to m_errorMessages. Else set the label to "".
| name | :: name of the field, so as to be recognised by the user |
| field | :: the field object to be checked |
| errorLabel | :: the "*" or "" label. |
Implements MantidQt::CustomInterfaces::IUserInputValidator.
Definition at line 67 of file UserInputValidator.cpp.
References addErrorMessage(), name, and setErrorLabel().
|
overridevirtual |
Check that the given QLineEdit field is valid as per any validators it might have.
| field | :: the field to be checked |
| errorLabel | :: the "" or "*" label |
| errorMessage | :: the message to log if invalid |
Implements MantidQt::CustomInterfaces::IUserInputValidator.
Definition at line 87 of file UserInputValidator.cpp.
References addErrorMessage(), and setErrorLabel().
|
overridevirtual |
Check that the given FileFinderWidget widget has valid files.
| name | :: the "name" of the widget so as to be recognised by the user. |
| widget | :: the widget to check |
Implements MantidQt::CustomInterfaces::IUserInputValidator.
Definition at line 127 of file UserInputValidator.cpp.
References addErrorMessage(), MantidQt::API::FileFinderWidget::getFileProblem(), MantidQt::API::FileFinderWidget::isValid(), and name.
| bool MantidQt::CustomInterfaces::UserInputValidator::checkNotEqual | ( | const QString & | name, |
| double | x, | ||
| double | y = 0.0, |
||
| double | tolerance = 0.00000001 |
||
| ) |
Checks two values are not equal.
| name | Name of value |
| x | First value |
| y | Second value (defaults to zero) |
| tolerance | Tolerance to which to compare |
Definition at line 274 of file UserInputValidator.cpp.
References addErrorMessage(), Mantid::Kernel::delta, name, tolerance, Mantid::Geometry::x, and Mantid::Geometry::y.
|
overridevirtual |
Check that the given "outer" range completely encloses the given "inner" range.
| outerName | :: the end of the range |
| outer | :: pair of range bounds |
| innerName | :: the start of the range |
| inner | :: pair of range bounds |
Implements MantidQt::CustomInterfaces::IUserInputValidator.
Definition at line 210 of file UserInputValidator.cpp.
References addErrorMessage().
|
overridevirtual |
Check that the given ranges dont overlap.
| rangeA | :: the start of the range |
| rangeB | :: the end of the range |
Implements MantidQt::CustomInterfaces::IUserInputValidator.
Definition at line 183 of file UserInputValidator.cpp.
References addErrorMessage().
|
overridevirtual |
Check that the given start and end range is valid.
| name | :: the name of the range |
| range | :: the range |
Implements MantidQt::CustomInterfaces::IUserInputValidator.
Definition at line 162 of file UserInputValidator.cpp.
References addErrorMessage(), and name.
|
overridevirtual |
Checks that a workspace exists in the ADS.
Checks that a workspace exists within the ADS.
| workspaceName | Name of the workspace |
| silent | True if an error should not be added to the validator. |
Implements MantidQt::CustomInterfaces::IUserInputValidator.
Definition at line 295 of file UserInputValidator.cpp.
References addErrorMessage().
Referenced by checkWorkspaceNumberOfBins(), and checkWorkspaceNumberOfHistograms().
|
overridevirtual |
Checks that a workspace group contains valid matrix workspace's.
Checks that a workspaces group is not empty and doesn't contain null workspaces.
| groupName | The name of the workspace group |
| inputType | The name to put in the error message (e.g. "Sample") |
| silent | True if an error should not be added to the validator. |
Implements MantidQt::CustomInterfaces::IUserInputValidator.
Definition at line 375 of file UserInputValidator.cpp.
References addErrorMessage(), error, and group.
| bool MantidQt::CustomInterfaces::UserInputValidator::checkWorkspaceNumberOfBins | ( | const Mantid::API::MatrixWorkspace_sptr & | workspace, |
| std::size_t const & | validSize | ||
| ) |
Checks that a workspaces has a valid number of bins.
| workspace | The workspace |
| validSize | The valid number of bins |
Definition at line 357 of file UserInputValidator.cpp.
References addErrorMessage(), std::to_string(), and workspace.
| bool MantidQt::CustomInterfaces::UserInputValidator::checkWorkspaceNumberOfBins | ( | QString const & | workspaceName, |
| std::size_t const & | validSize | ||
| ) |
Checks the number of bins in a workspace.
Checks that a workspaces has a valid number of bins.
| workspaceName | Name of the workspace |
| validSize | The valid number of bins |
Definition at line 344 of file UserInputValidator.cpp.
References checkWorkspaceExists(), checkWorkspaceNumberOfBins(), and MantidQt::MantidWidgets::WorkspaceUtils::getADSWorkspace().
Referenced by checkWorkspaceNumberOfBins().
| bool MantidQt::CustomInterfaces::UserInputValidator::checkWorkspaceNumberOfHistograms | ( | const Mantid::API::MatrixWorkspace_sptr & | workspace, |
| std::size_t const & | validSize | ||
| ) |
Checks that a workspaces has a valid number of histograms.
| workspace | The workspace |
| validSize | The valid number of histograms |
Definition at line 328 of file UserInputValidator.cpp.
References addErrorMessage(), std::to_string(), and workspace.
| bool MantidQt::CustomInterfaces::UserInputValidator::checkWorkspaceNumberOfHistograms | ( | QString const & | workspaceName, |
| std::size_t const & | validSize | ||
| ) |
Checks the number of histograms in a workspace.
Checks that a workspaces has a valid number of histograms.
| workspaceName | Name of the workspace |
| validSize | The valid number of histograms |
Definition at line 315 of file UserInputValidator.cpp.
References checkWorkspaceExists(), checkWorkspaceNumberOfHistograms(), and MantidQt::MantidWidgets::WorkspaceUtils::getADSWorkspace().
Referenced by checkWorkspaceNumberOfHistograms().
|
overridevirtual |
Check that the given WorkspaceSelector is not empty.
Appends a message to m_errorMessages if so.
| name | :: the "name" of the workspace selector, so as to be recognised by the user |
| workspaceSelector | :: the workspace selector to check |
Implements MantidQt::CustomInterfaces::IUserInputValidator.
Definition at line 111 of file UserInputValidator.cpp.
References addErrorMessage(), and name.
|
overridevirtual |
Returns an error message which contains all the error messages raised by the check functions.
Generates and returns an error message which contains all the error messages raised by the check functions.
Implements MantidQt::CustomInterfaces::IUserInputValidator.
Definition at line 405 of file UserInputValidator.cpp.
References m_errorMessages.
|
overridevirtual |
Checks to see if all input is valid.
Checks if the user input checked is valid.
Implements MantidQt::CustomInterfaces::IUserInputValidator.
Definition at line 417 of file UserInputValidator.cpp.
References m_error.
|
overridevirtual |
Sets a validation label.
Sets a validation label that is displyed next to the widget on the UI.
| errorLabel | Label to change |
| valid | If the input was valid |
Implements MantidQt::CustomInterfaces::IUserInputValidator.
Definition at line 425 of file UserInputValidator.cpp.
Referenced by checkFieldIsNotEmpty(), and checkFieldIsValid().
|
private |
True if there has been an error.
Definition at line 121 of file UserInputValidator.h.
Referenced by addErrorMessage(), and isAllInputValid().
|
private |
Any raised error messages.
Definition at line 119 of file UserInputValidator.h.
Referenced by addErrorMessage(), and generateErrorMessage().