ColorMapItem.cpp
Go to the documentation of this file.
1 #include "../../../../color/ColorBar.h"
2 #include "../../../../maptools/AbstractLayer.h"
3 #include "../../../../se/Categorize.h"
4 #include "../../../../se/ColorMap.h"
5 #include "../../../../se/Interpolate.h"
6 #include "../../../../se/InterpolationPoint.h"
7 #include "../../../../se/MapItem.h"
8 #include "../../../../se/RasterSymbolizer.h"
9 #include "../../../../se/Recode.h"
10 #include "../../../../se/Utils.h"
11 
12 #include "ColorMapSliceItem.h"
13 #include "ColorMapItem.h"
14 #include "LayerItem.h"
15 #include "RuleItem.h"
16 #include "StyleItem.h"
17 
18 #include <QObject>
19 #include <QString>
20 
22 {
23  if(cMap->getCategorize())
24  {
25  std::vector<te::se::ParameterValue*> t = cMap->getCategorize()->getThresholds();
26  std::vector<te::se::ParameterValue*> tV = cMap->getCategorize()->getThresholdValues();
27 
28  for(std::size_t i = 1; i < tV.size() - 1; ++i)
29  {
30  double lowerLimit, upperLimit;
31 
32  if(i == 0)
33  {
34  lowerLimit = std::numeric_limits<double>::min();
35  upperLimit = te::se::GetDouble(t[i]);
36  }
37  else if(i == tV.size() - 1)
38  {
39  lowerLimit = te::se::GetDouble(t[i - 1]);
40  upperLimit = std::numeric_limits<double>::max();
41  }
42  else
43  {
44  lowerLimit = te::se::GetDouble(t[i - 1]);
45  upperLimit = te::se::GetDouble(t[i]);
46  }
47 
48  QString title = QString::number(lowerLimit);
49  title.append(" - ");
50  title.append(QString::number(upperLimit));
51 
52  std::string colorName = te::se::GetString(tV[i]);
53  te::color::RGBAColor color(colorName);
54 
55  QColor qC(color.getRed(), color.getGreen(), color.getBlue());
56 
57  item->addChild(new te::qt::widgets::ColorMapSliceItem(title.toUtf8().data(), qC));
58  }
59  }
60  else if(cMap->getInterpolate())
61  {
62  std::vector<te::se::InterpolationPoint*> ip = cMap->getInterpolate()->getInterpolationPoints();
63 
64  for(std::size_t i = 0; i < ip.size() - 1; ++i)
65  {
66  te::se::InterpolationPoint* ipItemInit = ip[i];
67 
68  std::string colorName = te::se::GetString(ipItemInit->getValue());
69  te::color::RGBAColor colorInit(colorName);
70 
71  QColor qBeg(colorInit.getRed(), colorInit.getGreen(), colorInit.getBlue());
72  double lowerLimit = ipItemInit->getData();
73 
74  te::se::InterpolationPoint* ipItemEnd = ip[i + 1];
75 
76  colorName = te::se::GetString(ipItemEnd->getValue());
77  te::color::RGBAColor colorEnd(colorName);
78 
79  QColor qEnd(colorEnd.getRed(), colorEnd.getGreen(), colorEnd.getBlue());
80  double upperLimit = ipItemEnd->getData();
81 
82  QString title = QString::number(lowerLimit);
83  title.append(" - ");
84  title.append(QString::number(upperLimit));
85 
86  item->addChild(new te::qt::widgets::ColorMapSliceItem(title.toUtf8().data(), qBeg, qEnd));
87  }
88  }
89  else if (cMap->getRecode())
90  {
91  te::se::Recode* r = cMap->getRecode();
92  std::vector<te::se::MapItem*> mItems = r->getMapItems();
93 
94  for (std::size_t i = 0; i < mItems.size(); ++i)
95  {
96  double data = mItems[i]->getData();
97  std::string colorName = te::se::GetString(mItems[i]->getValue());
98  std::string title = mItems[i]->getTitle();
99 
100  if (title.empty())
101  title = QString::number(data).toUtf8().data();
102 
103  te::color::RGBAColor color(colorName);
104 
105  QColor qC(color.getRed(), color.getGreen(), color.getBlue());
106 
107  item->addChild(new te::qt::widgets::ColorMapSliceItem(title, qC));
108  }
109  }
110 }
111 
113  TreeItem("COLORMAP"),
114  m_colorMap(map)
115 {
116  QString type;
117 
118  if(map->getCategorize())
119  type = QObject::tr("Categorization");
120  else if(map->getInterpolate())
121  type = QObject::tr("Interpolation");
122  else if (map->getRecode())
123  type = QObject::tr("Recode");
124 
125  m_label = type.toUtf8().data();
126 
127  AddSliceItems(this, m_colorMap);
128 }
129 
131 
133 {
134  return m_label;
135 }
136 
138 {
139  return Qt::ItemIsEnabled;
140 }
ParameterValue * getValue() const
Qt::ItemFlags flags()
Returns the flags to be used by the model.
int getRed() const
It returns the red component color value (a value from 0 to 255).
Definition: RGBAColor.h:307
Interpolate * getInterpolate() const
Definition: ColorMap.cpp:84
A class that represents a style of a layer in a LayerTreeModel.
int getBlue() const
It returns the blue component color value (a value from 0 to 255).
Definition: RGBAColor.h:317
int getGreen() const
It returns the green component color value (a value from 0 to 255).
Definition: RGBAColor.h:312
const std::vector< InterpolationPoint * > & getInterpolationPoints() const
Definition: Interpolate.cpp:91
TESEEXPORT double GetDouble(const te::se::ParameterValue *param)
It gets the parameter value as a double.
Defines a hierarchical structure.
const std::vector< ParameterValue * > & getThresholds() const
Definition: Categorize.cpp:109
ColorMapItem(const te::se::ColorMap *map)
Constructor.
void AddSliceItems(te::qt::widgets::ColorMapItem *item, const te::se::ColorMap *cMap)
const te::se::ColorMap * m_colorMap
ColorMap being used.
Definition: ColorMapItem.h:88
std::string getAsString() const
Returns the label of the item to be presented in a Qt view.
void addChild(TreeItem *item)
Adds a child to the item. The child is added to the end of the list.
Recode * getRecode() const
Definition: ColorMap.cpp:95
Transformation of discrete values to other values.
Definition: Recode.h:75
A class that represents a slice of a ColorMapItem.
std::vector< MapItem * > getMapItems() const
Definition: Recode.cpp:73
They are used to define a graph of points.
Defines a rule item.
Represents a color map of rastersymbolizer of a layer in a LayerItemModel.
Definition: ColorMapItem.h:51
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
Defines a layer item.
Categorize * getCategorize() const
Definition: ColorMap.cpp:73
A class that represents a slice of a ColorMapItem.
TESEEXPORT std::string GetString(const te::se::ParameterValue *param)
It gets the parameter value as a string.
A ColorMap defines either the colors of a pallette-type raster source or the mapping of numeric pixel...
Definition: ColorMap.h:61
const std::vector< ParameterValue * > & getThresholdValues() const
Definition: Categorize.cpp:114
std::string m_label
Label to be presented on the Qt view.
Definition: ColorMapItem.h:87
A class that represents a color map of rastersymbolizer of a layer in a LayerItemModel.