All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RasterLayerItem.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/RasterLayerItem.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/RasterLayer.h"
29 #include "../../../../se/Style.h"
30 #include "../../Exception.h"
31 #include "RasterLayerItem.h"
32 #include "LegendItem.h"
33 
34 // Qt
35 #include <QMenu>
36 #include <QWidget>
37 
39  : AbstractTreeItem(parent)
40 {
41  m_layer = boost::dynamic_pointer_cast<te::map::RasterLayer>(l);
42 }
43 
45 {
46 }
47 
49 {
50  return 1;
51 }
52 
53 QVariant te::qt::widgets::RasterLayerItem::data(int /*column*/, int role) const
54 {
55  //if(role == Qt::DecorationRole)
56  // return QVariant(QIcon::fromTheme("dataset-layer"));
57 
58  if(role == Qt::DisplayRole)
59  return QVariant(QString::fromStdString(m_layer->getTitle()));
60 
61  if(role == Qt::CheckStateRole)
62  return QVariant(m_layer->getVisibility() == te::map::VISIBLE ? Qt::Checked : Qt::Unchecked);
63 
64  return QVariant();
65 }
66 
67 QMenu* te::qt::widgets::RasterLayerItem::getMenu(QWidget* /*parent*/) const
68 {
69  //QMenu* m = new QMenu(parent);
70 
71  //QAction* aOpenDataSource = m->addAction(tr("&Open data source"));
72 
73  //connect(aOpenDataSource, SIGNAL(triggered()), this, SLOT(openDataSource()));
74 
75  //return m;
76  return 0;
77 }
78 
80 {
81  return children().isEmpty();
82 }
83 
85 {
86  return Qt::ItemIsUserCheckable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;;
87 }
88 
90 {
91  if(!children().isEmpty())
92  return;
93 
94  //if(m_layer->getStyle())
95  //{
96  // const std::vector<te::se::Rule*>& rules = m_layer->getStyle()->getRules();
97 
98  // for(std::size_t i = 0; i != rules.size(); ++i)
99  // new LegendItem(rules[i], this);
100  //}
101 }
102 
104 {
105  return false;
106 }
107 
108 bool te::qt::widgets::RasterLayerItem::setData(int column, const QVariant& value, int role)
109 {
110  if(role == Qt::CheckStateRole)
111  {
112  bool ok = false;
113  Qt::CheckState checkState = static_cast<Qt::CheckState>(value.toInt(&ok));
114 
115  if(!ok)
116  return false;
117 
118  if(checkState == Qt::Checked)
119  m_layer->setVisibility(te::map::VISIBLE);
120  else if(checkState == Qt::Unchecked)
121  m_layer->setVisibility(te::map::NOT_VISIBLE);
122 
123  return true;
124  }
125 
126  return false;
127 }
128 
130 {
131  return m_layer;
132 }
133 
135 {
136  return "RASTER_LAYER_ITEM";
137 }
QMenu * getMenu(QWidget *parent=0) const
const std::string getItemType() const
It returns the item type: "RASTER_LAYER_ITEM".
bool setData(int column, const QVariant &value, int role=Qt::EditRole)
The class that represents an item in a LayerTreeModel.
A class that represents a legend item of a layer in a LayerTreeModel.
te::map::RasterLayerPtr m_layer
A layer with reference to a raster.
Definition: RasterLayer.h:52
The class that represents a raster layer item in a LayerTreeModel.
RasterLayerItem(const te::map::AbstractLayerPtr &l, QObject *parent=0)
QVariant data(int column, int role) const
te::map::AbstractLayerPtr getLayer() const
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr