Revision e111d9ab
Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt
EntityManager.pro | ||
---|---|---|
src/validators/errormsg.h \
|
||
src/validators/defaultvalidator.h \
|
||
src/validators/validatorfactory.h \
|
||
src/validators/validatorrule.h
|
||
src/validators/validatorrule.h \
|
||
src/validators/requiredvalidator.h \
|
||
src/validators/numbervalidator.h
|
||
|
||
SOURCES += \
|
||
src/entity.cpp \
|
||
... | ... | |
src/validators/errormsg.cpp \
|
||
src/validators/defaultvalidator.cpp \
|
||
src/validators/validatorfactory.cpp \
|
||
src/validators/validatorrule.cpp
|
||
src/validators/validatorrule.cpp \
|
||
src/validators/requiredvalidator.cpp \
|
||
src/validators/numbervalidator.cpp
|
||
|
||
CONFIG += c++14
|
||
QMAKE_CXXFLAGS += -std=c++14
|
samples/example/main.cpp | ||
---|---|---|
qWarning() << "-----------------------------";
|
||
qWarning() << "Merge Pupil";
|
||
qWarning() << "-----------------------------";
|
||
list.at(i)->setBirthday(QDate(2222,12,22));
|
||
list.at(i)->setBirthday(QDate(2222, 12, 22));
|
||
QSharedPointer<Entity> pupilE = list.at(i).objectCast<Entity>();
|
||
e->merge(pupilE,true);
|
||
e->merge(pupilE, true);
|
||
qWarning() << list.at(i)->toString();
|
||
}
|
||
qWarning() << "-----------------------------";
|
||
... | ... | |
qWarning() << "-----------------------------";
|
||
qWarning() << "Remove Group";
|
||
qWarning() << "-----------------------------";
|
||
//e->remove(entityGroupFindPtr);
|
||
|
||
|
||
|
||
e->remove(entityGroupFindPtr);
|
||
|
||
sqliteproc->sqliteDBMemFile(true, "db.sqlite");
|
||
qWarning() << "Duration:" << t.elapsed();
|
src/entitymanager.cpp | ||
---|---|---|
} else if (r.getType() == RelationType::ONE_TO_ONE
|
||
&& !r.getMappedBy().isEmpty()) {
|
||
auto e = EntityInstanceFactory::castQVariant(var);
|
||
this->save(e, true, false);
|
||
this->save(e, true, false);
|
||
auto fkProp = EntityHelper::mappedProperty(r, e);
|
||
if (fkProp.isValid()) {
|
||
EntityHelper::addEntityToListProperty(e, entity, fkProp);
|
||
... | ... | |
rc = true;
|
||
}
|
||
}
|
||
entity->idChanged();
|
||
return rc;
|
||
}
|
||
|
src/validators/defaultvalidator.cpp | ||
---|---|---|
#include "defaultvalidator.h"
|
||
#include "validator.h"
|
||
using namespace CuteEntityManager;
|
||
DefaultValidator::DefaultValidator() : Validator() {
|
||
}
|
src/validators/defaultvalidator.h | ||
---|---|---|
#define DEFAULTVALIDATOR_H
|
||
#include "validator.h"
|
||
namespace CuteEntityManager {
|
||
class ErrorMsg;
|
||
class DefaultValidator : public Validator {
|
||
Q_OBJECT
|
||
public:
|
src/validators/errormsg.h | ||
---|---|---|
#include <QString>
|
||
namespace CuteEntityManager {
|
||
class ErrorMsg {
|
||
public:
|
||
public:
|
||
ErrorMsg();
|
||
~ErrorMsg();
|
||
ErrorMsg(QString param, QString errorMsg, QString propertyName = "");
|
||
... | ... | |
QString getErrorMsg() const;
|
||
void setErrorMsg(const QString &value);
|
||
|
||
private:
|
||
private:
|
||
QString param;
|
||
QString propertyName;
|
||
QString errorMsg;
|
src/validators/numbervalidator.cpp | ||
---|---|---|
#include "numbervalidator.h"
|
||
using namespace CuteEntityManager;
|
||
NumberValidator::NumberValidator() : Validator() {
|
||
|
||
}
|
||
|
||
ErrorMsg NumberValidator::validateParam(QVariant value, Param param) const {
|
||
bool convert;
|
||
double converted = value.toDouble(&convert);
|
||
if (!convert) {
|
||
return ErrorMsg(param.getName(), "Value could not converted.");
|
||
}
|
||
if (param.getName() == "min" && param.getValue().toDouble() > converted) {
|
||
return ErrorMsg(param.getName(),
|
||
"Value must be no less than " + QString::number(param.getValue().toDouble()) +
|
||
".");
|
||
} else if (param.getName() == "max"
|
||
&& param.getValue().toDouble() < converted) {
|
||
return ErrorMsg(param.getName(),
|
||
"Value must be not greater than " + QString::number(param.getValue().toDouble())
|
||
+ ".");
|
||
}
|
||
return ErrorMsg();
|
||
}
|
src/validators/numbervalidator.h | ||
---|---|---|
#ifndef NUMBERVALIDATOR_H
|
||
#define NUMBERVALIDATOR_H
|
||
#include "validator.h"
|
||
namespace CuteEntityManager {
|
||
class NumberValidator : public Validator {
|
||
Q_OBJECT
|
||
public:
|
||
NumberValidator();
|
||
ErrorMsg validateParam(QVariant value, Param param) const final override;
|
||
};
|
||
}
|
||
#endif // NUMBERVALIDATOR_H
|
src/validators/requiredvalidator.cpp | ||
---|---|---|
#include "requiredvalidator.h"
|
||
using namespace CuteEntityManager;
|
||
RequiredValidator::RequiredValidator(): Validator() {
|
||
}
|
||
|
||
ErrorMsg RequiredValidator::validateParam(QVariant value, Param param) const {
|
||
if (value.isNull()) {
|
||
return ErrorMsg(param.getName(), "Value is not set");
|
||
}
|
||
return ErrorMsg();
|
||
}
|
src/validators/requiredvalidator.h | ||
---|---|---|
#ifndef REQUIREDVALIDATOR_H
|
||
#define REQUIREDVALIDATOR_H
|
||
#include "validator.h"
|
||
namespace CuteEntityManager {
|
||
class RequiredValidator : public Validator {
|
||
Q_OBJECT
|
||
public:
|
||
RequiredValidator();
|
||
ErrorMsg validateParam(QVariant value, Param param) const final override;
|
||
};
|
||
}
|
||
|
||
#endif // REQUIREDVALIDATOR_H
|
src/validators/validator.cpp | ||
---|---|---|
// hash.insert("size", "SizeValidator");
|
||
// hash.insert("number", "NumberValidator");
|
||
// hash.insert("date", "DateValidator");
|
||
// hash.insert("required", "RequiredValidator");
|
||
hash.insert("required", "RequiredValidator");
|
||
// hash.insert("unique", "UniqueValidator");
|
||
// hash.insert("url", "UrlValidator");
|
||
return hash;
|
src/validators/validatorfactory.cpp | ||
---|---|---|
#include "validatorfactory.h"
|
||
#include "defaultvalidator.h"
|
||
#include "requiredvalidator.h"
|
||
#include "numbervalidator.h"
|
||
using namespace CuteEntityManager;
|
||
|
||
ValidatorFactory::ValidatorFactory() {
|
||
... | ... | |
|
||
void ValidatorFactory::registerClasses() {
|
||
if (ValidatorFactory::instance.isEmpty()) {
|
||
// Validator::registerClass<CompareValidator>();
|
||
// ValidatorFactory::registerClass<CompareValidator>();
|
||
ValidatorFactory::registerClass<DefaultValidator>();
|
||
// Validator::registerClass<EmailValidator>();
|
||
// Validator::registerClass<ExistValidator>();
|
||
// Validator::registerClass<ImageValidator>();
|
||
// Validator::registerClass<SizeValidator>();
|
||
// Validator::registerClass<NumberValidator>();
|
||
// Validator::registerClass<DateValidator>();
|
||
// Validator::registerClass<RequiredValidator>();
|
||
// Validator::registerClass<UniqueValidator>();
|
||
// Validator::registerClass<UrlValidator>();
|
||
// ValidatorFactory::registerClass<EmailValidator>();
|
||
// ValidatorFactory::registerClass<ExistValidator>();
|
||
// ValidatorFactory::registerClass<ImageValidator>();
|
||
// ValidatorFactory::registerClass<SizeValidator>();
|
||
ValidatorFactory::registerClass<NumberValidator>();
|
||
// ValidatorFactory::registerClass<DateValidator>();
|
||
ValidatorFactory::registerClass<RequiredValidator>();
|
||
// ValidatorFactory::registerClass<UniqueValidator>();
|
||
// ValidatorFactory::registerClass<UrlValidator>();
|
||
}
|
||
}
|
src/validators/validatorrule.h | ||
---|---|---|
explicit ValidationRule(QString validatorName, QStringList attributeNames,
|
||
QString paramName1, QVariant paramValue1, QString paramName2,
|
||
QVariant paramValue2);
|
||
|
||
~ValidationRule();
|
||
QString getValidatorName() const;
|
||
void setValidatorName(const QString &value);
|
Auch abrufbar als: Unified diff
validators