Herunterladen als
root/tests/models.h @ 55f3201d
f2bd88b8 | Christian Ehringfeld | #ifndef MODELS_H
|
|
#define MODELS_H
|
|||
#include <QDateTime>
|
|||
#include <QString>
|
|||
#include <QList>
|
|||
#include <QObject>
|
|||
#include <QDebug>
|
|||
9e2d71d6 | Christian Ehringfeld | #include "entity.h"
|
|
f2bd88b8 | Christian Ehringfeld | ||
using namespace CuteEntityManager;
|
|||
10cc871a | Christian Ehringfeld | class Group;
|
|
f8b8663b | Christian Ehringfeld | class Relation;
|
|
f2bd88b8 | Christian Ehringfeld | class Person: public Entity {
|
|
e7cfc35a | Christian Ehringfeld | ||
f2bd88b8 | Christian Ehringfeld | Q_OBJECT
|
|
Q_PROPERTY(QString firstName READ getFirstName WRITE setFirstName)
|
|||
Q_PROPERTY(QString familyName READ getFamilyName WRITE setFamilyName)
|
|||
Q_PROPERTY(QString nickName READ getNickName WRITE setNickName)
|
|||
Q_PROPERTY(QDate birthday READ getBirthday WRITE setBirthday)
|
|||
Q_PROPERTY(Gender gender READ getGender WRITE setGender)
|
|||
Q_PROPERTY(QList<QSharedPointer<Group>> groups READ getGroups WRITE setGroups)
|
|||
9e2d71d6 | Christian Ehringfeld | Q_PROPERTY(QList<QSharedPointer<Group>> maintainedGroups READ
|
|
getMaintainedGroups WRITE setMaintainedGroups)
|
|||
37d98e0b | Christian Ehringfeld | EM_MACRO(Person)
|
|
f2bd88b8 | Christian Ehringfeld | ||
public:
|
|||
enum class Gender {MALE, FEMALE, UNKNOWNGENDER};
|
|||
c8192ee9 | Christian Ehringfeld | #if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
|
|
e7cfc35a | Christian Ehringfeld | Q_ENUM(Gender)
|
|
c8192ee9 | Christian Ehringfeld | #else
|
|
Q_ENUMS(Gender)
|
|||
#endif
|
|||
f2bd88b8 | Christian Ehringfeld | enum class NameOrder {FIRST_FAMILY_NAME_ORDER, FAMILY_FIRST_NAME_ORDER};
|
|
Q_INVOKABLE explicit Person(QObject *parent = 0);
|
|||
Person(QString firstName, QString familyName,
|
|||
Gender gender = Gender::UNKNOWNGENDER,
|
|||
QString nickName = QString(), QDate birthday = QDate(), QObject *parent = 0);
|
|||
10cc871a | Christian Ehringfeld | virtual const QHash<QString, CuteEntityManager::Relation> getRelations() const
|
|
override;
|
|||
f2bd88b8 | Christian Ehringfeld | ||
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 getNickName() const;
|
|||
void setNickName(const QString &value);
|
|||
QDate getBirthday() const;
|
|||
void setBirthday(const QDate &value);
|
|||
Gender getGender() const;
|
|||
void setGender(const Gender &value);
|
|||
e7cfc35a | Christian Ehringfeld | QList<QSharedPointer<Group>> getGroups() const;
|
|
void setGroups(const QList<QSharedPointer<Group>> &value);
|
|||
f2bd88b8 | Christian Ehringfeld | ||
e7cfc35a | Christian Ehringfeld | QList<QSharedPointer<Group>> getMaintainedGroups() const;
|
|
void setMaintainedGroups(const QList<QSharedPointer<Group>> &value);
|
|||
virtual QList<ValidationRule> validationRules() const override;
|
|||
f2bd88b8 | Christian Ehringfeld | ||
9e2d71d6 | Christian Ehringfeld | protected:
|
|
f2bd88b8 | Christian Ehringfeld | QString firstName;
|
|
QString familyName;
|
|||
QString nickName;
|
|||
QDate birthday;
|
|||
Gender gender;
|
|||
QList <QSharedPointer<Group>> groups;
|
|||
QList <QSharedPointer<Group>> maintainedGroups;
|
|||
};
|
|||
f8b8663b | Christian Ehringfeld | class Employee : public Person {
|
|
Q_OBJECT
|
|||
37d98e0b | Christian Ehringfeld | EM_MACRO(Employee)
|
|
f8b8663b | Christian Ehringfeld | Q_PROPERTY(QString department READ getDepartment WRITE setDepartment)
|
|
Q_PROPERTY(quint64 persNumber READ getPersNumber WRITE setPersNumber)
|
|||
Q_PROPERTY(bool manager READ isManager WRITE setManager)
|
|||
public:
|
|||
Employee() : Person() { }
|
|||
20e1ffec | Christian Ehringfeld | Employee(quint64 persNumber, QString firstName, QString familyName,
|
|
Gender gender = Gender::UNKNOWNGENDER,
|
|||
QString nickName = QString(), QDate birthday = QDate(), QString department = QString(),
|
|||
bool manager = false, QObject *parent = 0) : Person(firstName, familyName, gender,
|
|||
21826301 | Christian Ehringfeld | nickName, birthday, parent) {
|
|
20e1ffec | Christian Ehringfeld | this->department = department;
|
|
this->manager = manager;
|
|||
this->persNumber = persNumber;
|
|||
}
|
|||
f8b8663b | Christian Ehringfeld | virtual const QHash<QString, CuteEntityManager::Relation> getRelations() const
|
|
override;
|
|||
QString getDepartment() const;
|
|||
void setDepartment(const QString &value);
|
|||
bool isManager() const;
|
|||
void setManager(bool value);
|
|||
quint64 getPersNumber() const;
|
|||
void setPersNumber(const quint64 &value);
|
|||
20e1ffec | Christian Ehringfeld | ||
f8b8663b | Christian Ehringfeld | private:
|
|
QString department;
|
|||
quint64 persNumber;
|
|||
bool manager = false;
|
|||
};
|
|||
class WorkerGroup : public Entity {
|
|||
Q_OBJECT
|
|||
37d98e0b | Christian Ehringfeld | EM_MACRO(WorkerGroup)
|
|
f8b8663b | Christian Ehringfeld | Q_PROPERTY(QString name READ getName WRITE setName)
|
|
Q_PROPERTY(quint32 efficiency READ getEfficiency WRITE setEfficiency)
|
|||
Q_PROPERTY(bool active READ isActive WRITE setActive)
|
|||
Q_PROPERTY(QList<QSharedPointer<Employee>> workers READ getWorkers WRITE
|
|||
setWorkers)
|
|||
6e6097fb | Christian Ehringfeld | ||
f8b8663b | Christian Ehringfeld | public:
|
|
WorkerGroup() : Entity() { }
|
|||
c8192ee9 | Christian Ehringfeld | WorkerGroup(QString name, quint32 efficiency, bool active = true) : Entity() {
|
|
20e1ffec | Christian Ehringfeld | this->name = name;
|
|
this->efficiency = efficiency;
|
|||
this->active = active;
|
|||
}
|
|||
f8b8663b | Christian Ehringfeld | virtual const QHash<QString, CuteEntityManager::Relation> getRelations() const
|
|
override;
|
|||
QString getName() const;
|
|||
void setName(const QString &value);
|
|||
quint32 getEfficiency() const;
|
|||
void setEfficiency(const quint32 &value);
|
|||
bool isActive() const;
|
|||
void setActive(bool value);
|
|||
QList<QSharedPointer<Employee>> getWorkers() const;
|
|||
void setWorkers(const QList<QSharedPointer<Employee>> &value);
|
|||
20e1ffec | Christian Ehringfeld | void addWorker(const QSharedPointer<Employee> &value);
|
|
f8b8663b | Christian Ehringfeld | ||
private:
|
|||
QString name;
|
|||
quint32 efficiency;
|
|||
bool active = true;
|
|||
QList<QSharedPointer<Employee>> workers;
|
|||
};
|
|||
f2bd88b8 | Christian Ehringfeld | class Group: public CuteEntityManager::Entity {
|
|
Q_OBJECT
|
|||
37d98e0b | Christian Ehringfeld | EM_MACRO(Group)
|
|
f2bd88b8 | Christian Ehringfeld | Q_PROPERTY(QList<QSharedPointer<Person>> persons READ getPersons WRITE
|
|
setPersons)
|
|||
Q_PROPERTY(QString name READ getName WRITE setName)
|
|||
Q_PROPERTY(QSharedPointer<Person> leader READ getLeader WRITE
|
|||
setLeader)
|
|||
public:
|
|||
Q_INVOKABLE Group();
|
|||
const QHash<QString, CuteEntityManager::Relation> getRelations() const override;
|
|||
20e1ffec | Christian Ehringfeld | Group(QString name) : Entity() {
|
|
this->name = name;
|
|||
}
|
|||
f2bd88b8 | Christian Ehringfeld | QString getName() const;
|
|
void setName(const QString &value);
|
|||
QSharedPointer<Person> getLeader() const;
|
|||
void setLeader(const QSharedPointer<Person> &value);
|
|||
e7cfc35a | Christian Ehringfeld | QList<QSharedPointer<Person>> getPersons() const;
|
|
void addPerson(const QSharedPointer<Person> &value);
|
|||
void setPersons(const QList<QSharedPointer<Person>> &value);
|
|||
void removePerson(const QSharedPointer<Person> &value);
|
|||
f2bd88b8 | Christian Ehringfeld | ||
protected:
|
|||
QList<QSharedPointer<Person>> persons;
|
|||
QSharedPointer<Person> leader;
|
|||
QString name;
|
|||
};
|
|||
9e2d71d6 | Christian Ehringfeld | class Article : public CuteEntityManager::Entity {
|
|
Q_OBJECT
|
|||
37d98e0b | Christian Ehringfeld | EM_MACRO(Article)
|
|
9e2d71d6 | Christian Ehringfeld | Q_PROPERTY(double price READ getPrice WRITE setPrice)
|
|
Q_PROPERTY(QString name READ getName WRITE setName)
|
|||
private:
|
|||
double price;
|
|||
QString name;
|
|||
public:
|
|||
virtual ~Article();
|
|||
Q_INVOKABLE Article();
|
|||
Article(double price, QString name);
|
|||
double getPrice() const;
|
|||
void setPrice(double value);
|
|||
QString getName() const;
|
|||
void setName(const QString &value);
|
|||
};
|
|||
f2bd88b8 | Christian Ehringfeld | #endif // MODELS_H
|