Revision b5d490c7
Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt
samples/example/models/enums.h | ||
---|---|---|
#ifndef ENUMS_H
|
||
#define ENUMS_H
|
||
#include <QObject>
|
||
struct Enums {
|
||
Q_GADGET
|
||
public:
|
||
enum ContactCategory {EMAIL_CONTACT, MOBILE_CONTACT, LANDLINE_CONTACT, MESSENGER_CONTACT, EXTRA1_CONTACT, EXTRA2_CONTACT, EXTRA3_CONTACT, EXTRA4_CONTACT, EXTRA5_CONTACT, EXTRA6_CONTACT} ;
|
||
Q_ENUM(ContactCategory)
|
||
enum class Orientation {LANDSCAPE_ORIENTATION, PORTRAIT_ORIENTATION, LANDSCAPE_180_ORIENTATION, PORTRAIT_180_ORIENTATION};
|
||
Q_ENUM(Orientation)
|
||
enum class NameOrder {FIRST_FAMILY_NAME_ORDER, FAMILY_FIRST_NAME_ORDER};
|
||
Q_ENUM(NameOrder)
|
||
enum class DataFieldPosition {TOP_LEFT_DATA = 0, TOP_DATA = 1, TOP_RIGHT_DATA = 2, UPPER_LEFT_DATA = 3, UPPER_DATA = 4, UPPER_RIGHT_DATA = 5, LOWER_LEFT_DATA = 6, LOWER_DATA = 7, LOWER_RIGHT_DATA = 8, BOTTOM_LEFT_DATA = 9, BOTTOM_DATA = 10, BOTTOM_RIGHT_DATA = 11, CENTER_DATA = 12};
|
||
Q_ENUM(DataFieldPosition)
|
||
enum class IconPosition {TOP_LEFT_ICON, TOP_RIGHT_ICON, BOTTOM_LEFT_ICON, BOTTOM_RIGHT_ICON, CENTER_ICON, TOP_ICON, BOTTOM_ICON, LEFT_ICON, RIGHT_ICON};
|
||
Q_ENUM(IconPosition)
|
||
enum class ShadowPosition {TOP_LEFT_SHADOW, TOP_RIGHT_SHADOW, BOTTOM_LEFT_SHADOW, BOTTOM_RIGHT_SHADOW, INVALID_SHADOW};
|
||
Q_ENUM(ShadowPosition)
|
||
enum class Gender {MALE, FEMALE, UNKNOWNGENDER};
|
||
Q_ENUM(Gender)
|
||
};
|
||
|
||
#endif // ENUMS_H
|
src/entity.cpp | ||
---|---|---|
}
|
||
|
||
QString Entity::toString() const {
|
||
return this->getTablename() + ":" + QString::number(this->id);
|
||
QString r = "";
|
||
r.append(this->getClassname());
|
||
r.append(": {");
|
||
auto properties = this->getMetaProperties();
|
||
for (auto var = properties.constBegin(); var != properties.constEnd(); ++var) {
|
||
r.append(var.key() + ": " + var.value().read(this).toString() + ", ");
|
||
}
|
||
r.append("}");
|
||
return r;
|
||
}
|
||
|
||
Entity::~Entity() {
|
||
... | ... | |
return this->metaObject()->className();
|
||
}
|
||
|
||
QVariant Entity::property(const QString &name) const {
|
||
QVariant Entity::getProperty(const QString &name) const {
|
||
if (!name.isEmpty()) {
|
||
return QObject::property(name.toLatin1().constData());
|
||
}
|
||
return QVariant();
|
||
}
|
||
|
||
bool Entity::setProperty(const QString &name, const QVariant &value) {
|
||
return QObject::setProperty(name.toLatin1().constData(), value);
|
||
}
|
||
|
||
qint64 Entity::getId() const {
|
||
return id;
|
||
}
|
src/entity.h | ||
---|---|---|
const QHash<Relation, QMetaProperty> getRelationProperties() const;
|
||
const char *getClassname() const;
|
||
|
||
QVariant property(const QString &name) const;
|
||
QVariant getProperty(const QString &name) const;
|
||
bool setProperty(const QString &name, const QVariant &value);
|
||
|
||
qint64 getId() const;
|
||
void setId(const qint64 &value);
|
src/entitymanager.cpp | ||
---|---|---|
}
|
||
|
||
void EntityManager::refresh(QSharedPointer<Entity> &entity) {
|
||
entity = this->findById(entity->property(
|
||
entity = this->findById(entity->getProperty(
|
||
entity->getPrimaryKey()).toLongLong(),
|
||
QString(entity->getClassname()));
|
||
}
|
||
... | ... | |
e->getTablename(),
|
||
this->schema->getQueryBuilder()->generateColumnNameID(
|
||
r.getMappedBy()),
|
||
entity->property(entity->getPrimaryKey()).toLongLong(), 1);
|
||
entity->getProperty(entity->getPrimaryKey()).toLongLong(), 1);
|
||
auto listMap = this->convertQueryResult(q);
|
||
auto entities = this->convert(listMap, e->getClassname(), refresh);
|
||
if (!entities.isEmpty()) {
|
||
... | ... | |
void EntityManager::setProperty(const QSharedPointer<Entity> &entiy,
|
||
QSharedPointer<Entity> value,
|
||
const QMetaProperty &property) const {
|
||
if (value && value->property(value->getPrimaryKey()).toLongLong()
|
||
if (value && value->getProperty(value->getPrimaryKey()).toLongLong()
|
||
> -1) {
|
||
property.write(entiy.data(), QVariant(value));
|
||
}
|
||
... | ... | |
q = builder->manyToManyInsert(tblName,
|
||
builder->generateManyToManyColumnName(entity),
|
||
builder->generateManyToManyColumnName(ptr));
|
||
q.bindValue(0, entity->getId());
|
||
q.bindValue(0, entity->getProperty(entity->getPrimaryKey()));
|
||
auto prop = this->mappedProperty(r, ptr);
|
||
QSharedPointer<Entity> item;
|
||
for (int var = 0; var < saved.size(); ++var) {
|
||
item = list.at(var);
|
||
if (ptr->property(ptr->getPrimaryKey()).toLongLong() > -1) {
|
||
q.bindValue(1, ptr->property(ptr->getPrimaryKey()));
|
||
if (item->getProperty(item->getPrimaryKey()).toLongLong() > -1) {
|
||
q.bindValue(1, item->getProperty(ptr->getPrimaryKey()));
|
||
q.exec();
|
||
if (prop.isReadable()) {
|
||
this->addEntityToListProperty(entity, ptr, prop);
|
||
... | ... | |
bool EntityManager::shouldBeSaved(QSharedPointer<Entity> &entity,
|
||
const Relation &r) {
|
||
return entity && (r.getCascadeType().contains(ALL)
|
||
|| (entity->property(entity->getPrimaryKey()) > -1
|
||
|| (entity->getProperty(entity->getPrimaryKey()) > -1
|
||
&& r.getCascadeType().contains(MERGE))
|
||
|| (entity->property(entity->getPrimaryKey()) <= -1
|
||
|| (entity->getProperty(entity->getPrimaryKey()) <= -1
|
||
&& r.getCascadeType().contains(PERSIST)));
|
||
}
|
||
|
||
... | ... | |
if (this->schema->getTables().contains(tblName)) {
|
||
QSqlQuery q = builder->manyToManyDelete(
|
||
tblName, builder->generateManyToManyColumnName(e),
|
||
e->property(e->getPrimaryKey()).toLongLong());
|
||
e->getProperty(e->getPrimaryKey()).toLongLong());
|
||
bool refresh = r.getCascadeType().contains(REFRESH)
|
||
|| r.getCascadeType().contains(ALL);
|
||
bool remove = r.getCascadeType().contains(REMOVE)
|
||
... | ... | |
if (this->schema->getTables().contains(tblName)) {
|
||
QSqlQuery q = builder->manyToManyDelete(
|
||
tblName, builder->generateManyToManyColumnName(entity),
|
||
entity->property(entity->getPrimaryKey()).toLongLong());
|
||
entity->getProperty(entity->getPrimaryKey()).toLongLong());
|
||
if (this->db->transaction(q)) {
|
||
auto nList = EntityInstanceFactory::castQVariantList(property);
|
||
this->persistMappedByRelation(nList, q, entity, ptr, r, tblName);
|
||
... | ... | |
if (this->schema->getTables().contains(tblName)) {
|
||
QSqlQuery q = builder->manyToMany(tblName,
|
||
builder->generateManyToManyColumnName(entity),
|
||
entity->property(entity->getPrimaryKey()).toLongLong(),
|
||
entity->getProperty(entity->getPrimaryKey()).toLongLong(),
|
||
builder->generateManyToManyColumnName(secEntityPtr),
|
||
secEntityPtr->getTablename());
|
||
auto listMap = this->convertQueryResult(q);
|
||
... | ... | |
break;
|
||
}
|
||
if (first) {
|
||
entity->setProperty(
|
||
entity->getPrimaryKey().toLatin1().constData(), query.lastInsertId());
|
||
entity->setProperty(entity->getPrimaryKey(), query.lastInsertId());
|
||
first = false;
|
||
}
|
||
}
|
||
... | ... | |
|
||
bool EntityManager::save(QSharedPointer<Entity> &entity,
|
||
const bool persistRelations) {
|
||
if (entity->property(entity->getPrimaryKey()) > -1) {
|
||
if (entity->getProperty(entity->getPrimaryKey()) > -1) {
|
||
return this->merge(entity, persistRelations);
|
||
} else {
|
||
return this->create(entity, persistRelations);
|
src/querybuilder.cpp | ||
---|---|---|
const {
|
||
QList<QSqlQuery> queries = QList<QSqlQuery>();
|
||
queries.append(this->remove(entity->getTablename(),
|
||
entity->property(entity->getPrimaryKey()).toLongLong()));
|
||
entity->getProperty(entity->getPrimaryKey()).toLongLong()));
|
||
if (entity->getInheritanceStrategy() != PER_CLASS_TABLE
|
||
&& entity->isInheritanceCascaded()) {
|
||
auto classes = entity->superClasses(true);
|
||
... | ... | |
auto instance = EntityInstanceFactory::createInstance(item->className());
|
||
if (instance) {
|
||
queries.append(this->remove(instance->getTablename(),
|
||
entity->property(entity->getPrimaryKey()).toLongLong()));
|
||
entity->getProperty(entity->getPrimaryKey()).toLongLong()));
|
||
delete instance;
|
||
instance = 0;
|
||
}
|
||
... | ... | |
foreignKey) + " WHERE " + this->schema->quoteColumnName(
|
||
attribute) + "=:id;";
|
||
q.prepare(sql);
|
||
q.bindValue(":id", id);
|
||
q.bindValue(":id", QVariant(id));
|
||
return q;
|
||
}
|
||
|
||
... | ... | |
void QueryBuilder::insertRelationId(const Entity *e,
|
||
QHash<QString, QVariant> &map,
|
||
QString relName) const {
|
||
if (e && e->property(e->getPrimaryKey()).toLongLong() > -1) {
|
||
if (e && e->getProperty(e->getPrimaryKey()).toLongLong() > -1) {
|
||
map.insert(this->generateColumnNameID(relName),
|
||
e->property(e->getPrimaryKey()));
|
||
e->getProperty(e->getPrimaryKey()));
|
||
}
|
||
}
|
||
|
Auch abrufbar als: Unified diff
fix