Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 37d98e0b

Von Christian Ehringfeld vor mehr als 8 Jahren hinzugefügt

  • ID 37d98e0b1ca290d7264bc2560629fa18ea45a3a6
  • Vorgänger efe7a06f
  • Nachfolger 51f88a34

test

Unterschiede anzeigen:

samples/example/models/address.h
class Pupil;
class Address: public CuteEntityManager::Entity {
Q_OBJECT
EM_MACRO(Address)
Q_PROPERTY(QString label READ getLabel WRITE setLabel)
Q_PROPERTY(QString street READ getStreet WRITE setStreet)
Q_PROPERTY(QString postcode READ getPostcode WRITE setPostcode)
samples/example/models/contact.h
class Pupil;
class Contact: public CuteEntityManager::Entity {
Q_OBJECT
EM_MACRO(Contact)
Q_PROPERTY(QString content READ getContent WRITE setContent)
Q_PROPERTY(Category category READ getCategory WRITE setCategory)
Q_PROPERTY(QString label READ getLabel WRITE setLabel)
samples/example/models/group.h
class Group: public CuteEntityManager::Entity {
Q_OBJECT
EM_MACRO(Group)
Q_PROPERTY(QList<QSharedPointer<Pupil>> pupils READ getPupils WRITE setPupils)
Q_PROPERTY(QList<QSharedPointer<Person>> persons READ getPersons WRITE
setPersons)
samples/example/models/person.h
class Person: public Entity {
Q_OBJECT
EM_MACRO(Person)
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/simple/article.h
class Article : public CuteEntityManager::Entity {
Q_OBJECT
EM_MACRO(Article)
Q_PROPERTY(double price READ getPrice WRITE setPrice)
Q_PROPERTY(QString name READ getName WRITE setName)
private:
samples/validators/address.h
class Pupil;
class Address: public CuteEntityManager::Entity {
Q_OBJECT
EM_MACRO(Address)
Q_PROPERTY(QString label READ getLabel WRITE setLabel)
Q_PROPERTY(QString street READ getStreet WRITE setStreet)
Q_PROPERTY(QString postcode READ getPostcode WRITE setPostcode)
samples/validators/person.h
class Person: public Entity {
Q_OBJECT
EM_MACRO(Person)
Q_PROPERTY(QString firstName READ getFirstName WRITE setFirstName)
Q_PROPERTY(QString familyName READ getFamilyName WRITE setFamilyName)
Q_PROPERTY(QString namePrefix READ getNamePrefix WRITE setNamePrefix)
src/cache.cpp
return;
}
}
this->cache.insert(key, entity.toWeakRef());
//this->cache.insert(key, entity.toWeakRef());
}
}
src/databasemigration.h
namespace CuteEntityManager {
class DatabaseMigration : public Entity {
Q_OBJECT
EM_MACRO(DatabaseMigration)
Q_PROPERTY(QString version READ getVersion WRITE setVersion)
Q_PROPERTY(QDateTime applyTime READ getApplyTime WRITE setApplyTime)
src/entity.h
QVariant var; \
var.setValue<QList<QSharedPointer<type>>>(list); \
property.write(this, var); \
} \
virtual void setProperty(QSharedPointer<Entity> &entity, const QMetaProperty &property) override { \
QSharedPointer<type> e = *reinterpret_cast<QSharedPointer<type>*>(&entity); \
QVariant var; \
var.setValue<QSharedPointer<type>>(e); \
property.write(this, var); \
}
//#define EM_PROPERTY(type,attribute,getter,setter)
......
QString getErrorsAsString() const;
void setErrors(const QList<ErrorMsg> &value);
virtual void setListProperty(QList<QSharedPointer<Entity>> &entList,
const QMetaProperty &property) {
Q_UNUSED(entList);
Q_UNUSED(property);
}
const QMetaProperty &property) = 0;
virtual void setProperty(QSharedPointer<Entity> &entity, const QMetaProperty &property) = 0;
protected:
explicit Entity (QObject *parent = 0);
src/entityhelper.cpp
entity->setListProperty(list,property);
}
}
#include <QDebug>
void EntityHelper::setProperty(const QSharedPointer<Entity> &entity,
QSharedPointer<Entity> value,
const QMetaProperty &property) {
......
> -1) {
QVariant var;
var.setValue<QSharedPointer<Entity>>(value);
property.write(entity.data(), var);
entity->setProperty(value,property);
qDebug() << "-----------------------------------------------------";
//Q_ASSERT(property.write(entity.data(), var));
qDebug() << "-----------------------------------------------------";
}
}
void EntityHelper::setProperty(const QSharedPointer<Entity> &entity,
QSharedPointer<Entity> value, const QString property) {
auto props = EntityHelper::getMetaProperties(entity.data());
tests/em/tst_em.cpp
}
}
void EmTest::testNonCachedInheritedRelations()
{
QSharedPointer<Employee> e1 = QSharedPointer<Employee>(new Employee(42, "Fenja", "S.",
Person::Gender::FEMALE, "Lotta", QDate(1990, 10, 10), "Psychology"));
QSharedPointer<Employee> e2 = QSharedPointer<Employee>(new Employee(11, "Janine",
"Musterfrau",
Person::Gender::FEMALE, "", QDate(2000, 1, 1), "Health", true));
QSharedPointer<WorkerGroup> wg = QSharedPointer<WorkerGroup>(new
WorkerGroup("Taskforce P&H", 42));
wg->addWorker(e1);
wg->addWorker(e2);
try {
QVERIFY(e->create(wg));
QSharedPointer<Group> g = QSharedPointer<Group>(new Group("EmployeeGroup"));
g->setPersons({e1, e2});
QVERIFY(e->create(g));
g->setName("Taskforce 0008");
QVERIFY(e->merge(g));
QVERIFY(e->remove(g));
} catch(QString e) {
QFAIL(e.toUtf8().constData());
}
}
void EmTest::createRelationTables() {
QStringList relationTables = QStringList() << "Employee" << "WorkerGroup";
QVERIFY2(this->e->startup("emTestB", relationTables), "Failure");
tests/em/tst_em.h
void testRelations();
void testRelationTableCreation();
void testInheritedRelations();
void testNonCachedInheritedRelations();
void testDatabaseMigrationTable();
void testTableCreation();
tests/models.h
Q_PROPERTY(QList<QSharedPointer<Group>> groups READ getGroups WRITE setGroups)
Q_PROPERTY(QList<QSharedPointer<Group>> maintainedGroups READ
getMaintainedGroups WRITE setMaintainedGroups)
EM_MACRO(Group)
// EM_LIST_PROPERTY(Group,groups,getGroups,setGroups)
// EM_LIST_PROPERTY(Group,maintainedGroups,getMaintainedGroups,setMaintainedGroups)
EM_MACRO(Person)
public:
enum class Gender {MALE, FEMALE, UNKNOWNGENDER};
......
class Employee : public Person {
Q_OBJECT
EM_MACRO(Employee)
Q_PROPERTY(QString department READ getDepartment WRITE setDepartment)
Q_PROPERTY(quint64 persNumber READ getPersNumber WRITE setPersNumber)
Q_PROPERTY(bool manager READ isManager WRITE setManager)
......
class WorkerGroup : public Entity {
Q_OBJECT
EM_MACRO(WorkerGroup)
Q_PROPERTY(QString name READ getName WRITE setName)
Q_PROPERTY(quint32 efficiency READ getEfficiency WRITE setEfficiency)
Q_PROPERTY(bool active READ isActive WRITE setActive)
Q_PROPERTY(QList<QSharedPointer<Employee>> workers READ getWorkers WRITE
setWorkers)
EM_MACRO(Employee)
public:
WorkerGroup() : Entity() { }
......
class Group: public CuteEntityManager::Entity {
Q_OBJECT
EM_MACRO(Group)
Q_PROPERTY(QList<QSharedPointer<Person>> persons READ getPersons WRITE
setPersons)
Q_PROPERTY(QString name READ getName WRITE setName)
Q_PROPERTY(QSharedPointer<Person> leader READ getLeader WRITE
setLeader)
EM_MACRO(Person)
public:
Q_INVOKABLE Group();
......
class Article : public CuteEntityManager::Entity {
Q_OBJECT
EM_MACRO(Article)
Q_PROPERTY(double price READ getPrice WRITE setPrice)
Q_PROPERTY(QString name READ getName WRITE setName)
private:

Auch abrufbar als: Unified diff