All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ChartItem.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/ChartItem.cpp
22 
23  \brief A class that represents a chart of a layer in a LayerTreeModel.
24 */
25 
26 // TerraLib
27 #include "../../../../maptools/Chart.h"
28 #include "../../Utils.h"
29 #include "ChartItem.h"
30 #include "ChartSliceItem.h"
31 
32 // Qt
33 #include <QMenu>
34 
35 // STL
36 #include <vector>
37 
39  : AbstractTreeItem(parent),
40  m_chart(chart),
41  m_isCheckable(true),
42  m_isChecked(true)
43 {
44 }
45 
47 {
48 }
49 
51 {
52  return 1;
53 }
54 
55 QVariant te::qt::widgets::ChartItem::data(int /*column*/, int role) const
56 {
57  if(role == Qt::DecorationRole)
58  return QVariant(QIcon::fromTheme("chart-pie"));
59 
60  if(role == Qt::DisplayRole)
61  {
62  switch(m_chart->getType())
63  {
64  case te::map::Pie:
65  return QVariant(tr("Pie Chart"));
66 
67  case te::map::Bar:
68  return QVariant(tr("Bar Chart"));
69 
70  default:
71  return QVariant(tr("Chart"));
72  }
73  }
74 
75  if(role == Qt::CheckStateRole && m_isCheckable)
76  return QVariant(m_isChecked ? Qt::Checked : Qt::Unchecked);
77 
78  return QVariant();
79 }
80 
81 QMenu* te::qt::widgets::ChartItem::getMenu(QWidget* /*parent*/) const
82 {
83  return 0;
84 }
85 
87 {
88  return !m_chart->getProperties().empty() && children().isEmpty();
89 }
90 
91 Qt::ItemFlags te::qt::widgets::ChartItem::flags() const
92 {
93  return (m_isCheckable ? (Qt::ItemIsEnabled | Qt::ItemIsUserCheckable) : Qt::ItemIsEnabled);
94 }
95 
97 {
98  if(!children().isEmpty())
99  return;
100 
101  int contourWidth = static_cast<int>(m_chart->getContourWidth());
102  QColor contourColor = Convert2Qt(m_chart->getContourColor());
103 
104  const std::vector<std::string>& properties = m_chart->getProperties();
105 
106  for(std::size_t i = 0; i < properties.size(); ++i)
107  {
108  QColor color = Convert2Qt(m_chart->getColor(i));
109  new ChartSliceItem(properties[i].c_str(), color, contourColor, contourWidth, this);
110  }
111 }
112 
114 {
115  return !m_chart->getProperties().empty();
116 }
117 
118 bool te::qt::widgets::ChartItem::setData(int /*column*/, const QVariant& value, int role)
119 {
120  if(role == Qt::CheckStateRole && m_isCheckable)
121  {
122  bool ok = false;
123  Qt::CheckState checkState = static_cast<Qt::CheckState>(value.toInt(&ok));
124 
125  if(!ok)
126  return false;
127 
128  m_isChecked = (checkState == Qt::Checked ? true : false);
129 
130  m_chart->setVisibility(m_isChecked);
131 
132  return true;
133  }
134 
135  return false;
136 }
137 
139 {
140  return te::map::AbstractLayerPtr(0);
141 }
142 
144 {
145  return "CHART_ITEM";
146 }
147 
149 {
150  m_isCheckable = checkable;
151 }
152 
154 {
155  return m_isCheckable;
156 }
const std::string getItemType() const
It returns the item type: "CHART_ITEM".
Definition: ChartItem.cpp:143
void setCheckable(bool checkable)
Definition: ChartItem.cpp:148
Qt::ItemFlags flags() const
Definition: ChartItem.cpp:91
The class that represents an item in a LayerTreeModel.
te::map::AbstractLayerPtr getLayer() const
Definition: ChartItem.cpp:138
QVariant data(int column, int role) const
Definition: ChartItem.cpp:55
This class represents the informations needed to build map charts.
Definition: Chart.h:51
QMenu * getMenu(QWidget *parent=0) const
Definition: ChartItem.cpp:81
A class that represents a chart of a layer in a LayerTreeModel.
bool canFetchMore() const
Definition: ChartItem.cpp:86
ChartItem(te::map::Chart *chart, QObject *parent=0)
Definition: ChartItem.cpp:38
TEQTWIDGETSEXPORT QColor Convert2Qt(const te::color::RGBAColor &color)
It converts a TerraLib Color to Qt Color.
Definition: Utils.cpp:232
bool setData(int column, const QVariant &value, int role=Qt::EditRole)
Definition: ChartItem.cpp:118
A class that represents a chart slice in a LayerTreeModel.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr