TreeFrogFramework  1.18
tformvalidator.h
Go to the documentation of this file.
1 #ifndef TFORMVALIDATOR_H
2 #define TFORMVALIDATOR_H
3 
4 #include <QStringList>
5 #include <QRegExp>
6 #include <QPair>
7 #include <QVariant>
8 #include <TGlobal>
9 
10 
12 {
13 public:
15  TFormValidator(const TFormValidator &other);
16  virtual ~TFormValidator() { }
17  TFormValidator &operator=(const TFormValidator &other);
18 
19  void setRule(const QString &key, Tf::ValidationRule rule, bool enable = true, const QString &errorMessage = QString());
20  void setRule(const QString &key, Tf::ValidationRule rule, const QString &errorMessage);
21  void setRule(const QString &key, Tf::ValidationRule rule, const char *errorMessage);
22  void setRule(const QString &key, Tf::ValidationRule rule, float val, const QString &errorMessage = QString());
23  void setRule(const QString &key, Tf::ValidationRule rule, double val, const QString &errorMessage = QString());
24  void setRule(const QString &key, Tf::ValidationRule rule, int val, const QString &errorMessage = QString());
25  void setRule(const QString &key, Tf::ValidationRule rule, qint64 val, const QString &errorMessage = QString());
26  void setPatternRule(const QString &key, const QRegExp &rx, const QString &errorMessage = QString());
27  QString message(const QString &key, Tf::ValidationRule rule) const;
28 
29  void setDateFormat(const QString &format);
30  QString dateFormat() const;
31  void setTimeFormat(const QString &format);
32  QString timeFormat() const;
33  void setDateTimeFormat(const QString &format);
34  QString dateTimeFormat() const;
35 
36  virtual bool validate(const QVariantMap &map);
37  bool hasValidationError() const;
38  bool isValidationError(const QString &key) const;
39  QStringList validationErrorKeys() const;
40  QString errorMessage(const QString &key) const;
41  QStringList errorMessages() const;
42  QString value(const QString &key, const QString &defaultValue = QString()) const;
43  Tf::ValidationRule errorRule(const QString &key) const;
44  void setValidationError(const QString &key, const QString &errorMessage);
45 
46 protected:
47  class RuleEntry
48  {
49  public:
50  QString key;
51  int rule;
52  QVariant value;
53  QString message;
54 
55  RuleEntry(const QString &key, int rule, bool enable, const QString &errorMessage);
56  RuleEntry(const QString &key, int rule, qint64 val, const QString &errorMessage);
57  RuleEntry(const QString &key, int rule, double val, const QString &errorMessage);
58  RuleEntry(const QString &key, int rule, const QRegExp &rx, const QString &errorMessage);
59  };
60 
61  bool containsRule(const QString &key, Tf::ValidationRule rule) const;
62  void removeRule(const QString &key, Tf::ValidationRule rule);
63  void setValidationError(const QString &errorMessage);
64 
65  QList<RuleEntry> rules;
66  QList<QPair<QString, int>> errors;
67 
68 private:
69  QString dateFmt;
70  QString timeFmt;
71  QString dateTimeFmt;
72  QVariantMap values;
73 };
74 
75 
76 inline void TFormValidator::setDateFormat(const QString &format)
77 { dateFmt = format; }
78 
79 inline void TFormValidator::setTimeFormat(const QString &format)
80 { timeFmt = format; }
81 
82 inline void TFormValidator::setDateTimeFormat(const QString &format)
83 { dateTimeFmt = format; }
84 
85 #endif // TFORMVALIDATOR_H
#define T_CORE_EXPORT
Definition: tglobal.h:81
The RuleEntry class is for internal use only.
Definition: tformvalidator.h:47
TFormValidator()
Constructor.
Definition: tformvalidator.h:14
void setTimeFormat(const QString &format)
Sets the time format to format for validation.
Definition: tformvalidator.h:79
ValidationRule
Definition: tfnamespace.h:109
QString key
Definition: tformvalidator.h:50
void setDateFormat(const QString &format)
Sets the date format to format for validation.
Definition: tformvalidator.h:76
QString message
Definition: tformvalidator.h:53
QList< QPair< QString, int > > errors
Definition: tformvalidator.h:66
virtual ~TFormValidator()
Destructor.
Definition: tformvalidator.h:16
The TFormValidator class provides form validation for a map-table-based dictionary.
Definition: tformvalidator.h:11
int rule
Definition: tformvalidator.h:51
QVariant value
Definition: tformvalidator.h:52
QList< RuleEntry > rules
Definition: tformvalidator.h:65
void setDateTimeFormat(const QString &format)
Sets the date and time format to format for validation.
Definition: tformvalidator.h:82