All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DataSetAdapterLayerItem.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/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 "../../../../maptools/DataSetAdapterLayer.h"
29 #include "../../../../se/Style.h"
30 #include "../../Exception.h"
31 #include "ChartItem.h"
33 #include "GroupingItem.h"
34 #include "LegendItem.h"
35 
36 // Qt
37 #include <QtGui/QMenu>
38 #include <QtGui/QWidget>
39 
41  : AbstractTreeItem(parent)
42 {
43  m_layer = boost::dynamic_pointer_cast<te::map::DataSetAdapterLayer>(l);
44 }
45 
47 {
48 }
49 
51 {
52  return 1;
53 }
54 
55 QVariant te::qt::widgets::DataSetAdapterLayerItem::data(int /*column*/, int role) const
56 {
57  if(role == Qt::DecorationRole)
58  return QVariant(QIcon::fromTheme("dataset-layer"));
59 
60  if(role == Qt::DisplayRole)
61  return QVariant(QString::fromStdString(m_layer->getTitle()));
62 
63  if(role == Qt::CheckStateRole)
64  return QVariant(m_layer->getVisibility() == te::map::VISIBLE ? Qt::Checked : Qt::Unchecked);
65 
66  return QVariant();
67 }
68 
69 QMenu* te::qt::widgets::DataSetAdapterLayerItem::getMenu(QWidget* /*parent*/) const
70 {
71  return 0;
72 }
73 
75 {
76  return (((m_layer->getStyle() != 0) && (!m_layer->getStyle()->getRules().empty())) || m_layer->getGrouping() != 0 || m_layer->getChart() != 0);
77 }
78 
80 {
81  return Qt::ItemIsUserCheckable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
82 }
83 
85 {
86  if(m_layer->getStyle() && children().empty())
87  {
88  const std::vector<te::se::Rule*>& rules = m_layer->getStyle()->getRules();
89 
90  for(std::size_t i = 0; i != rules.size(); ++i)
91  new LegendItem(rules[i], this);
92  }
93 
94  if(m_layer->getGrouping() && !hasGroupingItem())
95  new GroupingItem(m_layer->getGrouping(), this);
96 
97  if(m_layer->getChart() && !hasChartItem())
98  new ChartItem(m_layer->getChart(), this);
99 }
100 
102 {
103  return ((m_layer->getStyle() != 0) && (!m_layer->getStyle()->getRules().empty())) || m_layer->getGrouping() != 0 || m_layer->getChart() != 0;
104 }
105 
106 bool te::qt::widgets::DataSetAdapterLayerItem::setData(int column, const QVariant& value, int role)
107 {
108  if(role == Qt::CheckStateRole)
109  {
110  Qt::CheckState checkState = static_cast<Qt::CheckState>(value.toInt());
111 
112  if(checkState == Qt::Checked)
113  m_layer->setVisibility(te::map::VISIBLE);
114  else if(checkState == Qt::Unchecked)
115  m_layer->setVisibility(te::map::NOT_VISIBLE);
116 
117  m_layer->updateVisibilityOfAncestors();
118 
119  return true;
120  }
121 
122  return false;
123 }
124 
126 {
127  return m_layer;
128 }
129 
131 {
132  return "DATASET_ADAPTER_LAYER_ITEM";
133 }
134 
136 {
137  GroupingItem* groupingItem = findChild<GroupingItem*>();
138 
139  return groupingItem != 0;
140 }
141 
143 {
144  ChartItem* chartItem = findChild<ChartItem*>();
145 
146  return chartItem != 0;
147 }
QVariant data(int column, int role) const
A class that represents a legend item of a layer in a LayerTreeModel.
QMenu * getMenu(QWidget *parent=0) const
const std::string getItemType() const
It returns the item type.
A class that represents a grouping of a layer in a LayerTreeModel.
The class that represents an item in a LayerTreeModel.
te::map::AbstractLayerPtr getLayer() const
A layer with reference to a DataSetTypeConverter.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
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)
The class that represents a dataset adapter layer item in a LayerTreeModel.