All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
WMSLayerItem.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/wms/qt/WMSLayerItem.cpp
22 
23  \brief The class that represents a WMS layer item in a LayerTreeModel.
24 */
25 
26 // TerraLib
27 #include "../../common/Translator.h"
28 #include "../../dataaccess/datasource/DataSourceInfoManager.h"
29 #include "../../qt/widgets/layer/explorer/ColorMapItem.h"
30 #include "../../qt/widgets/layer/explorer/LegendItem.h"
31 #include "../../se/RasterSymbolizer.h"
32 #include "../../se/Style.h"
33 #include "../../se/Utils.h"
34 #include "../Exception.h"
35 #include "WMSLayerItem.h"
36 
37 // Qt
38 #include <QMenu>
39 #include <QWidget>
40 
41 // STL
42 #include <map>
43 
45  : te::qt::widgets::AbstractTreeItem(parent)
46 {
47  m_layer = boost::dynamic_pointer_cast<WMSLayer>(l);
48 }
49 
51 {
52 }
53 
55 {
56  return 1;
57 }
58 
59 QVariant te::wms::WMSLayerItem::data(int /*column*/, int role) const
60 {
61  if(role == Qt::DecorationRole)
62  return QVariant(QIcon::fromTheme("datasource-wms"));
63 
64  if(role == Qt::DisplayRole)
65  return QVariant(QString::fromStdString(m_layer->getTitle()));
66 
67  if(role == Qt::CheckStateRole)
68  return QVariant(m_layer->getVisibility() == te::map::VISIBLE ? Qt::Checked : Qt::Unchecked);
69 
70  if(role == Qt::ToolTipRole)
71  return buildToolTip();
72 
73  return QVariant();
74 }
75 
76 QMenu* te::wms::WMSLayerItem::getMenu(QWidget* /*parent*/) const
77 {
78  return 0;
79 }
80 
82 {
83  return ((m_layer->getStyle() != 0) && (!m_layer->getStyle()->getRules().empty()));
84 }
85 
86 Qt::ItemFlags te::wms::WMSLayerItem::flags() const
87 {
88  return Qt::ItemIsUserCheckable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
89 }
90 
92 {
93  if(m_layer->getStyle() && children().empty())
94  {
95  const std::vector<te::se::Rule*>& rules = m_layer->getStyle()->getRules();
96 
97  for(std::size_t i = 0; i != rules.size(); ++i)
98  new te::qt::widgets::LegendItem(rules[i], this);
99  }
100 
101  if(m_layer->getStyle())
102  {
103  te::se::RasterSymbolizer* rs = te::se::GetRasterSymbolizer(m_layer->getStyle());
104 
105  if(rs && rs->getColorMap() && !hasColorMapItem())
107  }
108 }
109 
111 {
112  return (m_layer->getStyle() != 0) && (!m_layer->getStyle()->getRules().empty());
113 }
114 
115 bool te::wms::WMSLayerItem::setData(int column, const QVariant& value, int role)
116 {
117  if(role == Qt::CheckStateRole)
118  {
119  Qt::CheckState checkState = static_cast<Qt::CheckState>(value.toInt());
120 
121  if(checkState == Qt::Checked)
122  m_layer->setVisibility(te::map::VISIBLE);
123  else if(checkState == Qt::Unchecked)
124  m_layer->setVisibility(te::map::NOT_VISIBLE);
125 
126  m_layer->updateVisibilityOfAncestors();
127 
128  return true;
129  }
130 
131  return false;
132 }
133 
135 {
136  return m_layer;
137 }
138 
139 const std::string te::wms::WMSLayerItem::getItemType() const
140 {
141  return "WMS_LAYER_ITEM";
142 }
143 
145 {
146  te::qt::widgets::ColorMapItem* cmi = findChild<te::qt::widgets::ColorMapItem*>();
147 
148  return cmi != 0;
149 }
150 
152 {
153  // Gets the connection info
154  const std::string& id = m_layer->getDataSourceId();
156  const std::map<std::string, std::string>& connInfo = info->getConnInfo();
157 
158  QString toolTip;
159 
160  std::size_t i = 0;
161  std::map<std::string, std::string>::const_iterator it;
162  for(it = connInfo.begin(); it != connInfo.end(); ++it)
163  {
164  toolTip += it->first.c_str();
165  toolTip += " = ";
166  toolTip += it->second.c_str();
167  ++i;
168  if(i != connInfo.size())
169  toolTip += "\n";
170  }
171 
172  return toolTip;
173 }
int columnCount() const
QString buildToolTip() const
TESEEXPORT RasterSymbolizer * GetRasterSymbolizer(Style *s)
Try to get raster symbolizer from a style.
Definition: Utils.cpp:371
const std::string getItemType() const
It returns the item type: "WMS_LAYER_ITEM".
WMSLayerItem(const te::map::AbstractLayerPtr &l, QObject *parent=0)
bool hasChildren() const
A layer with reference to a WMS Layer.
Definition: WMSLayer.h:45
static DataSourceInfoManager & getInstance()
It returns a reference to the singleton instance.
The class that represents a WMS layer item in a LayerTreeModel.
Qt::ItemFlags flags() const
The RasterSymbolizer describes how to render raster/matrix-coverage data (e.g., satellite photos...
QMenu * getMenu(QWidget *parent=0) const
bool canFetchMore() const
te::map::AbstractLayerPtr getLayer() const
QVariant data(int column, int role) const
te::se::ColorMap * getColorMap() const
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
bool setData(int column, const QVariant &value, int role=Qt::EditRole)
bool hasColorMapItem() const
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr