All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GroupingItem.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/GroupingItem.cpp
22 
23  \brief A class that represents a grouping of a layer in a LayerTreeModel.
24 */
25 
26 // TerraLib
27 #include "../../../../maptools/Grouping.h"
28 #include "GroupingSliceItem.h"
29 #include "GroupingItem.h"
30 
31 // Qt
32 #include <QMenu>
33 #include <QWidget>
34 
36  : AbstractTreeItem(parent),
37  m_grouping(grouping),
38  m_isCheckable(true),
39  m_isChecked(true)
40 {
41 }
42 
44 {
45 }
46 
48 {
49  return 1;
50 }
51 
52 QVariant te::qt::widgets::GroupingItem::data(int /*column*/, int role) const
53 {
54  if(role == Qt::DecorationRole)
55  return QVariant(QIcon::fromTheme("grouping"));
56 
57  if(role == Qt::DisplayRole)
58  {
59  QString text = tr("Classification by") + " " + m_grouping->getPropertyName().c_str();
60  return QVariant(text);
61  }
62 
63  if(role == Qt::CheckStateRole && m_isCheckable)
64  return QVariant(m_isChecked ? Qt::Checked : Qt::Unchecked);
65 
66  return QVariant();
67 }
68 
69 QMenu* te::qt::widgets::GroupingItem::getMenu(QWidget* /*parent*/) const
70 {
71  return 0;
72 }
73 
75 {
76  return !m_grouping->getGroupingItems().empty() && children().isEmpty();
77 }
78 
80 {
81  return (m_isCheckable ? (Qt::ItemIsEnabled | Qt::ItemIsUserCheckable) : Qt::ItemIsEnabled);
82 }
83 
85 {
86  if(!children().isEmpty())
87  return;
88 
89  const std::vector<te::map::GroupingItem*> items = m_grouping->getGroupingItems();
90  for(std::size_t i = 0; i < items.size(); ++i)
91  new GroupingSliceItem(items[i], this);
92 }
93 
95 {
96  return !m_grouping->getGroupingItems().empty();
97 }
98 
99 bool te::qt::widgets::GroupingItem::setData(int /*column*/, const QVariant& value, int role)
100 {
101  if(role == Qt::CheckStateRole && m_isCheckable)
102  {
103  bool ok = false;
104  Qt::CheckState checkState = static_cast<Qt::CheckState>(value.toInt(&ok));
105 
106  if(!ok)
107  return false;
108 
109  m_isChecked = (checkState == Qt::Checked ? true : false);
110 
111  m_grouping->setVisibility(m_isChecked);
112 
113  return true;
114  }
115 
116  return false;
117 }
118 
120 {
121  return te::map::AbstractLayerPtr(0);
122 }
123 
125 {
126  return "GROUPING_ITEM";
127 }
128 
130 {
131  m_isCheckable = checkable;
132 }
133 
135 {
136  return m_isCheckable;
137 }
GroupingItem(te::map::Grouping *grouping, QObject *parent=0)
const std::string getItemType() const
It returns the item type: "GROUPING_ITEM".
A class that represents a grouping of a layer in a LayerTreeModel.
The class that represents an item in a LayerTreeModel.
void setCheckable(bool checkable)
QVariant data(int column, int role) const
This class contains the parameters needed for grouping the values of a Property.
Definition: Grouping.h:59
QMenu * getMenu(QWidget *parent=0) const
bool setData(int column, const QVariant &value, int role=Qt::EditRole)
te::map::AbstractLayerPtr getLayer() const
Qt::ItemFlags flags() const
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
A class that represents a grouping item of a grouping in a LayerTreeModel.