All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ColorMapSliceItem.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/ColorMapSliceItem.cpp
22 
23  \brief A class that represents a grouping item of a color map in a LayerTreeModel.
24 */
25 
26 // TerraLib
27 #include "../../se/SymbologyPreview.h"
28 #include "ColorMapSliceItem.h"
29 
30 // Qt
31 #include <QMenu>
32 #include <QPainter>
33 #include <QWidget>
34 
35 
37  : AbstractTreeItem(parent),
38  m_min(min),
39  m_max(max),
40  m_rgbaColor(c),
41  m_categorize(true),
42  m_interpolate(false),
43  m_isCheckable(false),
44  m_isChecked(false)
45 {
46 }
47 
49  : AbstractTreeItem(parent),
50  m_min(min),
51  m_max(max),
52  m_rgbaColorBegin(cBegin),
53  m_rgbaColorEnd(cEnd),
54  m_categorize(false),
55  m_interpolate(true),
56  m_isCheckable(false),
57  m_isChecked(false)
58 {
59 }
60 
62 {
63 }
64 
66 {
67  return 1;
68 }
69 
70 QVariant te::qt::widgets::ColorMapSliceItem::data(int /*column*/, int role) const
71 {
72  if(role == Qt::DecorationRole)
73  {
74  if(m_categorize)
75  {
76  QPixmap pix(16, 16);
77  pix.fill(QColor(m_rgbaColor.getRed(), m_rgbaColor.getGreen(), m_rgbaColor.getBlue()));
78  QIcon icon(pix);
79  return QVariant(icon);
80  }
81 
82  if(m_interpolate)
83  {
84  QPixmap pix(16, 16);
85  QPainter p(&pix);
86 
87  p.fillRect(0,0,8, 16, QColor(m_rgbaColorBegin.getRed(), m_rgbaColorBegin.getGreen(), m_rgbaColorBegin.getBlue()));
88  p.fillRect(8,0,8, 16, QColor(m_rgbaColorEnd.getRed(), m_rgbaColorEnd.getGreen(), m_rgbaColorEnd.getBlue()));
89 
90  QIcon icon(pix);
91  return QVariant(icon);
92  }
93  }
94 
95  if(role == Qt::DisplayRole)
96  {
97  QString title;
98 
99  QString strMin;
100  strMin.setNum(m_min);
101 
102  QString strMax;
103  strMax.setNum(m_max);
104 
105  title.append(strMin);
106  title.append(" - ");
107  title.append(strMax);
108 
109  return QVariant(title);
110  }
111 
112  if(role == Qt::CheckStateRole && m_isCheckable)
113  return QVariant(m_isChecked ? Qt::Checked : Qt::Unchecked);
114 
115  return QVariant();
116 }
117 
118 QMenu* te::qt::widgets::ColorMapSliceItem::getMenu(QWidget* /*parent*/) const
119 {
120  return 0;
121 }
122 
124 {
125  return false;
126 }
127 
129 {
130  return (m_isCheckable ? (Qt::ItemIsEnabled | Qt::ItemIsUserCheckable) : Qt::ItemIsEnabled);
131 }
132 
134 {
135 }
136 
138 {
139  return false;
140 }
141 
142 bool te::qt::widgets::ColorMapSliceItem::setData(int /*column*/, const QVariant& value, int role)
143 {
144  if(role == Qt::CheckStateRole && m_isCheckable)
145  {
146  bool ok = false;
147  Qt::CheckState checkState = static_cast<Qt::CheckState>(value.toInt(&ok));
148 
149  if(!ok)
150  return false;
151 
152  m_isChecked = (checkState == Qt::Checked ? true : false);
153  }
154 
155  return false;
156 }
157 
159 {
160  return te::map::AbstractLayerPtr(0);
161 }
162 
164 {
165  return "COLORMAP_SLICE_ITEM";
166 }
167 
169 {
170  m_isCheckable = false;
171 }
172 
174 {
175  return false;
176 }
The class that represents an item in a LayerTreeModel.
const std::string getItemType() const
It returns the item type: "COLORMAP_SLICE_ITEM".
bool setData(int column, const QVariant &value, int role=Qt::EditRole)
ColorMapSliceItem(double min, double max, te::color::RGBAColor c, QObject *parent=0)
QMenu * getMenu(QWidget *parent=0) const
QVariant data(int column, int role) const
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
te::map::AbstractLayerPtr getLayer() const
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
A class that represents a grouping item of a color map in a LayerTreeModel.