Revision 51f88a34
Von Christian Ehringfeld vor mehr als 8 Jahren hinzugefügt
src/entity.h | ||
---|---|---|
void idChanged();
|
||
|
||
#define EM_MACRO(type) \
|
||
virtual void setListProperty(QList<QSharedPointer<Entity>> &entList, const QMetaProperty &property) override { \
|
||
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); \
|
||
QVariant var; \
|
||
var.setValue<QList<QSharedPointer<type>>>(list); \
|
||
property.write(this, var); \
|
||
property.write(e.data(), var); \
|
||
} \
|
||
virtual void setProperty(QSharedPointer<Entity> &entity, const QMetaProperty &property) override { \
|
||
QSharedPointer<type> e = *reinterpret_cast<QSharedPointer<type>*>(&entity); \
|
||
virtual void setProperty(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>>(e); \
|
||
property.write(this, var); \
|
||
var.setValue<QSharedPointer<type>>(en); \
|
||
property.write(e.data(), var); \
|
||
}
|
||
|
||
//#define EM_PROPERTY(type,attribute,getter,setter)
|
||
... | ... | |
QList<ErrorMsg> getErrors() const;
|
||
QString getErrorsAsString() const;
|
||
void setErrors(const QList<ErrorMsg> &value);
|
||
virtual void setListProperty(QList<QSharedPointer<Entity>> &entList,
|
||
virtual void setListProperty(const QSharedPointer<Entity> &e, QList<QSharedPointer<Entity>> &entList,
|
||
const QMetaProperty &property) = 0;
|
||
virtual void setProperty(QSharedPointer<Entity> &entity, const QMetaProperty &property) = 0;
|
||
virtual void setProperty(const QSharedPointer<Entity> &e, QSharedPointer<Entity> &value, const QMetaProperty &property) = 0;
|
||
|
||
protected:
|
||
explicit Entity (QObject *parent = 0);
|
src/entityhelper.cpp | ||
---|---|---|
var) : QList<QSharedPointer<Entity>>());
|
||
if (!list.contains(add)) {
|
||
list.append(add);
|
||
entity->setListProperty(list,property);
|
||
EntityHelper::setListProperty(entity, list, property);
|
||
}
|
||
}
|
||
|
||
... | ... | |
break;
|
||
}
|
||
}
|
||
entity->setListProperty(list,property);
|
||
EntityHelper::setListProperty(entity, list, property);
|
||
}
|
||
}
|
||
|
||
... | ... | |
if (var.canConvert<QList<QVariant>>()) {
|
||
auto list = EntityInstanceFactory::castQVariantList(var);
|
||
list.clear();
|
||
entity->setListProperty(list,property);
|
||
EntityHelper::setListProperty(entity, list, property);
|
||
}
|
||
}
|
||
#include <QDebug>
|
||
|
||
void EntityHelper::setProperty(const QSharedPointer<Entity> &entity,
|
||
QSharedPointer<Entity> value,
|
||
const QMetaProperty &property) {
|
||
if (value && value->getProperty(value->getPrimaryKey()).toLongLong()
|
||
> -1) {
|
||
QVariant var;
|
||
var.setValue<QSharedPointer<Entity>>(value);
|
||
entity->setProperty(value,property);
|
||
qDebug() << "-----------------------------------------------------";
|
||
//Q_ASSERT(property.write(entity.data(), var));
|
||
qDebug() << "-----------------------------------------------------";
|
||
auto i = EntityInstanceFactory::createInstance(EntityInstanceFactory::extractEntityType(property.typeName()));
|
||
if(i) {
|
||
i->setProperty(entity, value, property);
|
||
delete i;
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
void EntityHelper::setProperty(const QSharedPointer<Entity> &entity,
|
||
QSharedPointer<Entity> value, const QString property) {
|
||
auto props = EntityHelper::getMetaProperties(entity.data());
|
||
if (props.contains(property)) {
|
||
QVariant var;
|
||
var.setValue<QSharedPointer<Entity>>(value);
|
||
entity->setProperty(property, var);
|
||
void EntityHelper::setListProperty(const QSharedPointer<Entity> &entity,
|
||
QList<QSharedPointer<Entity>> &value, const QMetaProperty &property) {
|
||
auto i = EntityInstanceFactory::createInstance(EntityInstanceFactory::extractEntityType(property.typeName()));
|
||
auto t = property.typeName();
|
||
if(i) {
|
||
i->setListProperty(entity, value, property);
|
||
delete i;
|
||
}
|
||
}
|
||
|
||
|
||
QMetaProperty EntityHelper::mappedProperty(const Relation &r,
|
||
const QSharedPointer<Entity> &foreignEntity) {
|
||
QMetaProperty prop;
|
src/entityhelper.h | ||
---|---|---|
static void setProperty(const QSharedPointer<Entity> &entity,
|
||
QSharedPointer<Entity> value,
|
||
const QMetaProperty &property);
|
||
static void setProperty(const QSharedPointer<Entity> &entity,
|
||
QSharedPointer<Entity> value,
|
||
const QString property);
|
||
static void setListProperty(const QSharedPointer<Entity> &entity,
|
||
QList<QSharedPointer<Entity>> &value,
|
||
const QMetaProperty &property);
|
||
static QMetaProperty mappedProperty(const Relation &r,
|
||
const QSharedPointer<Entity> &foreignEntity);
|
||
static QHash<QString, QVariant> getEntityAttributes(const
|
src/entitymanager.cpp | ||
---|---|---|
&& (ptr = this->cache.get(convertedId, className)))) {
|
||
ptr = this->findById(convertedId, className);
|
||
}
|
||
EntityHelper::setProperty(entity, ptr, attr->getMetaProperty());
|
||
EntityHelper::setProperty(entity,ptr,attr->getMetaProperty());
|
||
}
|
||
}
|
||
|
||
... | ... | |
attr->getRelatedColumnName(), entity->getId());
|
||
QSqlQuery q = this->queryInterpreter->build(query);
|
||
auto listMap = this->convertQueryResult(q);
|
||
auto entities = this->convert(listMap, EntityHelper::getClassname(e.data()));
|
||
entity->setListProperty(entities,attr->getMetaProperty());
|
||
auto relationalClass = EntityHelper::getClassName(e.data());
|
||
auto entities = this->convert(listMap, relationalClass.toLatin1());
|
||
EntityHelper::setListProperty(entity,entities,attr->getMetaProperty());
|
||
}
|
||
}
|
||
}
|
tests/em/tst_querybuilder.cpp | ||
---|---|---|
QVERIFY(p);
|
||
QCOMPARE(p->getNickName(), QString("Lotta"));
|
||
QCOMPARE(p->getGroups().size(), 2);
|
||
QVERIFY(p->getGroups().first());
|
||
QVERIFY(p->getGroups().first()->getPersons().last());
|
||
QCOMPARE(p->getGroups().first()->getPersons().last()->getFamilyName(), QString("Sey."));
|
||
}
|
||
|
Auch abrufbar als: Unified diff
some progress