All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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 <QMenu>
42 #include <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  {
66  if(m_layer->isValid())
67  return QVariant(QIcon::fromTheme("dataset-layer"));
68  else
69  return QVariant(QIcon::fromTheme("dataset-layer-invalid"));
70  }
71 
72  if(role == Qt::DisplayRole)
73  return QVariant(QString::fromStdString(m_layer->getTitle()));
74 
75  if(role == Qt::CheckStateRole)
76  return QVariant(m_layer->getVisibility() == te::map::VISIBLE ? Qt::Checked : Qt::Unchecked);
77 
78  if(role == Qt::ToolTipRole)
79  return buildToolTip();
80 
81  return QVariant();
82 }
83 
84 QMenu* te::qt::widgets::DataSetLayerItem::getMenu(QWidget* /*parent*/) const
85 {
86  return 0;
87 }
88 
90 {
91  return (((m_layer->getStyle() != 0) && (!m_layer->getStyle()->getRules().empty())) || m_layer->getGrouping() != 0 || m_layer->getChart() != 0);
92 }
93 
95 {
96  return Qt::ItemIsUserCheckable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
97 }
98 
100 {
101  if(m_layer->getStyle() && children().empty())
102  {
103  const std::vector<te::se::Rule*>& rules = m_layer->getStyle()->getRules();
104 
105  for(std::size_t i = 0; i != rules.size(); ++i)
106  new LegendItem(rules[i], this);
107  }
108 
109  if(m_layer->getStyle())
110  {
111  te::se::RasterSymbolizer* rs = te::se::GetRasterSymbolizer(m_layer->getStyle());
112 
113  if(rs && rs->getColorMap() && !hasColorMapItem())
114  new ColorMapItem(rs->getColorMap(), this);
115  }
116 
117  if(m_layer->getGrouping() && !hasGroupingItem())
118  new GroupingItem(m_layer->getGrouping(), this);
119 
120  if(m_layer->getChart() && !hasChartItem())
121  new ChartItem(m_layer->getChart(), this);
122 }
123 
125 {
126  return ((m_layer->getStyle() != 0) && (!m_layer->getStyle()->getRules().empty())) || m_layer->getGrouping() != 0 || m_layer->getChart() != 0;
127 }
128 
129 bool te::qt::widgets::DataSetLayerItem::setData(int column, const QVariant& value, int role)
130 {
131  if(role == Qt::CheckStateRole)
132  {
133  Qt::CheckState checkState = static_cast<Qt::CheckState>(value.toInt());
134 
135  if(checkState == Qt::Checked)
136  m_layer->setVisibility(te::map::VISIBLE);
137  else if(checkState == Qt::Unchecked)
138  m_layer->setVisibility(te::map::NOT_VISIBLE);
139 
140  m_layer->updateVisibilityOfAncestors();
141 
142  return true;
143  }
144 
145  return false;
146 }
147 
149 {
150  return m_layer;
151 }
152 
154 {
155  return "DATASET_LAYER_ITEM";
156 }
157 
159 {
160  GroupingItem* groupingItem = findChild<GroupingItem*>();
161 
162  return groupingItem != 0;
163 }
164 
166 {
167  ChartItem* chartItem = findChild<ChartItem*>();
168 
169  return chartItem != 0;
170 }
171 
173 {
174  ColorMapItem* cmi = findChild<ColorMapItem*>();
175 
176  return cmi != 0;
177 }
178 
180 {
181  if(!m_layer->isValid())
182  return tr("Invalid Layer");
183 
184  QString toolTip;
185 
186  // Gets the data set name
187  toolTip += tr("DataSet") + ": " + m_layer->getDataSetName().c_str() + "\n";
188 
189  // Gets the connection info
190  const std::string& id = m_layer->getDataSourceId();
192  const std::map<std::string, std::string>& connInfo = info->getConnInfo();
193 
194  toolTip += tr("Connection Info") + ":\n";
195 
196  std::size_t i = 0;
197  std::map<std::string, std::string>::const_iterator it;
198  for(it = connInfo.begin(); it != connInfo.end(); ++it)
199  {
200  toolTip += it->first.c_str();
201  toolTip += ": ";
202  toolTip += it->second.c_str();
203  ++i;
204  if(i != connInfo.size())
205  toolTip += "\n";
206  }
207 
208  return toolTip;
209 }
QMenu * getMenu(QWidget *parent=0) const
A class that represents a grouping of a layer in a LayerTreeModel.
TESEEXPORT RasterSymbolizer * GetRasterSymbolizer(Style *s)
Try to get raster symbolizer from a style.
Definition: Utils.cpp:371
te::map::DataSetLayerPtr m_layer
The class that represents an item in a LayerTreeModel.
The class that represents a dataset layer item in a LayerTreeModel.
A class that represents a legend item of a layer in a LayerTreeModel.
const std::string getItemType() const
It returns the item type: "DATASET_LAYER_ITEM".
static DataSourceInfoManager & getInstance()
It returns a reference to the singleton instance.
DataSetLayerItem(const te::map::AbstractLayerPtr &l, QObject *parent=0)
The RasterSymbolizer describes how to render raster/matrix-coverage data (e.g., satellite photos...
bool setData(int column, const QVariant &value, int role=Qt::EditRole)
A class that represents a chart of a layer in a LayerTreeModel.
te::map::AbstractLayerPtr getLayer() const
te::se::ColorMap * getColorMap() const
A layer with reference to a dataset.
Definition: DataSetLayer.h:47
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
QVariant data(int column, int role) const
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
A class that represents a color map of rastersymbolizer of a layer in a LayerTreeModel.