Revision fa408e04
Von Christian Ehringfeld vor mehr als 8 Jahren hinzugefügt
- ID fa408e042c3e347cea466ab3488e63f81ec3300d
- Vorgänger 63d91df4
src/entityhelper.cpp | ||
---|---|---|
#include "entity.h"
|
||
#include "relation.h"
|
||
#include "cache.h"
|
||
#include <QDebug>
|
||
|
||
using namespace CuteEntityManager;
|
||
EntityHelper::EntityHelper() {
|
||
... | ... | |
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);
|
||
// if ( constructor == nullptr ) {
|
||
// return nullptr;
|
||
// }
|
||
// return (*constructor)();
|
||
|
||
if(!list.isEmpty()) {
|
||
auto ab = property.read(entity.data());
|
||
auto i = EntityInstanceFactory::getInstance();
|
||
auto constructor = i.value(EntityInstanceFactory::extractEntityType(QString(ab.typeName())).toUtf8());
|
||
if(constructor) {
|
||
auto obj = (*constructor)();
|
||
auto var = qVariantFromValue(list);
|
||
EntityHelper::writeListProperty(entity,var,property,obj);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
// QVariant var = qVariantFromValue(list);
|
||
// auto data = var.data();
|
||
|
||
//auto tes = ab.data_ptr().type;
|
||
// auto bl = QMetaType::typeName(tes);
|
||
// auto b = QMetaType::metaObjectForType(tes);
|
||
//auto ab12 = QVariant::
|
||
//auto typeName = ab.typeName();
|
||
|
||
|
||
//auto t = QVariant::nameToType(var.typeName());
|
||
//auto data = entity.data();
|
||
//EntityHelper::writeProperty(entity,var,ab,property);
|
||
//var.setValue<QList<QSharedPointer<Entity>>>(list);
|
||
//auto ok = property.write(data,var);
|
||
// qDebug() << property.typeName();
|
||
//
|
||
|
||
|
||
// qDebug() << var.convert(property.type());
|
||
// auto var123 = property.read(data);
|
||
// auto li = var123.toList();
|
||
// for (int i = 0; i < list.size(); ++i) {
|
||
// QVariant v;
|
||
// v.setValue<QSharedPointer<Entity>>(list.at(i));
|
||
// li.append(v);
|
||
// }
|
||
////qDebug() << qMetaTypeId(EntityInstanceFactory::extractEntityType(property.typeName()));
|
||
|
||
// qDebug() << property.write(data,var123) << "1";
|
||
// qDebug() << property.write(data,li)<< "2";
|
||
// qDebug() << property.write(data, QVariant::fromValue(list))<< "3";
|
||
// qDebug() << var<< "4";
|
||
}
|
||
|
||
void EntityHelper::addEntityToListProperty(const QSharedPointer<Entity>
|
src/entityhelper.h | ||
---|---|---|
static void setListProperty(const QSharedPointer<Entity> &entity,
|
||
QList<QSharedPointer<Entity>> &list,
|
||
const QMetaProperty &property);
|
||
template<class T>
|
||
static void writeListProperty(const QSharedPointer<Entity> &entity, QVariant data, const QMetaProperty &property,T object) {
|
||
Q_UNUSED(object)
|
||
QVariant variant;
|
||
T *t = new T();
|
||
|
||
QList<QSharedPointer<T>> li;
|
||
//variant = qVariantFromValue(li);
|
||
|
||
//auto list = *reinterpret_cast<QList<QSharedPointer<T>>*>(data.data());
|
||
|
||
//variant.setValue<QList<QSharedPointer<T>>>(list);
|
||
// property.write(entity.data(),variant);
|
||
}
|
||
|
||
static void setProperty(const QSharedPointer<Entity> &entity,
|
||
QSharedPointer<Entity> value,
|
||
const QMetaProperty &property);
|
src/entityinstancefactory.cpp | ||
---|---|---|
EntityInstanceFactory::extractEntityType(
|
||
attr->getMetaProperty().typeName()));
|
||
}
|
||
|
||
typedef Entity *(*Constructor)();
|
||
QHash<QByteArray, Constructor> EntityInstanceFactory::getInstance() {
|
||
return instance;
|
||
}
|
src/entityinstancefactory.h | ||
---|---|---|
class Entity;
|
||
class EntityInstanceFactory {
|
||
public:
|
||
typedef Entity *(*Constructor)();
|
||
static Entity *createInstance(const char *className);
|
||
static Entity *createInstance(const QString &className);
|
||
static Entity *createInstance(int metaTypeId);
|
||
... | ... | |
}
|
||
static Entity *createInstance(Attribute *&attr);
|
||
|
||
|
||
//http://www.mimec.org/node/350
|
||
template<typename T>
|
||
static void registerClass() {
|
||
... | ... | |
return (*constructor)();
|
||
}
|
||
|
||
private:
|
||
typedef Entity *(*Constructor)();
|
||
static QHash<QByteArray, Constructor> getInstance();
|
||
|
||
private:
|
||
template<typename T>
|
||
static Entity *constructorHelper() {
|
||
return new T();
|
src/logger.cpp | ||
---|---|---|
#include <QTextStream>
|
||
#include <QDateTime>
|
||
#include <QtGlobal>
|
||
#include <QSqlDriver>
|
||
|
||
using namespace CuteEntityManager;
|
||
|
Auch abrufbar als: Unified diff
tried something