All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DataSetLayerItem.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2001-2013 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 terralib/qt/widgets/layer/explorer/DataSetLayerItem.cpp
22 
23  \brief The class that represents a dataset layer item in a LayerTreeModel.
24 */
25 
26 // TerraLib
27 #include "../../../../common/Translator.h"
28 #include "../../../../dataaccess/datasource/DataSourceInfoManager.h"
29 #include "../../../../maptools/DataSetLayer.h"
30 #include "../../../../se/RasterSymbolizer.h"
31 #include "../../../../se/Style.h"
32 #include "../../../../se/Utils.h"
33 #include "../../Exception.h"
34 #include "ChartItem.h"
35 #include "ColorMapItem.h"
36 #include "DataSetLayerItem.h"
37 #include "GroupingItem.h"
38 #include "LegendItem.h"
39 
40 // Qt
41 #include <QtGui/QMenu>
42 #include <QtGui/QWidget>
43 
44 // STL
45 #include <map>
46 
48  : AbstractTreeItem(parent)
49 {
50  m_layer = boost::dynamic_pointer_cast<te::map::DataSetLayer>(l);
51 }
52 
54 {
55 }
56 
58 {
59  return 1;
60 }
61 
62 QVariant te::qt::widgets::DataSetLayerItem::data(int /*column*/, int role) const
63 {
64  if(role == Qt::DecorationRole)
65  return QVariant(QIcon::fromTheme("dataset-layer"));
66 
67  if(role == Qt::DisplayRole)
68  return QVariant(QString::fromStdString(m_layer->getTitle()));
69 
70  if(role == Qt::CheckStateRole)
71  return QVariant(m_layer->getVisibility() == te::map::VISIBLE ? Qt::Checked : Qt::Unchecked);
72 
73  if(role == Qt::ToolTipRole)
74  return buildToolTip();
75 
76  return QVariant();
77 }
78 
79 QMenu* te::qt::widgets::DataSetLayerItem::getMenu(QWidget* /*parent*/) const
80 {
81  return 0;
82 }
83 
85 {
86  return (((m_layer->getStyle() != 0) && (!m_layer->getStyle()->getRules().empty())) || m_layer->getGrouping() != 0 || m_layer->getChart() != 0);
87 }
88 
90 {
91  return Qt::ItemIsUserCheckable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
92 }
93 
95 {
96  if(m_layer->getStyle() && children().empty())
97  {
98  const std::vector<te::se::Rule*>& rules = m_layer->getStyle()->getRules();
99 
100  for(std::size_t i = 0; i != rules.size(); ++i)
101  new LegendItem(rules[i], this);
102  }
103 
104  if(m_layer->getStyle())
105  {
106  te::se::RasterSymbolizer* rs = te::se::GetRasterSymbolizer(m_layer->getStyle());
107 
108  if(rs && rs->getColorMap() && !hasColorMapItem())
109  new ColorMapItem(rs->getColorMap(), this);
110  }
111 
112  if(m_layer->getGrouping() && !hasGroupingItem())
113  new GroupingItem(m_layer->getGrouping(), this);
114 
115  if(m_layer->getChart() && !hasChartItem())
116  new ChartItem(m_layer->getChart(), this);
117 }
118 
120 {
121  return ((m_layer->getStyle() != 0) && (!m_layer->getStyle()->getRules().empty())) || m_layer->getGrouping() != 0 || m_layer->getChart() != 0;
122 }
123 
124 bool te::qt::widgets::DataSetLayerItem::setData(int column, const QVariant& value, int role)
125 {
126  if(role == Qt::CheckStateRole)
127  {
128  Qt::CheckState checkState = static_cast<Qt::CheckState>(value.toInt());
129 
130  if(checkState == Qt::Checked)
131  m_layer->setVisibility(te::map::VISIBLE);
132  else if(checkState == Qt::Unchecked)
133  m_layer->setVisibility(te::map::NOT_VISIBLE);
134 
135  m_layer->updateVisibilityOfAncestors();
136 
137  return true;
138  }
139 
140  return false;
141 }
142 
144 {
145  return m_layer;
146 }
147 
149 {
150  return "DATASET_LAYER_ITEM";
151 }
152 
154 {
155  GroupingItem* groupingItem = findChild<GroupingItem*>();
156 
157  return groupingItem != 0;
158 }
159 
161 {
162  ChartItem* chartItem = findChild<ChartItem*>();
163 
164  return chartItem != 0;
165 }
166 
168 {
169  ColorMapItem* cmi = findChild<ColorMapItem*>();
170 
171  return cmi != 0;
172 }
173 
175 {
176  // Gets the connection info
177  const std::string& id = m_layer->getDataSourceId();
179  const std::map<std::string, std::string>& connInfo = info->getConnInfo();
180 
181  QString toolTip;
182 
183  std::size_t i = 0;
184  std::map<std::string, std::string>::const_iterator it;
185  for(it = connInfo.begin(); it != connInfo.end(); ++it)
186  {
187  toolTip += it->first.c_str();
188  toolTip += " = ";
189  toolTip += it->second.c_str();
190  ++i;
191  if(i != connInfo.size())
192  toolTip += "\n";
193  }
194 
195  return toolTip;
196 }
The RasterSymbolizer describes how to render raster/matrix-coverage data (e.g., satellite photos...
A layer with reference to a dataset.
Definition: DataSetLayer.h:47
const std::string getItemType() const
It returns the item type: &quot;DATASET_LAYER_ITEM&quot;.
A class that represents a legend item of a layer in a LayerTreeModel.
te::map::AbstractLayerPtr getLayer() const
DataSetLayerItem(const te::map::AbstractLayerPtr &l, QObject *parent=0)
The class that represents a dataset layer item in a LayerTreeModel.
QVariant data(int column, int role) const
bool setData(int column, const QVariant &value, int role=Qt::EditRole)
QMenu * getMenu(QWidget *parent=0) const
A class that represents a grouping of a layer in a LayerTreeModel.
A class that represents a color map of rastersymbolizer of a layer in a LayerTreeModel.
te::se::ColorMap * getColorMap() const
TESEEXPORT RasterSymbolizer * GetRasterSymbolizer(Style *s)
Try to get raster symbolizer from a style.
Definition: Utils.cpp:369
The class that represents an item in a LayerTreeModel.
te::map::DataSetLayerPtr m_layer
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
static DataSourceInfoManager & getInstance()
It returns a reference to the singleton instance.
A class that represents a chart of a layer in a LayerTreeModel.
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr