Projekt

Allgemein

Profil

Herunterladen als
Herunterladen (1,88 KB) Statistiken
| Zweig: | Revision:
e2ee17bf Christian Ehringfeld
#include "validator.h"
#include "validatorfactory.h"
using namespace CuteEntityManager;
Validator::Validator() : QObject() {
ValidatorFactory::registerClasses();
}

Validator::~Validator() {
}

const QHash<QString, QString> Validator::builtInValidators() {
QHash<QString, QString> hash = QHash<QString, QString>();
b7f1ce8e Christian Ehringfeld
hash.insert("compare", "CuteEntityManager::CompareValidator");
hash.insert("default", "CuteEntityManager::DefaultValidator");
hash.insert("email", "CuteEntityManager::EmailValidator");
hash.insert("exists", "CuteEntityManager::ExistValidator");
hash.insert("file", "CuteEntityManager::FileValidator");
hash.insert("image", "CuteEntityManager::ImageValidator");
hash.insert("number", "CuteEntityManager::NumberValidator");
hash.insert("date", "CuteEntityManager::DateValidator");
hash.insert("required", "CuteEntityManager::RequiredValidator");
hash.insert("unique", "CuteEntityManager::UniqueValidator");
hash.insert("url", "CuteEntityManager::UrlValidator");
hash.insert("pattern", "CuteEntityManager::PatternValidator");
hash.insert("length", "CuteEntityManager::LengthValidator");
e2ee17bf Christian Ehringfeld
return hash;
}

QList<ErrorMsg> Validator::validate(QVariant value, QList<Param> params) const {
QList<ErrorMsg> msgs = QList<ErrorMsg>();
b7f1ce8e Christian Ehringfeld
if (params.isEmpty()) {
params.append(Param(""));
}
e2ee17bf Christian Ehringfeld
for (int i = 0; i < params.size(); ++i) {
ErrorMsg msg = this->validateParam(value, params.at(i));
if (!msg.getErrorMsg().isEmpty()) {
msgs.append(msg);
}
}
return msgs;
}

QString Validator::generateErrorMsg(ErrorMsg msg) {
if (msg.getPropertyName().isEmpty()) {
//return tr(msg.getErrorMsg());
return msg.getErrorMsg();
}
//return tr(msg.getErrorMsg()).replace("<property>", msg.getPropertyName());
return msg.getErrorMsg().replace("<property>", msg.getPropertyName());
}