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) 2001-2014 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 "Property.h"
30 
31 // STL
32 #include <vector>
33 #include <algorithm>
34 
36  m_name("unknown"),
37  m_id("unknown"),
38  m_editable(true),
39  m_type(DataTypeNone)
40 {
41 
42 }
43 
45 {
46 
47 }
48 
50 {
51  return m_name;
52 }
53 
54 void te::layout::Property::setName( std::string name )
55 {
56  m_name = name;
57 }
58 
60 {
61  return m_type;
62 }
63 
65 {
66  return m_id;
67 }
68 
69 void te::layout::Property::setId( std::string id )
70 {
71  m_id = id;
72 }
73 
75 {
76  return m_value;
77 }
78 
80 {
81  if(m_options.empty())
82  {
83  m_currentChoice = variant;
84  }
85 
86  m_options.push_back(variant);
87 }
88 
90 {
91  for(std::vector<Variant>::iterator it = m_options.begin(); it != m_options.end(); it++)
92  {
93  if((*it) == variant)
94  {
95  m_options.erase(it);
96  break;
97  }
98  }
99 }
100 
102 {
103  m_currentChoice = variant;
104 }
105 
107 {
108  return m_currentChoice;
109 }
110 
111 std::vector<te::layout::Variant> te::layout::Property::getOptionChoices()
112 {
113  return m_options;;
114 }
115 
117 {
118  return m_editable;
119 }
120 
122 {
123  m_editable = editable;
124 }
125 
127 {
128  m_subProperty.push_back(property);
129 }
130 
132 {
133  for(std::vector<Property>::iterator it = m_subProperty.begin(); it != m_subProperty.end(); it++)
134  {
135  if((*it) == property)
136  {
137  m_subProperty.erase(it);
138  break;
139  }
140  }
141 }
142 
143 std::vector<te::layout::Property> te::layout::Property::getSubProperty()
144 {
145  return m_subProperty;
146 }
147 
149 {
150  bool result = true;
151 
152  if(m_value.isNull())
153  {
154  if(!m_options.empty())
155  {
156  result = false;
157  }
158  }
159  else
160  {
161  result = false;
162  }
163 
164  return result;
165 }
166 
168 {
169  bool is_present = false;
170 
171  if(std::find(m_subProperty.begin(), m_subProperty.end(), subProperty) != m_subProperty.end())
172  {
173  is_present = true;
174  }
175 
176  return is_present;
177 }
178 
180 {
181  Property property;
182  property.setName(name);
183 
184  if(std::find(m_subProperty.begin(), m_subProperty.end(), property) != m_subProperty.end())
185  {
186  std::vector<Property>::iterator it = std::find(m_subProperty.begin(), m_subProperty.end(), property);
187 
188  property = (*it);
189  }
190  else
191  property.setName("");
192 
193  return property;
194 }
195 
197 {
198  m_name = "unknown";
199  m_id = "unknown";
200  m_editable = true;
201  m_type = DataTypeNone;
202  m_value.clear();
203  m_currentChoice.clear();
204  m_options.clear();
205  m_subProperty.clear();
206 }
207 
209 {
210  m_value = variant;
211  m_type = variant.getType();
212 }
void removeSubProperty(Property property)
Definition: Property.cpp:131
std::string getName()
Definition: Property.cpp:49
Variant getValue()
Definition: Property.cpp:74
void addSubProperty(Property property)
Definition: Property.cpp:126
void addOption(Variant variant)
Definition: Property.cpp:79
Variant getOptionByCurrentChoice()
Definition: Property.cpp:106
void setValue(typename ValueType value, LayoutPropertyDataType type)
Definition: Property.h:106
virtual bool containsSubProperty(Property subProperty)
Definition: Property.cpp:167
std::vector< Variant > getOptionChoices()
Definition: Property.cpp:111
void removeOption(Variant variant)
Definition: Property.cpp:89
LayoutPropertyDataType getType()
Definition: Variant.cpp:71
LayoutPropertyDataType getType()
Definition: Property.cpp:59
void setEditable(bool editable)
Definition: Property.cpp:121
void setName(std::string name)
Definition: Property.cpp:54
std::string getId()
Definition: Property.cpp:64
LayoutPropertyDataType
Enum LayoutPropertyDataType.
Definition: AbstractType.h:131
void setId(std::string id)
Definition: Property.cpp:69
std::vector< te::layout::Property > getSubProperty()
Definition: Property.cpp:143
void setOptionChoice(Variant variant)
Definition: Property.cpp:101
virtual ~Property()
Definition: Property.cpp:44