All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ColorMapItem.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/ColorMapItem.cpp
22 
23  \brief A class that represents a color map of rastersymbolizer of a layer in a LayerTreeModel.
24 */
25 
26 // TerraLib
27 #include "../../../../color/ColorBar.h"
28 #include "../../../../se/Categorize.h"
29 #include "../../../../se/ColorMap.h"
30 #include "../../../../se/Interpolate.h"
31 #include "../../../../se/InterpolationPoint.h"
32 #include "../../../../se/Utils.h"
33 #include "ColorMapSliceItem.h"
34 #include "ColorMapItem.h"
35 
36 // Qt
37 #include <QMenu>
38 #include <QWidget>
39 
41  : AbstractTreeItem(parent),
42  m_colorMap(cm),
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::ColorMapItem::data(int /*column*/, int role) const
58 {
59  if(role == Qt::DecorationRole)
60  return QVariant(QIcon::fromTheme("grouping"));
61 
62  if(role == Qt::DisplayRole)
63  {
64  QString type;
65 
66  if(m_colorMap->getCategorize())
67  {
68  type = tr("Categorization");
69  }
70  else if(m_colorMap->getInterpolate())
71  {
72  type = tr("Interpolation");
73  }
74 
75  QString text = tr("Classification by") + " " + type;
76  return QVariant(text);
77  }
78 
79  if(role == Qt::CheckStateRole && m_isCheckable)
80  return QVariant(m_isChecked ? Qt::Checked : Qt::Unchecked);
81 
82  return QVariant();
83 }
84 
85 QMenu* te::qt::widgets::ColorMapItem::getMenu(QWidget* /*parent*/) const
86 {
87  return 0;
88 }
89 
91 {
92  return (m_colorMap->getCategorize() || m_colorMap->getInterpolate()) && children().isEmpty();
93 }
94 
96 {
97  return (m_isCheckable ? (Qt::ItemIsEnabled | Qt::ItemIsUserCheckable) : Qt::ItemIsEnabled);
98 }
99 
101 {
102  if(!children().isEmpty())
103  return;
104 
105  if(m_colorMap->getCategorize())
106  {
107  std::vector<te::se::ParameterValue*> t = m_colorMap->getCategorize()->getThresholds();
108  std::vector<te::se::ParameterValue*> tV = m_colorMap->getCategorize()->getThresholdValues();
109 
110  for(std::size_t i = 1; i < tV.size() - 1; ++i)
111  {
112  double lowerLimit, upperLimit;
113 
114  if(i == 0)
115  {
116  lowerLimit = std::numeric_limits<double>::min();
117  upperLimit = te::se::GetDouble(t[i]);
118  }
119  else if(i == tV.size() - 1)
120  {
121  lowerLimit = te::se::GetDouble(t[i - 1]);
122  upperLimit = std::numeric_limits<double>::max();
123  }
124  else
125  {
126  lowerLimit = te::se::GetDouble(t[i - 1]);
127  upperLimit = te::se::GetDouble(t[i]);
128  }
129 
130  std::string colorName = te::se::GetString(tV[i]);
131  te::color::RGBAColor color(colorName);
132  color.setColor(color.getRed(), color.getGreen(), color.getBlue());
133 
134  new ColorMapSliceItem(lowerLimit, upperLimit, color, this);
135  }
136  }
137  else if(m_colorMap->getInterpolate())
138  {
139  std::vector<te::se::InterpolationPoint*> ip = m_colorMap->getInterpolate()->getInterpolationPoints();
140 
141  for(std::size_t i = 0; i < ip.size() - 1; ++i)
142  {
143  te::se::InterpolationPoint* ipItemInit = ip[i];
144 
145  std::string colorName = te::se::GetString(ipItemInit->getValue());
146  te::color::RGBAColor colorInit(colorName);
147  colorInit.setColor(colorInit.getRed(), colorInit.getGreen(), colorInit.getBlue());
148  double lowerLimit = ipItemInit->getData();
149 
150  te::se::InterpolationPoint* ipItemEnd = ip[i + 1];
151 
152  colorName = te::se::GetString(ipItemEnd->getValue());
153  te::color::RGBAColor colorEnd(colorName);
154  colorEnd.setColor(colorEnd.getRed(), colorEnd.getGreen(), colorEnd.getBlue());
155  double upperLimit = ipItemEnd->getData();
156 
157  new ColorMapSliceItem(lowerLimit, upperLimit, colorInit, colorEnd, this);
158  }
159  }
160 }
161 
163 {
164  if(m_colorMap->getCategorize())
165  {
166  return !m_colorMap->getCategorize()->getThresholdValues().empty();
167  }
168 
169  if(m_colorMap->getInterpolate())
170  {
171  return !m_colorMap->getInterpolate()->getInterpolationPoints().empty();
172  }
173 
174  return false;
175 }
176 
177 bool te::qt::widgets::ColorMapItem::setData(int /*column*/, const QVariant& value, int role)
178 {
179  if(role == Qt::CheckStateRole && m_isCheckable)
180  {
181  bool ok = false;
182  Qt::CheckState checkState = static_cast<Qt::CheckState>(value.toInt(&ok));
183 
184  if(!ok)
185  return false;
186 
187  m_isChecked = (checkState == Qt::Checked ? true : false);
188 
189  return true;
190  }
191 
192  return false;
193 }
194 
196 {
197  return te::map::AbstractLayerPtr(0);
198 }
199 
201 {
202  return "COLORMAP_ITEM";
203 }
204 
206 {
207  m_isCheckable = false;
208 }
209 
211 {
212  return false;
213 }
ParameterValue * getValue() const
void setColor(const std::string &hexColor)
It sets the color using a two hexadecimal RGB-encoded color.
Definition: RGBAColor.h:329
int getRed() const
It returns the red component color value (a value from 0 to 255).
Definition: RGBAColor.h:295
ColorMapItem(te::se::ColorMap *cm, QObject *parent=0)
int getBlue() const
It returns the blue component color value (a value from 0 to 255).
Definition: RGBAColor.h:305
The class that represents an item in a LayerTreeModel.
int getGreen() const
It returns the green component color value (a value from 0 to 255).
Definition: RGBAColor.h:300
TESEEXPORT double GetDouble(const te::se::ParameterValue *param)
It gets the parameter value as a double.
Definition: Utils.cpp:448
const std::string getItemType() const
It returns the item type: "COLORMAP_ITEM".
Qt::ItemFlags flags() const
void setCheckable(bool checkable)
QMenu * getMenu(QWidget *parent=0) const
They are used to define a graph of points.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
bool setData(int column, const QVariant &value, int role=Qt::EditRole)
QVariant data(int column, int role) const
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
A class that represents a grouping item of a color map in a LayerTreeModel.
TESEEXPORT std::string GetString(const te::se::ParameterValue *param)
It gets the parameter value as a string.
Definition: Utils.cpp:453
A ColorMap defines either the colors of a pallette-type raster source or the mapping of numeric pixel...
Definition: ColorMap.h:60
te::map::AbstractLayerPtr getLayer() const
A class that represents a color map of rastersymbolizer of a layer in a LayerTreeModel.