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/qt/widgets/datasource/explorer/PropertyGroupItem.cpp
22 
23  \brief A class used to group a set of properties from a dataset in a TreeModel.
24 */
25 
26 // TerraLib
27 #include "../../../../common/STLUtils.h"
28 #include "../../../../core/translator/Translator.h"
29 #include "../../../../dataaccess/dataset/DataSetType.h"
30 #include "../../../../datatype/Property.h"
31 #include "../../Exception.h"
32 #include "DataSetItem.h"
33 #include "PropertyGroupItem.h"
34 #include "PropertyItem.h"
35 
36 // STL
37 #include <memory>
38 
39 // Qt
40 #include <QMenu>
41 #include <QWidget>
42 
45 {
46 }
47 
49 
51 {
52  return 1;
53 }
54 
55 QVariant te::qt::widgets::PropertyGroupItem::data(int /*column*/, int role) const
56 {
57  if(role == Qt::DecorationRole)
58  return QVariant(QIcon::fromTheme("properties"));
59 
60  if(role == Qt::DisplayRole)
61  return QVariant(QString("properties"));
62 
63  return QVariant();
64 }
65 
67 {
68  QMenu* m = new QMenu(parent);
69 
70  QAction* aOpenProperties = m->addAction(tr("&Open properties"));
71 
72  connect(aOpenProperties, SIGNAL(triggered()), this, SLOT(openProperties()));
73 
74  return m;
75 }
76 
78 {
79  if(!children().empty())
80  return false;
81 
82  return hasChildren();
83 }
84 
86 {
87  return Qt::NoItemFlags;
88 }
89 
91 {
92  if(parent() == nullptr)
93  return;
94 
95 // if parent is a dataset item we can get more data otherwise we can do nothing
96  DataSetItem* parentItem = dynamic_cast<DataSetItem*>(parent());
97 
98  if(parentItem == nullptr)
99  return;
100 
101  const te::da::DataSetTypePtr& dt = parentItem->getDataSet();
102 
103  if(dt.get() == nullptr)
104  return;
105 
106  const std::size_t nproperties = dt->size();
107 
108  for(std::size_t i = 0; i < nproperties; ++i)
109  {
110  te::dt::Property* p = dt->getProperty(i);
111 
112  if(p == nullptr)
113  continue;
114 
115  new PropertyItem(p, this);
116  }
117 }
118 
120 {
121  if(parent() == nullptr)
122  return false;
123 
124  DataSetItem* parentItem = dynamic_cast<DataSetItem*>(parent());
125 
126  if(parentItem == nullptr)
127  return false;
128 
129  const te::da::DataSetTypePtr& dt = parentItem->getDataSet();
130 
131  if(dt.get() == nullptr)
132  return false;
133 
134  return dt->size() != 0;
135 }
136 
137 bool te::qt::widgets::PropertyGroupItem::setData(const QVariant& /*value*/, int /*role*/)
138 {
139  return false;
140 }
141 
A class that represents a dataset in a TreeModel.
bool setData(const QVariant &value, int role=Qt::EditRole)
boost::shared_ptr< DataSetType > DataSetTypePtr
Definition: DataSetType.h:653
It models a property definition.
Definition: Property.h:59
A class that represents a dataset in a TreeModel.
PropertyGroupItem(AbstractDataSourceTreeItem *parent)
static te::dt::TimeDuration dt(20, 30, 50, 11)
te::gm::Polygon * p
QVariant data(int column, int role) const
QMenu * getMenu(QWidget *parent=0) const
A class used to group a set of properties from a dataset in a TreeModel.