Revision 0ec1cbfb
Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt
README.md | ||
---|---|---|
# CuteEntityManager for Qt
|
||
## German
|
||
Mit dem CuteEntityManager ist es möglich Entities zu persistieren, zu mergen, zu finden und zu löschen. Die Funktionalität ist dem EntityManager der JPA nachempfunden. Für eine Anwendung war ich auf der Suche nach einem leicht zu benutzenden ORM. Entweder enthielt die jeweilige Library zusätzliche Abhängigkeiten, hatte nicht den gewünschten Funktionsumfang, war in der Benutzung zu "kompliziert"(imho) oder war nur an bestimmte Plattformen gekoppelt. Der CuteEntityManager unterstützt grundsätzlich alle von Qt unterstützten Plattformen. Da ich hauptberuflich Java & PHP Entwickler bin, ist der CuteEntityManager dem o.g. EntityManager der JPA und zum Teil dem PHP Yii Framework nachempfunden.
|
||
Der CuteEntityManager basiert ausschließlich auf Qt/C++ Techniken. Der Properties für das ORM werden anhand von Q_PROPERTY Makros festgelegt. Es ist möglich Vererbung zu nutzen. Relationen (ONE_TO_ONE, MANY_TO_ONE, ONE_TO_MANY und MANY_TO_MANY) sind natürlich auch möglich. Um SELECT Statements zu vereinfachen gibt es eine Query API. Man kann also ohne ein Stückchen SQL eine komplette Anwendung mit SQL Datenbank Anbindung implementieren. Man sollte sich natürlich über die "Besonderheiten" einer relationalen Datenbank im Klaren sein (insbesondere eben bei Relationen). Aktuell ist nur einigermaßen die SQLite Unterstützung getestet. Eine Erweiterung für MySQL/PGSQL/MSSQL sollte relativ problemlos möglich sein.
|
||
Mit dem CuteEntityManager ist es möglich Entities zu persistieren, zu
|
||
mergen, zu finden und zu löschen. Die Funktionalität ist dem
|
||
EntityManager der JPA nachempfunden. Für eine andere Anwendung war ich
|
||
auf der Suche nach einem leicht zu benutzenden ORM. Entweder enthielten
|
||
die jeweiligen Librarys zusätzliche Abhängigkeiten, hatten nicht den
|
||
gewünschten Funktionsumfang, waren in der Benutzung zu
|
||
"kompliziert"(imho) oder an bestimmte Plattformen gekoppelt.
|
||
|
||
Der CuteEntityManager ist sicherlich weit davon entfernt in einem guten (getesteten) bzw. fertigen Zustand zu sein, da er aber für die Entwicklung einer anderen Anwendung genutzt wird, wird sich der Zustand sicherlich fortlaufend verbessern. Kritik, Lob, Verbesserungsvorschläge, Pull Requests, Code Reviews sind jederzeit Willkommen. Man kann mich auf direktem Wege per Mail an c.ehringfeld[at]t-online.de erreichen.
|
||
Der CuteEntityManager unterstützt grundsätzlich alle von Qt
|
||
unterstützten Plattformen. Da ich hauptberuflich Java & PHP Entwickler
|
||
bin, ist der CuteEntityManager dem o.g. EntityManager der JPA und zum
|
||
Teil dem PHP Yii Framework nachempfunden.
|
||
|
||
Der CuteEntityManager basiert ausschließlich auf Qt/C++ Techniken. Der
|
||
Properties für das ORM werden anhand von Q_PROPERTY Makros festgelegt.
|
||
Es ist möglich Vererbung zu nutzen. Relationen (ONE_TO_ONE, MANY_TO_ONE,
|
||
ONE_TO_MANY und MANY_TO_MANY) sind natürlich auch möglich. Um SELECT
|
||
Statements zu vereinfachen gibt es eine Query API. Man kann also ohne
|
||
ein Stückchen SQL eine komplette Anwendung mit SQL-Datenbank Anbindung
|
||
implementieren. Man sollte sich natürlich über die "Besonderheiten"
|
||
einer relationalen Datenbank im Klaren sein (insbesondere eben bei
|
||
Relationen). Aktuell ist nur die SQLite Unterstützung einigermaßen
|
||
getestet. Erweiterungen für MySQL/PGSQL/MSSQL sollte relativ problemlos
|
||
möglich sein.
|
||
|
||
Der CuteEntityManager ist sicherlich weit davon entfernt in einem guten
|
||
(getesteten) bzw. fertigen Zustand zu sein, da er aber für die
|
||
Entwicklung einer anderen Anwendung genutzt wird, wird sich der Zustand
|
||
sicherlich fortlaufend verbessern. Kritik, Lob, Verbesserungsvorschläge,
|
||
Pull Requests, Code Reviews sind jederzeit Willkommen. Man kann mich auf
|
||
direktem Wege per Mail an c.ehringfeld[at]t-online.de erreichen.
|
||
|
||
## English
|
||
tbc.
|
||
With CuteEntityManager it is possible to persist, merge, find or delete
|
||
entities. It's funcionality is based on JPA's EntityManager. For a
|
||
different application I was in search of an easy-to-use ORM. Either
|
||
those particular libraries had additional dependencies, a smaller
|
||
functional range, were too "complicated" to use (imho) or bound to
|
||
specific platforms.
|
||
|
||
CuteEntityManager basically supports all platforms supported by Qt.
|
||
Because I am a Java & PHP developer for a living, CuteEntityManager is
|
||
conceptionally based on the aforementioned EntityManager of JPA and in
|
||
parts on the PHP Yii framework.
|
||
|
||
CuteEntityManager builds solely on Qt/C++ techniqes. The properties for
|
||
the ORM are established by the usage of Q_PROPERTY macros. It is
|
||
possible to use inheritance. Of course, relations (ONE_TO_ONE,
|
||
MANY_TO_ONE, ONE_TO_MANY and MANY_TO_MANY) are also possible. To
|
||
simplify SELECT statements there is a Query API. Thus, it's possible to
|
||
implement a whole Application with database connection without using a
|
||
single bit of SQL. Of course, you should be aware of the "specifics" of
|
||
a relational database (notably in matters of relations). Currently, only
|
||
SQLite support is passably tested. Extensions for MySQL/PGSQL/MSSQL
|
||
should be possible quite smoothly.
|
||
|
||
CuteEntityManager is definitely far from a proper (and tested) or even
|
||
finished state, but because of it's use for the creation of another
|
||
application, surely this state will successively improve. Criticism,
|
||
praise, improvement suggestions, pull requests and code reviews are
|
||
welcome at any time. You can reach me directly by mail under
|
||
c.ehringfeld[at]t-online.de.
|
samples/simple/Simple.pro | ||
---|---|---|
main.cpp \
|
||
artikel.cpp
|
||
|
||
unix:!macx: LIBS += -L$$PWD/../../../build-EntityManager-Desktop-Debug -lCuteEntityManager
|
||
unix:!macx:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../build-EntityManager-Desktop-Debug -lCuteEntityManager
|
||
else:unix:!macx:CONFIG(release, release|debug): LIBS += -L$$PWD/../../../build-EntityManager-Desktop-Release/ -lCuteEntityManager
|
||
unix:INCLUDEPATH += $$PWD/../../src
|
||
unix:DEPENDPATH += $$PWD/../../src
|
||
CONFIG += c++14
|
||
QMAKE_CXXFLAGS += -std=c++14
|
||
|
||
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../build-EntityManager-Desktop_Qt_5_4_1_MinGW_32bit-Debug/release/ -lCuteEntityManager
|
||
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../build-EntityManager-Desktop_Qt_5_4_1_MinGW_32bit-Debug/debug/ -lCuteEntityManager
|
||
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../build-EntityManager-Desktop-Release/release/ -lCuteEntityManager
|
||
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../build-EntityManager-Desktop-Debug/debug/ -lCuteEntityManager
|
||
|
||
win32:INCLUDEPATH += $$PWD/../../build-EntityManager-Desktop_Qt_5_4_1_MinGW_32bit-Debug/debug
|
||
win32:DEPENDPATH += $$PWD/../../build-EntityManager-Desktop_Qt_5_4_1_MinGW_32bit-Debug/debug
|
||
win32:INCLUDEPATH += $$PWD/../../../build-EntityManager-Desktop-Debug/debug
|
||
win32:DEPENDPATH += $$PWD/../../../build-EntityManager-Desktop-Debug/debug
|
||
|
||
INCLUDEPATH += $$PWD/../../src
|
||
DEPENDPATH += $$PWD/../../src
|
||
|
||
unix {
|
||
QMAKE_CXXFLAGS += -Wall -Wextra -Wmaybe-uninitialized -Wsuggest-final-types -Wsuggest-final-methods -Wsuggest-override -Wunsafe-loop-optimizations -pedantic -Wfloat-equal -Wundef -Wpointer-arith -Wcast-align -Wunreachable-code -O -Winit-self
|
||
}
|
||
|
||
win32-g++ {
|
||
CONFIG += c++11
|
||
QMAKE_CXXFLAGS += -std=c++11 -Wall
|
||
}
|
||
|
||
CONFIG(release, debug|release):DEFINES += QT_NO_DEBUG_OUTPUT
|
samples/simple/main.cpp | ||
---|---|---|
#include "artikel.h"
|
||
#include "../../src/entitymanager.h"
|
||
#include "../../src/entityinstancefactory.h"
|
||
/**
|
||
* create,remove und merge funktionieren
|
||
*/
|
||
|
||
|
||
using namespace CuteEntityManager;
|
||
int main(int argc, char *argv[]) {
|
||
Q_UNUSED(argc) Q_UNUSED(argv)
|
||
... | ... | |
CuteEntityManager::EntityManager *e = new
|
||
CuteEntityManager::EntityManager("QSQLITE",
|
||
QDir::currentPath() + "/db.sqlite");
|
||
EntityInstanceFactory::registerClass<Artikel>();
|
||
QStringList inits = QStringList() << "Artikel";
|
||
e->startup("0.1", inits);
|
||
QSharedPointer<Artikel> a = QSharedPointer<Artikel>(new Artikel(20.0,
|
||
"Müsli"));
|
||
auto ep = a.dynamicCast<CuteEntityManager::Entity>();
|
||
e->create(ep, true, true);
|
||
// auto artikel = e->findById<Artikel *>(1);
|
||
// qDebug() << "ArtikelID:" << artikel.data()->getId();
|
||
|
||
auto ep = a.objectCast<CuteEntityManager::Entity>();
|
||
qDebug() << e->create(ep, true, true);
|
||
return 0;
|
||
}
|
samples/validators/Validators.pro | ||
---|---|---|
#-------------------------------------------------
|
||
#
|
||
# Project created by QtCreator 2013-08-01T15:03:24
|
||
#
|
||
#-------------------------------------------------
|
||
|
||
QT += core
|
||
QT += sql
|
||
|
||
QT -= gui
|
||
|
||
#TARGET = EntityManager
|
||
CONFIG += console
|
||
CONFIG -= app_bundle
|
||
|
||
TEMPLATE = app
|
||
|
||
HEADERS += \
|
||
address.h \
|
||
person.h
|
||
|
||
SOURCES += \
|
||
main.cpp \
|
||
address.cpp \
|
||
person.cpp
|
||
|
||
unix:!macx:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../build-EntityManager-Desktop-Debug -lCuteEntityManager
|
||
else:unix:!macx:CONFIG(release, release|debug): LIBS += -L$$PWD/../../../build-EntityManager-Desktop-Release/ -lCuteEntityManager
|
||
unix:INCLUDEPATH += $$PWD/../../src
|
||
unix:DEPENDPATH += $$PWD/../../src
|
||
CONFIG += c++14
|
||
QMAKE_CXXFLAGS += -std=c++14
|
||
|
||
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../build-EntityManager-Desktop-Release/release/ -lCuteEntityManager
|
||
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../build-EntityManager-Desktop-Debug/debug/ -lCuteEntityManager
|
||
|
||
win32:INCLUDEPATH += $$PWD/../../../build-EntityManager-Desktop-Debug/debug
|
||
win32:DEPENDPATH += $$PWD/../../../build-EntityManager-Desktop-Debug/debug
|
||
|
||
INCLUDEPATH += $$PWD/../../src
|
||
DEPENDPATH += $$PWD/../../src
|
||
|
||
unix {
|
||
QMAKE_CXXFLAGS += -Wall -Wextra -Wmaybe-uninitialized -Wsuggest-final-types -Wsuggest-final-methods -Wsuggest-override -Wunsafe-loop-optimizations -pedantic -Wfloat-equal -Wundef -Wpointer-arith -Wcast-align -Wunreachable-code -O -Winit-self
|
||
}
|
||
|
||
win32-g++ {
|
||
CONFIG += c++11
|
||
QMAKE_CXXFLAGS += -std=c++11 -Wall
|
||
}
|
||
|
||
CONFIG(release, debug|release):DEFINES += QT_NO_DEBUG_OUTPUT
|
samples/validators/address.cpp | ||
---|---|---|
#include "address.h"
|
||
#include "person.h"
|
||
Address::Address(QString label, QString street, QString postcode,
|
||
QString city) {
|
||
this->label = label;
|
||
this->street = street;
|
||
this->postcode = postcode;
|
||
this->city = city;
|
||
}
|
||
|
||
QList<ValidationRule> Address::validationRules() const {
|
||
QList<ValidationRule> rules = QList<ValidationRule>();
|
||
rules.append(ValidationRule("required", {"street", "postcode","label"}));
|
||
//rules.append(ValidationRule("required"));
|
||
return rules;
|
||
}
|
||
|
||
QString Address::getLabel() const {
|
||
return label;
|
||
}
|
||
|
||
void Address::setLabel(const QString &value) {
|
||
label = value;
|
||
}
|
||
|
||
QString Address::getStreet() const {
|
||
return street;
|
||
}
|
||
|
||
void Address::setStreet(const QString &value) {
|
||
street = value;
|
||
}
|
||
|
||
QString Address::getPostcode() const {
|
||
return postcode;
|
||
}
|
||
|
||
void Address::setPostcode(const QString &value) {
|
||
postcode = value;
|
||
}
|
||
|
||
QString Address::getCity() const {
|
||
return city;
|
||
}
|
||
|
||
void Address::setCity(const QString &value) {
|
||
city = value;
|
||
}
|
||
|
||
QList<QSharedPointer<Person> > Address::getPersons() const {
|
||
return persons;
|
||
}
|
||
|
||
void Address::setPersons(const QList<QSharedPointer<Person> > &value) {
|
||
persons = value;
|
||
}
|
||
|
||
const QHash<QString, CuteEntityManager::Relation> Address::getRelations()
|
||
const {
|
||
auto hash = Entity::getRelations();
|
||
hash.insert("persons", CuteEntityManager::Relation("persons",
|
||
RelationType::MANY_TO_MANY,
|
||
QString("addresses")));
|
||
return hash;
|
||
}
|
||
|
||
|
samples/validators/address.h | ||
---|---|---|
#ifndef ADDRESS_H
|
||
#define ADDRESS_H
|
||
|
||
#include <QString>
|
||
#include <QHash>
|
||
#include "entity.h"
|
||
|
||
class Person;
|
||
class Relation;
|
||
class Pupil;
|
||
class Address: public CuteEntityManager::Entity {
|
||
Q_OBJECT
|
||
Q_PROPERTY(QString label READ getLabel WRITE setLabel)
|
||
Q_PROPERTY(QString street READ getStreet WRITE setStreet)
|
||
Q_PROPERTY(QString postcode READ getPostcode WRITE setPostcode)
|
||
Q_PROPERTY(QString city READ getCity WRITE setCity)
|
||
Q_PROPERTY(QList<QSharedPointer<Person>> persons READ
|
||
getPersons WRITE setPersons)
|
||
|
||
public:
|
||
Q_INVOKABLE Address() {}
|
||
Address(QString label, QString street, QString postcode, QString city);
|
||
virtual QList<CuteEntityManager::ValidationRule> validationRules() const
|
||
override;
|
||
|
||
QString getLabel() const;
|
||
void setLabel(const QString &value);
|
||
|
||
QString getStreet() const;
|
||
void setStreet(const QString &value);
|
||
|
||
QString getPostcode() const;
|
||
void setPostcode(const QString &value);
|
||
|
||
QString getCity() const;
|
||
void setCity(const QString &value);
|
||
|
||
QList<QSharedPointer<Person> > getPersons() const;
|
||
void setPersons(const QList<QSharedPointer<Person> > &value);
|
||
|
||
const QHash<QString, CuteEntityManager::Relation> getRelations() const override;
|
||
|
||
protected:
|
||
QString label;
|
||
QString street;
|
||
QString postcode;
|
||
QString city;
|
||
QList<QSharedPointer<Person>> persons;
|
||
};
|
||
|
||
#endif // ADDRESS_H
|
samples/validators/main.cpp | ||
---|---|---|
#include <QCoreApplication>
|
||
#include <QDir>
|
||
#include <QDebug>
|
||
#include "person.h"
|
||
#include "address.h"
|
||
#include "../../src/entitymanager.h"
|
||
#include "../../src/entityinstancefactory.h"
|
||
/**
|
||
* create,remove und merge funktionieren
|
||
*/
|
||
using namespace CuteEntityManager;
|
||
int main(int argc, char *argv[]) {
|
||
Q_UNUSED(argc) Q_UNUSED(argv)
|
||
CuteEntityManager::EntityManager *e = new
|
||
CuteEntityManager::EntityManager("QSQLITE", QDir::currentPath() + "/db.sqlite");
|
||
EntityInstanceFactory::registerClass<Person>();
|
||
EntityInstanceFactory::registerClass<Address>();
|
||
e->createTable("Person");
|
||
e->createTable("Address");
|
||
|
||
QSharedPointer<Entity> p1 = QSharedPointer<Person>(new Person("Thomas", "Berg",
|
||
Person::Gender::MALE, "", QString(), QString(), QDate(1971, 7, 13), 0));
|
||
QSharedPointer<Entity>p2 = QSharedPointer<Person>(new Person("Teresa", "Conrad",
|
||
Person::Gender::FEMALE, "", QString(), QString(), QDate(1970, 7, 13), 0));
|
||
QSharedPointer<Entity> p3 = QSharedPointer<Person>(new Person("Heinz", "Dunst",
|
||
Person::Gender::MALE, "", QString(), QString(), QDate(1972, 7, 13), 0));
|
||
|
||
//validation takes also place before save/create/merge
|
||
qDebug() << "p1 valid:" << e->validate(p1);
|
||
qDebug() << "p2 valid:" << e->validate(p2);
|
||
qDebug() << "p3 valid:" << e->validate(p3);
|
||
|
||
QSharedPointer<Entity> a1 = QSharedPointer<Address>(new Address("",
|
||
"Mentzelstraße 327",
|
||
"33617", "Bielefeld"));
|
||
QSharedPointer<Entity> a2 = QSharedPointer<Address>(new Address("Erzieher",
|
||
"Bundesallee 252",
|
||
"49082", "Osnabrück"));
|
||
|
||
qDebug() << "a1 valid:" << e->validate(a1);
|
||
qDebug() << "a2 valid:" << e->validate(a2);
|
||
|
||
|
||
return 0;
|
||
}
|
samples/validators/person.cpp | ||
---|---|---|
#include "person.h"
|
||
#include "address.h"
|
||
|
||
Person::Person(QObject *parent): Entity(parent) {
|
||
}
|
||
|
||
Person::Person(QString firstName, QString familyName, Gender gender,
|
||
QString customPictureFileName, QString namePrefix, QString nickName,
|
||
QDate birthday, QObject *parent): Entity(parent) {
|
||
setFirstName(firstName);
|
||
setFamilyName(familyName);
|
||
setNamePrefix(namePrefix);
|
||
setNickName(nickName);
|
||
setBirthday(birthday);
|
||
setGender(gender);
|
||
setCustomPictureFileName(customPictureFileName);
|
||
}
|
||
|
||
const QHash<QString, CuteEntityManager::Relation> Person::getRelations() const {
|
||
auto hash = QHash<QString, CuteEntityManager::Relation>();
|
||
hash.insert("addresses", CuteEntityManager::Relation("addresses",
|
||
RelationType::MANY_TO_MANY));
|
||
return hash;
|
||
}
|
||
|
||
QList<ValidationRule> Person::validationRules() const {
|
||
return Entity::validationRules();
|
||
}
|
||
|
||
QString Person::fullName(NameOrder nameOrder) const {
|
||
QString name = QString();
|
||
if (nameOrder == NameOrder::FAMILY_FIRST_NAME_ORDER) {
|
||
name += this->getFamilyName();
|
||
name += ", ";
|
||
if (!this->getNamePrefix().isEmpty()) {
|
||
name += this->getNamePrefix();
|
||
name += " ";
|
||
}
|
||
name += this->getFirstName();
|
||
} else {
|
||
name += this->getFirstName();
|
||
name += " ";
|
||
name += this->getFamilyName();
|
||
if (!this->getNamePrefix().isEmpty()) {
|
||
name += ", ";
|
||
name += this->getNamePrefix();
|
||
}
|
||
}
|
||
return name;
|
||
}
|
||
QString Person::getFirstName() const {
|
||
return firstName;
|
||
}
|
||
|
||
void Person::setFirstName(const QString &value) {
|
||
firstName = value;
|
||
}
|
||
QString Person::getFamilyName() const {
|
||
return familyName;
|
||
}
|
||
|
||
void Person::setFamilyName(const QString &value) {
|
||
familyName = value;
|
||
}
|
||
QString Person::getNamePrefix() const {
|
||
return namePrefix;
|
||
}
|
||
|
||
void Person::setNamePrefix(const QString &value) {
|
||
namePrefix = value;
|
||
}
|
||
QString Person::getNickName() const {
|
||
return nickName;
|
||
}
|
||
|
||
void Person::setNickName(const QString &value) {
|
||
nickName = value;
|
||
}
|
||
QDate Person::getBirthday() const {
|
||
return birthday;
|
||
}
|
||
|
||
void Person::setBirthday(const QDate &value) {
|
||
birthday = value;
|
||
}
|
||
Person::Gender Person::getGender() const {
|
||
return gender;
|
||
}
|
||
|
||
void Person::setGender(const Gender &value) {
|
||
gender = value;
|
||
}
|
||
QString Person::getCustomPictureFileName() const {
|
||
return customPictureFileName;
|
||
}
|
||
|
||
void Person::setCustomPictureFileName(const QString &value) {
|
||
customPictureFileName = value;
|
||
}
|
||
|
||
QList<QSharedPointer<Address> > Person::getAddresses() const {
|
||
return addresses;
|
||
}
|
||
|
||
void Person::setAddresses(const QList<QSharedPointer<Address> > &value) {
|
||
addresses = value;
|
||
}
|
||
|
||
void Person::addAddress(Address *address) {
|
||
this->addresses.append(QSharedPointer<Address>(address));
|
||
}
|
||
|
samples/validators/person.h | ||
---|---|---|
#ifndef PERSON_H
|
||
#define PERSON_H
|
||
|
||
#include <QDateTime>
|
||
#include <QString>
|
||
#include <QList>
|
||
#include <QObject>
|
||
#include <QAbstractListModel>
|
||
#include <QDebug>
|
||
#include "../../entitymanager/src/entity.h"
|
||
|
||
using namespace CuteEntityManager;
|
||
class Group;
|
||
class Contact;
|
||
class Address;
|
||
|
||
class Person: public Entity {
|
||
Q_OBJECT
|
||
Q_PROPERTY(QString firstName READ getFirstName WRITE setFirstName)
|
||
Q_PROPERTY(QString familyName READ getFamilyName WRITE setFamilyName)
|
||
Q_PROPERTY(QString namePrefix READ getNamePrefix WRITE setNamePrefix)
|
||
Q_PROPERTY(QString nickName READ getNickName WRITE setNickName)
|
||
Q_PROPERTY(QString customPictureFileName READ getCustomPictureFileName WRITE
|
||
setCustomPictureFileName)
|
||
Q_PROPERTY(QDate birthday READ getBirthday WRITE setBirthday)
|
||
Q_PROPERTY(Gender gender READ getGender WRITE setGender)
|
||
Q_PROPERTY(QList<QSharedPointer<Address>> addresses READ
|
||
getAddresses WRITE setAddresses)
|
||
|
||
public:
|
||
enum class Gender {MALE, FEMALE, UNKNOWNGENDER};
|
||
Q_ENUM(Gender)
|
||
enum class NameOrder {FIRST_FAMILY_NAME_ORDER, FAMILY_FIRST_NAME_ORDER};
|
||
Q_ENUM(NameOrder)
|
||
Q_INVOKABLE explicit Person(QObject *parent = 0);
|
||
Person(QString firstName, QString familyName,
|
||
Gender gender = Gender::UNKNOWNGENDER,
|
||
QString customPictureFileName = QString(), QString namePrefix = QString(),
|
||
QString nickName = QString(), QDate birthday = QDate(), QObject *parent = 0);
|
||
|
||
virtual const QHash<QString, CuteEntityManager::Relation> getRelations() const override;
|
||
virtual QList<ValidationRule> validationRules() const override;
|
||
|
||
|
||
bool isPresent(QDateTime date = QDateTime::currentDateTime());
|
||
QString fullName(NameOrder nameOrder = NameOrder::FAMILY_FIRST_NAME_ORDER)
|
||
const;
|
||
|
||
QString getFirstName() const;
|
||
void setFirstName(const QString &value);
|
||
|
||
QString getFamilyName() const;
|
||
void setFamilyName(const QString &value);
|
||
|
||
QString getNamePrefix() const;
|
||
void setNamePrefix(const QString &value);
|
||
|
||
QString getNickName() const;
|
||
void setNickName(const QString &value);
|
||
|
||
QDate getBirthday() const;
|
||
void setBirthday(const QDate &value);
|
||
|
||
Gender getGender() const;
|
||
void setGender(const Gender &value);
|
||
|
||
QString getCustomPictureFileName() const;
|
||
void setCustomPictureFileName(const QString &value);
|
||
|
||
QList<QSharedPointer<Address> > getAddresses() const;
|
||
void setAddresses(const QList<QSharedPointer<Address> > &value);
|
||
|
||
void addAddress(Address *address);
|
||
|
||
protected:
|
||
QString firstName;
|
||
QString familyName;
|
||
QString namePrefix;
|
||
QString nickName;
|
||
QDate birthday;
|
||
Gender gender;
|
||
QString customPictureFileName;
|
||
QList <QSharedPointer<Address>> addresses;
|
||
|
||
|
||
};
|
||
|
||
|
||
#endif // PERSON_H
|
src/entitymanager.cpp | ||
---|---|---|
ValidationRule rule = rules.at(i);
|
||
QSharedPointer<Validator> validator = ValidatorFactory::getValidatorObject(
|
||
rule.getValidatorName());
|
||
qDebug() << "VALIDATOR" << validator;
|
||
if (validator) {
|
||
for (int var = 0; var < rule.getAttributes().size(); ++var) {
|
||
QString attr = rule.getAttributes().at(var);
|
||
... | ... | |
createRelationTables);
|
||
}
|
||
|
||
bool EntityManager::createTable(QString className, bool createRelationTables) {
|
||
QSharedPointer<Entity> e = QSharedPointer<Entity>
|
||
(EntityInstanceFactory::createInstance(className));
|
||
return this->schema->getQueryBuilder()->createTable(e, createRelationTables);
|
||
}
|
||
|
||
quint8 EntityManager::count(const QSharedPointer<Entity> &entity,
|
||
bool ignoreID) {
|
||
qint8 rc = -1;
|
src/entitymanager.h | ||
---|---|---|
bool removeAll(QString tblname);
|
||
bool createTable(const QSharedPointer<Entity> &entity,
|
||
bool createRelationTables = true);
|
||
bool createTable(QString className, bool createRelationTables = true);
|
||
quint8 count(const QSharedPointer<Entity> &entity, bool ignoreID = true);
|
||
quint8 count(const QString &tableName);
|
||
QSharedPointer<Database> getDb() const;
|
Auch abrufbar als: Unified diff
readme update, example updates, new method for entitymanager