commit 6e6097fb3b08e878787a5ce4618736a6174bdf0c
Author: Christian Ehringfeld <c.ehringfeld@t-online.de>
Date:   Fri Sep 2 22:55:39 2016 +0200

    huray

diff --git a/src/entity.h b/src/entity.h
index 90ec5cd..41d114f 100644
--- a/src/entity.h
+++ b/src/entity.h
@@ -19,6 +19,7 @@
 #include <QObject>
 #include <QSharedPointer>
 #include <QStringList>
+#include <QMetaProperty>
 #include "relation.h"
 #include "validators/validatorrule.h"
 #include "validators/errormsg.h"
@@ -37,6 +38,15 @@ class Entity : public QObject {
   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;
     /**
@@ -69,6 +79,11 @@ class Entity : public QObject {
     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);
diff --git a/src/entityhelper.cpp b/src/entityhelper.cpp
index 6b3e438..2fe7bee 100644
--- a/src/entityhelper.cpp
+++ b/src/entityhelper.cpp
@@ -196,12 +196,15 @@ const QString EntityHelper::getClassName(const Entity *entity) {
     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>
@@ -212,7 +215,7 @@ 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);
     }
 }
 
@@ -228,7 +231,7 @@ void EntityHelper::removeEntityFromListProperty(const QSharedPointer<Entity>
                 break;
             }
         }
-        EntityHelper::setListProperty(entity, list, property);
+        entity->setListProperty(list,property);
     }
 }
 
@@ -238,7 +241,7 @@ void EntityHelper::clearEntityListProperty(const QSharedPointer<Entity> &entity,
     if (var.canConvert<QList<QVariant>>()) {
         auto list = EntityInstanceFactory::castQVariantList(var);
         list.clear();
-        EntityHelper::setListProperty(entity, list, property);
+        entity->setListProperty(list,property);
     }
 }
 
diff --git a/src/entitymanager.cpp b/src/entitymanager.cpp
index 68c0359..edc35eb 100644
--- a/src/entitymanager.cpp
+++ b/src/entitymanager.cpp
@@ -444,7 +444,7 @@ void EntityManager::oneToMany(const QSharedPointer<Entity> &entity,
             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());
         }
     }
 }
diff --git a/tests/models.h b/tests/models.h
index 90deeed..3eb1813 100644
--- a/tests/models.h
+++ b/tests/models.h
@@ -22,6 +22,7 @@ class Person: public Entity {
     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};
@@ -118,6 +119,8 @@ class WorkerGroup : public Entity {
     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() {
@@ -156,6 +159,7 @@ class Group: public CuteEntityManager::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();
