All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ObjectInspectorOutside.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 ObjectInspectorOutside.cpp
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
29 #include "ObjectInspectorOutside.h"
30 #include "../../core/pattern/singleton/Context.h"
31 #include "../../core/AbstractScene.h"
32 #include "../core/Scene.h"
33 #include "../../core/pattern/mvc/OutsideModelObservable.h"
34 #include "../../core/pattern/mvc/ItemObserver.h"
35 #include "../../core/pattern/mvc/OutsideObserver.h"
36 #include "../../core/pattern/mvc/OutsideController.h"
37 #include "../../../geometry/Envelope.h"
38 #include "../../core/enum/Enums.h"
39 #include "../core/propertybrowser/VariantPropertiesBrowser.h"
40 #include "../core/propertybrowser/DialogPropertiesBrowser.h"
41 #include "../item/MovingItemGroup.h"
42 
43 //Qt
44 #include <QGraphicsWidget>
45 #include <QVBoxLayout>
46 #include <QGroupBox>
47 
49  QWidget(0),
50  OutsideObserver(controller, o)
51 {
53  setBaseSize(box.getWidth(), box.getHeight());
54  setVisible(false);
55  setWindowTitle("Object Inspector");
56  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
57 
58  if(!propertyBrowser)
60  else
61  m_layoutPropertyBrowser = propertyBrowser;
62 
63  QVBoxLayout* layout = new QVBoxLayout(this);
64  layout->setMargin(0);
65  layout->addWidget(m_layoutPropertyBrowser->getPropertyEditor());
66 
67  QGroupBox* groupBox = new QGroupBox;
68  groupBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
69  groupBox->setLayout(layout);
70 
71  QVBoxLayout* layoutAll = new QVBoxLayout(this);
72  layoutAll->setMargin(0);
73 
74  layoutAll->addWidget(groupBox);
75 
76  setLayout(layoutAll);
77 
78  m_layoutPropertyBrowser->getPropertyEditor()->setAlternatingRowColors(false);
79 }
80 
82 {
83 
84 }
85 
87 {
88  setVisible(context.isShow());
89  if(context.isShow() == true)
90  show();
91  else
92  hide();
93 }
94 
95 void te::layout::ObjectInspectorOutside::setPosition( const double& x, const double& y )
96 {
97  move(x,y);
98  refresh();
99 }
100 
102 {
103  QPointF posF = pos();
104  qreal valuex = posF.x();
105  qreal valuey = posF.y();
106 
107  te::gm::Coord2D coordinate;
108  coordinate.x = valuex;
109  coordinate.y = valuey;
110 
111  return coordinate;
112 }
113 
114 void te::layout::ObjectInspectorOutside::itemsInspector(QList<QGraphicsItem*> graphicsItems)
115 {
116  if(hasMoveItemGroup(graphicsItems))
117  {
118  return;
119  }
120 
121  m_layoutPropertyBrowser->clearAll();
122 
123  m_graphicsItems = graphicsItems;
124 
125  if(m_graphicsItems.empty())
126  return;
127 
129 
130  foreach(QGraphicsItem *item, graphicsItems)
131  {
132  if (item)
133  {
134  ItemObserver* lItem = dynamic_cast<ItemObserver*>(item);
135  if(lItem)
136  {
137  if(!lItem->getModel())
138  {
139  continue;
140  }
141 
142  if(lItem->getModel()->getType() == enumObj->getPaperItem())
143  {
144  continue;
145  }
146 
147  // No add MoveItemGroup, because is alive just for mouse move
148  MovingItemGroup* moving = dynamic_cast<MovingItemGroup*>(item);
149  if(moving)
150  {
151  continue;
152  }
153 
154  addProperty(item);
155  }
156  }
157  }
158 
159  update();
160 }
161 
162 void te::layout::ObjectInspectorOutside::onRemoveProperties( std::vector<std::string> names )
163 {
164  std::vector<std::string>::iterator it;
165 
166  for(it = names.begin() ; it != names.end() ; ++it)
167  {
168  Property prop = m_layoutPropertyBrowser->getVariantPropertiesBrowser()->getProperty(*it);
169 
170  if(prop.isNull())
171  {
172  prop = m_layoutPropertyBrowser->getDialogPropertiesBrowser()->getProperty(*it);
173  }
174 
175  m_layoutPropertyBrowser->removeProperty(prop);
176  }
177 }
178 
179 void te::layout::ObjectInspectorOutside::selectItems( QList<QGraphicsItem*> graphicsItems )
180 {
181  foreach(QGraphicsItem *item, graphicsItems)
182  {
183  if (item)
184  {
185  ItemObserver* iOb = dynamic_cast<ItemObserver*>(item);
186  if(iOb)
187  {
188  if(iOb->getModel())
189  {
190  m_layoutPropertyBrowser->selectProperty(iOb->getModel()->getName());
191  }
192  }
193  }
194  }
195 }
196 
198 {
199  return m_layoutPropertyBrowser;
200 }
201 
202 bool te::layout::ObjectInspectorOutside::hasMoveItemGroup( QList<QGraphicsItem*> graphicsItems )
203 {
204  bool result = false;
205 
207 
208  if(!enumObj)
209  {
210  return result;
211  }
212 
213  foreach(QGraphicsItem *item, graphicsItems)
214  {
215  if (item)
216  {
217  ItemObserver* movingItem = dynamic_cast<ItemObserver*>(item);
218 
219  if(movingItem->getModel()->getType() == enumObj->getMovingItemGroup())
220  {
221  result = true;
222  break;
223  }
224  }
225  }
226 
227  return result;
228 }
229 
230 QtProperty* te::layout::ObjectInspectorOutside::addProperty( QGraphicsItem* item )
231 {
232  QtProperty* prop = 0;
233 
234  if(!item)
235  {
236  return prop;
237  }
238 
239  ItemObserver* lItem = dynamic_cast<ItemObserver*>(item);
240  if(!lItem)
241  {
242  return prop;
243  }
244 
245  Property pro_class = createProperty(lItem);
246 
247  if(hasProperty(pro_class))
248  {
249  return prop;
250  }
251 
252  if(item->parentItem())
253  {
254  return prop;
255  }
256 
257  prop = m_layoutPropertyBrowser->addProperty(pro_class);
258 
259  if(!item->childItems().isEmpty())
260  {
261  createSubProperty(item, prop);
262  }
263 
264  return prop;
265 }
266 
267 void te::layout::ObjectInspectorOutside::createSubProperty( QGraphicsItem* item, QtProperty* prop )
268 {
269  if(!item || !prop)
270  {
271  return;
272  }
273 
274  foreach(QGraphicsItem *item, item->childItems())
275  {
276  if(!item)
277  {
278  continue;
279  }
280 
281  ItemObserver* lItem = dynamic_cast<ItemObserver*>(item);
282  if(!lItem)
283  {
284  continue;
285  }
286 
287  Property pro_class = createProperty(lItem);
288  if(hasProperty(pro_class))
289  {
290  continue;
291  }
292 
293  QtProperty* subProp = m_layoutPropertyBrowser->addProperty(pro_class);
294  if(!subProp)
295  {
296  continue;
297  }
298 
299  m_layoutPropertyBrowser->addSubProperty(prop, subProp);
300  }
301 }
302 
304 {
305  Property pro_class;
306  if(!item)
307  {
308  return pro_class;
309  }
310 
311  if(!item->getModel())
312  {
313  return pro_class;
314  }
315 
317  if(!dataType)
318  {
319  return pro_class;
320  }
321 
322  pro_class.setName(item->getModel()->getName());
323  pro_class.setValue(item->getNameClass(), dataType->getDataTypeString());
324  pro_class.setEditable(false);
325 
326  return pro_class;
327 }
328 
330 {
331  std::string name = property.getName();
332  std::string label = property.getLabel();
333 
334  QtProperty* prop = m_layoutPropertyBrowser->findProperty(name);
335  if(!prop)
336  {
337  prop = m_layoutPropertyBrowser->findProperty(label);
338  }
339 
340  if(!prop)
341  {
342  return false;
343  }
344 
345  return true;
346 }
347 
348 
349 
350 
351 
352 
353 
354 
Abstract class to represent an observable. "Model" part of MVC component.
Definition: Observable.h:56
Class responsible for maintaining the drawing context of a MVC component. It is always used by the "M...
Definition: ContextItem.h:49
Class to represent a graphic object (MVC component) and widget object (MVC widget) type enumeration...
virtual void itemsInspector(QList< QGraphicsItem * > graphicsItems)
double y
y-coordinate.
Definition: Coord2D.h:114
virtual EnumDataType * getEnumDataType()
Returns data type enumeration.
Definition: Enums.cpp:52
Tree of names of all the items entered on the scene, MVC components, using Qt to present the name of ...
double x
x-coordinate.
Definition: Coord2D.h:113
QtTreePropertyBrowser * getPropertyEditor()
bool isNull()
Returns true if no value has been set, false otherwise.
Definition: Property.cpp:146
virtual EnumType * getPaperItem() const
Returns value that represents paper (MVC Component) type belonging to enumeration.
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 te::gm::Coord2D getPosition()
Method that returns the position llx, lly Reimplement this function in a ItemObserver subclass to pro...
double getWidth() const
It returns the envelope width.
Definition: Envelope.h:443
Abstract class to represent an observer. "View" part of MVC component. All classes representing the g...
Definition: ItemObserver.h:52
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
virtual bool hasProperty(Property property)
virtual EnumObjectType * getEnumObjectType()
Returns graphic object (MVC component) and widget object (MVC widget) type enumeration.
Definition: Enums.cpp:62
virtual void onRemoveProperties(std::vector< std::string > names)
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...
Manage properties variants values. Maps the QProperty properties (Qt) and Property (Layout) and add t...
virtual PropertyBrowser * getObjectInspector()
virtual bool hasMoveItemGroup(QList< QGraphicsItem * > graphicsItems)
virtual EnumType * getType()=0
Returns the type of component Reimplement this function in a Observable subclass to provide the model...
static Enums & getInstance()
It returns a reference to the singleton instance.
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
ObjectInspectorOutside(OutsideController *controller, Observable *o, PropertyBrowser *propertyBrowser=0)
virtual std::string getNameClass()
Method that returns the class name.
Class to represent a data type enumeration. Ex.: int, double, bool, te::color::RGBAColor (color)...
Definition: EnumDataType.h:48
virtual void createSubProperty(QGraphicsItem *item, QtProperty *prop)
virtual void updateObserver(ContextItem context)
Reimplemented from Observer.
virtual EnumType * getMovingItemGroup() const
Returns value that represents moving item group (MVC Component) type belonging to enumeration...
virtual void selectItems(QList< QGraphicsItem * > graphicsItems)
virtual Property createProperty(ItemObserver *item)
void setValue(ValueType value, EnumType *type)
Stores a copy of value.
Definition: Property.h:298
Observable * m_model
"Model" part of MVC widget.
virtual Observable * getModel()
Returns the "Model" part of the MVC.
void setEditable(bool editable)
Sets true if property is editable, false otherwise.
Definition: Property.cpp:119
virtual QtProperty * addProperty(QGraphicsItem *item)
void setName(std::string name)
Sets the name of this property.
Definition: Property.cpp:62
Abstract class to represent a controller. "Controller" part of MVC widget. All classes representing t...
virtual EnumType * getDataTypeString() const
Returns value that represents type string belonging to enumeration.
virtual std::string getName()=0
Method that returns the name of the MVC component. Reimplement this function in a Observable subclass...
double getHeight() const
It returns the envelope height.
Definition: Envelope.h:448
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