All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GridSettingsController.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 GridSettingsController.h
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
29 #include "GridSettingsController.h"
30 #include "OutsideParamsCreate.h"
31 #include "OutsideModelObservable.h"
32 #include "AbstractOutsideFactory.h"
33 #include "Context.h"
34 #include "Observable.h"
35 #include "GridSettingsModel.h"
36 
39 {
41  OutsideParamsCreate params(this, m_model);
42  if(factory)
43  m_view = (Observer*)factory->make(TPGridSettings, params);
44 }
45 
47 {
48 
49 }
50 
51 void te::layout::GridSettingsController::setPosition( const double& x, const double& y )
52 {
53  if(m_model)
54  {
55  OutsideModelObservable* model = dynamic_cast<OutsideModelObservable*>(m_model);
56  if(model)
57  return model->setPosition(x, y);
58  }
59 }
60 
62 {
63  return m_update;
64 }
65 
67 {
68  m_update.clear();
69  m_gridGeodesic.clear();
70  m_gridPlanar.clear();
71 }
72 
74 {
75  GridSettingsModel* outsideModel = 0;
76 
77  if(m_model)
78  {
79  OutsideModelObservable* model = dynamic_cast<OutsideModelObservable*>(m_model);
80  outsideModel = dynamic_cast<GridSettingsModel*>(model);
81  }
82 
83  if(!outsideModel)
84  return;
85 
86  if(m_update.isNull())
87  {
88  Property prop = outsideModel->getOutsideProperty();
89 
90  m_update.setEditable(prop.isEditable());
91  m_update.setId(prop.getId());
92 
93  m_update.setName(prop.getName());
94  m_update.setValue(prop.getValue());
95  }
96 
97  Property property = outsideModel->containsOutsideSubProperty(name, gridType);
98 
99  if(!property.isNull())
100  {
101  if(property.getOptionChoices().empty())
102  {
103  if(property.getValue() != variant)
104  {
105  property.setValue(variant);
106  outsideModel->updateOutsideSubProperty(property, gridType);
107  }
108  else
109  {
110  return;
111  }
112  }
113  else
114  {
115  if(property.getOptionByCurrentChoice() != variant)
116  {
117  property.setOptionChoice(variant);
118  outsideModel->updateOutsideSubProperty(property, gridType);
119  }
120  else
121  {
122  return;
123  }
124  }
125 
126  if(gridType == TypeGeodesic)
127  {
128  addUpdateGeodesicProperty(outsideModel, property, gridType);
129  }
130  if(gridType == TypePlanar)
131  {
132  addUpdatePlanarProperty(outsideModel, property, gridType);
133  }
134  }
135 }
136 
138 {
139  if(m_gridGeodesic.isNull())
140  {
141  Property prop = outsideModel->containsGrid(gridType);
142 
143  m_gridGeodesic.setEditable(prop.isEditable());
144  m_gridGeodesic.setId(prop.getId());
145 
146  m_gridGeodesic.setName(prop.getName());
147  m_gridGeodesic.setValue(prop.getValue());
148  }
149 
150  if(!subProperty.isNull())
151  {
152  if(m_gridGeodesic.containsSubProperty(subProperty))
153  {
154  m_gridGeodesic.removeSubProperty(subProperty);
155  }
156  m_gridGeodesic.addSubProperty(subProperty);
157 
158  if(m_update.containsSubProperty(m_gridGeodesic))
159  {
160  m_update.removeSubProperty(m_gridGeodesic);
161  }
162  m_update.addSubProperty(m_gridGeodesic);
163  }
164 }
165 
167 {
168  if(m_gridPlanar.isNull())
169  {
170  Property prop = outsideModel->containsGrid(gridType);
171 
172  m_gridPlanar.setEditable(prop.isEditable());
173  m_gridPlanar.setId(prop.getId());
174 
175  m_gridPlanar.setName(prop.getName());
176  m_gridPlanar.setValue(prop.getValue());
177  }
178 
179  if(!subProperty.isNull())
180  {
181  if(m_gridPlanar.containsSubProperty(subProperty))
182  {
183  m_gridPlanar.removeSubProperty(subProperty);
184  }
185  m_gridPlanar.addSubProperty(subProperty);
186 
187  if(m_update.containsSubProperty(m_gridPlanar))
188  {
189  m_update.removeSubProperty(m_gridPlanar);
190  }
191  m_update.addSubProperty(m_gridPlanar);
192  }
193 }
194 
196 {
197  GridSettingsModel* outsideModel = 0;
198  Property prop;
199 
200  if(m_model)
201  {
202  OutsideModelObservable* model = dynamic_cast<OutsideModelObservable*>(m_model);
203  outsideModel = dynamic_cast<GridSettingsModel*>(model);
204  }
205 
206  if(!outsideModel)
207  return prop;
208 
209  prop = outsideModel->containsOutsideSubProperty(name, gridType);
210 
211  return prop;
212 }
std::string getName()
Definition: Property.cpp:49
AbstractOutsideFactory * getOutsideFactory()
Definition: Context.cpp:96
Variant getValue()
Definition: Property.cpp:74
virtual void addUpdatePlanarProperty(GridSettingsModel *outsideModel, Property subProperty, LayoutGridType gridType)
virtual Observer * make(LayoutAbstractObjectType type, OutsideParamsCreate params=OutsideParamsCreate())=0
virtual void updateOutsideSubProperty(Property subProperty, LayoutGridType gridType)
void setValue(typename ValueType value, LayoutPropertyDataType type)
Definition: Property.h:106
virtual te::layout::Property containsOutsideSubProperty(std::string name, LayoutGridType gridType)
virtual Property getProperty(std::string name, LayoutGridType gridType)
virtual void setPosition(const double &x, const double &y)
virtual void addUpdateProperty(std::string name, Variant variant, LayoutGridType gridType)
virtual void setPosition(const double &x, const double &y)
virtual void addUpdateGeodesicProperty(GridSettingsModel *outsideModel, Property subProperty, LayoutGridType gridType)
void setEditable(bool editable)
Definition: Property.cpp:121
virtual Property containsGrid(LayoutGridType gridType)
std::string getId()
Definition: Property.cpp:64
static Context * getInstance()
This function is called to create an instance of the class.
Definition: Context.cpp:46
LayoutGridType
Enum LayoutGridType. This is the enumeration of the grid types.
Definition: EnumMode.h:82
virtual Property getOutsideProperty()