All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 
39 QDockWidget(parent, Qt::Widget),
40  m_displayWidget(displayWidget),
41  m_layer(0)
42 {
43  setWidget(m_displayWidget);
44  m_displayWidget->setParent(this);
45 
46  setAttribute(Qt::WA_DeleteOnClose, true);
47 
48  connect (m_displayWidget, SIGNAL(selected(te::da::ObjectIdSet*, const bool&)), SLOT(selectionChanged(te::da::ObjectIdSet*, const bool&)));
49 }
50 
52 {
53  delete m_displayWidget;
54  emit closed(this);
55 }
56 
58 {
59  m_layer = layer;
60 
61  //Configuring the default selection color
62  te::qt::widgets::ChartConfigurer cc(m_displayWidget);
63  cc.config(m_layer);
64 
65  //Adjusting the selected objectIdSet
66  m_displayWidget->highlightOIds(m_layer->getSelected());
67 
68  if(m_layer==0)
69  return;
70 
71  setWindowTitle(m_layer->getTitle().c_str());
72 }
73 
75 {
76  m_displayWidget->setSelectionColor(selColor);
77 }
78 
80 {
81  return m_layer;
82 }
83 
85 {
86  switch(evt->m_id)
87  {
89  {
91 
92  if(ev->m_layer->getId() == m_layer->getId())
93  {
94  m_displayWidget->highlightOIds(ev->m_layer->getSelected());
95  }
96  }
97  break;
98 
100  {
102 
103  if(ev->m_layer->getId() == m_layer->getId())
104  {
105  this->close();
106  }
107  }
108  break;
109 
110  }
111 }
112 
114 {
115  te::da::ObjectIdSet* added = oids->clone();
116 
117  if(m_layer->getSelected())
118  {
119  if (add)
120  {
121  te::da::ObjectIdSet* removed = new te::da::ObjectIdSet();
122  //Checking if the objectIds need to be inserted or removed from the current selection
123  std::set<te::da::ObjectId*, te::common::LessCmp<te::da::ObjectId*> >::const_iterator itObjSet;
124  for(itObjSet = oids->begin(); itObjSet != oids->end(); ++itObjSet)
125  {
126  if(m_layer->getSelected()->contains(*itObjSet))
127  {
128  removed->add(*itObjSet);
129  added->remove(*itObjSet);
130  }
131  }
132  m_layer->deselect(removed);
133  }
134  else
135  {
136  m_layer->clearSelected();
137  }
138  }
139 
140  std::vector<std::size_t> objIdIdx;
141  te::da::GetOIDPropertyPos(m_layer->getSchema().get(), objIdIdx);
142 
143  std::vector<size_t>::iterator it;
144 
145  for(it=objIdIdx.begin(); it!=objIdIdx.end(); ++it)
146  added->addProperty(m_layer->getData()->getPropertyName(*it), *it, m_layer->getData()->getPropertyDataType(*it));
147 
148  oids->clear();
149  m_layer->select(added);
152 }
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:53
This is the base class for layers.
Definition: AbstractLayer.h:76
A wdiget used to display a chart.
void clear()
It clears this object id set.
void remove(ObjectId *oid)
Removes the object id from set.
static ApplicationController & getInstance()
It gives access to the controller singleton.
void setSelectionColor(QColor selColor)
color used to hgihlight selected objects on this display.
te::map::AbstractLayerPtr m_layer
Layer whose selected objects were changed.
Definition: LayerEvents.h:186
ChartDisplayDockWidget(te::qt::widgets::ChartDisplayWidget *displayWidget, QWidget *parent=0)
Constructor.
te::map::AbstractLayer * getLayer() const
Returns the layer being used.
void onApplicationTriggered(te::qt::af::evt::Event *evt)
Used to capture events sent by the application framework.
TEDATAACCESSEXPORT void GetOIDPropertyPos(const DataSetType *type, std::vector< std::size_t > &ppos)
Definition: Utils.cpp:351
void config(const te::se::Symbolizer *symbolizer)
It configs the chart based on given symbolizer.
Contains a list of the layer events.
std::set< ObjectId *, te::common::LessCmp< ObjectId * > >::const_iterator begin() const
Returns an iterator for the object ids in container.
std::set< ObjectId *, te::common::LessCmp< ObjectId * > >::const_iterator end() const
Returns an iterator for the object ids in container.
int m_id
Identifier.
Definition: Event.h:70
te::map::AbstractLayerPtr m_layer
Layer removed.
Definition: LayerEvents.h:119
te::qt::widgets::ChartDisplayWidget * m_displayWidget
The widget containing the display.
A base class for application events.
Definition: Event.h:59
This event signals that a layer is to be removed from the layer explorer.
Definition: LayerEvents.h:106
void setLayer(te::map::AbstractLayer *layer)
Sets the layer to be showed on view. This DOES NOT takes the ownership of layer.
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:173
ObjectIdSet * clone() const
A dock widget for chart display objects.
void add(ObjectId *oid)
It adds an object id to this object id set.
Definition: ObjectIdSet.cpp:71
void selectionChanged(te::da::ObjectIdSet *oids, const bool &add)
Used to handle a selection change.
void broadcast(te::qt::af::evt::Event *evt)
Send events in broadcast for all registered components.
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);