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