All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
QueryLayerItem.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/QueryLayerItem.cpp
22 
23  \brief The class that represents a query layer item in a LayerTreeModel.
24 */
25 
26 // TerraLib
27 #include "../../../../common/Translator.h"
28 #include "../../../../maptools/QueryLayer.h"
29 #include "../../../../se/Style.h"
30 #include "../../Exception.h"
31 #include "ChartItem.h"
32 #include "GroupingItem.h"
33 #include "LegendItem.h"
34 #include "QueryLayerItem.h"
35 
36 
37 // STL
38 #include <cassert>
39 
40 // Qt
41 #include <QMenu>
42 #include <QWidget>
43 
45  : AbstractTreeItem(parent)
46 {
47  m_layer = boost::dynamic_pointer_cast<te::map::QueryLayer>(l);
48 }
49 
51 {
52 }
53 
55 {
56  return 1;
57 }
58 
59 QVariant te::qt::widgets::QueryLayerItem::data(int /*column*/, int role) const
60 {
61  if(role == Qt::DecorationRole)
62  return QVariant(QIcon::fromTheme("query-layer"));
63 
64  if(role == Qt::DisplayRole)
65  return QVariant(QString::fromUtf8(m_layer->getTitle().c_str()));
66 
67  if(role == Qt::CheckStateRole)
68  return QVariant(m_layer->getVisibility() == te::map::VISIBLE ? Qt::Checked : Qt::Unchecked);
69 
70  return QVariant();
71 }
72 
73 QMenu* te::qt::widgets::QueryLayerItem::getMenu(QWidget* /*parent*/) const
74 {
75  //QMenu* m = new QMenu(parent);
76 
77  //QAction* aOpenDataSource = m->addAction(tr("&Open data source"));
78 
79  //connect(aOpenDataSource, SIGNAL(triggered()), this, SLOT(openDataSource()));
80 
81  //return m;
82  return 0;
83 }
84 
86 {
87  return (((m_layer->getStyle() != 0) && (!m_layer->getStyle()->getRules().empty())) || m_layer->getGrouping() != 0 || m_layer->getChart() != 0);
88 }
89 
91 {
92  return Qt::ItemIsUserCheckable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;;
93 }
94 
96 {
97  if(m_layer->getStyle() && children().empty())
98  {
99  const std::vector<te::se::Rule*>& rules = m_layer->getStyle()->getRules();
100 
101  for(std::size_t i = 0; i != rules.size(); ++i)
102  new LegendItem(rules[i], this);
103  }
104 
105  if(m_layer->getGrouping() && !hasGroupingItem())
106  new GroupingItem(m_layer->getGrouping(), this);
107 
108  if(m_layer->getChart() && !hasChartItem())
109  new ChartItem(m_layer->getChart(), this);
110 }
111 
113 {
114  return (m_layer->getStyle() != 0) && (m_layer->getStyle()->getRules().empty() == false);
115 }
116 
117 bool te::qt::widgets::QueryLayerItem::setData(int column, const QVariant& value, int role)
118 {
119  if(role == Qt::CheckStateRole)
120  {
121  Qt::CheckState checkState = static_cast<Qt::CheckState>(value.toInt());
122  if(checkState == Qt::Checked)
123  m_layer->setVisibility(te::map::VISIBLE);
124  else if(checkState == Qt::Unchecked)
125  m_layer->setVisibility(te::map::NOT_VISIBLE);
126 
127  m_layer->updateVisibilityOfAncestors();
128 
129  return true;
130  }
131 
132  return false;
133 }
134 
136 {
137  return m_layer;
138 }
139 
141 {
142  return "QUERY_LAYER_ITEM";
143 }
144 
146 {
147  GroupingItem* groupingItem = findChild<GroupingItem*>();
148 
149  return groupingItem != 0;
150 }
151 
153 {
154  ChartItem* chartItem = findChild<ChartItem*>();
155 
156  return chartItem != 0;
157 }
158 
159 
160 
A class that represents a grouping of a layer in a LayerTreeModel.
const std::string getItemType() const
It returns the item type: "QUERY_LAYER_ITEM".
QVariant data(int column, int role) const
Qt::ItemFlags flags() const
The class that represents an item in a LayerTreeModel.
A layer resulting from a query.
Definition: QueryLayer.h:50
A class that represents a legend item of a layer in a LayerTreeModel.
bool setData(int column, const QVariant &value, int role=Qt::EditRole)
A class that represents a chart of a layer in a LayerTreeModel.
The class that represents a query layer item in a LayerTreeModel.
te::map::QueryLayerPtr m_layer
QueryLayerItem(const te::map::AbstractLayerPtr &l, QObject *parent=0)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
te::map::AbstractLayerPtr getLayer() const
QMenu * getMenu(QWidget *parent=0) const