Revision dcb097f9
Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt
samples/validators/main.cpp | ||
---|---|---|
*/
|
||
|
||
QSharedPointer<Entity> p1 = QSharedPointer<Person>(new Person("Thomas", "B",
|
||
Person::Gender::MALE, "", QString(), QString(), QDate(1971, 7, 13), 0));
|
||
Person::Gender::MALE, "", QString(), QString(), QDate(), 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",
|
src/validators/emailvalidator.cpp | ||
---|---|---|
ErrorMsg EmailValidator::validateParam(QVariant value, Param param) const {
|
||
QRegularExpression exp = QRegularExpression();
|
||
QString val = value.toString();
|
||
if (param.getName() == "full") {
|
||
exp.setPattern(this->getFullPattern());
|
||
} else {
|
||
exp.setPattern(this->getPattern());
|
||
if (!val.isEmpty()) {
|
||
if (param.getName() == "full") {
|
||
exp.setPattern(this->getFullPattern());
|
||
} else {
|
||
exp.setPattern(this->getPattern());
|
||
}
|
||
if (exp.match(val).hasMatch()) {
|
||
return ErrorMsg();
|
||
}
|
||
return ErrorMsg(param.getName(), "<property> is not a valid email address.");
|
||
}
|
||
if (exp.match(val).hasMatch()) {
|
||
return ErrorMsg();
|
||
}
|
||
return ErrorMsg(param.getName(), "<property> is not a valid email address.");
|
||
return ErrorMsg();
|
||
}
|
||
|
||
QString EmailValidator::getPattern() const {
|
src/validators/filevalidator.cpp | ||
---|---|---|
* @return
|
||
*/
|
||
ErrorMsg FileValidator::validateParam(QVariant value, Param param) const {
|
||
QFileInfo file = QFileInfo(value.toString());
|
||
if (param.getName() == "mimeTypes") {
|
||
return this->validateMIMEType(file, param);
|
||
} else if (param.getName() == "extensions") {
|
||
return this->validateExtension(file, param);
|
||
} else if (param.getName() == "minSize"
|
||
&& file.size() < param.getValue().toLongLong()) {
|
||
return ErrorMsg(param.getName(),
|
||
"The file <property> is too small. Its size cannot be smaller than " +
|
||
param.getValue().toString() + " bytes.");
|
||
QString fileName = value.toString();
|
||
if (!fileName.isEmpty()) {
|
||
QFileInfo file = QFileInfo(value.toString());
|
||
if (param.getName() == "mimeTypes") {
|
||
return this->validateMIMEType(file, param);
|
||
} else if (param.getName() == "extensions") {
|
||
return this->validateExtension(file, param);
|
||
} else if (param.getName() == "minSize"
|
||
&& file.size() < param.getValue().toLongLong()) {
|
||
return ErrorMsg(param.getName(),
|
||
"The file <property> is too small. Its size cannot be smaller than " +
|
||
param.getValue().toString() + " bytes.");
|
||
|
||
} else if (param.getName() == "maxSize") {
|
||
return ErrorMsg(param.getName(),
|
||
"The file <property> is too big. Its size cannot exceed " +
|
||
param.getValue().toString() + " bytes.");
|
||
} else if (param.getName() == "maxSize") {
|
||
return ErrorMsg(param.getName(),
|
||
"The file <property> is too big. Its size cannot exceed " +
|
||
param.getValue().toString() + " bytes.");
|
||
}
|
||
}
|
||
return ErrorMsg();
|
||
}
|
src/validators/patternvalidator.cpp | ||
---|---|---|
}
|
||
|
||
ErrorMsg PatternValidator::validateParam(QVariant value, Param param) const {
|
||
QRegularExpression regExp = QRegularExpression();
|
||
if (param.getName().isEmpty()) {
|
||
regExp.setPattern(param.getValue().toString());
|
||
} else {
|
||
regExp.setPattern(param.getName());
|
||
if (!value.toString().isEmpty()) {
|
||
QRegularExpression regExp = QRegularExpression();
|
||
if (param.getName().isEmpty()) {
|
||
regExp.setPattern(param.getValue().toString());
|
||
} else {
|
||
regExp.setPattern(param.getName());
|
||
}
|
||
if (regExp.match(value.toString()).hasMatch()) {
|
||
return ErrorMsg();
|
||
}
|
||
return ErrorMsg(param.getName(), "<property> not matches the pattern.");
|
||
}
|
||
if (regExp.match(value.toString()).hasMatch()) {
|
||
return ErrorMsg();
|
||
}
|
||
return ErrorMsg(param.getName(), "<property> not matches the pattern.");
|
||
return ErrorMsg();
|
||
}
|
||
|
src/validators/urlvalidator.cpp | ||
---|---|---|
|
||
ErrorMsg UrlValidator::validateParam(QVariant value, Param param) const {
|
||
QString val = value.toString();
|
||
if (val.size() < 2000) {
|
||
if (!val.isEmpty() && val.size() < 2000) {
|
||
if (param.getName() == "defaultScheme" && !param.getValue().isNull()) {
|
||
val = param.getValue().toString() + "://" + val;
|
||
}
|
Auch abrufbar als: Unified diff
validator stuff