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) 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 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  emit closed(this);
68 }
69 
71 {
72  m_layer = layer;
73 
74  //Configuring the default selection color
75  te::qt::widgets::ChartConfigurer cc(m_displayWidget);
76  cc.config(m_layer);
77 
78  //Adjusting the selected objectIdSet
79  m_displayWidget->highlightOIds(m_layer->getSelected(), m_layer->getSchema().get());
80 
81  if(m_layer==0)
82  return;
83 
84  setWindowTitle(m_layer->getTitle().c_str());
85 }
86 
88 {
89  m_displayWidget->setSelectionColor(selColor);
90 }
91 
93 {
94  return m_layer;
95 }
96 
98 {
99  switch(evt->m_id)
100  {
102  {
104 
105  if(ev->m_layer->getId() == m_layer->getId())
106  {
107  m_displayWidget->highlightOIds(ev->m_layer->getSelected(), ev->m_layer->getSchema().get());
108  }
109  }
110  break;
111 
113  {
115 
116  if(ev->m_layer->getId() == m_layer->getId())
117  {
118  this->close();
119  }
120  }
121  break;
122 
123  }
124 }
125 
127 {
128  te::da::ObjectIdSet* added = oids->clone();
129 
130  if(m_layer->getSelected())
131  {
132  if (add)
133  {
134  te::da::ObjectIdSet* removed = new te::da::ObjectIdSet();
135  //Checking if the objectIds need to be emoved from the current selection
136  std::set<te::da::ObjectId*, te::common::LessCmp<te::da::ObjectId*> >::const_iterator itObjSet;
137  for(itObjSet = oids->begin(); itObjSet != oids->end(); ++itObjSet)
138  {
139  if(m_layer->getSelected()->contains(*itObjSet))
140  {
141  removed->add(*itObjSet);
142  added->remove(*itObjSet);
143  }
144  }
145  m_layer->deselect(removed);
146  }
147  else
148  {
149  m_layer->clearSelected();
150  }
151  }
152 
153  std::vector<std::size_t> objIdIdx;
154  te::da::GetOIDPropertyPos(m_layer->getSchema().get(), objIdIdx);
155 
156  std::vector<size_t>::iterator it;
157 
158  for(it=objIdIdx.begin(); it!=objIdIdx.end(); ++it)
159  added->addProperty(m_layer->getData()->getPropertyName(*it), *it, m_layer->getData()->getPropertyDataType(*it));
160 
161  //Acquiring the envelope
162  if(added->size() > 0 && m_layer->getSchema()->hasGeom())
163  {
164  std::auto_ptr<te::da::DataSet> ds = m_layer->getData(added);
165  ds->moveBeforeFirst();
166 
167  size_t numProp = ds->getNumProperties();
168  size_t geomPos = 0;
169 
170  for(size_t i=0; i<numProp; i++)
171  {
172  if(ds->getPropertyDataType(i) == te::dt::GEOMETRY_TYPE)
173  {
174  geomPos = i;
175  break;
176  }
177  }
178 
179  m_layer->select(added);
182  }
183  else
184  {
185  m_layer->select(added);
188  }
189  oids->clear();
190 }
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:75
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:55
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:401
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:83
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:104