Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 75cecd67

Von Christian Ehringfeld vor mehr als 8 Jahren hinzugefügt

  • ID 75cecd6788d56ed391e44e354609ec91116335db
  • Vorgänger 638e5843
  • Nachfolger 949b3ea3

hmm

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)
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)
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/example/models/pupil.h
class Pupil : public Person {
Q_OBJECT
EM_MACRO(Pupil)
Q_PROPERTY(QString legalGuardianNote READ getLegalGuardianNote WRITE
setLegalGuardianNote)
public:
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/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
#include "relation.h"
#include "validators/validatorrule.h"
#include "validators/errormsg.h"
#include <QDebug>
namespace CuteEntityManager {
/**
......
signals:
void idChanged();
#define EM_LIST_MACRO(type) \
virtual void setListProperty(QList<QSharedPointer<Entity>> &entList, const QMetaProperty &property) { \
#define EM_MACRO(type) \
virtual void setAsListProperty(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); \
}
//#define EM_PROPERTY(type,attribute,getter,setter)
......
//#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)
......
QList<ErrorMsg> getErrors() const;
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);
}
virtual void setAsListProperty(const QSharedPointer<Entity> &e, QList<QSharedPointer<Entity>> &entList, const QMetaProperty &property) = 0;
protected:
explicit Entity (QObject *parent = 0);
src/entityhelper.cpp
void EntityHelper::setListProperty(const QSharedPointer<Entity> &entity,
QList<QSharedPointer<Entity>> &list,
const QMetaProperty &property) {
QVariant var;
var.setValue<QList<QSharedPointer<Entity>>>(list);
entity->setProperty(property.name(),var);
if(!list.isEmpty()) {
auto instance = EntityInstanceFactory::createInstance(list.at(0)->getClassname());
instance->setAsListProperty(entity, list, property);
}
property.reset(entity.data());
}
void EntityHelper::addEntityToListProperty(const QSharedPointer<Entity>
......
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);
}
}
src/entitymanager.cpp
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());
EntityHelper::setListProperty(entity,entities,attr->getMetaProperty());
}
}
}
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(Person)
// EM_LIST_PROPERTY(Group,groups,getGroups,setGroups)
// EM_LIST_PROPERTY(Group,maintainedGroups,getMaintainedGroups,setMaintainedGroups)
......
Q_PROPERTY(QString department READ getDepartment WRITE setDepartment)
Q_PROPERTY(quint64 persNumber READ getPersNumber WRITE setPersNumber)
Q_PROPERTY(bool manager READ isManager WRITE setManager)
EM_MACRO(Employee)
public:
Employee() : Person() { }
Employee(quint64 persNumber, QString firstName, QString familyName,
......
Q_PROPERTY(bool active READ isActive WRITE setActive)
Q_PROPERTY(QList<QSharedPointer<Employee>> workers READ getWorkers WRITE
setWorkers)
EM_LIST_MACRO(Employee)
EM_MACRO(WorkerGroup)
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(Group)
public:
Q_INVOKABLE Group();
......
Q_OBJECT
Q_PROPERTY(double price READ getPrice WRITE setPrice)
Q_PROPERTY(QString name READ getName WRITE setName)
EM_MACRO(Article)
private:
double price;
QString name;

Auch abrufbar als: Unified diff