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) 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 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  {
68  std::auto_ptr<te::da::DataSetType> schema = m_layer->getSchema();
69 
70  if(!schema->hasGeom() && !schema->hasRaster())
71  return QVariant(QIcon::fromTheme("dataset-layer-tabular"));
72  else
73  return QVariant(QIcon::fromTheme("dataset-layer"));
74  }
75  else
76  {
77  return QVariant(QIcon::fromTheme("dataset-layer-invalid"));
78  }
79  }
80 
81  if(role == Qt::DisplayRole)
82  return QVariant(QString::fromStdString(m_layer->getTitle()));
83 
84  if(role == Qt::CheckStateRole)
85  return QVariant(m_layer->getVisibility() == te::map::VISIBLE ? Qt::Checked : Qt::Unchecked);
86 
87  if(role == Qt::ToolTipRole)
88  return buildToolTip();
89 
90  return QVariant();
91 }
92 
93 QMenu* te::qt::widgets::DataSetLayerItem::getMenu(QWidget* /*parent*/) const
94 {
95  return 0;
96 }
97 
99 {
100  return (((m_layer->getStyle() != 0) && (!m_layer->getStyle()->getRules().empty())) || m_layer->getGrouping() != 0 || m_layer->getChart() != 0);
101 }
102 
104 {
105  return Qt::ItemIsUserCheckable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
106 }
107 
109 {
110  if(m_layer->getStyle() && children().empty())
111  {
112  const std::vector<te::se::Rule*>& rules = m_layer->getStyle()->getRules();
113 
114  for(std::size_t i = 0; i != rules.size(); ++i)
115  new LegendItem(rules[i], this);
116  }
117 
118  if(m_layer->getStyle())
119  {
120  te::se::RasterSymbolizer* rs = te::se::GetRasterSymbolizer(m_layer->getStyle());
121 
122  if(rs && rs->getColorMap() && !hasColorMapItem())
123  new ColorMapItem(rs->getColorMap(), this);
124  }
125 
126  if(m_layer->getGrouping() && !hasGroupingItem())
127  new GroupingItem(m_layer->getGrouping(), this);
128 
129  if(m_layer->getChart() && !hasChartItem())
130  new ChartItem(m_layer->getChart(), this);
131 }
132 
134 {
135  return ((m_layer->getStyle() != 0) && (!m_layer->getStyle()->getRules().empty())) || m_layer->getGrouping() != 0 || m_layer->getChart() != 0;
136 }
137 
138 bool te::qt::widgets::DataSetLayerItem::setData(int column, const QVariant& value, int role)
139 {
140  if(role == Qt::CheckStateRole)
141  {
142  Qt::CheckState checkState = static_cast<Qt::CheckState>(value.toInt());
143 
144  if(checkState == Qt::Checked)
145  m_layer->setVisibility(te::map::VISIBLE);
146  else if(checkState == Qt::Unchecked)
147  m_layer->setVisibility(te::map::NOT_VISIBLE);
148 
149  m_layer->updateVisibilityOfAncestors();
150 
151  return true;
152  }
153 
154  return false;
155 }
156 
158 {
159  return m_layer;
160 }
161 
163 {
164  return "DATASET_LAYER_ITEM";
165 }
166 
168 {
169  GroupingItem* groupingItem = findChild<GroupingItem*>();
170 
171  return groupingItem != 0;
172 }
173 
175 {
176  ChartItem* chartItem = findChild<ChartItem*>();
177 
178  return chartItem != 0;
179 }
180 
182 {
183  ColorMapItem* cmi = findChild<ColorMapItem*>();
184 
185  return cmi != 0;
186 }
187 
189 {
190  if(!m_layer->isValid())
191  return tr("Invalid Layer");
192 
193  QString toolTip;
194 
195  // Gets the data set name
196  toolTip += tr("DataSet") + ": " + m_layer->getDataSetName().c_str() + "\n";
197 
198  // Gets the connection info
199  const std::string& id = m_layer->getDataSourceId();
201  const std::map<std::string, std::string>& connInfo = info->getConnInfo();
202 
203  toolTip += tr("Connection Info") + ":\n";
204 
205  std::size_t i = 0;
206  std::map<std::string, std::string>::const_iterator it;
207  for(it = connInfo.begin(); it != connInfo.end(); ++it)
208  {
209  toolTip += it->first.c_str();
210  toolTip += ": ";
211  toolTip += it->second.c_str();
212  ++i;
213  if(i != connInfo.size())
214  toolTip += "\n";
215  }
216 
217  return toolTip;
218 }
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.