Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision ec6a9500

Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt

  • ID ec6a9500750fce573d6d3cf1e21a0077678178f5
  • Vorgänger 51bbd62c
  • Nachfolger 93bf6dcb

validators

Unterschiede anzeigen:

EntityManager.pro
src/validators/validatorfactory.h \
src/validators/validatorrule.h \
src/validators/requiredvalidator.h \
src/validators/numbervalidator.h
src/validators/numbervalidator.h \
src/validators/urlvalidator.h \
src/validators/comparevalidator.h \
src/validators/datevalidator.h \
src/validators/emailvalidator.h \
src/validators/existvalidator.h \
src/validators/filevalidator.h \
src/validators/imagevalidator.h \
src/validators/uniquevalidator.h
SOURCES += \
src/entity.cpp \
......
src/validators/validatorfactory.cpp \
src/validators/validatorrule.cpp \
src/validators/requiredvalidator.cpp \
src/validators/numbervalidator.cpp
src/validators/numbervalidator.cpp \
src/validators/urlvalidator.cpp \
src/validators/comparevalidator.cpp \
src/validators/datevalidator.cpp \
src/validators/emailvalidator.cpp \
src/validators/existvalidator.cpp \
src/validators/filevalidator.cpp \
src/validators/imagevalidator.cpp \
src/validators/uniquevalidator.cpp
CONFIG += c++14
QMAKE_CXXFLAGS += -std=c++14
src/validators/comparevalidator.cpp
#include "comparevalidator.h"
using namespace CuteEntityManager;
CompareValidator::CompareValidator() : Validator() {
}
ErrorMsg CompareValidator::validateParam(QVariant value, Param param) const {
}
src/validators/comparevalidator.h
#ifndef COMPAREVALIDATOR_H
#define COMPAREVALIDATOR_H
#include "validator.h"
namespace CuteEntityManager {
class CompareValidator : public Validator {
Q_OBJECT
public:
CompareValidator();
ErrorMsg validateParam(QVariant value, Param param) const final override;
};
}
#endif // COMPAREVALIDATOR_H
src/validators/datevalidator.cpp
#include "datevalidator.h"
using namespace CuteEntityManager;
DateValidator::DateValidator() : Validator() {
}
ErrorMsg DateValidator::validateParam(QVariant value, Param param) const {
}
src/validators/datevalidator.h
#ifndef DATEVALIDATOR_H
#define DATEVALIDATOR_H
#include "validator.h"
namespace CuteEntityManager {
class DateValidator : public Validator {
Q_OBJECT
public:
DateValidator();
ErrorMsg validateParam(QVariant value, Param param) const final override;
};
}
#endif // DATEVALIDATOR_H
src/validators/emailvalidator.cpp
#include "emailvalidator.h"
using namespace CuteEntityManager;
EmailValidator::EmailValidator() : Validator() {
}
ErrorMsg EmailValidator::validateParam(QVariant value, Param param) const {
}
src/validators/emailvalidator.h
#ifndef EMAILVALIDATOR_H
#define EMAILVALIDATOR_H
#include "validator.h"
namespace CuteEntityManager {
class EmailValidator : public Validator {
Q_OBJECT
public:
EmailValidator();
ErrorMsg validateParam(QVariant value, Param param) const final override;
};
}
#endif // EMAILVALIDATOR_H
src/validators/existvalidator.cpp
#include "existvalidator.h"
using namespace CuteEntityManager;
ExistValidator::ExistValidator() : Validator() {
}
ErrorMsg ExistValidator::validateParam(QVariant value, Param param) const {
}
src/validators/existvalidator.h
#ifndef EXISTVALIDATOR_H
#define EXISTVALIDATOR_H
#include "validator.h"
namespace CuteEntityManager {
class ExistValidator : public Validator {
Q_OBJECT
public:
ExistValidator();
ErrorMsg validateParam(QVariant value, Param param) const final override;
};
}
#endif // EXISTVALIDATOR_H
src/validators/filevalidator.cpp
#include "filevalidator.h"
using namespace CuteEntityManager;
FileValidator::FileValidator() : Validator() {
}
ErrorMsg FileValidator::validateParam(QVariant value, Param param) const {
}
src/validators/filevalidator.h
#ifndef FILEVALIDATOR_H
#define FILEVALIDATOR_H
#include "validator.h"
namespace CuteEntityManager {
class FileValidator : public Validator {
Q_OBJECT
public:
FileValidator();
virtual ErrorMsg validateParam(QVariant value, Param param) const override;
};
}
#endif // FILEVALIDATOR_H
src/validators/imagevalidator.cpp
#include "imagevalidator.h"
using namespace CuteEntityManager;
ImageValidator::ImageValidator() : FileValidator() {
}
ErrorMsg ImageValidator::validateParam(QVariant value, Param param) const {
}
src/validators/imagevalidator.h
#ifndef IMAGEVALIDATOR_H
#define IMAGEVALIDATOR_H
#include "filevalidator.h"
namespace CuteEntityManager {
class ImageValidator : public FileValidator {
Q_OBJECT
public:
ImageValidator();
ErrorMsg validateParam(QVariant value, Param param) const final override;
};
}
#endif // IMAGEVALIDATOR_H
src/validators/uniquevalidator.cpp
#include "uniquevalidator.h"
using namespace CuteEntityManager;
UniqueValidator::UniqueValidator() {
}
ErrorMsg UniqueValidator::validateParam(QVariant value, Param param) const {
}
src/validators/uniquevalidator.h
#ifndef UNIQUEVALIDATOR_H
#define UNIQUEVALIDATOR_H
#include "validator.h"
namespace CuteEntityManager {
class UniqueValidator : public Validator {
Q_OBJECT
public:
UniqueValidator();
ErrorMsg validateParam(QVariant value, Param param) const final override;
};
}
#endif // UNIQUEVALIDATOR_H
src/validators/urlvalidator.cpp
#include "urlvalidator.h"
using namespace CuteEntityManager;
#include <QRegularExpression>
UrlValidator::UrlValidator() : Validator() {
}
ErrorMsg UrlValidator::validateParam(QVariant value, Param param) const {
QString val = value.toString();
if (val.size() < 2000) {
if (param.getName() == "defaultScheme" && !param.getValue().isNull()) {
val = param.getValue().toString() + "://" + val;
}
QString pattern = "";
if (this->pattern.indexOf("{schemes}") != -1) {
QString replacement = "(";
bool first = true;
for (int i = 0; i < this->validSchemes.size(); ++i) {
if (first) {
first = false;
} else {
replacement += "|";
}
replacement += this->validSchemes.at(i);
}
replacement += ")";
pattern = this->getPattern().replace("{schemes}", replacement);
} else {
pattern = this->pattern;
}
QRegularExpression regExp = QRegularExpression(pattern);
if (regExp.match(val).hasMatch()) {
return ErrorMsg();
} else {
return ErrorMsg(param.getName(), "Value is not a valid URL.");
}
}
return ErrorMsg();
}
QStringList UrlValidator::getValidSchemes() const {
return validSchemes;
}
void UrlValidator::setValidSchemes(const QStringList &value) {
validSchemes = value;
}
QString UrlValidator::getPattern() const {
return pattern;
}
void UrlValidator::setPattern(const QString &value) {
pattern = value;
}
src/validators/urlvalidator.h
#ifndef URLVALIDATOR_H
#define URLVALIDATOR_H
#include "validator.h"
namespace CuteEntityManager {
class UrlValidator : public Validator {
Q_OBJECT
public:
UrlValidator();
ErrorMsg validateParam(QVariant value, Param param) const final override;
QStringList getValidSchemes() const;
void setValidSchemes(const QStringList &value);
QString getPattern() const;
void setPattern(const QString &value);
protected:
QString pattern =
QStringLiteral("/^{schemes}:\\/\\/(([A-Z0-9][A-Z0-9_-]*)(\\.[A-Z0-9][A-Z0-9_-]*)+)/i");
QStringList validSchemes = {"http", "https"};
};
}
#endif // URLVALIDATOR_H
src/validators/validator.cpp
const QHash<QString, QString> Validator::builtInValidators() {
QHash<QString, QString> hash = QHash<QString, QString>();
// hash.insert("compare", "CompareValidator");
hash.insert("compare", "CompareValidator");
hash.insert("default", "DefaultValidator");
// hash.insert("email", "EmailValidator");
// hash.insert("exist", "ExistValidator");
// hash.insert("image", "ImageValidator");
// hash.insert("size", "SizeValidator");
hash.insert("email", "EmailValidator");
hash.insert("exist", "ExistValidator");
hash.insert("file", "FileValidator");
hash.insert("image", "ImageValidator");
hash.insert("number", "NumberValidator");
// hash.insert("date", "DateValidator");
hash.insert("date", "DateValidator");
hash.insert("required", "RequiredValidator");
// hash.insert("unique", "UniqueValidator");
// hash.insert("url", "UrlValidator");
hash.insert("unique", "UniqueValidator");
hash.insert("url", "UrlValidator");
return hash;
}
src/validators/validatorfactory.cpp
#include "defaultvalidator.h"
#include "requiredvalidator.h"
#include "numbervalidator.h"
#include "comparevalidator.h"
#include "emailvalidator.h"
#include "existvalidator.h"
#include "filevalidator.h"
#include "imagevalidator.h"
#include "datevalidator.h"
#include "requiredvalidator.h"
#include "urlvalidator.h"
#include "uniquevalidator.h"
using namespace CuteEntityManager;
ValidatorFactory::ValidatorFactory() {
......
void ValidatorFactory::registerClasses() {
if (ValidatorFactory::instance.isEmpty()) {
// ValidatorFactory::registerClass<CompareValidator>();
ValidatorFactory::registerClass<CompareValidator>();
ValidatorFactory::registerClass<DefaultValidator>();
// ValidatorFactory::registerClass<EmailValidator>();
// ValidatorFactory::registerClass<ExistValidator>();
// ValidatorFactory::registerClass<ImageValidator>();
// ValidatorFactory::registerClass<SizeValidator>();
ValidatorFactory::registerClass<EmailValidator>();
ValidatorFactory::registerClass<ExistValidator>();
ValidatorFactory::registerClass<FileValidator>();
ValidatorFactory::registerClass<ImageValidator>();
ValidatorFactory::registerClass<NumberValidator>();
// ValidatorFactory::registerClass<DateValidator>();
ValidatorFactory::registerClass<DateValidator>();
ValidatorFactory::registerClass<RequiredValidator>();
// ValidatorFactory::registerClass<UniqueValidator>();
// ValidatorFactory::registerClass<UrlValidator>();
ValidatorFactory::registerClass<UniqueValidator>();
ValidatorFactory::registerClass<UrlValidator>();
}
}
src/validators/validatorrule.cpp
void ValidationRule::setParams(const QList<Param> &value) {
params = value;
}

Auch abrufbar als: Unified diff