entity.h
Go to the documentation of this file.
1 #ifndef DNAI_MODELS_GUI_DECLARABLE_ENTITY_H
2 #define DNAI_MODELS_GUI_DECLARABLE_ENTITY_H
3 
8 
9 namespace dnai
10 {
11  namespace models
12  {
13  namespace gui
14  {
15  namespace declarable
16  {
17  template<class T, class U>
19  {
20  //IModelData implementation
21  public:
22  Entity() = default;
23  virtual ~Entity() override = default;
24 
25  virtual bool setData(const T& data) override
26  {
27  if (m_data == data)
28  return false;
29  m_data = data;
30  return true;
31  }
32 
33  virtual int index() const override
34  {
35  return m_data.index;
36  }
37 
38  virtual bool setIndex(const int index) override
39  {
40  if (m_data.index == index)
41  return false;
42  m_data.index = index;
43  return true;
44  }
45 
46  virtual QUuid listIndex() const override
47  {
48  return m_data.listIndex;
49  }
50 
51  virtual bool setListIndex(QUuid listIndex) override
52  {
53  if (m_data.listIndex == listIndex)
54  return false;
55  m_data.listIndex = listIndex;
56  return true;
57  }
58 
59  virtual const QString& description() const override
60  {
61  return m_data.description;
62  }
63 
64  virtual bool setDescription(const QString& description) override
65  {
66  if (m_data.description == description)
67  return false;
68  m_data.description = description;
69  return true;
70  }
71 
72  virtual bool expanded() const override
73  {
74  return m_data.expanded;
75  }
76 
77  virtual bool setExpanded(bool exp) override
78  {
79  if (m_data.expanded == exp)
80  return false;
81  m_data.expanded = exp;
82  return true;
83  }
84 
85  virtual const T& data() const override
86  {
87  return m_data;
88  }
89 
90  virtual void serialize(QJsonObject& obj) const override
91  {
92 // obj["expanded"] = m_data.expanded;
93  obj["description"] = m_data.description;
94  obj["index"] = m_data.index;
95  obj["listIndex"] = m_data.listIndex.toString();
96  }
97  protected:
98  virtual void _deserialize(const QJsonObject& obj) override
99  {
100 // m_data.expanded = obj["expanded"].toBool();
101  m_data.description = obj["description"].toString();
102  m_data.index = obj["index"].toInt();
103  m_data.listIndex = QUuid(obj["listIndex"].toString());
104  }
105 
106  protected:
108  };
109  }
110  }
111  }
112 }
113 
114 #endif //DNAI_MODELS_GUI_DECLARABLE_ENTITY_H
virtual ~Entity() override=default
Definition: entity.cpp:80
Entity()=default
Definition: entity.cpp:71
Allow inherited class to serialize and deserialize itself.
Definition: iserializable.h:33
virtual const QString & description() const override
Definition: entity.h:59
virtual const T & data() const override
Return the data component.
Definition: entity.h:85
Definition: ientity.h:12
virtual QUuid listIndex() const override
Definition: entity.h:46
Definition: imodeldata.h:9
virtual bool setIndex(const int index) override
Definition: entity.h:38
virtual int index() const override
Definition: entity.h:33
virtual bool setDescription(const QString &description) override
Definition: entity.h:64
virtual bool setListIndex(QUuid listIndex) override
Definition: entity.h:51
virtual void _deserialize(const QJsonObject &obj) override
Implement this function in order to use deserialize(const QJsonObject &obj)
Definition: entity.h:98
Definition: api.h:13
virtual bool expanded() const override
Definition: entity.h:72
virtual bool setData(const T &data) override
set the data component of this object
Definition: entity.h:25
virtual bool setExpanded(bool exp) override
Definition: entity.h:77
T m_data
Definition: entity.h:107
virtual void serialize(QJsonObject &obj) const override
Implement this function to serialize into QJsonObject.
Definition: entity.h:90