Mantid
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
MantidQt::CustomInterfaces::UserInputValidator Class Referencefinal

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>

Inheritance diagram for MantidQt::CustomInterfaces::UserInputValidator:
MantidQt::CustomInterfaces::IUserInputValidator

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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ UserInputValidator()

MantidQt::CustomInterfaces::UserInputValidator::UserInputValidator ( )

Default Constructor.

Definition at line 52 of file UserInputValidator.cpp.

◆ ~UserInputValidator()

MantidQt::CustomInterfaces::UserInputValidator::~UserInputValidator ( )
overridedefault

Member Function Documentation

◆ addErrorMessage()

void MantidQt::CustomInterfaces::UserInputValidator::addErrorMessage ( const std::string &  message,
bool const  silent = false 
)
overridevirtual

◆ checkBins()

bool MantidQt::CustomInterfaces::UserInputValidator::checkBins ( double  lower,
double  binWidth,
double  upper,
double  tolerance = 0.00000001 
)
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.

Parameters
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
Returns
True if the input was valid

Implements MantidQt::CustomInterfaces::IUserInputValidator.

Definition at line 235 of file UserInputValidator.cpp.

References addErrorMessage(), lower, tolerance, and upper.

◆ checkDataSelectorIsValid()

bool MantidQt::CustomInterfaces::UserInputValidator::checkDataSelectorIsValid ( const QString &  name,
DataSelector widget,
bool const  silent = false,
bool const  autoLoad = true 
)
overridevirtual

Check that the given DataSelector widget has valid input.

Check that the given DataSelector widget has valid files.

Parameters
name:: the "name" of the widget so as to be recognised by the user.
widget:: the widget to check
silentTrue if an error should not be added to the validator.
autoLoadTrue if the data should be reloaded if it is not in the ADS.
Returns
True if the input was valid

Implements MantidQt::CustomInterfaces::IUserInputValidator.

Definition at line 145 of file UserInputValidator.cpp.

References addErrorMessage(), MantidQt::MantidWidgets::DataSelector::getProblem(), MantidQt::MantidWidgets::DataSelector::isValid(), and name.

◆ checkFieldIsNotEmpty()

bool MantidQt::CustomInterfaces::UserInputValidator::checkFieldIsNotEmpty ( const QString &  name,
QLineEdit *  field,
QLabel *  errorLabel = nullptr 
)
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 "".

Parameters
name:: name of the field, so as to be recognised by the user
field:: the field object to be checked
errorLabel:: the "*" or "" label.
Returns
True if the input was valid

Implements MantidQt::CustomInterfaces::IUserInputValidator.

Definition at line 67 of file UserInputValidator.cpp.

References addErrorMessage(), name, and setErrorLabel().

◆ checkFieldIsValid()

bool MantidQt::CustomInterfaces::UserInputValidator::checkFieldIsValid ( const QString &  errorMessage,
QLineEdit *  field,
QLabel *  errorLabel = nullptr 
)
overridevirtual

Check that the given QLineEdit field is valid as per any validators it might have.

Parameters
field:: the field to be checked
errorLabel:: the "" or "*" label
errorMessage:: the message to log if invalid
Returns
True if the input was valid

Implements MantidQt::CustomInterfaces::IUserInputValidator.

Definition at line 87 of file UserInputValidator.cpp.

References addErrorMessage(), and setErrorLabel().

◆ checkFileFinderWidgetIsValid()

bool MantidQt::CustomInterfaces::UserInputValidator::checkFileFinderWidgetIsValid ( const QString &  name,
const FileFinderWidget widget 
)
overridevirtual

Check that the given FileFinderWidget widget has valid files.

Parameters
name:: the "name" of the widget so as to be recognised by the user.
widget:: the widget to check
Returns
True if the input was valid

Implements MantidQt::CustomInterfaces::IUserInputValidator.

Definition at line 127 of file UserInputValidator.cpp.

References addErrorMessage(), MantidQt::API::FileFinderWidget::getFileProblem(), MantidQt::API::FileFinderWidget::isValid(), and name.

◆ checkNotEqual()

bool MantidQt::CustomInterfaces::UserInputValidator::checkNotEqual ( const QString &  name,
double  x,
double  y = 0.0,
double  tolerance = 0.00000001 
)

Checks two values are not equal.

Parameters
nameName of value
xFirst value
ySecond value (defaults to zero)
toleranceTolerance to which to compare
Returns
True if input was valid

Definition at line 274 of file UserInputValidator.cpp.

References addErrorMessage(), Mantid::Kernel::delta, name, tolerance, Mantid::Geometry::x, and Mantid::Geometry::y.

◆ checkRangeIsEnclosed()

bool MantidQt::CustomInterfaces::UserInputValidator::checkRangeIsEnclosed ( const QString &  outerName,
std::pair< double, double >  outer,
const QString &  innerName,
std::pair< double, double >  inner 
)
overridevirtual

Check that the given "outer" range completely encloses the given "inner" range.

Parameters
outerName:: the end of the range
outer:: pair of range bounds
innerName:: the start of the range
inner:: pair of range bounds
Returns
True if the input was valid

Implements MantidQt::CustomInterfaces::IUserInputValidator.

Definition at line 210 of file UserInputValidator.cpp.

References addErrorMessage().

◆ checkRangesDontOverlap()

bool MantidQt::CustomInterfaces::UserInputValidator::checkRangesDontOverlap ( std::pair< double, double >  rangeA,
std::pair< double, double >  rangeB 
)
overridevirtual

Check that the given ranges dont overlap.

Parameters
rangeA:: the start of the range
rangeB:: the end of the range
Returns
True if the input was valid

Implements MantidQt::CustomInterfaces::IUserInputValidator.

