Revision cbfd2b95
Von Christian Ehringfeld vor mehr als 7 Jahren hinzugefügt
samples/example/main.cpp | ||
---|---|---|
CreateFakeModelData::fillGroup(gPtr.data());
|
||
gPtr->setName("9b");
|
||
QSharedPointer<Entity> groupPtr = gPtr.objectCast<Entity>();
|
||
QSharedPointer<Person> mainTeacher = QSharedPointer<Person>(new Person("Max",
|
||
"Mustermann", Person::Gender::MALE));
|
||
QSharedPointer<Person> mainTeacher = QSharedPointer<Person>(new Person("Julia",
|
||
"Musterfrau", Person::Gender::MALE));
|
||
gPtr->setMainTeacher(mainTeacher);
|
||
//Persons will also persisted
|
||
if (e->count(groupPtr->getTablename()) <= 0) {
|
samples/example/models/person.h | ||
---|---|---|
class Person: public Entity {
|
||
Q_OBJECT
|
||
EM_MACRO(Person)
|
||
Q_ENUMS(Gender)
|
||
Q_ENUMS(NameOrder)
|
||
Q_PROPERTY(QString firstName READ getFirstName WRITE setFirstName)
|
||
Q_PROPERTY(QString familyName READ getFamilyName WRITE setFamilyName)
|
||
Q_PROPERTY(QString namePrefix READ getNamePrefix WRITE setNamePrefix)
|
samples/example/models/pupil.cpp | ||
---|---|---|
void Pupil::setLegalGuardianNote(const QString &value) {
|
||
legalGuardianNote = value;
|
||
}
|
||
|
||
const QHash<QString, Relation> Pupil::getRelations() const {
|
||
auto hash = Person::getRelations();
|
||
hash.insert("groups", CuteEntityManager::Relation("groups",
|
||
RelationType::MANY_TO_MANY));
|
||
return hash;
|
||
}
|
samples/example/models/pupil.h | ||
---|---|---|
|
||
QString getLegalGuardianNote() const;
|
||
void setLegalGuardianNote(const QString &value);
|
||
virtual const QHash<QString, CuteEntityManager::Relation> getRelations() const override;
|
||
|
||
QString getForm() const;
|
||
void setForm(const QString &value);
|
src/entity.cpp | ||
---|---|---|
this->errors = value;
|
||
}
|
||
|
||
void Entity::setProperty(const QSharedPointer<Entity> &e, const QSharedPointer<Entity> &value, const QMetaProperty &property) {
|
||
void Entity::setProperty(const QSharedPointer<Entity> &e, QSharedPointer<Entity> &value, const QMetaProperty &property) {
|
||
property.write(e.data(), QVariant::fromValue(value));
|
||
}
|
||
|
src/entity.h | ||
---|---|---|
#include "relation.h"
|
||
#include "validators/validatorrule.h"
|
||
#include "validators/errormsg.h"
|
||
#include <QDebug>
|
||
namespace CuteEntityManager {
|
||
|
||
/**
|
||
... | ... | |
virtual void setListProperty(const QSharedPointer<Entity> &e,QList<QSharedPointer<Entity>> &entList, const QMetaProperty &property) override { \
|
||
QList<QSharedPointer<type>> list = *reinterpret_cast<QList<QSharedPointer<type>>*>(&entList); \
|
||
property.write(e.data(), QVariant::fromValue(list)); \
|
||
} \
|
||
virtual void setFoundProperty(const QSharedPointer<Entity> &e,QSharedPointer<Entity> &value, const QMetaProperty &property) override { \
|
||
QSharedPointer<type> en = *reinterpret_cast<QSharedPointer<type>*>(&value); \
|
||
QVariant var; \
|
||
var.setValue<QSharedPointer<type>>(en); \
|
||
property.write(e.data(), var); \
|
||
}
|
||
|
||
public:
|
||
... | ... | |
void setErrors(const QList<ErrorMsg> &value);
|
||
virtual void setListProperty(const QSharedPointer<Entity> &e, QList<QSharedPointer<Entity>> &entList,
|
||
const QMetaProperty &property) = 0;
|
||
virtual void setProperty(const QSharedPointer<Entity> &e, const QSharedPointer<Entity> &value, const QMetaProperty &property);
|
||
virtual void setProperty(const QSharedPointer<Entity> &e, QSharedPointer<Entity> &value, const QMetaProperty &property);
|
||
virtual void setFoundProperty(const QSharedPointer<Entity> &e, QSharedPointer<Entity> &value, const QMetaProperty &property) = 0;
|
||
|
||
protected:
|
||
explicit Entity (QObject *parent = 0);
|
src/entityhelper.cpp | ||
---|---|---|
}
|
||
}
|
||
|
||
void EntityHelper::setFoundProperty(const QSharedPointer<Entity> &entity,
|
||
QSharedPointer<Entity> value,
|
||
const QMetaProperty &property) {
|
||
if (value && value->getProperty(value->getPrimaryKey()).toLongLong()
|
||
> -1) {
|
||
auto i = EntityInstanceFactory::createInstance(EntityInstanceFactory::extractEntityType(property.typeName()));
|
||
if(i) {
|
||
i->setFoundProperty(entity, value, property);
|
||
delete i;
|
||
}
|
||
}
|
||
}
|
||
|
||
void EntityHelper::setListProperty(const QSharedPointer<Entity> &entity,
|
||
QList<QSharedPointer<Entity>> &value, const QMetaProperty &property) {
|
||
auto i = EntityInstanceFactory::createInstance(EntityInstanceFactory::extractEntityType(property.typeName()));
|
src/entityhelper.h | ||
---|---|---|
static void setProperty(const QSharedPointer<Entity> &entity,
|
||
QSharedPointer<Entity> value,
|
||
const QMetaProperty &property);
|
||
static void setFoundProperty(const QSharedPointer<Entity> &entity,
|
||
QSharedPointer<Entity> value,
|
||
const QMetaProperty &property);
|
||
static void setListProperty(const QSharedPointer<Entity> &entity,
|
||
QList<QSharedPointer<Entity>> &value,
|
||
const QMetaProperty &property);
|
src/entitymanager.cpp | ||
---|---|---|
&& (ptr = this->cache.get(convertedId, className)))) {
|
||
ptr = this->findById(convertedId, className);
|
||
}
|
||
EntityHelper::setProperty(entity,ptr,attr->getMetaProperty());
|
||
EntityHelper::setFoundProperty(entity,ptr,attr->getMetaProperty());
|
||
}
|
||
}
|
||
|
||
... | ... | |
auto entities = this->convert(listMap, EntityHelper::getClassname(e.data()));
|
||
if (!entities.isEmpty()) {
|
||
QSharedPointer<Entity> ptr = entities.at(0);
|
||
EntityHelper::setProperty(entity, ptr, attr->getMetaProperty());
|
||
EntityHelper::setFoundProperty(entity, ptr, attr->getMetaProperty());
|
||
}
|
||
}
|
||
}
|
||
... | ... | |
auto ptr = QSharedPointer<Entity>(EntityInstanceFactory::createInstance(
|
||
EntityInstanceFactory::extractEntityType(QString(property.typeName()))));
|
||
auto builder = this->schema->getQueryBuilder();
|
||
QString tblName = builder->generateManyToManyTableName(entity, ptr, r);
|
||
QString tblName = builder->generateManyToManyTableName(ptr, entity, r);
|
||
if (this->schema->containsTable(tblName)) {
|
||
bool ok = newItem;
|
||
QSqlQuery q;
|
src/querybuilder.cpp | ||
---|---|---|
return map;
|
||
}
|
||
|
||
/**
|
||
* @todo Fix TableName Generation with Inheritence
|
||
* @brief QueryBuilder::generateManyToManyTableName
|
||
* @param firstEntity
|
||
* @param secondEntity
|
||
* @param r
|
||
* @return
|
||
*/
|
||
QString QueryBuilder::generateManyToManyTableName(const QSharedPointer<Entity>
|
||
&firstEntity,
|
||
const QSharedPointer<Entity> &secondEntity, const Relation &r) const {
|
Auch abrufbar als: Unified diff
...