All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PropertyItem.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/vp/qt/PropertyItem.cpp
22 
23  \brief A class that represents a Property in a LayerTreeModel.
24 */
25 
26 // TerraLib
27 #include "../../common/Translator.h"
28 #include "../../datatype/Property.h"
29 #include "../Exception.h"
30 #include "LayerItem.h"
31 #include "PropertyItem.h"
32 
33 // Qt
34 #include <QWidget>
35 
36 te::vp::PropertyItem::PropertyItem(te::dt::Property* p, AbstractTreeItem* parent)
37  : AbstractTreeItem(parent),
38  m_property(p),
39  m_selected(false)
40 {
41 }
42 
44 {
45  if(m_property && (m_property->getParent() == 0))
46  delete m_property;
47 }
48 
50 {
51  return 2;
52 }
53 
54 QVariant te::vp::PropertyItem::data(int column, int role) const
55 {
56  LayerItem* litem = dynamic_cast<LayerItem*>(parent()->parent());
57 
58  if(role == Qt::DisplayRole && column == 0)
59  return QVariant(m_property->getName().c_str());
60 
61  if(role == Qt::CheckStateRole && column == 0 && litem != 0)
62  return ((m_selected && litem->isSelected()) ? Qt::Checked : Qt::Unchecked);
63 
64  return QVariant();
65 }
66 
67 QMenu* te::vp::PropertyItem::getMenu(QWidget* parent) const
68 {
69  /*QMenu* m = new QMenu(parent);
70 
71  QAction* aOpenProperty = m->addAction(tr("&Open property"));
72 
73  connect(aOpenProperty, SIGNAL(triggered()), this, SLOT(openProperty()));*/
74 
75  return 0;
76 }
77 
79 {
80  return false;
81 }
82 
83 Qt::ItemFlags te::vp::PropertyItem::flags() const
84 {
85  return Qt::ItemIsUserCheckable;
86 }
87 
89 {
90 }
91 
93 {
94  return false;
95 }
96 
97 bool te::vp::PropertyItem::setData(int column, const QVariant& value, int role)
98 {
99  if(role == Qt::CheckStateRole)
100  {
101  bool ok = false;
102  Qt::CheckState checkState = static_cast<Qt::CheckState>(value.toInt(&ok));
103 
104  if(!ok)
105  return false;
106 
107  if(column == 0)
108  {
109  if(checkState == Qt::Checked)
110  m_selected = true;
111  else if(checkState == Qt::Unchecked)
112  m_selected = false;
113  }
114  return true;
115  }
116 
117  return true;
118 }
119 
121 {
122  return m_property;
123 }
124 
126 {
127  return 0;
128 }
129 
131 {
132  m_selected = selected;
133 }
134 
136 {
137  return m_selected;
138 }
139 
140 const std::string te::vp::PropertyItem::getItemType() const
141 {
142  return "LEGEND_ITEM";
143 }
QMenu * getMenu(QWidget *parent=0) const
bool canFetchMore() const
void isSelected(bool selected)
Set the Layer as selected.
Definition: LayerItem.cpp:195
bool setData(int column, const QVariant &value, int role=Qt::EditRole)
int columnCount() const
te::map::AbstractLayerPtr getLayer() const
QVariant data(int column, int role) const
It models a property definition.
Definition: Property.h:59
te::dt::Property * getProperty() const
void setSelected(bool selected)
Set the Property as selected.
bool isSelected()
Check if the Property is selected.
Qt::ItemFlags flags() const
A class that represents a Property in a LayerTreeModel.
PropertyItem(te::dt::Property *p, te::qt::widgets::AbstractTreeItem *parent)
A class that represents a Layer in a LayerTreeModel.
bool hasChildren() const
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
const std::string getItemType() const
It returns the item type.