All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Property.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file Property.cpp
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
29 #include "../enum/Enums.h"
30 #include "Property.h"
31 
32 // STL
33 #include <vector>
34 #include <algorithm>
35 
36 te::layout::Property::Property( int parentItemHashCode ) :
37  m_parentItemHashCode(parentItemHashCode),
38  m_name("unknown"),
39  m_type(0),
40  m_editable(true),
41  m_label(""),
42  m_menu(false),
43  m_icon(""),
44  m_visible(true),
45  m_required(false),
46  m_composeWidget(false),
47  m_public(false)
48 {
49  m_type = Enums::getInstance().getEnumDataType()->getDataTypeNone();
50 }
51 
53 {
54 
55 }
56 
58 {
59  return m_name;
60 }
61 
62 void te::layout::Property::setName( std::string name )
63 {
64  m_name = name;
65 }
66 
68 {
69  return m_type;
70 }
71 
73 {
74  return m_value;
75 }
76 
78 {
79  if(m_options.empty())
80  {
81  m_currentChoice = variant;
82  }
83 
84  m_options.push_back(variant);
85 }
86 
88 {
89  for(std::vector<Variant>::iterator it = m_options.begin(); it != m_options.end(); it++)
90  {
91  if((*it) == variant)
92  {
93  m_options.erase(it);
94  break;
95  }
96  }
97 }
98 
100 {
101  m_currentChoice = variant;
102 }
103 
105 {
106  return m_currentChoice;
107 }
108 
109 std::vector<te::layout::Variant> te::layout::Property::getOptionChoices()
110 {
111  return m_options;;
112 }
113 
115 {
116  return m_editable;
117 }
118 
120 {
121  m_editable = editable;
122 }
123 
125 {
126  m_subProperty.push_back(property);
127 }
128 
130 {
131  for(std::vector<Property>::iterator it = m_subProperty.begin(); it != m_subProperty.end(); it++)
132  {
133  if((*it) == property)
134  {
135  m_subProperty.erase(it);
136  break;
137  }
138  }
139 }
140 
141 std::vector<te::layout::Property> te::layout::Property::getSubProperty()
142 {
143  return m_subProperty;
144 }
145 
147 {
148  bool result = true;
149 
150  if(m_value.isNull())
151  {
152  if(!m_options.empty())
153  {
154  result = false;
155  }
156  }
157  else
158  {
159  result = false;
160  }
161 
162  return result;
163 }
164 
166 {
167  bool is_present = false;
168 
169  if(std::find(m_subProperty.begin(), m_subProperty.end(), subProperty) != m_subProperty.end())
170  {
171  is_present = true;
172  }
173 
174  return is_present;
175 }
176 
178 {
179  Property property;
180  property.setName(name);
181 
182  if(std::find(m_subProperty.begin(), m_subProperty.end(), property) != m_subProperty.end())
183  {
184  std::vector<Property>::iterator it = std::find(m_subProperty.begin(), m_subProperty.end(), property);
185 
186  property = (*it);
187  }
188  else
189  property.setName("");
190 
191  return property;
192 }
193 
195 {
197 
198  m_name = "unknown";
199  m_editable = true;
200  m_type = dataType->getDataTypeNone();
201  m_value.clear();
202  m_currentChoice.clear();
203  m_options.clear();
204  m_subProperty.clear();
205  m_menu = false;
206  m_icon = "";
207  m_required = false;
208  m_composeWidget = false;
209  m_label = "";
210 }
211 
213 {
214  m_value = variant;
215  m_type = variant.getType();
216 }
217 
218 void te::layout::Property::setLabel( std::string label )
219 {
220  m_label = label;
221 }
222 
224 {
225  return m_label;
226 }
227 
229 {
230  m_menu = menu;
231 }
232 
234 {
235  return m_menu;
236 }
237 
238 void te::layout::Property::setIcon( std::string icon )
239 {
240  m_icon = icon;
241 }
242 
244 {
245  return m_icon;
246 }
247 
249 {
250  return m_value.isComplex();
251 }
252 
254 {
255  m_visible = visible;
256 }
257 
259 {
260  return m_visible;
261 }
262 
264 {
265  return m_required;
266 }
267 
269 {
270  m_required = required;
271 }
272 
274 {
275  m_parentItemHashCode = hashCode;
276 }
277 
279 {
280  return m_parentItemHashCode;
281 }
282 
284 {
285  return m_composeWidget;
286 }
287 
289 {
290  m_composeWidget = compose;
291 }
292 
294 {
295  return m_public;
296 }
297 
298 void te::layout::Property::setPublic( bool publicProperty )
299 {
300  /*
301  If the component, father of this property, is a child of another component,
302  then this property can be used by the parent component to display the value or call windows. It can not be edited.
303  */
304  m_public = publicProperty;
305  if(m_public)
306  {
307  m_editable = false;
308  }
309 }
310 
311 
312 
313 
314 
315 
void clear()
Reset state of this object. Null state.
Definition: Property.cpp:194
void removeSubProperty(Property property)
Definition: Property.cpp:129
std::string getName()
Method that returns the name of this property.
Definition: Property.cpp:57
virtual bool isComplex()
Return true if value is not of common C++ data type, false otherwise.
Definition: Property.cpp:248
EnumType * getType()
Returns data type of this object.
Definition: Variant.cpp:77
Variant getValue()
Returns stored value.
Definition: Property.cpp:72
virtual EnumDataType * getEnumDataType()
Returns data type enumeration.
Definition: Enums.cpp:52
void addSubProperty(Property property)
Definition: Property.cpp:124
void addOption(Variant variant)
Definition: Property.cpp:77
void setPublic(bool publicProperty)
Sets true if property is public, false otherwise If the component, father of this property...
Definition: Property.cpp:298
bool isNull()
Returns true if no value has been set, false otherwise.
Definition: Property.cpp:146
int getParentItemHashCode()
Returns the hashcode of the object that owns this property.
Definition: Property.cpp:278
virtual void setVisible(bool visible)
Sets the visibility of this property.
Definition: Property.cpp:253
virtual EnumType * getDataTypeNone() const
Returns value that represents type none belonging to enumeration.
Variant getOptionByCurrentChoice()
Definition: Property.cpp:104
void setRequired(bool required)
Sets true if property is required, false otherwise.
Definition: Property.cpp:268
virtual bool isMenu()
Returns true if property will be used in a menu, false otherwise.
Definition: Property.cpp:233
virtual bool isVisible()
Return true if visible, false otherwise.
Definition: Property.cpp:258
static Enums & getInstance()
It returns a reference to the singleton instance.
Class to represent a data type enumeration. Ex.: int, double, bool, te::color::RGBAColor (color)...
Definition: EnumDataType.h:48
Class acts like a union for some C++/TerraLib5 data types. Responsible for storing the value...
Definition: Variant.h:80
virtual void setIcon(std::string icon)
Definition: Property.cpp:238
bool isEditable()
Returns true if property is editable, false otherwise.
Definition: Property.cpp:114
bool isRequired()
Returns true if property is required, false otherwise.
Definition: Property.cpp:263
EnumType * m_type
data type of this property
Definition: Property.h:282
Property(int parentItemHashCode=0)
Constructor.
Definition: Property.cpp:36
virtual std::string getIcon()
Definition: Property.cpp:243
void setComposeWidget(bool compose)
Sets true if property compose a widget, false otherwise If true, and the object that owns this proper...
Definition: Property.cpp:288
bool isComposeWidget()
Returns true if property compose a widget, false otherwise. If true, and the object that owns this pr...
Definition: Property.cpp:283
virtual bool containsSubProperty(Property subProperty)
Definition: Property.cpp:165
std::vector< Variant > getOptionChoices()
Definition: Property.cpp:109
void setValue(ValueType value, EnumType *type)
Stores a copy of value.
Definition: Property.h:298
void removeOption(Variant variant)
Definition: Property.cpp:87
Class that represents the value of an enumeration. An enumeration is made of "1..n" objects EnumType...
Definition: EnumType.h:48
void setEditable(bool editable)
Sets true if property is editable, false otherwise.
Definition: Property.cpp:119
void setName(std::string name)
Sets the name of this property.
Definition: Property.cpp:62
virtual void setMenu(bool menu)
Sets true if property will be used in a menu, false otherwise.
Definition: Property.cpp:228
std::vector< te::layout::Property > getSubProperty()
Definition: Property.cpp:141
virtual void setLabel(std::string label)
Sets the label of this property.
Definition: Property.cpp:218
EnumType * getType()
Returns the type of this property.
Definition: Property.cpp:67
void setOptionChoice(Variant variant)
Definition: Property.cpp:99
A property acts like a attribute member of a object and stores the state of this attribute. A set of properties stores the state of an object. Any data type, not included in the convertValue method in the class te::layout::Variant, it will be by default "std::string" value.
Definition: Property.h:47
bool isPublic()
Returns true if property is public, false otherwise. If the component, father of this property...
Definition: Property.cpp:293
virtual ~Property()
Destructor.
Definition: Property.cpp:52
void setParentItemHashCode(int hashCode)
Sets the hashcode of the object that owns this property.
Definition: Property.cpp:273
virtual std::string getLabel()
Returns the label of this property.
Definition: Property.cpp:223