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) 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 PropertiesOutside.cpp
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
29 #include "PropertiesOutside.h"
30 #include "../../core/pattern/singleton/Context.h"
31 #include "../../core/pattern/mvc/Observable.h"
32 #include "../../core/pattern/mvc/ItemObserver.h"
33 #include "../../core/pattern/mvc/OutsideObserver.h"
34 #include "../../core/pattern/mvc/OutsideController.h"
35 #include "../../../geometry/Envelope.h"
36 #include "../core/propertybrowser/PropertyBrowser.h"
37 #include "../item/MapItem.h"
38 #include "../../core/property/SharedProperties.h"
39 #include "../../core/pattern/mvc/ItemModelObservable.h"
40 #include "../../item/MapModel.h"
41 #include "../core/ItemUtils.h"
42 #include "../../core/pattern/derivativevisitor/VisitorUtils.h"
43 #include "../../core/enum/Enums.h"
44 #include "../core/pattern/command/ChangePropertyCommand.h"
45 #include "../core/Scene.h"
46 #include "../core/propertybrowser/PropertiesUtils.h"
47 
48 // Qt
49 #include <QGroupBox>
50 #include <QGraphicsItem>
51 #include <QVBoxLayout>
52 #include <QHBoxLayout>
53 #include <QToolButton>
54 #include <QLabel>
55 #include <QUndoCommand>
56 
58  QWidget(0),
59  OutsideObserver(controller, o),
60  m_updatingValues(false),
61  m_sharedProps(0),
62  m_propUtils(0)
63 {
65  setBaseSize(box.getWidth(), box.getHeight());
66  setVisible(false);
67  setWindowTitle("Properties");
68  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
69 
71 
72  if(!propertyBrowser)
74  else
75  m_layoutPropertyBrowser = propertyBrowser;
76 
77  connect(m_layoutPropertyBrowser,SIGNAL(changePropertyValue(Property)),
78  this,SLOT(onChangePropertyValue(Property)));
79 
80  createLayout();
81 
83 }
84 
86 {
87  if(m_propUtils)
88  {
89  delete m_propUtils;
90  m_propUtils = 0;
91  }
92 
93  if(m_layoutPropertyBrowser)
94  {
95  delete m_layoutPropertyBrowser;
96  m_layoutPropertyBrowser = 0;
97  }
98 
99  if(m_sharedProps)
100  {
101  delete m_sharedProps;
102  m_sharedProps = 0;
103  }
104 }
105 
107 {
108  //Layout
109 
110  QVBoxLayout* layout = new QVBoxLayout(this);
111  layout->setMargin(0);
112 
113  QHBoxLayout* filterLayout = new QHBoxLayout;
114 
115  m_configurePropertyEditor = new QToolButton(this);
116  m_configurePropertyEditor->setText(tr("Config"));
117  m_configurePropertyEditor->setBaseSize(QSize(16,16));
118  m_configurePropertyEditor->setVisible(false);
119 
120  m_propertyFilterEdit = new QLineEdit(this);
121  m_propertyFilterEdit->setToolTip(tr("String or regular expression to filter property list with"));
122 
123  connect(m_propertyFilterEdit,SIGNAL(textChanged(QString)),
124  m_layoutPropertyBrowser,SLOT(onChangeFilter(QString)));
125 
126  filterLayout->addWidget(m_propertyFilterEdit);
127  filterLayout->addWidget(m_configurePropertyEditor);
128 
129  layout->addLayout(filterLayout);
130  m_nameLabel = new QLabel(tr("Component::"), this);
131  layout->addWidget(m_nameLabel);
132  layout->addWidget(m_layoutPropertyBrowser->getPropertyEditor());
133 
134  QGroupBox* groupBox = new QGroupBox(this);
135  groupBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
136  groupBox->setLayout(layout);
137 
138  QVBoxLayout* layoutAll = new QVBoxLayout(this);
139  layoutAll->setMargin(0);
140 
141  layoutAll->addWidget(groupBox);
142 
143  setLayout(layoutAll);
144 }
145 
147 {
148  setVisible(context.isShow());
149  if(context.isShow() == true)
150  show();
151  else
152  hide();
153 }
154 
155 void te::layout::PropertiesOutside::setPosition( const double& x, const double& y )
156 {
157  move(x,y);
158  refresh();
159 }
160 
162 {
163  QPointF posF = pos();
164  qreal valuex = posF.x();
165  qreal valuey = posF.y();
166 
167  te::gm::Coord2D coordinate;
168  coordinate.x = valuex;
169  coordinate.y = valuey;
170 
171  return coordinate;
172 }
173 
174 void te::layout::PropertiesOutside::itemsSelected(QList<QGraphicsItem*> graphicsItems, QList<QGraphicsItem*> allItems)
175 {
176  m_updatingValues = false;
177  bool window = false;
178 
179  m_layoutPropertyBrowser->clearAll();
180  m_nameLabel->setText(tr("Component::"));
181 
182  m_graphicsItems = graphicsItems;
183 
184  m_allItems = allItems;
185 
186  if(m_graphicsItems.empty())
187  return;
188 
189  Properties* props = m_propUtils->intersection(graphicsItems, window);
190  m_layoutPropertyBrowser->setHasWindows(window);
191 
192  if(!props)
193  return;
194 
195  m_nameLabel->setText(tr("Component::") + props->getObjectName().c_str());
196 
197  foreach( Property prop, props->getProperties())
198  {
199  if(prop.isMenu() || !prop.isVisible())
200  continue;
201 
202  m_propUtils->checkDynamicProperty(prop, allItems);
203  m_layoutPropertyBrowser->addProperty(prop);
204  }
205 
206  update();
207 }
208 
210 {
212 
213  if(property.getType() == dataType->getDataTypeNone())
214  return;
215 
216  Scene* lScene = dynamic_cast<Scene*>(Context::getInstance().getScene());
217 
218  if(property.getParentItemHashCode() <= 0)
219  {
220  sendPropertyToSelectedItems(property);
221  }
222  else
223  {
224  sendPropertyToSelectedItem(property);
225  }
226 
227  changeMapVisitable(property);
228  lScene->update();
229 }
230 
232 {
233  bool result = true;
234 
235  Scene* lScene = dynamic_cast<Scene*>(Context::getInstance().getScene());
236 
237  std::vector<QGraphicsItem*> commandItems;
238  std::vector<Properties*> commandOld;
239  std::vector<Properties*> commandNew;
240 
241  QGraphicsItem *itemSelected = m_propUtils->equalsHashCode(property, m_graphicsItems);
242  if(!itemSelected)
243  {
244  return false;
245  }
246 
247  ItemObserver* lItem = dynamic_cast<ItemObserver*>(itemSelected);
248  if(lItem)
249  {
250  if(!lItem->getModel())
251  {
252  return false;
253  }
254 
255  Properties* props = new Properties("");
256  Properties* beforeProps = lItem->getModel()->getProperties();
257  Properties* oldCommand = new Properties(*beforeProps);
258  if(props)
259  {
260  props->setObjectName(lItem->getModel()->getProperties()->getObjectName());
261  props->setTypeObj(lItem->getModel()->getProperties()->getTypeObj());
262  props->addProperty(property);
263 
264  lItem->getModel()->updateProperties(props);
265  lItem->redraw();
266 
267  if(beforeProps)
268  {
269  beforeProps = lItem->getModel()->getProperties();
270  Properties* newCommand = new Properties(*beforeProps);
271  commandItems.push_back(itemSelected);
272  commandOld.push_back(oldCommand);
273  commandNew.push_back(newCommand);
274  }
275  }
276  }
277 
278  if(!m_graphicsItems.isEmpty())
279  {
280  QUndoCommand* command = new ChangePropertyCommand(commandItems, commandOld, commandNew, this);
281  lScene->addUndoStack(command);
282  }
283  return result;
284 }
285 
287 {
288  bool result = true;
289  Scene* lScene = dynamic_cast<Scene*>(Context::getInstance().getScene());
290 
291  std::vector<QGraphicsItem*> commandItems;
292  std::vector<Properties*> commandOld;
293  std::vector<Properties*> commandNew;
294 
295  foreach( QGraphicsItem *item, m_graphicsItems)
296  {
297  if (item)
298  {
299  ItemObserver* lItem = dynamic_cast<ItemObserver*>(item);
300  if(lItem)
301  {
302  if(!lItem->getModel())
303  {
304  continue;
305  }
306 
307  Properties* props = new Properties("");
308  Properties* beforeProps = lItem->getModel()->getProperties();
309  Properties* oldCommand = new Properties(*beforeProps);
310  if(props)
311  {
312  props->setObjectName(lItem->getModel()->getProperties()->getObjectName());
313  props->setTypeObj(lItem->getModel()->getProperties()->getTypeObj());
314  props->addProperty(property);
315 
316  lItem->getModel()->updateProperties(props);
317  lItem->redraw();
318 
319  if(beforeProps)
320  {
321  beforeProps = lItem->getModel()->getProperties();
322  Properties* newCommand = new Properties(*beforeProps);
323  commandItems.push_back(item);
324  commandOld.push_back(oldCommand);
325  commandNew.push_back(newCommand);
326  }
327  }
328  }
329  }
330  }
331 
332  if(!m_graphicsItems.isEmpty())
333  {
334  QUndoCommand* command = new ChangePropertyCommand(commandItems, commandOld, commandNew, this);
335  lScene->addUndoStack(command);
336  }
337  return result;
338 }
339 
340 void te::layout::PropertiesOutside::closeEvent( QCloseEvent * event )
341 {
342  m_layoutPropertyBrowser->closeAllWindows();
343 }
344 
346 {
347  if(property.getName().compare(m_sharedProps->getMapName()) != 0)
348  return;
349 
350  std::string name = property.getValue().toString();
351  if(name.compare("") == 0)
352  {
353  name = property.getOptionByCurrentChoice().toString();
354  }
355 
356  if(name.compare("") == 0)
357  return;
358 
360  if(!iUtils)
361  return;
362 
363  MapItem* item = iUtils->getMapItem(name);
364  if(!item)
365  return;
366 
367  ItemModelObservable* obsMdl = dynamic_cast<ItemModelObservable*>(item->getModel());
368  if(!obsMdl)
369  return;
370 
371  MapModel* model = dynamic_cast<MapModel*>(obsMdl);
372 
373  if(!model)
374  return;
375 
376  te::layout::VisitorUtils::getInstance().changeMapVisitable(m_graphicsItems, model);
377 }
378 
380 {
381  MapModel* map = 0;
382 
384  if(!iUtils)
385  return map;
386 
387  MapItem* item = iUtils->getMapItem(nameMap);
388  if(!item)
389  return map;
390 
391  ItemModelObservable* obsMdl = dynamic_cast<ItemModelObservable*>(item->getModel());
392  if(!obsMdl)
393  return map;
394 
395  MapModel* model = dynamic_cast<MapModel*>(obsMdl);
396  map = model;
397 
398  return map;
399 }
400 
402 {
403  itemsSelected(m_graphicsItems, m_allItems);
404 }
405 
406 void te::layout::PropertiesOutside::onClear( std::vector<std::string> names )
407 {
408  m_updatingValues = false;
409  m_nameLabel->setText(tr("Component::"));
410  m_layoutPropertyBrowser->clearAll();
411 }
412 
413 
414 
415 
416 
417 
Abstract class to represent an observable. "Model" part of MVC component.
Definition: Observable.h:56
std::string getName()
Method that returns the name of this property.
Definition: Property.cpp:57
Class responsible for maintaining the drawing context of a MVC component. It is always used by the "M...
Definition: ContextItem.h:49
virtual bool addProperty(Property property)
Adds the specified property to the set of properties for this object.
Definition: Properties.h:193
double y
y-coordinate.
Definition: Coord2D.h:114
virtual EnumDataType * getEnumDataType()
Returns data type enumeration.
Definition: Enums.cpp:52
double x
x-coordinate.
Definition: Coord2D.h:113
void onChangePropertyValue(Property property)
int getParentItemHashCode()
Returns the hashcode of the object that owns this property.
Definition: Property.cpp:278
virtual te::gm::Envelope getBox()=0
Returns the bounding rectangle of the component in scene coordinates(millimeters). Starting point is llx, lly. Reimplement this function in a Observable subclass to provide the model's getBox implementation.
Abstract class to represent an observer. "View" part of MVC widget. All classes representing the grap...
virtual EnumType * getDataTypeNone() const
Returns value that represents type none belonging to enumeration.
virtual MapModel * getMapModel(std::string nameMap)
virtual bool sendPropertyToSelectedItems(Property property)
Abstract class to represent an observable. "Model" part of MVC component. All classes representing th...
double getWidth() const
It returns the envelope width.
Definition: Envelope.h:443
The Properties class represents a persistent set of properties. The Properties can be saved to a file...
Definition: Properties.h:52
Abstract class to represent an observer. "View" part of MVC component. All classes representing the g...
Definition: ItemObserver.h:52
virtual std::vector< Property > getProperties()
Returns set of all properties.
Definition: Properties.h:220
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
virtual bool isMenu()
Returns true if property will be used in a menu, false otherwise.
Definition: Property.cpp:233
virtual void setObjectName(std::string name)
Sets object name that owns these properties.
Definition: Properties.h:236
virtual void redraw(bool bRefresh=true)
Redraws the graphic component.
virtual void changeMapVisitable(Property property)
virtual bool isVisible()
Return true if visible, false otherwise.
Definition: Property.cpp:258
Manage properties variants values. Maps the QProperty properties (Qt) and Property (Layout) and add t...
virtual void setTypeObj(EnumType *type)
Sets object type that owns these properties.
Definition: Properties.h:246
virtual void updateProperties(te::layout::Properties *properties)=0
Updated model state with properties. Reimplement this function in a Observable subclass to provide th...
static Enums & getInstance()
It returns a reference to the singleton instance.
virtual void updateObserver(ContextItem context)
Reimplemented from Observer.
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
virtual void closeEvent(QCloseEvent *event)
virtual EnumType * getTypeObj()
Returns object type that owns these properties.
Definition: Properties.h:241
Class to represent a data type enumeration. Ex.: int, double, bool, te::color::RGBAColor (color)...
Definition: EnumDataType.h:48
virtual std::string getObjectName()
Returns object name that owns these properties.
Definition: Properties.h:231
ItemUtils * getItemUtils()
Returns pointer for manipulating items in the scene and vectorization of text and legend...
Definition: Context.cpp:273
virtual te::layout::Properties * getProperties() const =0
Returns the model state as properties. Reimplement this function in a Observable subclass to provide ...
Utility class for manipulating items in the scene and vectorization of text and legend.
Definition: ItemUtils.h:62
virtual void onClear(std::vector< std::string > names)
Class representing the scene. This scene is child of QGraphicsScene, part of Graphics View Framework...
Definition: Scene.h:80
virtual void itemsSelected(QList< QGraphicsItem * > graphicsItems, QList< QGraphicsItem * > allItems)
Class that represents a "Model" part of Map MVC component. Its coordinate system is the same of scene...
Definition: MapModel.h:61
virtual MapItem * getMapItem(std::string name)
Search for te::layout::MapItem by name.
Definition: ItemUtils.cpp:92
Utility class with functions to facilitate handling of qt properties and properties layout module...
Observable * m_model
"Model" part of MVC widget.
virtual void setPosition(const double &x, const double &y)
Change coordinate llx,lly of the MVC widget. Reimplement this function in a ItemController subclass t...
virtual Observable * getModel()
Returns the "Model" part of the MVC.
virtual void addUndoStack(QUndoCommand *command)
Method that insert command Undo/Redo of type AddCommand in the Undo/Redo stack.
Definition: Scene.cpp:313
virtual bool sendPropertyToSelectedItem(Property property)
virtual te::gm::Coord2D getPosition()
Method that returns the position llx, lly Reimplement this function in a ItemObserver subclass to pro...
AbstractScene * getScene()
Returns abstract scene for QGraphicsScene class, part of Graphics View Framework. ...
Definition: Context.cpp:88
Abstract class to represent a controller. "Controller" part of MVC widget. All classes representing t...
virtual void setHasWindows(bool windows)
Definition: Properties.h:280
Undo/Redo for changes in component properties.
PropertiesOutside(OutsideController *controller, Observable *o, PropertyBrowser *propertyBrowser=0)
Properties tree for any item, MVC component, using Qt for presentation and editing.
double getHeight() const
It returns the envelope height.
Definition: Envelope.h:448
EnumType * getType()
Returns the type of this property.
Definition: Property.cpp:67
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
PropertyBrowser * m_layoutPropertyBrowser
This class is a proxy MapDisplay. This makes it possible to add a MapDisplay as item of a scene...
Definition: MapItem.h:74