ChartItem.cpp
Go to the documentation of this file.
1 #include "../../../../color/RGBAColor.h"
2 #include "../../../../maptools/AbstractLayer.h"
3 #include "../../../../maptools/Chart.h"
4 //#include "../../../../se/Categorize.h"
5 //#include "../../../../se/ColorMap.h"
6 //#include "../../../../se/Interpolate.h"
7 //#include "../../../../se/InterpolationPoint.h"
8 //#include "../../../../se/RasterSymbolizer.h"
9 //#include "../../../../se/Utils.h"
10 
11 #include "ChartItem.h"
12 #include "ChartSliceItem.h"
13 #include "LayerItem.h"
14 
15 #include <QColor>
16 #include <QObject>
17 
19 {
20  int contourWidth = (int)chart->getContourWidth();
21  QColor contourColor(chart->getContourColor().getRed(), chart->getContourColor().getGreen(), chart->getContourColor().getBlue());
22 
23  std::vector<std::string> properties = chart->getProperties();
24 
25  for(std::size_t i = 0; i < properties.size(); ++i)
26  {
27  te::color::RGBAColor c = chart->getColor(i);
28  QColor color(c.getRed(), c.getGreen(), c.getBlue());
29  item->addChild(new te::qt::widgets::ChartSliceItem(properties[i].c_str(), color, contourColor, contourWidth));
30  }
31 }
32 
34  TreeItem("CHART"),
35  m_chart(chart)
36 {
37  switch(m_chart->getType())
38  {
39  case te::map::Pie:
40  m_label = QObject::tr("Pie Chart").toUtf8().data();
41  break;
42 
43  case te::map::Bar:
44  m_label = QObject::tr("Bar Chart").toUtf8().data();
45  break;
46 
47  default:
48  m_label = QObject::tr("Chart").toUtf8().data();
49  }
50 
51  AddSliceItems(this, m_chart);
52 }
53 
55 {
56  if(m_parent == nullptr)
57  return;
58 
59  te::map::AbstractLayerPtr layer = ((LayerItem*)m_parent)->getLayer();
60 
61  te::map::Chart* chart = layer->getChart();
62 
63  if(chart == m_chart)
64  layer->setChart(nullptr);
65 }
66 
68 {
69  return m_label;
70 }
71 
73 {
74  return m_chart->isVisible() ? TOTALLY : NONE;
75 }
76 
77 void te::qt::widgets::ChartItem::setVisible(const VISIBLE& visible, const bool&, const bool&)
78 {
79  m_chart->setVisibility(visible == TOTALLY ? true : false);
80 }
81 
83 {
84  return TreeItem::flags() | Qt::ItemIsUserCheckable;
85 }
ChartType getType() const
Definition: Chart.cpp:92
const std::vector< std::string > & getProperties() const
Definition: Chart.cpp:97
TreeItem * m_parent
Pointer to the parent.
te::map::Chart * m_chart
Chart being used.
Definition: ChartItem.h:91
int getRed() const
It returns the red component color value (a value from 0 to 255).
Definition: RGBAColor.h:307
An item that contains a te::map::AbstractLayerPtr.
Definition: LayerItem.h:51
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
void setVisible(const VISIBLE &visible, const bool &updateAncestors=false, const bool &updateDescendents=false)
Updates the visibilty state of the item.
Definition: ChartItem.cpp:77
Defines a hierarchical structure.
std::string m_label
Label to be presented on the Qt view.
Definition: ChartItem.h:90
const te::color::RGBAColor & getColor(std::size_t i) const
Definition: Chart.cpp:112
This class represents the informations needed to build map charts.
Definition: Chart.h:51
A class that represents a chart of a layer in a LayerTreeModel.
Definition: ChartItem.h:50
bool isVisible() const
It gets the chart visibility.
Definition: Chart.cpp:191
void setVisibility(bool visible)
It sets the chart visibility.
Definition: Chart.cpp:196
void addChild(TreeItem *item)
Adds a child to the item. The child is added to the end of the list.
~ChartItem()
Destructor.
Definition: ChartItem.cpp:54
A class that represents a chart slice in a LayerItemModel.
ChartItem(te::map::Chart *chart)
Constructor.
Definition: ChartItem.cpp:33
VISIBLE isVisible() const
Returns the visibilty state of the item.
Definition: ChartItem.cpp:72
VISIBLE
Defines the visibility of an item.
std::size_t getContourWidth() const
Definition: Chart.cpp:136
const te::color::RGBAColor & getContourColor() const
Definition: Chart.cpp:126
A class that represents a chart of a layer in a LayerTreeModel.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
Defines a layer item.
A class that represents a chart slice in a LayerItemModel.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
std::string getAsString() const
Returns the label of the item to be presented in a Qt view.
Definition: ChartItem.cpp:67
virtual Qt::ItemFlags flags()
Returns the flags to be used by the model.
Qt::ItemFlags flags()
Returns the flags to be used by the model.
Definition: ChartItem.cpp:82
void AddSliceItems(te::qt::widgets::ChartItem *item, const te::map::Chart *chart)
Definition: ChartItem.cpp:18