Cutelyst  1.5.0
Public Member Functions | Protected Member Functions | List of all members
Cutelyst::ValidatorAfter Class Reference

Checks if a date, time or datetime is after a comparison value. More...

#include <validatorafter.h>

Inheritance diagram for Cutelyst::ValidatorAfter:
Inheritance graph
[legend]

Public Member Functions

 ValidatorAfter (const QString &field, const QVariant &dateTime, const QString &inputFormat=QString(), const QString &label=QString(), const QString &customError=QString())
 Constructs a new after validator. More...
 
 ~ValidatorAfter ()
 Deconstructs the after validator.
 
void setDateTime (const QVariant &dateTime)
 Sets the QDate, QTime or QDateTime to compare against.
 
void setInputFormat (const QString &format)
 Sets optional format for input data parsing.
 
QString validate () const override
 Performs the validation and returns an empty QString on success, otherwise an error message.
 
- Public Member Functions inherited from Cutelyst::ValidatorRule
 ValidatorRule (const QString &field, const QString &label=QString(), const QString &customError=QString())
 Constructs a new ValidatorRule with given parameters and parent. More...
 
 ~ValidatorRule ()
 Deconstructs the ValidatorRule.
 
QString field () const
 Returns the name of the field to validate. More...
 
QString label () const
 Returns the human readable field label used for generic error messages. More...
 
ParamsMultiMap parameters () const
 Returns the parameters to validate. More...
 
void setCustomError (const QString &customError)
 Sets a cutom error returned with errorMessage() More...
 
void setCustomParsingError (const QString &custom)
 Sets a custom error message that is shown if parsing of input data fails. More...
 
void setCustomValidationDataError (const QString &custom)
 Sets a custom error message if validation data is invalid or missing. More...
 
void setField (const QString &field)
 Sets the name of the field to validate. More...
 
void setLabel (const QString &label)
 Sets human readable field label for generic error messages. More...
 
void setParameters (const ParamsMultiMap &params)
 Sets the request parameters to validate. More...
 
void setTrimBefore (bool trimBefore)
 Set to false to not trim input value before validation. More...
 
bool trimBefore () const
 Returns true if field value should be trimmed before validation. More...
 
QString value () const
 Returns the field value.
 

Protected Member Functions

 ValidatorAfter (ValidatorAfterPrivate &dd)
 
QString genericValidationError () const override
 Returns a generic error mesage if validation failed. More...
 
- Protected Member Functions inherited from Cutelyst::ValidatorRule
 ValidatorRule (ValidatorRulePrivate &dd)
 
virtual QString genericParsingError () const
 Returns a generic error message if an error occures while parsing input. More...
 
virtual QString genericValidationDataError () const
 Returns a generic error message if any validation data is missing or invalid. More...
 
QString parsingError () const
 Returns an error message if an error occured while parsing input. More...
 
QString validationDataError () const
 Returns an error message if any validation data is missing or invalid. More...
 
QString validationError () const
 Returns a descriptive error message if validation failed. More...
 

Additional Inherited Members

- Protected Attributes inherited from Cutelyst::ValidatorRule
const QScopedPointer< ValidatorRulePrivate > d_ptr
 

Detailed Description

This will check if the date, time or datetime in the input field is after a comparison value set via dateTime in the constructor or via setDateTime(). It depends on the comparison value how the input data is handled. If the comparative value is a QDateTime, the input data will be converted into a QDateTime to compare the both values and so on.

If the input data can not be parsed into a comparable format, the validation fails and ValidatorRule::parsingError() will return true. It will also fail if the comparative value is not of type QDate, QTime or QDateTime. Use inputFormat parameter of the constructor or setInputFormat() to set a custom input format. If no input format has been set, the validator will try to parse the input according to the following definitions: Qt::ISODate, Qt::RFC2822Date, Qt::TextDate

If ValidatorRule::trimBefore() is set to true (the default), whitespaces will be removed from the beginning and the end of the input value before validation. If the field's value is empty or if the field is missing in the input data, the validation will succeed without performing the validation itself. Use one of the required validators to require the field to be present and not empty.

See Validator for general usage of validators.

See also
ValidatorBefore

Definition at line 50 of file validatorafter.h.

Constructor & Destructor Documentation

Cutelyst::ValidatorAfter::ValidatorAfter ( const QString &  field,
const QVariant &  dateTime,
const QString &  inputFormat = QString(),
const QString &  label = QString(),
const QString &  customError = QString() 
)
Parameters
fieldName of the input field to validate.
dateTimeQDate, QTime or QDateTime to compare against. Any other type will lead to a validation data error and valiation fails.
inputFormatOptional input format for input data parsing.
labelHuman readable input field label, used for generic error messages.
customErrorCustom error message if validation fails.

Member Function Documentation

QString Cutelyst::ValidatorAfter::genericValidationError ( ) const
overrideprotectedvirtual

If you want to have a more specifc generic validation error message for your validator, reimplment this in a subclass.

Reimplemented from Cutelyst::ValidatorRule.