LayerViewDelegate.cpp
Go to the documentation of this file.
1 #include "LayerViewDelegate.h"
2 #include "LayerItem.h"
3 #include "LegendItem.h"
4 #include "ColorMapSliceItem.h"
5 #include "ChartSliceItem.h"
6 #include "RuleItem.h"
7 
8 #include "../../../../maptools/AbstractLayer.h"
9 
10 te::qt::widgets::LayerViewDelegate::LayerViewDelegate(QStyledItemDelegate* decorated, QObject* parent):
11 te::common::Decorator<QStyledItemDelegate>(decorated)
12 {
13  setParent(parent);
14 
15  m_layer = QIcon::fromTheme("dataset-layer");
16  m_folder = QIcon::fromTheme("folder");
17  m_style = QIcon::fromTheme("style");
18  m_colorMap = QIcon::fromTheme("grouping");
19  m_chart = QIcon::fromTheme("chart-pie");
20  m_queryLayer = QIcon::fromTheme("query-layer");
21  m_tabularLayer = QIcon::fromTheme("dataset-layer-tabular");
22  m_invalidLayer = QIcon::fromTheme("dataset-layer-invalid");
23 }
24 
26 
27 void te::qt::widgets::LayerViewDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
28 {
29  QStyleOptionViewItem opt(option);
30 
31  if(!index.isValid())
32  return;
33 
34  TreeItem* item = static_cast<TreeItem*>(index.internalPointer());
35 
36  QIcon ic = (item->getType() == "LEGEND") ? ((LegendItem*)item)->getIcon() :
37  (item->getType() == "RULE") ? ((RuleItem*)item)->getIcon() :
38  (item->getType() == "STYLE") ? m_style :
39  (item->getType() == "COLORMAP" || item->getType() == "GROUPING") ? m_colorMap :
40  (item->getType() == "COLORMAPSLICE") ? ((ColorMapSliceItem*)item)->getIcon() :
41  (item->getType() == "CHART") ? m_chart :
42  (item->getType() == "CHARTSLICE") ? ((ChartSliceItem*)item)->getIcon() :
43  (item->getType() == "FOLDER") ? m_folder : getIcon(index);
44 
45  QSize s(20, 20);
46 
47 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
48  if(opt.icon.isNull())
49  opt.icon = ic;
50 #endif
51 
52  opt.decorationSize = s;
53 
54 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
55  opt.features |= QStyleOptionViewItem::HasDecoration;
56 #endif
57 
58  if(m_decorated != nullptr)
59  {
60  m_decorated->paint(painter, opt, index);
61  return;
62  }
63 
64  QStyledItemDelegate::paint(painter, opt, index);
65 }
66 
67 QIcon te::qt::widgets::LayerViewDelegate::getIcon(const QModelIndex & index) const
68 {
69  if(!index.isValid())
70  throw;
71 
72  TreeItem* item = static_cast<TreeItem*>(index.internalPointer());
73 
74  if(item->getType() != "LAYER")
75  throw;
76 
77  te::map::AbstractLayerPtr l = ((LayerItem*)item)->getLayer();
78 
79  if(!l->isValid())
80  return m_invalidLayer;
81 
82  if(l->getType() == "QUERYLAYER")
83  return m_queryLayer;
84 
85  std::unique_ptr<te::da::DataSetType> schema = l->getSchema();
86 
87  if(schema.get())
88  {
89  if ((!schema->hasGeom() && !schema->hasRaster()) || l->getType() == "DATASETADAPTERLAYER")
90  return m_tabularLayer;
91  }
92 
93  return m_layer;
94 }
if(WIN32) add_definitions(-D_SCL_SECURE_NO_WARNINGS-DTEWCSDLL) endif() file(GLOB TERRALIB_SRC_FILES $
pthread endif() include_directories($
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
An item that contains a te::map::AbstractLayerPtr.
Definition: LayerItem.h:51
QIcon m_invalidLayer
Icon for an invalid layers.
Defines a legend item.
Represents a lengend in the tree structure.
Definition: LegendItem.h:53
QIcon m_layer
Icon for a layer not invalid.
Defines a hierarchical structure.
QIcon m_queryLayer
Icon for a query layer.
QStyledItemDelegate * m_decorated
The object decorated.
Definition: Decorator.h:98
URI C++ Library.
Definition: Attributes.h:37
QIcon getIcon(const QModelIndex &index) const
Returns the icon for a given index.
QIcon m_folder
Icon for a folder.
A class for rendering icons for layer and folder itens.
Represents a lengend in the tree structure.
Definition: RuleItem.h:53
A class that represents a chart slice in a LayerItemModel.
A class that represents a slice of a ColorMapItem.
QIcon m_colorMap
Icon for a ColorMap.
Defines a rule item.
Defines a layer item.
A class that represents a chart slice in a LayerItemModel.
QIcon m_tabularLayer
Icon for a tabular layer.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
A class that represents a slice of a ColorMapItem.
std::string getType() const
Returns the type of the item.
LayerViewDelegate(QStyledItemDelegate *decorated, QObject *parent=0)
Constructor.
void paint(te::qt::widgets::Canvas *c, bool generatePNG, std::string fileName)