NCL Composer  0.1.5
 All Classes Functions Variables Pages
Entity.h
1 /* Copyright (c) 2011 Telemidia/PUC-Rio.
2  * All rights reserved. This program and the accompanying materials
3  * are made available under the terms of the Eclipse Public License v1.0
4  * which accompanies this distribution, and is available at
5  * http://www.eclipse.org/legal/epl-v10.html
6  *
7  * Contributors:
8  * Telemidia/PUC-Rio - initial API and implementation
9  */
10 #ifndef ENTITY_H
11 #define ENTITY_H
12 
13 #include "../util/ComposerCoreControl_global.h"
14 
15 #include <QObject>
16 #include <QMutex>
17 #include <QMutexLocker>
18 #include <QMap>
19 #include <QUuid>
20 #include <QDebug>
21 
22 namespace composer{
23  namespace core {
24  class MessageControl;
25  class ProjectReader;
26 
27  namespace model {
28  class Project;
29  }
30  namespace util {
31  class EditCommand;
32  class AddCommand;
33  class RemoveCommand;
34  }
35 } } //end namespace
36 
37 namespace composer {
38  namespace core {
39  namespace model {
45 class COMPOSERCORESHARED_EXPORT Entity : public QObject
46 {
47  Q_OBJECT
48 
49  // The following classes are "reliable" and can acess the
50  // private and protected members of Entity.
51  friend class composer::core::model::Project;
52  friend class composer::core::MessageControl;
53  friend class composer::core::ProjectReader;
54 
58 
59 private:
60  QMutex lockAtts;
61  QMutex lockID;
62  QMutex lockType;
63  QMutex lockChildren;
64  QMutex lockParent;
65  QString _id;
66  QString type;
67  Entity* parent;
68  bool deleteChildren; /* initial value is true */
69  QVector <Entity*> children;
75  QMap<QString, QString> atts;
76 
77 protected:
83  explicit Entity(QObject *parent = 0);
90  explicit Entity(QMap<QString,QString> &atts, QObject *parent = 0);
99  explicit Entity(QString uniqueId, QString type, QMap<QString,QString> &atts,
100  QObject *parent = 0);
101 
105  ~Entity();
112  void setAttribute(QString name, QString value);
113 
120  void setAtrributes(QMap<QString,QString> &newatts);
121 
127  void setType(QString type);
128 
135  void setUniqueID(QString uniqueId);
136 
142  void setParent(Entity *parent);
143 
144  //OBS: This addChild updates the parent referency
145  bool addChild(Entity *entity);
146 
152  bool deleteChild(Entity *entity);
158  bool removeChildAppendChildren(Entity *entity);
162  void print();
163 
164 public:
171  QString getAttribute(QString name);
178  void getAttributeIterator (QMap<QString,QString>::iterator &begin,
179  QMap<QString,QString>::iterator &end);
187  bool hasAttribute(const QString &name);
188 
189  QString getUniqueId();
190 
191  QString getType();
192 
193  Entity* getParent();
194 
195  QString getParentUniqueId();
202  void setDeleteChildren(bool mustDelete);
203 
204  QVector <Entity *> getChildren();
205 
211  QString toString(int ntabs, bool writeuid = true);
212 
218  Entity *cloneEntity();
219 };
220 
221 } } } //end namespace
222 
223 #endif // ENTITY_H