Herunterladen als
root/src/entity.h @ 827458ed
81c23b56 | Christian Ehringfeld | /*
|
|
6899f814 | Christian Ehringfeld | * Copyright (C) 2015 Christian Ehringfeld <c.ehringfeld@t-online.de>
|
|
*
|
|||
* This program is free software; you can redistribute it and/or modify it
|
|||
* under the terms of the GNU Lesser General Public License as published by
|
|||
* the Free Software Foundation.
|
|||
*
|
|||
* This program is distributed in the hope that it will be useful, but
|
|||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|||
* for more details.
|
|||
*
|
|||
* You should have received a copy of the GNU Lesser General Public License
|
|||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|||
*/
|
|||
81c23b56 | Christian Ehringfeld | ||
586bb527 | Christian Ehringfeld | #ifndef ENTITY_H
|
|
#define ENTITY_H
|
|||
aa44e7d1 | Christian Ehringfeld | #include <QObject>
|
|
57d6da31 | Christian Ehringfeld | #include <QSharedPointer>
|
|
7e233492 | Christian Ehringfeld | #include <QStringList>
|
|
6e6097fb | Christian Ehringfeld | #include <QMetaProperty>
|
|
402ef73e | Christian Ehringfeld | #include "relation.h"
|
|
fc14f551 | Christian Ehringfeld | #include "validators/validatorrule.h"
|
|
#include "validators/errormsg.h"
|
|||
6899f814 | Christian Ehringfeld | namespace CuteEntityManager {
|
|
81c23b56 | Christian Ehringfeld | ||
9c2f773f | Christian Ehringfeld | /**
|
|
e332a521 | Christian Ehringfeld | * You must not name any persisted property objectName, because its pre used by Qt and will be ignored by Entity Manager
|
|
9c2f773f | Christian Ehringfeld | * @brief The Entity class
|
|
*/
|
|||
402ef73e | Christian Ehringfeld | class ValidationRule;
|
|
class ErrorMsg;
|
|||
aa44e7d1 | Christian Ehringfeld | class Entity : public QObject {
|
|
Q_OBJECT
|
|||
24c5480c | Christian Ehringfeld | Q_PROPERTY(qint64 id READ getId WRITE setId NOTIFY idChanged)
|
|
9d05e414 | Christian Ehringfeld | ||
612083d3 | Christian Ehringfeld | signals:
|
|
d933d48e | Christian Ehringfeld | void idChanged();
|
|
9d05e414 | Christian Ehringfeld | ||
f8748139 | Christian Ehringfeld | #define EM_MACRO(type) \
|
|
51f88a34 | Christian Ehringfeld | virtual void setListProperty(const QSharedPointer<Entity> &e,QList<QSharedPointer<Entity>> &entList, const QMetaProperty &property) override { \
|
|
6e6097fb | Christian Ehringfeld | QList<QSharedPointer<type>> list = *reinterpret_cast<QList<QSharedPointer<type>>*>(&entList); \
|
|
e8037987 | SebastianDiel | QVariant var; \
|
|
var.setValue<QList<QSharedPointer<type>>>(list); \
|
|||
property.write(e.data(), var); \
|
|||
} \
|
|||
virtual void setProperty(const QSharedPointer<Entity> &e,QSharedPointer<Entity> &value, const QMetaProperty &property) override { \
|
|||
QSharedPointer<type> en = *reinterpret_cast<QSharedPointer<type>*>(&value); \
|
|||
QVariant var; \
|
|||
var.setValue<QSharedPointer<type>>(en); \
|
|||
property.write(e.data(), var); \
|
|||
6e6097fb | Christian Ehringfeld | }
|
|
612083d3 | Christian Ehringfeld | public:
|
|
d933d48e | Christian Ehringfeld | virtual QString toString() const;
|
|
402ef73e | Christian Ehringfeld | /**
|
|
* @brief copy
|
|||
* depends on Q_PROPERTIES
|
|||
* Copies them with exceptions of primary key(mostly "id") and objectName
|
|||
* @return
|
|||
*/
|
|||
virtual Entity* copy() const;
|
|||
d933d48e | Christian Ehringfeld | virtual ~Entity();
|
|
fc14f551 | Christian Ehringfeld | virtual QList<ValidationRule> validationRules() const;
|
|
d933d48e | Christian Ehringfeld | virtual QString getTablename() const;
|
|
23337ecc | Christian Ehringfeld | virtual QString getClassname() const;
|
|
d933d48e | Christian Ehringfeld | virtual const QHash<QString, Relation> getRelations() const;
|
|
e3fc2748 | Christian Ehringfeld | virtual const Relation getRelation(const QString &name) const;
|
|
d933d48e | Christian Ehringfeld | virtual const QStringList getTransientAttributes() const;
|
|
virtual const QStringList getBLOBColumns() const;
|
|||
virtual InheritanceStrategy getInheritanceStrategy() const;
|
|||
virtual bool isInheritanceCascaded() const;
|
|||
24c5480c | Christian Ehringfeld | //return value must be the exact name defined in Q_PROPERTY
|
|
d933d48e | Christian Ehringfeld | virtual QString getPrimaryKey() const;
|
|
5ae606bb | Christian Ehringfeld | virtual QHash<QString, QVariant> getProperties();
|
|
virtual QHash<QString, QString> getPropertyLabels();
|
|||
abb9e8c5 | Christian Ehringfeld | ||
d933d48e | Christian Ehringfeld | QVariant getProperty(const QString &name) const;
|
|
bool setProperty(const QString &name, const QVariant &value);
|
|||
qint64 getId() const;
|
|||
void setId(const qint64 &value);
|
|||
24c5480c | Christian Ehringfeld | ||
fc14f551 | Christian Ehringfeld | bool hasErrors() const;
|
|
QList<ErrorMsg> getErrors() const;
|
|||
e80feccc | Christian Ehringfeld | QString getErrorsAsString() const;
|
|
fc14f551 | Christian Ehringfeld | void setErrors(const QList<ErrorMsg> &value);
|
|
51f88a34 | Christian Ehringfeld | virtual void setListProperty(const QSharedPointer<Entity> &e, QList<QSharedPointer<Entity>> &entList,
|
|
37d98e0b | Christian Ehringfeld | const QMetaProperty &property) = 0;
|
|
e8037987 | SebastianDiel | virtual void setProperty(const QSharedPointer<Entity> &e, QSharedPointer<Entity> &value, const QMetaProperty &property) = 0;
|
|
fc14f551 | Christian Ehringfeld | ||
612083d3 | Christian Ehringfeld | protected:
|
|
dfaffebe | Christian Ehringfeld | explicit Entity (QObject *parent = 0);
|
|
d933d48e | Christian Ehringfeld | virtual QString slimToString() const;
|
|
fc14f551 | Christian Ehringfeld | QList<ErrorMsg> errors;
|
|
70e3d0c6 | Christian Ehringfeld | qint64 id = -1;
|
|
81c23b56 | Christian Ehringfeld | };
|
|
}
|
|||
586bb527 | Christian Ehringfeld | #endif // ENTITY_H
|