All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ChartSliceItem.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/ChartSliceItem.cpp
22 
23  \brief A class that represents a chart slice in a LayerTreeModel.
24 */
25 
26 // TerraLib
27 #include "../../Utils.h"
28 #include "ChartSliceItem.h"
29 
30 // Qt
31 #include <QMenu>
32 #include <QWidget>
33 
34 te::qt::widgets::ChartSliceItem::ChartSliceItem(const QString& propertyName, const QColor& color,
35  const QColor& contourColor, int contourWidth,
36  QObject* parent)
37  : AbstractTreeItem(parent),
38  m_propertyName(propertyName),
39  m_color(color),
40  m_contourColor(contourColor),
41  m_contourWidth(contourWidth),
42  m_size(16),
43  m_isCheckable(false),
44  m_isChecked(false)
45 {
46 }
47 
49 {
50 }
51 
53 {
54  return 1;
55 }
56 
57 QVariant te::qt::widgets::ChartSliceItem::data(int /*column*/, int role) const
58 {
59  if(role == Qt::DecorationRole)
60  return QVariant(QIcon(CreatePixmapIcon(m_size, m_contourColor, m_color, m_contourWidth)));
61 
62  if(role == Qt::DisplayRole)
63  return QVariant(tr("Property") + ": " + m_propertyName);
64 
65  if(role == Qt::CheckStateRole && m_isCheckable)
66  return QVariant(m_isChecked ? Qt::Checked : Qt::Unchecked);
67 
68  return QVariant();
69 }
70 
71 QMenu* te::qt::widgets::ChartSliceItem::getMenu(QWidget* /*parent*/) const
72 {
73  return 0;
74 }
75 
77 {
78  return false;
79 }
80 
82 {
83  return (m_isCheckable ? (Qt::ItemIsEnabled | Qt::ItemIsUserCheckable) : Qt::ItemIsEnabled);
84 }
85 
87 {
88 }
89 
91 {
92  return false;
93 }
94 
95 bool te::qt::widgets::ChartSliceItem::setData(int /*column*/, const QVariant& value, int role)
96 {
97  if(role == Qt::CheckStateRole && m_isCheckable)
98  {
99  bool ok = false;
100  Qt::CheckState checkState = static_cast<Qt::CheckState>(value.toInt(&ok));
101 
102  if(!ok)
103  return false;
104 
105  m_isChecked = (checkState == Qt::Checked ? true : false);
106 
107  return true;
108  }
109 
110  return false;
111 }
112 
114 {
115  return te::map::AbstractLayerPtr(0);
116 }
117 
119 {
120  return "CHART_SLICE_ITEM";
121 }
122 
124 {
125  m_isCheckable = checkable;
126 }
127 
129 {
130  return m_isCheckable;
131 }
QVariant data(int column, int role) const
te::map::AbstractLayerPtr getLayer() const
ChartSliceItem(const QString &propertyName, const QColor &color, const QColor &contourColor, int contourWidth, QObject *parent=0)
The class that represents an item in a LayerTreeModel.
const std::string getItemType() const
It returns the item type: "CHART_SLICE_ITEM".
QMenu * getMenu(QWidget *parent=0) const
Qt::ItemFlags flags() const
bool setData(int column, const QVariant &value, int role=Qt::EditRole)
void setCheckable(bool checkable)
A class that represents a chart slice in a LayerTreeModel.
TEQTWIDGETSEXPORT QPixmap CreatePixmapIcon(const int &size, const QColor &penColor, const QColor &brushColor, const int &contourSize)
It creates a pixmap to use as icon (to be used as legend icon).
Definition: Utils.cpp:340
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr