Revision f8748139
Von Christian Ehringfeld vor mehr als 8 Jahren hinzugefügt
.gitignore | ||
---|---|---|
*.pro.user
|
||
*build
|
||
build*
|
||
*.swp
|
src/entity.h | ||
---|---|---|
signals:
|
||
void idChanged();
|
||
|
||
#define EM_LIST_MACRO(type) \
|
||
#define EM_MACRO(type) \
|
||
virtual void setListProperty(QList<QSharedPointer<Entity>> &entList, const QMetaProperty &property) { \
|
||
QList<QSharedPointer<type>> list = *reinterpret_cast<QList<QSharedPointer<type>>*>(&entList); \
|
||
QVariant var; \
|
||
... | ... | |
|
||
//#define EM_LIST_PROPERTY(type,attribute,getter,setter)
|
||
// Q_PROPERTY(QList<QSharedPointer<type>> attribute READ getter WRITE setter)
|
||
// EM_LIST_MACRO(type)
|
||
// EM_MACRO(type)
|
||
|
||
|
||
|
src/entityhelper.cpp | ||
---|---|---|
return QString(entity->metaObject()->className());
|
||
}
|
||
|
||
#include <QDebug>
|
||
|
||
void EntityHelper::setListProperty(const QSharedPointer<Entity> &entity,
|
||
QList<QSharedPointer<Entity>> &list,
|
||
const QMetaProperty &property) {
|
||
QVariant var;
|
||
var.setValue<QList<QSharedPointer<Entity>>>(list);
|
||
qDebug() << "<ab>" << entity->setProperty(property.name(),var);
|
||
//property.write(entity.data(), var);
|
||
}
|
||
|
||
void EntityHelper::addEntityToListProperty(const QSharedPointer<Entity>
|
||
&entity, QSharedPointer<Entity> add, const QMetaProperty &property) {
|
||
QVariant var = property.read(entity.data());
|
src/entityhelper.h | ||
---|---|---|
QSharedPointer<Entity> remove, const QMetaProperty &property);
|
||
static void clearEntityListProperty(const QSharedPointer<Entity> &entity,
|
||
const QMetaProperty &property);
|
||
static void setListProperty(const QSharedPointer<Entity> &entity,
|
||
QList<QSharedPointer<Entity>> &list,
|
||
const QMetaProperty &property);
|
||
static void setProperty(const QSharedPointer<Entity> &entity,
|
||
QSharedPointer<Entity> value,
|
||
const QMetaProperty &property);
|
tests/em/tst_em.cpp | ||
---|---|---|
g->removePerson(firstPerson);
|
||
QVERIFY(this->e->save(g, true, true));
|
||
this->e->refresh(firstPerson);
|
||
QVERIFY(firstPerson->getGroups().size() == 0 && g->getPersons().size() == 1);
|
||
QVERIFY(firstPerson->getGroups().size() == 0);
|
||
QVERIFY(g->getPersons().size() == 1);
|
||
}
|
tests/em/tst_querybuilder.cpp | ||
---|---|---|
QCOMPARE(groupList.at(0)->getPersons().size(), 3);
|
||
}
|
||
|
||
void QuerybuilderTest::testEnum()
|
||
{
|
||
auto qb = e->getQueryBuilder();
|
||
Query q = Query();
|
||
QVariant var;
|
||
var.setValue<Person::Gender>(Person::Gender::FEMALE);
|
||
q.appendWhere(q.equal(qb, "gender", var.toInt()));
|
||
QList<QSharedPointer<Person>> females = e->find<Person>(q, false);
|
||
QCOMPARE(females.size(), 4);
|
||
QCOMPARE(females.first()->getGender(), Person::Gender::FEMALE);
|
||
}
|
||
|
||
void QuerybuilderTest::testRefresh() {
|
||
e->clearCache();
|
||
auto persons = e->findAll<Person>(false);
|
tests/em/tst_querybuilder.h | ||
---|---|---|
void testQueryBuilderSingleAttributeOr();
|
||
void testQueryBuilderManyToOneRelationAttribute();
|
||
void testQueryBuilderManyToManyRelationAttribute();
|
||
void testEnum();
|
||
void testRefresh();
|
||
|
||
private:
|
tests/models.h | ||
---|---|---|
Q_PROPERTY(QList<QSharedPointer<Group>> groups READ getGroups WRITE setGroups)
|
||
Q_PROPERTY(QList<QSharedPointer<Group>> maintainedGroups READ
|
||
getMaintainedGroups WRITE setMaintainedGroups)
|
||
EM_LIST_MACRO(Group)
|
||
EM_MACRO(Group)
|
||
// EM_LIST_PROPERTY(Group,groups,getGroups,setGroups)
|
||
// EM_LIST_PROPERTY(Group,maintainedGroups,getMaintainedGroups,setMaintainedGroups)
|
||
|
||
... | ... | |
Q_PROPERTY(bool active READ isActive WRITE setActive)
|
||
Q_PROPERTY(QList<QSharedPointer<Employee>> workers READ getWorkers WRITE
|
||
setWorkers)
|
||
EM_LIST_MACRO(Employee)
|
||
EM_MACRO(Employee)
|
||
|
||
public:
|
||
WorkerGroup() : Entity() { }
|
||
... | ... | |
Q_PROPERTY(QString name READ getName WRITE setName)
|
||
Q_PROPERTY(QSharedPointer<Person> leader READ getLeader WRITE
|
||
setLeader)
|
||
EM_LIST_MACRO(Person)
|
||
EM_MACRO(Person)
|
||
|
||
public:
|
||
Q_INVOKABLE Group();
|
Auch abrufbar als: Unified diff
fix