TreeFrogFramework  1.18
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, qint64 val, const QString &errorMessage=QString())
 
void setPatternRule (const QString &key, const QRegExp &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)
 
void setValidationError (const QString &errorMessage)
 

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::TFormValidator ( )
inline

Constructor.

TFormValidator::TFormValidator ( const TFormValidator other)

Copy constructor.

TFormValidator::~TFormValidator ( )
inlinevirtual

Destructor.

Member Function Documentation

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.

QString TFormValidator::dateFormat ( ) const

Returns the date format specified by the validation settings file.

QString TFormValidator::dateTimeFormat ( ) const

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

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

Return a message of validation error with key.

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

QStringList TFormValidator::errorMessages ( ) const

Return messages of validation error.

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

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.

bool TFormValidator::hasValidationError ( ) const

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

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

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

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

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

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

Assignment operator.

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

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

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

Sets the date format to format for validation.

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

Sets the date and time format to format for validation.

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

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

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.

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.

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.

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.

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.

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.

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

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

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

Sets the time format to format for validation.

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

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

void TFormValidator::setValidationError ( const QString &  errorMessage)
protected

Sets the message of custom validation error to errorMessage.

[obsolete]

QString TFormValidator::timeFormat ( ) const

Returns the time format specified by the validation settings file.

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);

QStringList TFormValidator::validationErrorKeys ( ) const

Returns a list of all keys of validation errors.

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

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

Returns the value associated with the key key.

Member Data Documentation

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

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