All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PropertyGroupItem.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/PropertyGroupItem.cpp
22 
23  \brief A class that represents a group of properties 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 "PropertyGroupItem.h"
32 #include "PropertyItem.h"
33 
34 // Qt
35 #include <QWidget>
36 
37 te::vp::PropertyGroupItem::PropertyGroupItem(std::vector<te::dt::Property*> properties, AbstractTreeItem* parent)
38  : AbstractTreeItem(parent)
39 {
40  if(properties.empty())
41  return;
42 
43  for(size_t i = 0; i < properties.size(); ++i)
44  {
45  te::dt::Property* prop = properties[i]->clone();
46 
47  if(prop->getType() == te::dt::GEOMETRY_TYPE)
48  continue;
49 
50  te::qt::widgets::AbstractTreeItem* item = new PropertyItem(prop, this);
51 
52  m_items.push_back(item);
53  }
54 }
55 
57 {
58  //if(m_property && (m_property->getParent() == 0))
59  // delete m_property;
60 }
61 
63 {
64  return 2;
65 }
66 
67 QVariant te::vp::PropertyGroupItem::data(int column, int role) const
68 {
69  if(role == Qt::DisplayRole && column == 0)
70  return QVariant(TE_TR("Properties"));
71 
72  return QVariant();
73 }
74 
75 QMenu* te::vp::PropertyGroupItem::getMenu(QWidget* parent) const
76 {
77  /*QMenu* m = new QMenu(parent);
78 
79  QAction* aOpenProperty = m->addAction(tr("&Open property"));
80 
81  connect(aOpenProperty, SIGNAL(triggered()), this, SLOT(openProperty()));*/
82 
83  return 0;
84 }
85 
87 {
88  if(!children().empty ())
89  return false;
90 
91  return hasChildren();
92 }
93 
94 Qt::ItemFlags te::vp::PropertyGroupItem::flags() const
95 {
96  return Qt::ItemIsUserCheckable;
97 }
98 
100 {
101  /*if(parent() == 0)
102  return;
103 
104  LayerItem* parentItem = dynamic_cast<LayerItem*>(parent());
105 
106  if(!parentItem->hasChildren())
107  return;
108 
109  te::map::AbstractLayerPtr layer = parentItem->getLayer();
110 
111  if(layer->hasChildren())
112  {
113  for(size_t i = 0; i < layer->getChildrenCount(); ++i)
114  {
115  te::map::AbstractLayerPtr child = boost::dynamic_pointer_cast<te::map::AbstractLayer>(layer->getChild(i));
116  new LayerItem(child, this);
117  }
118  }
119  else if(layer->getSchema()->getProperties().size() > 0)
120  {
121  const te::map::LayerSchema* schema = parentItem->getLayer()->getSchema();
122 
123  if(schema == 0)
124  return;
125 
126  std::vector<te::dt::Property*> properties = schema->getProperties();
127 
128  for(size_t i = 0; i < properties.size(); ++i)
129  {
130  te::dt::Property* p = schema->getProperty(i);
131 
132  if(p == 0)
133  continue;
134 
135  new PropertyItem(properties[i], this);
136  }
137  }*/
138 }
139 
141 {
142  return m_items.size() > 0 ? true : false;
143 }
144 
145 bool te::vp::PropertyGroupItem::setData(int column, const QVariant& value, int role)
146 {
147  return true;
148 }
149 
151 {
152  return 0;
153 }
154 
155 std::vector<te::qt::widgets::AbstractTreeItem*> te::vp::PropertyGroupItem::getItems() const
156 {
157  return m_items;
158 }
159 
160 const std::string te::vp::PropertyGroupItem::getItemType() const
161 {
162  return "GROUPING_ITEM";
163 }
QMenu * getMenu(QWidget *parent=0) const
te::map::AbstractLayerPtr getLayer() const
virtual Property * clone() const =0
It returns a clone of the object.
The class that represents an item in a LayerTreeModel.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
It models a property definition.
Definition: Property.h:59
std::vector< te::qt::widgets::AbstractTreeItem * > getItems() const
A class that represents a group of Properties in a LayerTreeModel.
bool setData(int column, const QVariant &value, int role=Qt::EditRole)
PropertyGroupItem(std::vector< te::dt::Property * > properties, te::qt::widgets::AbstractTreeItem *parent)
A class that represents a Property in a LayerTreeModel.
const std::string getItemType() const
It returns the item type.
int getType() const
It returns the property data type.
Definition: Property.h:161
A class that represents a Layer in a LayerTreeModel.
Qt::ItemFlags flags() const
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
QVariant data(int column, int role) const