Definition at line 183 of file UserInputValidator.cpp.

References addErrorMessage().

◆ checkValidRange()

bool MantidQt::CustomInterfaces::UserInputValidator::checkValidRange ( const QString &  name,
std::pair< double, double >  range 
)
overridevirtual

Check that the given start and end range is valid.

Parameters
name:: the name of the range
range:: the range
Returns
True if the input was valid

Implements MantidQt::CustomInterfaces::IUserInputValidator.

Definition at line 162 of file UserInputValidator.cpp.

References addErrorMessage(), and name.

◆ checkWorkspaceExists()

bool MantidQt::CustomInterfaces::UserInputValidator::checkWorkspaceExists ( QString const &  workspaceName,
bool  silent = false 
)
overridevirtual

Checks that a workspace exists in the ADS.

Checks that a workspace exists within the ADS.

Parameters
workspaceNameName of the workspace
silentTrue if an error should not be added to the validator.
Returns
True if the workspace is in the ADS

Implements MantidQt::CustomInterfaces::IUserInputValidator.

Definition at line 295 of file UserInputValidator.cpp.

References addErrorMessage().

Referenced by checkWorkspaceNumberOfBins(), and checkWorkspaceNumberOfHistograms().

◆ checkWorkspaceGroupIsValid()

bool MantidQt::CustomInterfaces::UserInputValidator::checkWorkspaceGroupIsValid ( QString const &  groupName,
QString const &  inputType,
bool  silent = false 
)
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.

Parameters
groupNameThe name of the workspace group
inputTypeThe name to put in the error message (e.g. "Sample")
silentTrue if an error should not be added to the validator.
Returns
True if the workspace group is valid

Implements MantidQt::CustomInterfaces::IUserInputValidator.

Definition at line 375 of file UserInputValidator.cpp.

References addErrorMessage(), error, and group.

◆ checkWorkspaceNumberOfBins() [1/2]

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.

Parameters
workspaceThe workspace
validSizeThe valid number of bins
Returns
True if the workspace has the correct size

Definition at line 357 of file UserInputValidator.cpp.

References addErrorMessage(), std::to_string(), and workspace.

◆ checkWorkspaceNumberOfBins() [2/2]

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.

Parameters
workspaceNameName of the workspace
validSizeThe valid number of bins
Returns
True if the workspace has the correct size

Definition at line 344 of file UserInputValidator.cpp.

References checkWorkspaceExists(), checkWorkspaceNumberOfBins(), and MantidQt::MantidWidgets::WorkspaceUtils::getADSWorkspace().

Referenced by checkWorkspaceNumberOfBins().

◆ checkWorkspaceNumberOfHistograms() [1/2]

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.

Parameters
workspaceThe workspace
validSizeThe valid number of histograms
Returns
True if the workspace has the correct size

Definition at line 328 of file UserInputValidator.cpp.

References addErrorMessage(), std::to_string(), and workspace.

◆ checkWorkspaceNumberOfHistograms() [2/2]

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.

Parameters
workspaceNameName of the workspace
validSizeThe valid number of histograms
Returns
True if the workspace has the correct size

Definition at line 315 of file UserInputValidator.cpp.

References checkWorkspaceExists(), checkWorkspaceNumberOfHistograms(), and MantidQt::MantidWidgets::WorkspaceUtils::getADSWorkspace().

Referenced by checkWorkspaceNumberOfHistograms().

◆ checkWorkspaceSelectorIsNotEmpty()

bool MantidQt::CustomInterfaces::UserInputValidator::checkWorkspaceSelectorIsNotEmpty ( const QString &  name,
WorkspaceSelector workspaceSelector 
)
overridevirtual

Check that the given WorkspaceSelector is not empty.

Appends a message to m_errorMessages if so.

Parameters
name:: the "name" of the workspace selector, so as to be recognised by the user
workspaceSelector:: the workspace selector to check
Returns
True if the input was valid

Implements MantidQt::CustomInterfaces::IUserInputValidator.

Definition at line 111 of file UserInputValidator.cpp.

References addErrorMessage(), and name.

◆ generateErrorMessage()

std::string MantidQt::CustomInterfaces::UserInputValidator::generateErrorMessage ( ) const
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.

◆ isAllInputValid()

bool MantidQt::CustomInterfaces::UserInputValidator::isAllInputValid ( ) const
overridevirtual

Checks to see if all input is valid.

Checks if the user input checked is valid.

Returns
True if all input is valid, false otherwise

Implements MantidQt::CustomInterfaces::IUserInputValidator.

Definition at line 417 of file UserInputValidator.cpp.

References m_error.

◆ setErrorLabel()

void MantidQt::CustomInterfaces::UserInputValidator::setErrorLabel ( QLabel *  errorLabel,
bool  valid 
)
overridevirtual

Sets a validation label.

Sets a validation label that is displyed next to the widget on the UI.

Parameters
errorLabelLabel to change
validIf the input was valid

Implements MantidQt::CustomInterfaces::IUserInputValidator.

Definition at line 425 of file UserInputValidator.cpp.

Referenced by checkFieldIsNotEmpty(), and checkFieldIsValid().

Member Data Documentation

◆ m_error

bool MantidQt::CustomInterfaces::UserInputValidator::m_error
private

True if there has been an error.

Definition at line 121 of file UserInputValidator.h.

Referenced by addErrorMessage(), and isAllInputValid().

◆ m_errorMessages

QStringList MantidQt::CustomInterfaces::UserInputValidator::m_errorMessages
private

Any raised error messages.

Definition at line 119 of file UserInputValidator.h.

Referenced by addErrorMessage(), and generateErrorMessage().


The documentation for this class was generated from the following files: