All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PropertiesOutside.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 PropertiesOutside.cpp
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
29 #include "PropertiesOutside.h"
30 #include "Context.h"
31 #include "Observable.h"
32 #include "ItemObserver.h"
33 #include "OutsideObserver.h"
34 #include "OutsideController.h"
35 #include "../../../../geometry/Envelope.h"
37 #include "MapItem.h"
38 #include "SharedProperties.h"
39 #include "ItemModelObservable.h"
40 #include "MapModel.h"
41 #include "ItemUtils.h"
42 #include "VisitorUtils.h"
43 
44 // Qt
45 #include <QGroupBox>
46 #include <QGraphicsItem>
47 #include <QVBoxLayout>
48 #include <QHBoxLayout>
49 #include <QToolButton>
50 #include <QLabel>
51 
53  QDockWidget("", 0, 0),
54  OutsideObserver(controller, o),
55  m_updatingValues(false),
56  m_sharedProps(0)
57 {
59  setBaseSize(box.getWidth(), box.getHeight());
60  setVisible(false);
61  setWindowTitle("Layout - Propriedades");
62  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
63 
64  setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
65 
67 
68  connect(m_layoutPropertyBrowser, SIGNAL(updateOutside(Property)),
69  this, SLOT(onChangePropertyValue(Property)));
70 
71  connect(m_layoutPropertyBrowser,SIGNAL(changePropertyValue(Property)),
72  this,SLOT(onChangePropertyValue(Property)));
73 
74  createLayout();
75 
77 }
78 
80 {
81  if(m_layoutPropertyBrowser)
82  {
83  delete m_layoutPropertyBrowser;
84  m_layoutPropertyBrowser = 0;
85  }
86 
87  if(m_sharedProps)
88  {
89  delete m_sharedProps;
90  m_sharedProps = 0;
91  }
92 }
93 
95 {
96  //Layout
97 
98  QVBoxLayout* layout = new QVBoxLayout(this);
99  layout->setMargin(0);
100 
101  QHBoxLayout* filterLayout = new QHBoxLayout;
102 
103  m_configurePropertyEditor = new QToolButton(this);
104  m_configurePropertyEditor->setText(tr("Config"));
105  m_configurePropertyEditor->setBaseSize(QSize(16,16));
106 
107  m_propertyFilterEdit = new QLineEdit(this);
108  m_propertyFilterEdit->setToolTip(tr("String or regular expression to filter property list with"));
109 
110  connect(m_propertyFilterEdit,SIGNAL(textChanged(QString)),
111  m_layoutPropertyBrowser,SLOT(onChangeFilter(QString)));
112 
113  filterLayout->addWidget(m_propertyFilterEdit);
114  filterLayout->addWidget(m_configurePropertyEditor);
115 
116  layout->addLayout(filterLayout);
117  m_nameLabel = new QLabel(tr("QObject::unknown"), this);
118  layout->addWidget(m_nameLabel);
119  layout->addWidget(m_layoutPropertyBrowser->getPropertyEditor());
120 
121  QGroupBox* groupBox = new QGroupBox;
122  groupBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
123  groupBox->setLayout(layout);
124 
125  setWidget(groupBox);
126 }
127 
129 {
130  setVisible(context.getShow());
131  if(context.getShow() == true)
132  show();
133  else
134  hide();
135 }
136 
137 void te::layout::PropertiesOutside::setPosition( const double& x, const double& y )
138 {
139  move(x,y);
140  refresh();
141 }
142 
144 {
145  QPointF posF = pos();
146  qreal valuex = posF.x();
147  qreal valuey = posF.y();
148 
149  te::gm::Coord2D coordinate;
150  coordinate.x = valuex;
151  coordinate.y = valuey;
152 
153  return coordinate;
154 }
155 
156 void te::layout::PropertiesOutside::itemsSelected(QList<QGraphicsItem*> graphicsItems, QList<QGraphicsItem*> allItems)
157 {
158  m_updatingValues = false;
159 
160  m_layoutPropertyBrowser->clearAll();
161 
162  m_graphicsItems = graphicsItems;
163 
164  m_allItems = allItems;
165 
166  if(m_graphicsItems.empty())
167  return;
168 
169  bool gridWindow = false;
170  Properties* props = intersection(graphicsItems, gridWindow);
171  m_layoutPropertyBrowser->setHasGridWindows(gridWindow);
172 
173  if(!props)
174  return;
175 
176  foreach( Property prop, props->getProperties())
177  {
178  checkDynamicProperty(prop, allItems);
179  m_layoutPropertyBrowser->addProperty(prop);
180  }
181 
182  update();
183 }
184 
186 {
187  if(property.getType() == DataTypeNone)
188  return;
189 
190  foreach( QGraphicsItem *item, m_graphicsItems)
191  {
192  if (item)
193  {
194  ItemObserver* lItem = dynamic_cast<ItemObserver*>(item);
195  if(lItem)
196  {
197  Properties* props = new Properties("");
198  if(props)
199  {
200  props->setObjectName(lItem->getProperties()->getObjectName());
201  props->setTypeObj(lItem->getProperties()->getTypeObj());
202  props->addProperty(property);
203 
204  lItem->updateProperties(props);
205  delete props;
206  props = 0;
207  }
208  }
209  }
210  }
211 
212  changeMapVisitable(property);
213 }
214 
215 void te::layout::PropertiesOutside::closeEvent( QCloseEvent * event )
216 {
217  m_layoutPropertyBrowser->closeAllWindows();
218 }
219 
220 te::layout::Properties* te::layout::PropertiesOutside::intersection( QList<QGraphicsItem*> graphicsItems, bool& gridWindow )
221 {
222  Properties* props = 0;
223 
224  if(graphicsItems.size() == 1)
225  {
226  QGraphicsItem* item = graphicsItems.first();
227  if (item)
228  {
229  ItemObserver* lItem = dynamic_cast<ItemObserver*>(item);
230  if(lItem)
231  {
232  props = const_cast<Properties*>(lItem->getProperties());
233  gridWindow = props->hasGridWindows();
234  }
235  }
236  }
237  else
238  {
239  props = sameProperties(graphicsItems, gridWindow);
240  }
241 
242  return props;
243 }
244 
245 te::layout::Properties* te::layout::PropertiesOutside::sameProperties( QList<QGraphicsItem*> graphicsItems, bool& gridWindow )
246 {
247  Properties* props = 0;
248  std::vector<Properties*> propsVec = getAllProperties(graphicsItems, gridWindow);
249 
250  QGraphicsItem* firstItem = graphicsItems.first();
251  ItemObserver* lItem = dynamic_cast<ItemObserver*>(firstItem);
252 
253  if(!lItem)
254  {
255  return props;
256  }
257 
258  Properties* firstProps = const_cast<Properties*>(lItem->getProperties());
259  if(!firstProps)
260  {
261  return props;
262  }
263 
264  std::vector<Properties*>::iterator it = propsVec.begin();
265  std::vector<Properties*>::iterator itend = propsVec.end();
266  bool result = false;
267  foreach( Property prop, firstProps->getProperties())
268  {
269  contains(itend, it, prop.getName(), result);
270  if(result)
271  {
272  if(!props)
273  {
274  props = new Properties("");
275  }
276  props->addProperty(prop);
277  }
278  }
279 
280  return props;
281 }
282 
283 void te::layout::PropertiesOutside::contains( std::vector<Properties*>::iterator itend,
284  std::vector<Properties*>::iterator it, std::string name, bool& result )
285 {
286  Property prop = (*it)->contains(name);
287  if(prop.isNull())
288  {
289  result = false;
290  return;
291  }
292  else
293  {
294  ++it;
295  result = true;
296  if(it != itend)
297  {
298  contains(itend, it, name, result);
299  }
300  }
301 }
302 
303 std::vector<te::layout::Properties*>
304  te::layout::PropertiesOutside::getAllProperties( QList<QGraphicsItem*> graphicsItems, bool& gridWindow )
305 {
306  Properties* props = 0;
307  std::vector<Properties*> propsVec;
308  bool result = true;
309 
310  foreach( QGraphicsItem *item, graphicsItems)
311  {
312  if (item)
313  {
314  ItemObserver* lItem = dynamic_cast<ItemObserver*>(item);
315  if(lItem)
316  {
317  Properties* propsItem = const_cast<Properties*>(lItem->getProperties());
318  if(propsItem)
319  {
320  propsVec.push_back(propsItem);
321  if(result)
322  {
323  result = propsItem->hasGridWindows();
324  }
325  }
326  }
327  }
328  }
329 
330  gridWindow = result;
331  return propsVec;
332 }
333 
334 void te::layout::PropertiesOutside::addDynamicOptions( Property& property, std::vector<std::string> list )
335 {
336  foreach(std::string str, list)
337  {
338  Variant v;
339  v.setValue(str, DataTypeString);
340  property.addOption(v);
341  }
342 }
343 
344 void te::layout::PropertiesOutside::checkDynamicProperty( Property& property, QList<QGraphicsItem*> graphicsItems )
345 {
346  if(property.getName().compare(m_sharedProps->getMapName()) == 0)
347  {
348  mapNameDynamicProperty(property, graphicsItems);
349  }
350 }
351 
352 void te::layout::PropertiesOutside::mapNameDynamicProperty( Property& property, QList<QGraphicsItem*> graphicsItems )
353 {
354  std::string currentName = property.getValue().toString();
355 
356  if(currentName.compare("") == 0)
357  {
358  currentName = property.getOptionByCurrentChoice().toString();
359  }
360 
361  std::vector<std::string> strList = te::layout::mapNameList(m_allItems);
362 
363  if(std::find(strList.begin(), strList.end(), currentName) != strList.end())
364  {
365  std::vector<std::string>::iterator it = std::find(strList.begin(), strList.end(), currentName);
366  strList.erase(it);
367  }
368 
369  addDynamicOptions(property, strList);
370 }
371 
373 {
374  if(property.getName().compare(m_sharedProps->getMapName()) != 0)
375  return;
376 
377  std::string name = property.getValue().toString();
378  if(name.compare("") == 0)
379  {
380  name = property.getOptionByCurrentChoice().toString();
381  }
382 
383  if(name.compare("") == 0)
384  return;
385 
386  MapItem* item = te::layout::getMapItem(m_allItems, name);
387  if(!item)
388  return;
389 
390  ItemModelObservable* obsMdl = dynamic_cast<ItemModelObservable*>(item->getModel());
391  if(!obsMdl)
392  return;
393 
394  MapModel* model = dynamic_cast<MapModel*>(obsMdl);
395 
396  if(!model)
397  return;
398 
399  te::layout::changeMapVisitable(m_graphicsItems, model);
400 }
401 
403 {
404  MapModel* map = 0;
405 
406  MapItem* item = te::layout::getMapItem(m_allItems, nameMap);
407  if(!item)
408  return map;
409 
410  ItemModelObservable* obsMdl = dynamic_cast<ItemModelObservable*>(item->getModel());
411  if(!obsMdl)
412  return map;
413 
414  MapModel* model = dynamic_cast<MapModel*>(obsMdl);
415  map = model;
416 
417  return map;
418 }
419 
std::string getName()
Definition: Property.cpp:49
virtual std::vector< Properties * > getAllProperties(QList< QGraphicsItem * > graphicsItems, bool &gridWindow)
virtual bool addProperty(Property property)
Definition: Properties.h:89
double y
y-coordinate.
Definition: Coord2D.h:87
double x
x-coordinate.
Definition: Coord2D.h:86
TELAYOUTEXPORT MapItem * getMapItem(QList< QGraphicsItem * > graphicsItems, std::string name)
Definition: ItemUtils.cpp:61
void onChangePropertyValue(Property property)
virtual te::gm::Envelope getBox()=0
virtual void mapNameDynamicProperty(Property &property, QList< QGraphicsItem * > graphicsItems)
virtual MapModel * getMapModel(std::string nameMap)
double getWidth() const
It returns the envelope width.
Definition: Envelope.h:443
TELAYOUTEXPORT std::vector< std::string > mapNameList(QList< QGraphicsItem * > graphicsItems)
Definition: ItemUtils.cpp:87
virtual std::vector< Property > getProperties()
Definition: Properties.h:116
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
virtual Properties * sameProperties(QList< QGraphicsItem * > graphicsItems, bool &gridWindow)
virtual void setObjectName(std::string name)
Definition: Properties.h:132
virtual void changeMapVisitable(Property property)
void setValue(typename ValueType value, LayoutPropertyDataType type)
Definition: Variant.h:107
virtual void checkDynamicProperty(Property &property, QList< QGraphicsItem * > graphicsItems)
PropertiesOutside(OutsideController *controller, Observable *o)
virtual void updateObserver(ContextItem context)
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
virtual void closeEvent(QCloseEvent *event)
virtual bool hasGridWindows()
Definition: Properties.h:181
PropertiesItemPropertyBrowser * m_layoutPropertyBrowser
virtual std::string getObjectName()
Definition: Properties.h:127
virtual LayoutAbstractObjectType getTypeObj()
Definition: Properties.h:137
virtual void itemsSelected(QList< QGraphicsItem * > graphicsItems, QList< QGraphicsItem * > allItems)
virtual void setPosition(const double &x, const double &y)
virtual Observable * getModel()
virtual void addDynamicOptions(Property &property, std::vector< std::string > list)
LayoutPropertyDataType getType()
Definition: Property.cpp:59
virtual te::gm::Coord2D getPosition()
virtual te::layout::Properties * getProperties() const
virtual Properties * intersection(QList< QGraphicsItem * > graphicsItems, bool &gridWindow)
virtual void setTypeObj(LayoutAbstractObjectType type)
Definition: Properties.h:142
virtual void contains(std::vector< Properties * >::iterator itend, std::vector< Properties * >::iterator it, std::string name, bool &result)
double getHeight() const
It returns the envelope height.
Definition: Envelope.h:448
TELAYOUTEXPORT bool changeMapVisitable(QList< QGraphicsItem * > graphicsItems, Visitable *visitable)
virtual void updateProperties(te::layout::Properties *properties)