Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 3f097a32

Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt

  • ID 3f097a324dd82c58aa663b226daa55141a29cff5
  • Vorgänger a0c6df62
  • Nachfolger dcb097f9

fix

Unterschiede anzeigen:

samples/validators/main.cpp
QSharedPointer<Entity> p1 = QSharedPointer<Person>(new Person("Thomas", "B",
Person::Gender::MALE, "", QString(), QString(), QDate(1971, 7, 13), 0));
QSharedPointer<Entity>p2 = QSharedPointer<Person>(new Person("Teresa", "Conrad",
Person::Gender::FEMALE, "", QString(), QString(), QDate(1970, 7, 13), 0));
QSharedPointer<Entity> p2 = QSharedPointer<Person>(new Person("Teresa", "Conrad",
Person::Gender::FEMALE, "", QString(), QString(), QDate(2016, 7, 13), 0));
QSharedPointer<Entity> p3 = QSharedPointer<Person>(new Person("Heinz", "Dunst",
Person::Gender::MALE, "", QString(), QString(), QDate(1972, 7, 13), 0));
samples/validators/person.cpp
QList<ValidationRule> Person::validationRules() const {
QList<ValidationRule> rules = QList<ValidationRule>();
rules.append(ValidationRule("length", {"firstName", "familyName"}, "min", 2));
rules.append(ValidationRule("date", "birthday", "past", "", "min", QDate(1973,
1, 1)));
return rules;
}
src/validators/datevalidator.cpp
#include "datevalidator.h"
#include <QDate>
#include <QLocale>
#include <QDebug>
using namespace CuteEntityManager;
DateValidator::DateValidator() : Validator() {
}
ErrorMsg DateValidator::validateParam(QVariant value, Param param) const {
......
if (date.isValid()) {
if (param.getName() == "future") {
if (date < QDate::currentDate()) {
ErrorMsg(param.getName(), "<property> is not in the future.");
return ErrorMsg(param.getName(), "<property> is not in the future.");
}
} else if (param.getName() == "past") {
if (date > QDate::currentDate()) {
ErrorMsg(param.getName(), "<property> is not in the past.");
return ErrorMsg(param.getName(), "<property> is not in the past.");
}
} else if (param.getName() == "min" && date < param.getValue().toDate()) {
ErrorMsg(param.getName(),
"<property> must be no less than " + param.getValue().toString());
return ErrorMsg(param.getName(),
"<property> must be no less than " + param.getValue().toString() + ".");
} else if (param.getName() == "max" && date > param.getValue().toDate()) {
ErrorMsg(param.getName(),
"<property> must be no greater than " + param.getValue().toString());
return ErrorMsg(param.getName(),
"<property> must be no greater than " + param.getValue().toString() + ".");
}
}
//cause we don't want to replace functionality of RequiredValidator

Auch abrufbar als: Unified diff