]> Johnzone git - learnqt-cm.git/commitdiff
c++ part of data models done master
authorJohn Janus <mail@johnzone.org>
Thu, 13 Sep 2018 21:25:25 +0000 (23:25 +0200)
committerJohn Janus <mail@johnzone.org>
Thu, 13 Sep 2018 21:25:25 +0000 (23:25 +0200)
13 files changed:
cm-lib/cm-lib.pro
cm-lib/src/controllers/master-controller.cpp
cm-lib/src/controllers/master-controller.h
cm-lib/src/data/entity-collection.h
cm-lib/src/models/address.cpp [new file with mode: 0644]
cm-lib/src/models/address.h [new file with mode: 0644]
cm-lib/src/models/appointment.cpp [new file with mode: 0644]
cm-lib/src/models/appointment.h [new file with mode: 0644]
cm-lib/src/models/client.cpp
cm-lib/src/models/client.h
cm-lib/src/models/contact.cpp [new file with mode: 0644]
cm-lib/src/models/contact.h [new file with mode: 0644]
cm-ui/src/main.cpp

index 0aaaec77be8d5dca18b36b4201e790a015c56b8e..f8d6815f2fbcd4aa1ec3fad6f6dbdd52ee73819b 100644 (file)
@@ -39,7 +39,10 @@ SOURCES += \
     src/data/intdecorator.cpp \
     src/data/datetimedecorator.cpp \
     src/data/enumeratordecorator.cpp \
     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 \
 
 HEADERS += \
         src/models/client.h \
@@ -54,7 +57,10 @@ HEADERS += \
     src/data/datetimedecorator.h \
     src/data/enumeratordecorator.h \
     src/data/entity.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
 
 unix {
     target.path = /usr/lib
index f6b95ac331a7238c1fdbf82547b1a3b18819ef2a..2e812dba6619e62f25b9fc62c9b5fbc06dd4bfee 100644 (file)
@@ -10,11 +10,13 @@ namespace cm::controllers {
     {
       navigationController = new NavigationController(_masterController);
       commandController = new CommandController(_masterController);
     {
       navigationController = new NavigationController(_masterController);
       commandController = new CommandController(_masterController);
+      newClient = new models::Client(masterController);
     }
 
     MasterController* masterController{nullptr};
     NavigationController* navigationController{nullptr};
     CommandController* commandController{nullptr};
     }
 
     MasterController* masterController{nullptr};
     NavigationController* navigationController{nullptr};
     CommandController* commandController{nullptr};
+    models::Client* newClient{nullptr};
     QString welcomeMessage = "This is MasterController to Major Tom";
   };
 
     QString welcomeMessage = "This is MasterController to Major Tom";
   };
 
@@ -38,6 +40,11 @@ namespace cm::controllers {
     return implementation->commandController;
   }
 
     return implementation->commandController;
   }
 
+  models::Client* MasterController::newClient()
+  {
+    return implementation->newClient;
+  }
+
   const QString& MasterController::welcomeMessage() const
   {
     return implementation->welcomeMessage;
   const QString& MasterController::welcomeMessage() const
   {
     return implementation->welcomeMessage;
index bf2db84ffff4f2f17fd31cc2aa02a7ef362f375d..33fe2b13248b395b99fa38a7d5f48f55c033002e 100644 (file)
@@ -8,15 +8,17 @@
 #include "cm-lib_global.h"
 #include "controllers/navigation-controller.h"
 #include "controllers/commandcontroller.h"
 #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
 
 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);
 
 public:
   explicit MasterController(QObject *parent = nullptr);
@@ -24,6 +26,7 @@ public:
 
   NavigationController* navigationController();
   CommandController* commandController();
 
   NavigationController* navigationController();
   CommandController* commandController();
+  models::Client* newClient();
   const QString& welcomeMessage() const;
 
 private:
   const QString& welcomeMessage() const;
 
 private:
index 5b8901e5134e2a4fef650e268990bd8788dc35db..d6381f819e484739c98e5624166a648b5951a0ba 100644 (file)
@@ -67,7 +67,7 @@ namespace cm::data {
     void clear() override
     {
       for (auto entity : collection) {
     void clear() override
     {
       for (auto entity : collection) {
-        entity->deletaLater();
+        entity->deleteLater();
       }
       collection.clear();
     }
       }
       collection.clear();
     }
diff --git a/cm-lib/src/models/address.cpp b/cm-lib/src/models/address.cpp
new file mode 100644 (file)
index 0000000..9739267
--- /dev/null
@@ -0,0 +1,24 @@
+#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());
+  }
+}
diff --git a/cm-lib/src/models/address.h b/cm-lib/src/models/address.h
new file mode 100644 (file)
index 0000000..d24be49
--- /dev/null
@@ -0,0 +1,36 @@
+#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
diff --git a/cm-lib/src/models/appointment.cpp b/cm-lib/src/models/appointment.cpp
new file mode 100644 (file)
index 0000000..1d70596
--- /dev/null
@@ -0,0 +1,21 @@
+#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);
+  }
+}
diff --git a/cm-lib/src/models/appointment.h b/cm-lib/src/models/appointment.h
new file mode 100644 (file)
index 0000000..2ee7e72
--- /dev/null
@@ -0,0 +1,29 @@
+#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
index e20037a5c726b2eaef7d9effa28442ca69aa851a..11ebc8b710d820862288349b278ffb4d474cdfa7 100644 (file)
@@ -1,7 +1,37 @@
 #include "client.h"
 
 namespace cm::models {
 #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());
   }
 }
   }
 }
index 098d11b93a877266bd568df713d839f852996160..fa0eee490e15c7ea629a309e46893659eb725154 100644 (file)
@@ -1,15 +1,47 @@
 #ifndef CLIENT_H
 #define CLIENT_H
 
 #ifndef CLIENT_H
 #define CLIENT_H
 
+#include <QObject>
+#include <QJsonObject>
+#include <QtQml/QQmlListProperty>
+
 #include "cm-lib_global.h"
 #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 {
 
 
 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:
 
 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
 };
 }
 #endif // CLIENT_H
diff --git a/cm-lib/src/models/contact.cpp b/cm-lib/src/models/contact.cpp
new file mode 100644 (file)
index 0000000..a70917f
--- /dev/null
@@ -0,0 +1,19 @@
+#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);
+  }
+}
diff --git a/cm-lib/src/models/contact.h b/cm-lib/src/models/contact.h
new file mode 100644 (file)
index 0000000..6afc49a
--- /dev/null
@@ -0,0 +1,45 @@
+#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
index c2e20591f34722fef731f56761b60ff4851265c2..6666ecbc027245ac9eedf4403cf9d51e9ef82ec7 100644 (file)
@@ -1,10 +1,23 @@
 #include <QGuiApplication>
 #include <QQmlApplicationEngine>
 #include <QQmlContext>
 #include <QGuiApplication>
 #include <QQmlApplicationEngine>
 #include <QQmlContext>
+
 #include "controllers/master-controller.h"
 #include "controllers/commandcontroller.h"
 #include "controllers/master-controller.h"
 #include "controllers/commandcontroller.h"
+
 #include "framework/command.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)
 int main(int argc, char *argv[])
 {
 #if defined(Q_OS_WIN)
@@ -15,8 +28,19 @@ int main(int argc, char *argv[])
   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::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::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;
   cm::controllers::MasterController masterController;
 
   QQmlApplicationEngine engine;