Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 6e6097fb

Von Christian Ehringfeld vor mehr als 7 Jahren hinzugefügt

  • ID 6e6097fb3b08e878787a5ce4618736a6174bdf0c
  • Vorgänger 63d91df4
  • Nachfolger 67f8e889

huray

Unterschiede anzeigen:

src/entity.h
#include <QObject>
#include <QSharedPointer>
#include <QStringList>
#include <QMetaProperty>
#include "relation.h"
#include "validators/validatorrule.h"
#include "validators/errormsg.h"
......
signals:
void idChanged();
#define EM_LIST_MACRO(type) \
virtual void setListProperty(QList<QSharedPointer<Entity>> &entList, const QMetaProperty &property) { \
QList<QSharedPointer<type>> list = *reinterpret_cast<QList<QSharedPointer<type>>*>(&entList); \
QVariant var; \
var.setValue<QList<QSharedPointer<type>>>(list); \
property.write(this, var); \
}
public:
virtual QString toString() const;
/**
......
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);
}
protected:
explicit Entity (QObject *parent = 0);
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);
property.write(entity.data(), var);
qDebug() << "<ab>" << entity->setProperty(property.name(),var);
//property.write(entity.data(), var);
}
void EntityHelper::addEntityToListProperty(const QSharedPointer<Entity>
......
var) : QList<QSharedPointer<Entity>>());
if (!list.contains(add)) {
list.append(add);
EntityHelper::setListProperty(entity, list, property);
entity->setListProperty(list,property);
}
}
......
break;
}
}
EntityHelper::setListProperty(entity, list, property);
entity->setListProperty(list,property);
}
}
......
if (var.canConvert<QList<QVariant>>()) {
auto list = EntityInstanceFactory::castQVariantList(var);
list.clear();
EntityHelper::setListProperty(entity, list, property);
entity->setListProperty(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()));
EntityHelper::setListProperty(entity, entities, attr->getMetaProperty());
entity->setListProperty(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)
public:
enum class Gender {MALE, FEMALE, UNKNOWNGENDER};
......
Q_PROPERTY(bool active READ isActive WRITE setActive)
Q_PROPERTY(QList<QSharedPointer<Employee>> workers READ getWorkers WRITE
setWorkers)
EM_LIST_MACRO(Employee)
public:
WorkerGroup() : Entity() { }
WorkerGroup(QString name, quint32 efficiency, bool active = true) : Entity() {
......
Q_PROPERTY(QString name READ getName WRITE setName)
Q_PROPERTY(QSharedPointer<Person> leader READ getLeader WRITE
setLeader)
EM_LIST_MACRO(Person)
public:
Q_INVOKABLE Group();

Auch abrufbar als: Unified diff