All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ChartDisplayDockWidget.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2011-2012 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 ChartDisplayDockWidget.cpp
22 
23  \brief A dock widget for chart display objects.
24 */
25 
26 #include "ChartDisplayDockWidget.h"
27 
28 // TerraLib
29 #include "../../../dataaccess/dataset/DataSet.h"
30 #include "../../../dataaccess/dataset/ObjectIdSet.h"
31 #include "../../../dataaccess/utils/Utils.h"
32 #include "../../../maptools/AbstractLayer.h"
33 #include "../../widgets/charts/ChartConfigurer.h"
34 #include "../../widgets/charts/ChartDisplayWidget.h"
35 #include "../events/LayerEvents.h"
36 #include "../ApplicationController.h"
37 
38 te::gm::Envelope* computeDataSetEnvelope(std::auto_ptr<te::da::DataSet> dataset, size_t propNum)
39 {
40  te::gm::Envelope* result = new te::gm::Envelope;
41 
42  while(dataset->moveNext())
43  {
44  te::gm::Geometry* geom = dataset->getGeometry(propNum).release();
45  assert(geom);
46  result->Union(*geom->getMBR());
47  }
48  return result;
49 }
50 
51 
53 QDockWidget(parent, Qt::Widget),
54  m_displayWidget(displayWidget),
55  m_layer(0)
56 {
57  setWidget(m_displayWidget);
58  m_displayWidget->setParent(this);
59 
60  setAttribute(Qt::WA_DeleteOnClose, true);
61 
62  connect (m_displayWidget, SIGNAL(selected(te::da::ObjectIdSet*, const bool&)), SLOT(selectionChanged(te::da::ObjectIdSet*, const bool&)));
63 }
64 
66 {
67  delete m_displayWidget;
68  emit closed(this);
69 }
70 
72 {
73  m_layer = layer;
74 
75  //Configuring the default selection color
76  te::qt::widgets::ChartConfigurer cc(m_displayWidget);
77  cc.config(m_layer);
78 
79  //Adjusting the selected objectIdSet
80  m_displayWidget->highlightOIds(m_layer->getSelected());
81 
82  if(m_layer==0)
83  return;
84 
85  setWindowTitle(m_layer->getTitle().c_str());
86 }
87 
89 {
90  m_displayWidget->setSelectionColor(selColor);
91 }
92 
94 {
95  return m_layer;
96 }
97 
99 {
100  switch(evt->m_id)
101  {
103  {
105 
106  if(ev->m_layer->getId() == m_layer->getId())
107  {
108  m_displayWidget->highlightOIds(ev->m_layer->getSelected());
109  }
110  }
111  break;
112 
114  {
116 
117  if(ev->m_layer->getId() == m_layer->getId())
118  {
119  this->close();
120  }
121  }
122  break;
123 
124  }
125 }
126 
128 {
129  te::da::ObjectIdSet* added = oids->clone();
130 
131  if(m_layer->getSelected())
132  {
133  if (add)
134  {
135  te::da::ObjectIdSet* removed = new te::da::ObjectIdSet();
136  //Checking if the objectIds need to be emoved from the current selection
137  std::set<te::da::ObjectId*, te::common::LessCmp<te::da::ObjectId*> >::const_iterator itObjSet;
138  for(itObjSet = oids->begin(); itObjSet != oids->end(); ++itObjSet)
139  {
140  if(m_layer->getSelected()->contains(*itObjSet))
141  {
142  removed->add(*itObjSet);
143  added->remove(*itObjSet);
144  }
145  }
146  m_layer->deselect(removed);
147  }
148  else
149  {
150  m_layer->clearSelected();
151  }
152  }
153 
154  std::vector<std::size_t> objIdIdx;
155  te::da::GetOIDPropertyPos(m_layer->getSchema().get(), objIdIdx);
156 
157  std::vector<size_t>::iterator it;
158 
159  for(it=objIdIdx.begin(); it!=objIdIdx.end(); ++it)
160  added->addProperty(m_layer->getData()->getPropertyName(*it), *it, m_layer->getData()->getPropertyDataType(*it));
161 
162  //Acquiring the envelope
163  if(added->size() > 0)
164  {
165  std::auto_ptr<te::da::DataSet> ds = m_layer->getData(added);
166  ds->moveBeforeFirst();
167 
168  size_t numProp, geomPos;
169  numProp = ds->getNumProperties();
170 
171  for(size_t i=0; i<numProp; i++)
172  {
173  if(ds->getPropertyDataType(i) == te::dt::GEOMETRY_TYPE)
174  {
175  geomPos = i;
176  break;
177  }
178  }
179 
180  m_layer->select(added);
183  }
184  else
185  {
186  m_layer->select(added);
189  }
190  oids->clear();
191 }
te::qt::widgets::ChartDisplayWidget * m_displayWidget
The widget containing the display.
This is the base class for layers.
Definition: AbstractLayer.h:76
te::map::AbstractLayerPtr m_layer
Layer whose selected objects were changed.
Definition: LayerEvents.h:192
A base class for application events.
Definition: Event.h:59
void setSelectionColor(QColor selColor)
color used to hgihlight selected objects on this display.
te::map::AbstractLayer * getLayer() const
Returns the layer being used.
void addProperty(const std::string &name, std::size_t pos, int type)
It adds a property that will be used to generate the unique ids.
Definition: ObjectIdSet.cpp:63
This event indicates that the selected objects of the layer were changed.
Definition: LayerEvents.h:178
A Symbology Enconding visitor that configures a given chart based on symbolizers elements. If you want to use this visitor, use a command like: te::qt::widgets::ChartConfigurer cc(chart); cc.config(symbolizer);
void Union(const Envelope &rhs)
It updates the envelop with coordinates of another envelope.
Definition: Envelope.h:555
static ApplicationController & getInstance()
It returns a reference to the singleton instance.
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:53
int m_id
Identifier.
Definition: Event.h:70
std::size_t size() const
It returns the object id set size.
te::gm::Envelope * computeDataSetEnvelope(std::auto_ptr< te::da::DataSet > dataset, size_t propNum)
void setLayer(te::map::AbstractLayer *layer)
Sets the layer to be showed on view. This DOES NOT takes the ownership of layer.
void selectionChanged(te::da::ObjectIdSet *oids, const bool &add)
Used to handle a selection change.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
A dock widget for chart display objects.
void onApplicationTriggered(te::qt::af::evt::Event *evt)
Used to capture events sent by the application framework.
void config(const te::se::Symbolizer *symbolizer)
It configs the chart based on given symbolizer.
A wdiget used to display a chart.
void broadcast(te::qt::af::evt::Event *evt)
Send events in broadcast for all registered components.
void remove(ObjectId *oid)
Removes the object id from set.
TEDATAACCESSEXPORT void GetOIDPropertyPos(const DataSetType *type, std::vector< std::size_t > &ppos)
Definition: Utils.cpp:352
te::map::AbstractLayerPtr m_layer
Layer removed.
Definition: LayerEvents.h:124
std::set< ObjectId *, te::common::LessCmp< ObjectId * > >::const_iterator end() const
Returns an iterator for the object ids in container.
void clear()
It clears this object id set.
void add(ObjectId *oid)
It adds an object id to this object id set.
Definition: ObjectIdSet.cpp:71
This event signals that a layer is to be removed from the layer explorer.
Definition: LayerEvents.h:111
ChartDisplayDockWidget(te::qt::widgets::ChartDisplayWidget *displayWidget, QWidget *parent=0)
Constructor.
std::set< ObjectId *, te::common::LessCmp< ObjectId * > >::const_iterator begin() const
Returns an iterator for the object ids in container.
ObjectIdSet * clone() const
const Envelope * getMBR() const
It returns the minimum bounding rectangle for the geometry in an internal representation.
Definition: Geometry.cpp:103