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 
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(nullptr),
56  m_app(nullptr)
57 {
58  setWidget(m_displayWidget);
59  m_displayWidget->setParent(this);
60 
61  setAttribute(Qt::WA_DeleteOnClose, true);
62 
63  connect (m_displayWidget, SIGNAL(selected(te::da::ObjectIdSet*, const bool&)), SLOT(selectionChanged(te::da::ObjectIdSet*, const bool&)));
64 }
65 
67 {
68  emit closed(this);
69 }
70 
72 {
73  m_layer = layer;
74 
75  //Configuring the default selection color
77  cc.config(m_layer);
78 
79  //Adjusting the selected objectIdSet
81 
82  if(m_layer==nullptr)
83  return;
84 
85  setWindowTitle(m_layer->getTitle().c_str());
86 }
87 
89 {
90  m_app = app;
91 }
92 
94 {
96 }
97 
99 {
100  return m_layer;
101 }
102 
104 {
105  switch(evt->m_id)
106  {
108  {
110 
111  if(ev->m_layer->getId() == m_layer->getId())
112  {
113  m_displayWidget->highlightOIds(ev->m_layer->getSelected(), ev->m_layer->getSchema().get());
114  }
115  }
116  break;
117 
119  {
121  for(std::list<te::map::AbstractLayerPtr>::iterator it = ev->m_layers.begin(); it != ev->m_layers.end(); ++it)
122  if((*it)->getId() == m_layer->getId())
123  {
124  this->close();
125  return;
126  }
127  }
128  break;
129 
130  }
131 }
132 
134 {
135  te::da::ObjectIdSet* added = oids->clone();
136 
137  if(m_layer->getSelected())
138  {
139  if (add)
140  {
141  te::da::ObjectIdSet* removed = new te::da::ObjectIdSet();
142  //Checking if the objectIds need to be emoved from the current selection
143  std::set<te::da::ObjectId*, te::common::LessCmp<te::da::ObjectId*> >::const_iterator itObjSet;
144  for(itObjSet = oids->begin(); itObjSet != oids->end(); ++itObjSet)
145  {
146  if(m_layer->getSelected()->contains(*itObjSet))
147  {
148  removed->add(*itObjSet);
149  added->remove(*itObjSet);
150  }
151  }
152  m_layer->deselect(removed);
153  }
154  else
155  {
157  }
158  }
159 
160  std::vector<std::size_t> objIdIdx;
161  te::da::GetOIDPropertyPos(m_layer->getSchema().get(), objIdIdx);
162 
163  std::vector<size_t>::iterator it;
164 
165  for(it=objIdIdx.begin(); it!=objIdIdx.end(); ++it)
166  added->addProperty(m_layer->getData()->getPropertyName(*it), *it, m_layer->getData()->getPropertyDataType(*it));
167 
168  //Acquiring the envelope
169  if(added->size() > 0 && m_layer->getSchema()->hasGeom())
170  {
171  std::unique_ptr<te::da::DataSet> ds = m_layer->getData(added);
172  ds->moveBeforeFirst();
173 
174  size_t numProp = ds->getNumProperties();
175  size_t geomPos = 0;
176 
177  for(size_t i=0; i<numProp; i++)
178  {
179  if(ds->getPropertyDataType(i) == te::dt::GEOMETRY_TYPE)
180  {
181  geomPos = i;
182  break;
183  }
184  }
185 
186  m_layer->select(added);
188 
189  emit triggered(&e);
190  }
191  else
192  {
193  m_layer->select(added);
195 
196  emit triggered(&e);
197  }
198  oids->clear();
199 }
virtual std::unique_ptr< te::gm::Geometry > getGeometry(std::size_t i) const =0
Method for retrieving a geometric attribute value.
virtual const std::string & getId() const
It returns the layer id.
te::qt::widgets::ChartDisplayWidget * m_displayWidget
The widget containing the display.
This is the base class for layers.
Definition: AbstractLayer.h:77
te::map::AbstractLayerPtr m_layer
Layer whose selected objects were changed.
Definition: LayerEvents.h:218
virtual const std::string & getTitle() const
It returns the layer title.
A base class for application events.
void setSelectionColor(QColor selColor)
color used to hgihlight selected objects on this display.
The base API for TerraLib applications.
void setSelectionColor(QColor selColor)
color used to hgihlight selected objects on this display.
te::map::AbstractLayer * getLayer() const
Returns the layer being used.
static te::dt::Date ds(2010, 01, 01)
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:204
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.
void highlightOIds(const te::da::ObjectIdSet *oids, te::da::DataSetType *dataType)
Highlights the objects identified by oids.
virtual bool moveNext()=0
It moves the internal pointer to the next item of the collection.
const Envelope * getMBR() const _NOEXCEPT_OP(true)
It returns the minimum bounding rectangle for the geometry in an internal representation.
An Envelope defines a 2D rectangular region.
te::map::AbstractLayer * m_layer
Layer being visualized.
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:55
void closed(te::qt::af::ChartDisplayDockWidget *)
Emitted before this widget was closed.
std::size_t size() const
It returns the object id set size.
virtual std::unique_ptr< LayerSchema > getSchema() const =0
It returns the layer schema.
void setLayer(te::map::AbstractLayer *layer)
Sets the layer to be showed on view. This DOES NOT takes the ownership of layer.
virtual void clearSelected()
It clears the selected group of this 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.
A dock widget for chart display objects.
void onApplicationTriggered(te::qt::af::evt::Event *evt)
Used to capture events sent by the application framework.
virtual void select(te::da::ObjectIdSet *oids)
It adds the given oids to the selected group of this Layer.
void config(const te::se::Symbolizer *symbolizer)
It configs the chart based on given symbolizer.
A dataset is the unit of information manipulated by the data access module of TerraLib.
void setAppController(ApplicationController *app)
Sets the app controller to emit signal to app. This DOES NOT takes the ownership of app controller...
A wdiget used to display a chart.
virtual const te::da::ObjectIdSet * getSelected() const
It returns the selected group of this Layer.
void remove(ObjectId *oid)
Removes the object id from set.
TEDATAACCESSEXPORT void GetOIDPropertyPos(const DataSetType *type, std::vector< std::size_t > &ppos)
virtual std::unique_ptr< te::da::DataSet > getData(te::common::TraverseType travType=te::common::FORWARDONLY, const te::common::AccessPolicy accessPolicy=te::common::RAccess) const =0
It gets the dataset identified by the layer name.
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.
bool contains(ObjectId *oid) const
It returns if the object id set contains the given oid.
void add(ObjectId *oid)
It adds an object id to this object id set.
Definition: ObjectIdSet.cpp:83
std::list< te::map::AbstractLayerPtr > m_layers
Layer removed.
Definition: LayerEvents.h:154
void triggered(te::qt::af::evt::Event *e)
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
te::gm::Envelope * computeDataSetEnvelope(te::da::DataSet *dataset, size_t propNum)
virtual void deselect(const te::da::ObjectIdSet *oids)
It removes the given oids from the selected group of this Layer.