TreeFrogFramework 2.10
Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
TFormValidator Class Reference

#include <tformvalidator.h>

Classes

class  RuleEntry
 

Public Member Functions

 TFormValidator ()
 
 TFormValidator (const TFormValidator &other)
 
virtual ~TFormValidator ()
 
TFormValidatoroperator= (const TFormValidator &other)
 
void setRule (const QString &key, Tf::ValidationRule rule, bool enable=true, const QString &errorMessage=QString())
 
void setRule (const QString &key, Tf::ValidationRule rule, const QString &errorMessage)
 
void setRule (const QString &key, Tf::ValidationRule rule, const char *errorMessage)
 
void setRule (const QString &key, Tf::ValidationRule rule, float val, const QString &errorMessage=QString())
 
void setRule (const QString &key, Tf::ValidationRule rule, double val, const QString &errorMessage=QString())
 
void setRule (const QString &key, Tf::ValidationRule rule, int val, const QString &errorMessage=QString())
 
void setRule (const QString &key, Tf::ValidationRule rule, int64_t val, const QString &errorMessage=QString())
 
void setPatternRule (const QString &key, const QRegularExpression &rx, const QString &errorMessage=QString())
 
QString message (const QString &key, Tf::ValidationRule rule) const
 
void setDateFormat (const QString &format)
 
QString dateFormat () const
 
void setTimeFormat (const QString &format)
 
QString timeFormat () const
 
void setDateTimeFormat (const QString &format)
 
QString dateTimeFormat () const
 
virtual bool validate (const QVariantMap &map)
 
bool hasValidationError () const
 
bool isValidationError (const QString &key) const
 
QStringList validationErrorKeys () const
 
QString errorMessage (const QString &key) const
 
QStringList errorMessages () const
 
QString value (const QString &key, const QString &defaultValue=QString()) const
 
Tf::ValidationRule errorRule (const QString &key) const
 
void setValidationError (const QString &key, const QString &errorMessage)
 

Protected Member Functions

bool containsRule (const QString &key, Tf::ValidationRule rule) const
 
void removeRule (const QString &key, Tf::ValidationRule rule)
 

Protected Attributes

QList< RuleEntryrules
 
QList< QPair< QString, int > > errors
 

Detailed Description

The TFormValidator class provides form validation for a map-table-based dictionary.

Constructor & Destructor Documentation

◆ TFormValidator() [1/2]

TFormValidator::TFormValidator ( )
inline

Constructor.

◆ TFormValidator() [2/2]

TFormValidator::TFormValidator ( const TFormValidator other)

Copy constructor.

◆ ~TFormValidator()

TFormValidator::~TFormValidator ( )
inlinevirtual

Destructor.

Member Function Documentation

◆ containsRule()

bool TFormValidator::containsRule ( const QString &  key,
Tf::ValidationRule  rule 
) const
protected

Returns true if the rules contains an item with the key; otherwise returns false.

◆ dateFormat()

QString TFormValidator::dateFormat ( ) const

Returns the date format specified by the validation settings file.

◆ dateTimeFormat()

QString TFormValidator::dateTimeFormat ( ) const

Returns the format of the date and time specified by the validation settings file.

◆ errorMessage()

QString TFormValidator::errorMessage ( const QString &  key) const

Return a message of validation error with key.

This function must be call after calling validate() function.

◆ errorMessages()

QStringList TFormValidator::errorMessages ( ) const

Return messages of validation error.

This function must be call after calling validate() function.

◆ errorRule()

Tf::ValidationRule TFormValidator::errorRule ( const QString &  key) const

Returns a rule of validation errors with key.

This function must be call after calling validate() function.

◆ hasValidationError()

bool TFormValidator::hasValidationError ( ) const

Returns false if validation error is not set, otherwise true.

◆ isValidationError()

bool TFormValidator::isValidationError ( const QString &  key) const

Returns true if an validation error is set for the key key, otherwise false.

◆ message()

