All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
FolderLayerItem.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/FolderLayerItem.cpp
22 
23  \brief The class that represents a folder layer item in a LayerTreeModel.
24 */
25 
26 // TerraLib
27 #include "../../../../maptools/FolderLayer.h"
28 #include "../../../../common/Translator.h"
29 #include "../../Exception.h"
31 #include "FolderLayerItem.h"
32 
33 // Qt
34 #include <QMenu>
35 #include <QWidget>
36 
38  : AbstractTreeItem(parent)
39 {
40  m_layer = boost::dynamic_pointer_cast<te::map::FolderLayer>(l);
41 }
42 
44 {
45 }
46 
48 {
49  return 1;
50 }
51 
52 QVariant te::qt::widgets::FolderLayerItem::data(int /*column*/, int role) const
53 {
54  if(role == Qt::DecorationRole)
55  return QVariant(QIcon::fromTheme("folder"));
56 
57  if(role == Qt::DisplayRole)
58  return QVariant(QString::fromStdString(m_layer->getTitle()));
59 
60  if(role == Qt::CheckStateRole)
61  {
62  if(m_layer->getVisibility() == te::map::VISIBLE)
63  return QVariant(Qt::Checked);
64  else if(m_layer->getVisibility() == te::map::NOT_VISIBLE)
65  return QVariant(Qt::Unchecked);
66  else
67  return QVariant(Qt::PartiallyChecked);
68  }
69 
70  return QVariant();
71 }
72 
73 QMenu* te::qt::widgets::FolderLayerItem::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->hasChildren() && children().empty();
88 }
89 
91 {
92  return Qt::ItemIsUserCheckable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
93 }
94 
96 {
97  if(!children().empty())
98  return;
99 
100  for(te::map::AbstractLayer::const_iterator it = m_layer->begin(); it != m_layer->end(); ++it)
101  {
102  AbstractTreeItemFactory::make(boost::dynamic_pointer_cast<te::map::AbstractLayer>(*it), this);
103  }
104 }
105 
107 {
108  return m_layer->hasChildren();
109 }
110 
111 bool te::qt::widgets::FolderLayerItem::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 "FOLDER_LAYER_ITEM";
137 }
te::map::FolderLayerPtr m_layer
The class that represents a folder layer item in a LayerTreeModel.
te::map::AbstractLayerPtr getLayer() const
The class that represents an item in a LayerTreeModel.
A layer that can be used as a container for other kind of layers.
Definition: FolderLayer.h:45
FolderLayerItem(const te::map::AbstractLayerPtr &l, QObject *parent=0)
A class for building layer items.
QMenu * getMenu(QWidget *parent=0) const
QVariant data(int column, int role) const
static AbstractTreeItem * make(const te::map::AbstractLayerPtr &layer, QObject *parent)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
std::list< TreeItemPtr >::const_iterator const_iterator
Definition: TreeItem.h:67
const std::string getItemType() const
It returns the item type: "FOLDER_LAYER_ITEM".
bool setData(int column, const QVariant &value, int role=Qt::EditRole)