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/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 "../../../../common/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 {
50 }
51 
53 {
54  return 1;
55 }
56 
57 QVariant te::qt::widgets::PropertyGroupItem::data(int /*column*/, int role) const
58 {
59  if(role == Qt::DecorationRole)
60  return QVariant(QIcon::fromTheme("properties"));
61 
62  if(role == Qt::DisplayRole)
63  return QVariant(QString("properties"));
64 
65  return QVariant();
66 }
67 
68 QMenu* te::qt::widgets::PropertyGroupItem::getMenu(QWidget* parent) const
69 {
70  QMenu* m = new QMenu(parent);
71 
72  QAction* aOpenProperties = m->addAction(tr("&Open properties"));
73 
74  connect(aOpenProperties, SIGNAL(triggered()), this, SLOT(openProperties()));
75 
76  return m;
77 }
78 
80 {
81  if(!children().empty())
82  return false;
83 
84  return hasChildren();
85 }
86 
88 {
89  return Qt::NoItemFlags;
90 }
91 
93 {
94  if(parent() == 0)
95  return;
96 
97 // if parent is a dataset item we can get more data otherwise we can do nothing
98  DataSetItem* parentItem = dynamic_cast<DataSetItem*>(parent());
99 
100  if(parentItem == 0)
101  return;
102 
103  const te::da::DataSetTypePtr& dt = parentItem->getDataSet();
104 
105  if(dt.get() == 0)
106  return;
107 
108  const std::size_t nproperties = dt->size();
109 
110  for(std::size_t i = 0; i < nproperties; ++i)
111  {
112  te::dt::Property* p = dt->getProperty(i);
113 
114  if(p == 0)
115  continue;
116 
117  new PropertyItem(p, this);
118  }
119 }
120 
122 {
123  if(parent() == 0)
124  return false;
125 
126  DataSetItem* parentItem = dynamic_cast<DataSetItem*>(parent());
127 
128  if(parentItem == 0)
129  return false;
130 
131  const te::da::DataSetTypePtr& dt = parentItem->getDataSet();
132 
133  if(dt.get() == 0)
134  return false;
135 
136  return dt->size() != 0;
137 }
138 
139 bool te::qt::widgets::PropertyGroupItem::setData(const QVariant& /*value*/, int /*role*/)
140 {
141  return false;
142 }
143 
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 used to group a set of properties from a dataset in a TreeModel.
PropertyGroupItem(AbstractDataSourceTreeItem *parent)
QVariant data(int column, int role) const
const te::da::DataSetTypePtr & getDataSet() const
QMenu * getMenu(QWidget *parent=0) const
A class that represents a dataset in a TreeModel.