All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
LegendItem.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/LegendItem.cpp
22 
23  \brief ???
24 */
25 
26 // TerraLib
27 #include "../../../../common/Translator.h"
28 #include "../../../../se/Description.h"
29 #include "../../../../se/Rule.h"
30 #include "../../se/SymbologyPreview.h"
31 #include "../../Exception.h"
32 #include "LegendItem.h"
33 
34 // Qt
35 #include <QMenu>
36 #include <QPixmap>
37 #include <QWidget>
38 
40  : AbstractTreeItem(parent),
41  m_rule(rule),
42  m_isCheckable(false),
43  m_isChecked(false)
44 {
45 }
46 
48 {
49 }
50 
52 {
53  return 1;
54 }
55 
56 QVariant te::qt::widgets::LegendItem::data(int column, int role) const
57 {
58  if(role == Qt::DecorationRole && column == 0)
59  {
60  return QVariant(QIcon(SymbologyPreview::build(m_rule, QSize(16, 16))));
61  }
62 
63  if(role == Qt::DisplayRole)
64  {
65  if(column == 0)
66  {
67  if(m_rule->getDescription())
68  return QVariant(QString::fromStdString(m_rule->getDescription()->getTitle()));
69 
70  if(m_rule->getName())
71  return QVariant(QString::fromStdString(*(m_rule->getName())));
72 
73  return QVariant(QString(tr("Style")));
74  }
75  }
76 
77  if(role == Qt::CheckStateRole && m_isCheckable && column == 0)
78  return QVariant(m_isChecked ? Qt::Checked : Qt::Unchecked);
79 
80  //if(role == Qt::CheckStateRole)
81  // return QVariant(m_layer->getVisibility() == te::map::VISIBLE ? Qt::Checked : Qt::Unchecked);
82 
83  return QVariant();
84 }
85 
86 QMenu* te::qt::widgets::LegendItem::getMenu(QWidget* /*parent*/) const
87 {
88  //QMenu* m = new QMenu(parent);
89 
90  //QAction* aOpenDataSource = m->addAction(tr("&Open data source"));
91 
92  //connect(aOpenDataSource, SIGNAL(triggered()), this, SLOT(openDataSource()));
93 
94  //return m;
95  return 0;
96 }
97 
99 {
100  return false;
101 }
102 
104 {
105  return (m_isCheckable ? (Qt::ItemIsEnabled | Qt::ItemIsUserCheckable) : Qt::ItemIsEnabled);
106 }
107 
109 {
110 }
111 
113 {
114  return false;
115 }
116 
117 bool te::qt::widgets::LegendItem::setData(int column, const QVariant& value, int role)
118 {
119  if(role == Qt::CheckStateRole && m_isCheckable)
120  {
121  bool ok = false;
122  Qt::CheckState checkState = static_cast<Qt::CheckState>(value.toInt(&ok));
123 
124  if(!ok)
125  return false;
126 
127  m_isChecked = (checkState == Qt::Checked ? true : false);
128  }
129 
130  //if(role == Qt::CheckStateRole)
131  //{
132  // bool vis = value.toBool();
133 
134  // m_layer->setVisibility(vis ? te::map::VISIBLE : te::map::NOT_VISIBLE);
135  // return true;
136  //}
137 
138  return false;
139 }
140 
142 {
143  return te::map::AbstractLayerPtr(0);
144 }
145 
147 {
148  return "LEGEND_ITEM";
149 }
150 
151 //te::qt::widgets::AbstractTreeItem* te::qt::widgets::LegendItem::clone(QObject* parent)
152 //{
153 // return new LegendItem(m_rule, parent);
154 //}
155 
157 {
158  m_isCheckable = checkable;
159 }
160 
162 {
163  return m_isCheckable;
164 }
const std::string getItemType() const
It returns the item type: "LEGEND_ITEM".
Definition: LegendItem.cpp:146
The class that represents an item in a LayerTreeModel.
A class that represents a legend item of a layer in a LayerTreeModel.
QVariant data(int column, int role) const
Definition: LegendItem.cpp:56
bool setData(int column, const QVariant &value, int role=Qt::EditRole)
Definition: LegendItem.cpp:117
void setCheckable(bool checkable)
Definition: LegendItem.cpp:156
te::map::AbstractLayerPtr getLayer() const
Definition: LegendItem.cpp:141
Qt::ItemFlags flags() const
Definition: LegendItem.cpp:103
A Rule is used to attach property/scale conditions to and group the individual symbols used for rende...
Definition: Rule.h:78
LegendItem(const te::se::Rule *rule, QObject *parent=0)
Definition: LegendItem.cpp:39
QMenu * getMenu(QWidget *parent=0) const
Definition: LegendItem.cpp:86
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
static QPixmap build(const te::se::Symbolizer *symb, const QSize &size)
Generates the preview of given symbolizer element.