Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision bb5e9339

Von Sebastian Diel vor mehr als 9 Jahren hinzugefügt

  • ID bb5e93396124921c3df2f8a9b6d261be365080c2
  • Vorgänger b02f465a
  • Nachfolger a205e8a9

Bei Sebastian

Unterschiede anzeigen:

example/main.cpp
#include <QMetaMethod>
#include <QMetaProperty>
#include "models/group.h"
#include "entity.h"
#include "entitymanager.h"
#include "../src/entity.h"
#include "../src/entitymanager.h"
#include <QGenericReturnArgument>
/**
* create,remove und merge funktionieren
*/
int main(int argc, char *argv[]) {
Q_UNUSED(argc) Q_UNUSED(argv)
CuteEntityManager::EntityManager *e = new CuteEntityManager::EntityManager("QSQLITE",
QDir::currentPath() + "/db.sqlite");
QSharedPointer<Artikel> a = QSharedPointer<Artikel>(new Artikel(20.0, "Müsli"));
example/models/artikel.h
#ifndef ARTIKEL_H
#define ARTIKEL_H
#include "entity.h"
#include "../../src/entity.h"
#include <QHash>
#include <QVariant>
example/models/group.cpp
#include "models/person.h"
#include "models/group.h"
#include "relation.h"
#include "../src/relation.h"
//#include <QQmlListProperty>
#include <QDebug>
example/models/person.h
#include <QString>
#include <QList>
#include <QObject>
#include "entity.h"
#include "../../src/entity.h"
#include <QAbstractListModel>
#include <QDebug>
src/entity.h
virtual QHash<QString, Relation> getRelations();
virtual QStringList getTransientAttributes();
virtual QStringList getBLOBColumns();
//return value must be the exact name defined in Q_PROPERTY
virtual QString getPrimaryKey();
QHash<QString, QMetaProperty> getMetaProperties() const;
src/entityinstancefactory.cpp
return EntityInstanceFactory::createInstance(className.toUtf8().constData());
}
Entity *EntityInstanceFactory::createInstance(int id) {
Entity *EntityInstanceFactory::createInstance(int metaTypeId) {
Entity *e = 0;
if (id != -1) {
e = static_cast<Entity *>(QMetaType::create(id));
if (metaTypeId != -1) {
e = static_cast<Entity *>(QMetaType::create(metaTypeId));
}
return e;
}
src/entityinstancefactory.h
public:
static Entity *createInstance(const char *className);
static Entity *createInstance(const QString &className);
static Entity *createInstance(int id);
static Entity *createInstance(int metaTypeId);
static Entity *createInstance(const char *className, const QHash<QString, QVariant> &attributes);
static Entity *setAttributes(Entity *e, const QHash<QString, QVariant> &attributes, QHash<QString, QMetaProperty> metaprops);
static Entity *setAttributes(Entity *e, const QHash<QString, QVariant> &attributes);
src/querybuilder.cpp
auto o = entity.data()->metaObject();
QHash<QString, Relation> relations = entity.data()->getRelations();
for (int var = 0; var < o->propertyCount(); ++var) {
o->property(var);
auto m = o->property(var);
if (m.name() != QString("objectName") && m.isReadable()
&& !entity.data()->getTransientAttributes().contains(m.name())) {
src/relation.h
#include <QString>
namespace CuteEntityManager {
enum RelationType {
ONE_TO_ONE, //e.g. specialization
ONE_TO_ONE, //e.g. specialization, heritage
ONE_TO_MANY, //@OneToMany(cascade=ALL, mappedBy="customer")
MANY_TO_ONE, //1-n Entity foreign key in same table
MANY_TO_MANY,
src/schema/sqlitequerybuilder.cpp
QString CuteEntityManager::SqliteQueryBuilder::addForeignKey(QString name, QString tableName, QStringList columns,
QString refTableName, QStringList refColumns, QString deleteConstraint, QString updateConstraint) const {
//not supported
Q_UNUSED(refTableName)
Q_UNUSED(refColumns)
Q_UNUSED(name)
Q_UNUSED(tableName)
Q_UNUSED(deleteConstraint)
Q_UNUSED(columns)
Q_UNUSED(updateConstraint)
return "";
}

Auch abrufbar als: Unified diff