NCL Composer  0.1.5
 All Classes Functions Variables Pages
qnstentity.cpp
1 /*
2  * Copyright 2011 TeleMidia/PUC-Rio.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library. If not, see
16  * <http://www.gnu.org/licenses/>.
17  */
18 #include "qnstentity.h"
19 
20 #include <QDebug>
21 
22 QnstEntity::QnstEntity(QnstEntity* parent)
23 {
24  setnstType(Qnst::NoType);
25 
26  setnstParent(parent);
27 
28  if(parent)
29  parent->addnstEntity(this);
30 
31  setnstUid((QString) QUuid::createUuid());
32 }
33 
34 QnstEntity::~QnstEntity()
35 {
36 
37 }
38 
39 QString QnstEntity::getnstUid() const
40 {
41  return uid;
42 }
43 
44 void QnstEntity::setnstUid(const QString &uid)
45 {
46  this->uid = uid;
47 }
48 
49 QString QnstEntity::getnstId() const
50 {
51  return id;
52 }
53 
54 void QnstEntity::setnstId(const QString &id)
55 {
56  this->id = id;
57 }
58 
59 QnstType QnstEntity::getnstType() const
60 {
61  return type;
62 }
63 
64 void QnstEntity::setnstType(QnstType type)
65 {
66  this->type = type;
67 }
68 
69 bool QnstEntity::isMedia()
70 {
71  return ( (this->type >= Qnst::Media) &&
72  (this->type <= Qnst::Settings) );
73 }
74 
75 QMap <QString, QString> QnstEntity::getUsrData()
76 {
77  return userData;
78 }
79 
80 void QnstEntity::setUsrData(QMap <QString, QString> newUserData)
81 {
82  userData = newUserData;
83 }
84 
85 QnstEntity* QnstEntity::getnstParent() const
86 {
87  return parent;
88 }
89 
90 void QnstEntity::setnstParent(QnstEntity* parent)
91 {
92  this->parent = parent;
93 }
94 
95 QSet <QnstEntity*> QnstEntity::getnstEntities()
96 {
97  return entities;
98 }
99 
100 void QnstEntity::addnstEntity(QnstEntity* entity)
101 {
102  if (entity != NULL)
103  {
104  // \fixme This is only an additional check. Maybe, the better way to do
105  // that could be using a set instead of a vector to entities.
106  if(entities.contains(entity))
107 
108 #ifdef Q_WS_MAC
109  qWarning() << "[QNST] Warning! You are adding the same entity twice as \
110  child of " << this << __FILE__ << __LINE__;
111 #else
112  qWarning() << "[QNST] Warning! You are adding the same entity twice as \
113  child of " << (int) this << __FILE__ << __LINE__;
114 #endif
115 
116  entity->setnstParent(this);
117  entities.insert(entity);
118  }
119 }
120 
121 void QnstEntity::removenstEntity(QnstEntity* entity)
122 {
123  if (entity != NULL)
124  {
125  entities.remove(entity);
126  entity->setnstParent(NULL);
127  }
128 }