STItemDelegate.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2001-2013 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 #include "STItemDelegate.h"
21 
22 // TerraLib
23 #include "../../widgets/layer/explorer/LayerItem.h"
24 
25 te::qt::plugins::st::STItemDelegate::STItemDelegate(QStyledItemDelegate* decorated, QObject* parent) :
26  te::common::Decorator<QStyledItemDelegate>(decorated, false)
27 {
28  setParent(parent);
29 
30  m_obsIcon = QIcon::fromTheme("observation-layer");
31  m_tmsIcon = QIcon::fromTheme("timeseries-layer");
32  m_trjIcon = QIcon::fromTheme("trajectory-layer");
33 }
34 
36 
37 void te::qt::plugins::st::STItemDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
38 {
39  te::qt::widgets::TreeItem* item = static_cast<te::qt::widgets::TreeItem*>(index.internalPointer());
40 
41  if(item->getType() == "LAYER")
42  {
44 
45  if(li->getLayer()->isValid())
46  {
47  QIcon ic = getIcon(li->getLayer().get());
48 
49  if(!ic.isNull())
50  {
51  QStyleOptionViewItem opt = option;
52  opt.decorationSize = QSize(16, 16);
53  opt.features |= QStyleOptionViewItem::HasDecoration;
54 
55  opt.icon = ic;
56 
57  QStyledItemDelegate::paint(painter, opt, index);
58 
59  return;
60  }
61  }
62  }
63 
64  if(m_decorated != 0)
65  m_decorated->paint(painter, option, index);
66  else
67  QStyledItemDelegate::paint(painter, option, index);
68 }
69 
71 {
72  return (l->getType() == "TRAJECTORYDATASETLAYER") ? m_trjIcon :
73  (l->getType() == "OBSERVATIONDATASETLAYER") ? m_obsIcon :
74  (l->getType() == "TIMESERIESDATASETLAYER") ? m_tmsIcon :
75  QIcon();
76 }
This is the base class for layers.
Definition: AbstractLayer.h:77
An item that contains a te::map::AbstractLayerPtr.
Definition: LayerItem.h:51
virtual const std::string & getType() const =0
It returns the layer type.
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
te::map::AbstractLayerPtr getLayer() const
Returns the layer contained in the item.
Definition: LayerItem.cpp:140
Defines a hierarchical structure.
QStyledItemDelegate * m_decorated
The object decorated.
Definition: Decorator.h:98
URI C++ Library.
Definition: Attributes.h:37
QIcon getIcon(const te::map::AbstractLayer *l) const
STItemDelegate(QStyledItemDelegate *decorated, QObject *parent=0)
std::string getType() const
Returns the type of the item.
void paint(te::qt::widgets::Canvas *c, bool generatePNG, std::string fileName)