QString TFormValidator::message ( const QString &  key,
Tf::ValidationRule  rule 
) const

Returns a message with key and rule in the validation rules.

◆ operator=()

TFormValidator & TFormValidator::operator= ( const TFormValidator other)

Assignment operator.

◆ removeRule()

void TFormValidator::removeRule ( const QString &  key,
Tf::ValidationRule  rule 
)
protected

Removes the specified item with the given key and rule from the validation rules.

◆ setDateFormat()

void TFormValidator::setDateFormat ( const QString &  format)
inline

Sets the date format to format for validation.

◆ setDateTimeFormat()

void TFormValidator::setDateTimeFormat ( const QString &  format)
inline

Sets the date and time format to format for validation.

◆ setPatternRule()

void TFormValidator::setPatternRule ( const QString &  key,
const QRegularExpression &  rx,
const QString &  errorMessage = QString() 
)

Sets the user-defined validaton rule for the key key and sets the error message of it to errorMessage.

◆ setRule() [1/7]

void TFormValidator::setRule ( const QString &  key,
Tf::ValidationRule  rule,
bool  enable = true,
const QString &  errorMessage = QString() 
)

Sets the validation rule for the key key and sets the error message of it to errorMessage.

If enable is true (by default), the rule is enabled.

◆ setRule() [2/7]

void TFormValidator::setRule ( const QString &  key,
Tf::ValidationRule  rule,
const char *  errorMessage 
)

Sets the validation rule for the key key and sets the error message of it to errorMessage.

◆ setRule() [3/7]

void TFormValidator::setRule ( const QString &  key,
Tf::ValidationRule  rule,
const QString &  errorMessage 
)

Sets the validation rule for the key key and sets the error message of it to errorMessage.

◆ setRule() [4/7]

void TFormValidator::setRule ( const QString &  key,
Tf::ValidationRule  rule,
double  val,
const QString &  errorMessage = QString() 
)

Sets the validation rule for the key key and sets the error message of it to errorMessage.

◆ setRule() [5/7]

void TFormValidator::setRule ( const QString &  key,
Tf::ValidationRule  rule,
float  val,
const QString &  errorMessage = QString() 
)

Sets the validation rule for the key key and set the error message of it to errorMessage.

◆ setRule() [6/7]

void TFormValidator::setRule ( const QString &  key,
Tf::ValidationRule  rule,
int  val,
const QString &  errorMessage = QString() 
)

Sets the validation rule for the key key and sets the error message of it to errorMessage.

◆ setRule() [7/7]

void TFormValidator::setRule ( const QString &  key,
Tf::ValidationRule  rule,
int64_t  val,
const QString &  errorMessage = QString() 
)

Sets the validation rule for the key key and sets the error message of it to errorMessage.

◆ setTimeFormat()

void TFormValidator::setTimeFormat ( const QString &  format)
inline

Sets the time format to format for validation.

◆ setValidationError()

void TFormValidator::setValidationError ( const QString &  key,
const QString &  errorMessage 
)

Sets the message of custom validation error to errorMessage for the key key.

◆ timeFormat()

QString TFormValidator::timeFormat ( ) const

Returns the time format specified by the validation settings file.

◆ validate()

bool TFormValidator::validate ( const QVariantMap &  map)
virtual

Validates the specified parameter map by the set rules.

As default, TF::Required is set for all parameters. If not required, set the rule to false like this: setRule("xxx", Tf::Required, false);

◆ validationErrorKeys()

QStringList TFormValidator::validationErrorKeys ( ) const

Returns a list of all keys of validation errors.

This function must be call after calling validate() function.

◆ value()

QString TFormValidator::value ( const QString &  key,
const QString &  defaultValue = QString() 
) const

Returns the value associated with the key key.

Member Data Documentation

◆ errors

QList<QPair<QString, int> > TFormValidator::errors
protected

◆ rules

QList<RuleEntry> TFormValidator::rules
protected

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