All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DataSetAdapterLayerItem.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/DataSetAdapterLayerItem.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/DataSetAdapterLayer.h"
30 #include "../../../../se/Style.h"
31 #include "../../Exception.h"
32 #include "ChartItem.h"
34 #include "GroupingItem.h"
35 #include "LegendItem.h"
36 
37 // Qt
38 #include <QMenu>
39 #include <QWidget>
40 
42  : AbstractTreeItem(parent)
43 {
44  m_layer = boost::dynamic_pointer_cast<te::map::DataSetAdapterLayer>(l);
45 }
46 
48 {
49 }
50 
52 {
53  return 1;
54 }
55 
56 QVariant te::qt::widgets::DataSetAdapterLayerItem::data(int /*column*/, int role) const
57 {
58  if(role == Qt::DecorationRole)
59  {
60  if(m_layer->isValid())
61  return QVariant(QIcon::fromTheme("dataset-layer-tabular"));
62  else
63  return QVariant(QIcon::fromTheme("dataset-layer-invalid"));
64  }
65 
66  if(role == Qt::DisplayRole)
67  return QVariant(QString::fromStdString(m_layer->getTitle()));
68 
69  if(role == Qt::CheckStateRole)
70  return QVariant(m_layer->getVisibility() == te::map::VISIBLE ? Qt::Checked : Qt::Unchecked);
71 
72  if(role == Qt::ToolTipRole)
73  return buildToolTip();
74 
75  return QVariant();
76 }
77 
78 QMenu* te::qt::widgets::DataSetAdapterLayerItem::getMenu(QWidget* /*parent*/) const
79 {
80  return 0;
81 }
82 
84 {
85  return (((m_layer->getStyle() != 0) && (!m_layer->getStyle()->getRules().empty())) || m_layer->getGrouping() != 0 || m_layer->getChart() != 0);
86 }
87 
89 {
90  return Qt::ItemIsUserCheckable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
91 }
92 
94 {
95  if(m_layer->getStyle() && children().empty())
96  {
97  const std::vector<te::se::Rule*>& rules = m_layer->getStyle()->getRules();
98 
99  for(std::size_t i = 0; i != rules.size(); ++i)
100  new LegendItem(rules[i], this);
101  }
102 
103  if(m_layer->getGrouping() && !hasGroupingItem())
104  new GroupingItem(m_layer->getGrouping(), this);
105 
106  if(m_layer->getChart() && !hasChartItem())
107  new ChartItem(m_layer->getChart(), this);
108 }
109 
111 {
112  return ((m_layer->getStyle() != 0) && (!m_layer->getStyle()->getRules().empty())) || m_layer->getGrouping() != 0 || m_layer->getChart() != 0;
113 }
114 
115 bool te::qt::widgets::DataSetAdapterLayerItem::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 
140 {
141  return "DATASET_ADAPTER_LAYER_ITEM";
142 }
143 
145 {
146  GroupingItem* groupingItem = findChild<GroupingItem*>();
147 
148  return groupingItem != 0;
149 }
150 
152 {
153  ChartItem* chartItem = findChild<ChartItem*>();
154 
155  return chartItem != 0;
156 }
157 
159 {
160  if(!m_layer->isValid())
161  return tr("Invalid Layer");
162 
163  QString toolTip;
164 
165  // Gets the data set name
166  toolTip += tr("DataSet") + ": " + m_layer->getDataSetName().c_str() + "\n";
167 
168  // Gets the connection info
169  const std::string& id = m_layer->getDataSourceId();
171  const std::map<std::string, std::string>& connInfo = info->getConnInfo();
172 
173  toolTip += tr("Connection Info") + ":\n";
174 
175  std::size_t i = 0;
176  std::map<std::string, std::string>::const_iterator it;
177  for(it = connInfo.begin(); it != connInfo.end(); ++it)
178  {
179  toolTip += it->first.c_str();
180  toolTip += ": ";
181  toolTip += it->second.c_str();
182  ++i;
183  if(i != connInfo.size())
184  toolTip += "\n";
185  }
186 
187  return toolTip;
188 }
The class that represents a dataset adapter layer item in a LayerTreeModel.
A class that represents a grouping of a layer in a LayerTreeModel.
The class that represents an 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.
A layer with reference to a DataSetTypeConverter.
static DataSourceInfoManager & getInstance()
It returns a reference to the singleton instance.
QMenu * getMenu(QWidget *parent=0) const
te::map::AbstractLayerPtr getLayer() const
A class that represents a chart of a layer in a LayerTreeModel.
bool setData(int column, const QVariant &value, int role=Qt::EditRole)
DataSetAdapterLayerItem(const te::map::AbstractLayerPtr &l, QObject *parent=0)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
QVariant data(int column, int role) const
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr