src/data/intdecorator.cpp \
src/data/datetimedecorator.cpp \
src/data/enumeratordecorator.cpp \
- src/data/entity.cpp
+ src/data/entity.cpp \
+ src/models/address.cpp \
+ src/models/appointment.cpp \
+ src/models/contact.cpp
HEADERS += \
src/models/client.h \
src/data/datetimedecorator.h \
src/data/enumeratordecorator.h \
src/data/entity.h \
- src/data/entity-collection.h
+ src/data/entity-collection.h \
+ src/models/address.h \
+ src/models/appointment.h \
+ src/models/contact.h
unix {
target.path = /usr/lib
{
navigationController = new NavigationController(_masterController);
commandController = new CommandController(_masterController);
+ newClient = new models::Client(masterController);
}
MasterController* masterController{nullptr};
NavigationController* navigationController{nullptr};
CommandController* commandController{nullptr};
+ models::Client* newClient{nullptr};
QString welcomeMessage = "This is MasterController to Major Tom";
};
return implementation->commandController;
}
+ models::Client* MasterController::newClient()
+ {
+ return implementation->newClient;
+ }
+
const QString& MasterController::welcomeMessage() const
{
return implementation->welcomeMessage;
#include "cm-lib_global.h"
#include "controllers/navigation-controller.h"
#include "controllers/commandcontroller.h"
+#include "models/client.h"
namespace cm::controllers {
class CMLIBSHARED_EXPORT MasterController : public QObject
{
Q_OBJECT
- Q_PROPERTY( QString ui_welcomeMessage READ welcomeMessage CONSTANT )
- Q_PROPERTY( cm::controllers::NavigationController* ui_navigationController READ navigationController CONSTANT )
- Q_PROPERTY( cm::controllers::CommandController* ui_commandController READ commandController CONSTANT )
+ Q_PROPERTY( QString ui_welcomeMessage READ welcomeMessage CONSTANT )
+ Q_PROPERTY( cm::controllers::NavigationController* ui_navigationController READ navigationController CONSTANT )
+ Q_PROPERTY( cm::controllers::CommandController* ui_commandController READ commandController CONSTANT )
+ Q_PROPERTY( cm::models::Client* ui_newClient READ newClient CONSTANT )
public:
explicit MasterController(QObject *parent = nullptr);
NavigationController* navigationController();
CommandController* commandController();
+ models::Client* newClient();
const QString& welcomeMessage() const;
private:
void clear() override
{
for (auto entity : collection) {
- entity->deletaLater();
+ entity->deleteLater();
}
collection.clear();
}
--- /dev/null
+#include "address.h"
+
+namespace cm::models {
+
+ Address::Address(QObject* parent)
+ : Entity(parent, "address")
+ {
+ building = static_cast<data::StringDecorator*>(addDataItem(new data::StringDecorator(this, "building", "Building")));
+ street = static_cast<data::StringDecorator*>(addDataItem(new data::StringDecorator(this, "stree", "Street")));
+ city = static_cast<data::StringDecorator*>(addDataItem(new data::StringDecorator(this, "city", "City")));
+ postcode = static_cast<data::StringDecorator*>(addDataItem(new data::StringDecorator(this, "postcode", "Post Code")));
+ }
+
+ Address::Address(QObject* parent, const QJsonObject& json)
+ : Address(parent)
+ {
+ update(json);
+ }
+
+ QString Address::fullAddress() const
+ {
+ return QString("%1 %2\n%3\n%4").arg(building->value(), street->value(), city->value(), postcode->value());
+ }
+}
--- /dev/null
+#ifndef ADDRESS_H
+#define ADDRESS_H
+
+#include <QObject>
+#include <QString>
+#include <QJsonObject>
+
+#include "data/entity.h"
+#include "data/stringdecorator.h"
+#include "cm-lib_global.h"
+
+namespace cm::models {
+
+ class CMLIBSHARED_EXPORT Address : public data::Entity
+ {
+ Q_OBJECT
+ Q_PROPERTY(cm::data::StringDecorator* ui_building MEMBER building CONSTANT)
+ Q_PROPERTY(cm::data::StringDecorator* ui_street MEMBER street CONSTANT)
+ Q_PROPERTY(cm::data::StringDecorator* ui_city MEMBER city CONSTANT)
+ Q_PROPERTY(cm::data::StringDecorator* ui_postcode MEMBER postcode CONSTANT)
+ Q_PROPERTY(QString ui_fullAddress READ fullAddress CONSTANT)
+
+ public:
+ explicit Address(QObject* parent = nullptr);
+ Address(QObject* parent, const QJsonObject& json);
+
+ data::StringDecorator* building{nullptr};
+ data::StringDecorator* street{nullptr};
+ data::StringDecorator* city{nullptr};
+ data::StringDecorator* postcode{nullptr};
+
+ QString fullAddress() const;
+ };
+}
+
+#endif // ADDRESS_H
--- /dev/null
+#include "appointment.h"
+
+namespace cm::models {
+
+ Appointment::Appointment(QObject* parent)
+ : Entity(parent, "appointment")
+ {
+ startAt = static_cast<data::DateTimeDecorator*>(
+ addDataItem(new data::DateTimeDecorator(this,"startAt", "Starts at")));
+ endAt = static_cast<data::DateTimeDecorator*>(
+ addDataItem(new data::DateTimeDecorator(this,"endAt", "Ends at")));
+ notes = static_cast<data::StringDecorator*>(
+ addDataItem(new data::StringDecorator(this, "notes", "Notes")));
+ }
+
+ Appointment::Appointment(QObject* parent, const QJsonObject& json)
+ : Appointment(parent)
+ {
+ update(json);
+ }
+}
--- /dev/null
+#ifndef APPOINTMENT_H
+#define APPOINTMENT_H
+
+#include <QObject>
+#include <QJsonObject>
+
+#include "data/entity.h"
+#include "data/stringdecorator.h"
+#include "data/datetimedecorator.h"
+#include "cm-lib_global.h"
+
+namespace cm::models {
+
+ class CMLIBSHARED_EXPORT Appointment : public data::Entity
+ {
+ Q_OBJECT
+ Q_PROPERTY(cm::data::DateTimeDecorator* ui_startAt MEMBER startAt CONSTANT)
+ Q_PROPERTY(cm::data::DateTimeDecorator* ui_endAt MEMBER endAt CONSTANT)
+ Q_PROPERTY(cm::data::StringDecorator* ui_notes MEMBER notes CONSTANT)
+ public:
+ explicit Appointment(QObject* parent = nullptr);
+ Appointment(QObject* parent, const QJsonObject& json);
+
+ data::DateTimeDecorator* startAt{nullptr};
+ data::DateTimeDecorator* endAt{nullptr};
+ data::StringDecorator* notes{nullptr};
+ };
+}
+#endif // APPOINTMENT_H
#include "client.h"
namespace cm::models {
- Client::Client()
+
+ Client::Client(QObject * parent)
+ : Entity(parent, "client")
+ {
+ reference = static_cast<data::StringDecorator*>(
+ addDataItem(new data::StringDecorator(this, "reference", "Client Ref")));
+ name = static_cast<data::StringDecorator*>(
+ addDataItem(new data::StringDecorator(this, "name", "Name")));
+ supplyAddress = static_cast<Address*>(
+ addChild(new Address(this), "supplyAddress"));
+ billingAddress = static_cast<Address*>(
+ addChild(new Address(this), "billingAddress"));
+ appointments = static_cast<data::EntityCollection<Appointment>*>(
+ addChildCollection(new data::EntityCollection<Appointment>(this, "appointments")));
+ contacts = static_cast<data::EntityCollection<Contact>*>(
+ addChildCollection(new data::EntityCollection<Contact>(this, "contacts")));
+ }
+
+ Client::Client(QObject* parent, const QJsonObject& json)
+ : Client(parent)
+ {
+ update(json);
+ }
+
+ QQmlListProperty<Appointment> Client::ui_appointments()
+ {
+ return QQmlListProperty<Appointment>(this, appointments->derivedEntities());
+ }
+
+ QQmlListProperty<Contact> Client::ui_contacts()
{
+ return QQmlListProperty<Contact>(this, contacts->derivedEntities());
}
}
#ifndef CLIENT_H
#define CLIENT_H
+#include <QObject>
+#include <QJsonObject>
+#include <QtQml/QQmlListProperty>
+
#include "cm-lib_global.h"
+#include "data/stringdecorator.h"
+#include "data/entity.h"
+#include "data/entity-collection.h"
+#include "models/address.h"
+#include "models/appointment.h"
+#include "models/contact.h"
namespace cm::models {
-class CMLIBSHARED_EXPORT Client
+class CMLIBSHARED_EXPORT Client : public data::Entity
{
+ Q_OBJECT
+ Q_PROPERTY(cm::data::StringDecorator* ui_reference MEMBER reference CONSTANT )
+ Q_PROPERTY(cm::data::StringDecorator* ui_name MEMBER name CONSTANT )
+ Q_PROPERTY(cm::models::Address* ui_supplyAddress MEMBER supplyAddress CONSTANT )
+ Q_PROPERTY(cm::models::Address* ui_billingAddress MEMBER billingAddress CONSTANT )
+ Q_PROPERTY(QQmlListProperty<Appointment> ui_appointments READ ui_appointments NOTIFY appointmentsChanged )
+ Q_PROPERTY(QQmlListProperty<Contact> ui_contacts READ ui_contacts NOTIFY contactsChanged )
public:
- Client();
+ explicit Client(QObject* parent = nullptr);
+ Client(QObject* parent, const QJsonObject& json);
+
+ data::StringDecorator* reference{nullptr};
+ data::StringDecorator* name{nullptr};
+ Address* supplyAddress{nullptr};
+ Address* billingAddress{nullptr};
+ data::EntityCollection<Appointment>* appointments{nullptr};
+ data::EntityCollection<Contact>* contacts{nullptr};
+
+ QQmlListProperty<cm::models::Appointment> ui_appointments();
+ QQmlListProperty<cm::models::Contact> ui_contacts();
+
+signals:
+ void appointmentsChanged();
+ void contactsChanged();
};
}
#endif // CLIENT_H
--- /dev/null
+#include "contact.h"
+
+namespace cm::models {
+
+ Contact::Contact(QObject* parent)
+ : data::Entity(parent, "contact")
+ {
+ type = static_cast<data::EnumeratorDecorator*>(
+ addDataItem(new data::EnumeratorDecorator(this, "type", "Contact Type", 0, contactTypeMapper)));
+ address = static_cast<data::StringDecorator*>(
+ addDataItem(new data::StringDecorator(this, "address", "Address")));
+ }
+
+ Contact::Contact(QObject* parent, const QJsonObject& json)
+ : Contact(parent)
+ {
+ update(json);
+ }
+}
--- /dev/null
+#ifndef CONTACT_H
+#define CONTACT_H
+
+#include <map>
+
+#include <QObject>
+
+#include "data/entity.h"
+#include "data/stringdecorator.h"
+#include "data/enumeratordecorator.h"
+#include "cm-lib_global.h"
+
+namespace cm::models {
+
+ class CMLIBSHARED_EXPORT Contact : public data::Entity
+ {
+ Q_OBJECT
+ Q_PROPERTY(cm::data::EnumeratorDecorator* ui_type MEMBER type CONSTANT)
+ Q_PROPERTY(cm::data::StringDecorator* ui_address MEMBER address CONSTANT)
+
+ public:
+ explicit Contact(QObject* parent = nullptr);
+ Contact(QObject* parent, const QJsonObject& json);
+
+ data::EnumeratorDecorator* type{nullptr};
+ data::StringDecorator* address{nullptr};
+
+ private:
+ enum eContactType {
+ Unknown = 0,
+ Telephone,
+ Email,
+ Fax
+ };
+
+ std::map<int, QString> contactTypeMapper = std::map<int, QString>
+ {
+ { Contact::eContactType::Unknown, "" },
+ { Contact::eContactType::Telephone, "Telephone" },
+ { Contact::eContactType::Email, "Email" },
+ { Contact::eContactType::Fax, "Fax" }
+ };
+ };
+}
+#endif // CONTACT_H
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
+
#include "controllers/master-controller.h"
#include "controllers/commandcontroller.h"
+
#include "framework/command.h"
+#include "data/datetimedecorator.h"
+#include "data/enumeratordecorator.h"
+#include "data/intdecorator.h"
+#include "data/stringdecorator.h"
+
+#include "models/address.h"
+#include "models/appointment.h"
+#include "models/contact.h"
+#include "models/client.h"
+
+
int main(int argc, char *argv[])
{
#if defined(Q_OS_WIN)
qmlRegisterType<cm::controllers::MasterController>("CM", 1, 0, "MasterController");
qmlRegisterType<cm::controllers::NavigationController>("CM", 1, 0, "NavigationController");
qmlRegisterType<cm::controllers::CommandController>("CM", 1, 0, "CommandController");
+
qmlRegisterType<cm::framework::Command>("CM", 1, 0, "Command");
+ qmlRegisterType<cm::data::DateTimeDecorator>("CM", 1, 0, "DateTimeDecorator");
+ qmlRegisterType<cm::data::EnumeratorDecorator>("CM", 1, 0, "EnumeratorDecorator");
+ qmlRegisterType<cm::data::IntDecorator>("CM", 1, 0, "IntDecorator");
+ qmlRegisterType<cm::data::StringDecorator>("CM", 1, 0, "StringDecorator");
+
+ qmlRegisterType<cm::models::Address>("CM", 1, 0, "Address");
+ qmlRegisterType<cm::models::Appointment>("CM", 1, 0, "Appointment");
+ qmlRegisterType<cm::models::Contact>("CM", 1, 0, "Contact");
+ qmlRegisterType<cm::models::Client>("CM", 1, 0, "Client");
+
cm::controllers::MasterController masterController;
QQmlApplicationEngine engine;