All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QueryLayerItem.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2011-2011 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 "LegendItem.h"
32 #include "QueryLayerItem.h"
33 
34 // STL
35 #include <cassert>
36 
37 // Qt
38 #include <QtGui/QMenu>
39 #include <QtGui/QWidget>
40 
42  : AbstractTreeItem(parent)
43 {
44  m_layer = boost::dynamic_pointer_cast<te::map::QueryLayer>(l);
45 }
46 
48 {
49 }
50 
52 {
53  return 1;
54 }
55 
56 QVariant te::qt::widgets::QueryLayerItem::data(int /*column*/, int role) const
57 {
58  //if(role == Qt::DecorationRole)
59  // return QVariant(QIcon::fromTheme("query-layer"));
60 
61  if(role == Qt::DisplayRole)
62  return QVariant(QString::fromUtf8(m_layer->getTitle().c_str()));
63 
64  if(role == Qt::CheckStateRole)
65  return QVariant(m_layer->getVisibility() == te::map::VISIBLE ? Qt::Checked : Qt::Unchecked);
66 
67  return QVariant();
68 }
69 
70 QMenu* te::qt::widgets::QueryLayerItem::getMenu(QWidget* /*parent*/) const
71 {
72  //QMenu* m = new QMenu(parent);
73 
74  //QAction* aOpenDataSource = m->addAction(tr("&Open data source"));
75 
76  //connect(aOpenDataSource, SIGNAL(triggered()), this, SLOT(openDataSource()));
77 
78  //return m;
79  return 0;
80 }
81 
83 {
84  return (m_layer->getStyle() != 0) && (m_layer->getStyle()->getRules().empty() == false) && children().isEmpty();
85 }
86 
88 {
89  return Qt::ItemIsUserCheckable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;;
90 }
91 
93 {
94  if(!children().isEmpty())
95  return;
96 
97  if(m_layer->getStyle())
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 
107 {
108  return (m_layer->getStyle() != 0) && (m_layer->getStyle()->getRules().empty() == false);
109 }
110 
111 bool te::qt::widgets::QueryLayerItem::setData(int column, const QVariant& value, int role)
112 {
113  if(role == Qt::CheckStateRole)
114  {
115  Qt::CheckState checkState = static_cast<Qt::CheckState>(value.toInt());
116  if(checkState == Qt::Checked)
117  m_layer->setVisibility(te::map::VISIBLE);
118  else if(checkState == Qt::Unchecked)
119  m_layer->setVisibility(te::map::NOT_VISIBLE);
120 
121  m_layer->updateVisibilityOfAncestors();
122 
123  return true;
124  }
125 
126  return false;
127 }
128 
130 {
131  return m_layer;
132 }
133 
135 {
136  return "QUERY_LAYER_ITEM";
137 }
te::map::QueryLayerPtr m_layer
Qt::ItemFlags flags() const
bool setData(int column, const QVariant &value, int role=Qt::EditRole)
A class that represents a legend item of a layer in a LayerTreeModel.
QMenu * getMenu(QWidget *parent=0) const
QVariant data(int column, int role) const
const std::string getItemType() const
It returns the item type: &quot;QUERY_LAYER_ITEM&quot;.
te::map::AbstractLayerPtr getLayer() const
A layer resulting from a query.
Definition: QueryLayer.h:50
The class that represents a query layer item in a LayerTreeModel.
The class that represents an item in a LayerTreeModel.
QueryLayerItem(const te::map::AbstractLayerPtr &l, QObject *parent=0)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr