All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DataSetItem.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/DataSetItem.cpp
22 
23  \brief A class that represents a dataset in a TreeModel.
24 */
25 
26 // TerraLib
27 #include "../../../../common/Translator.h"
28 #include "../../../../dataaccess/Enums.h"
29 #include "../../../../dataaccess/dataset/DataSetType.h"
30 #include "../../../../dataaccess/datasource/DataSource.h"
31 #include "../../../../dataaccess/datasource/DataSourceCatalog.h"
32 #include "../../../../dataaccess/utils/Utils.h"
33 #include "../../datasource/explorer/DataSetGroupItem.h"
34 #include "../../Exception.h"
35 #include "ConstraintsItem.h"
36 #include "DataSetItem.h"
37 #include "IndexGroupItem.h"
38 #include "PropertyGroupItem.h"
39 
40 // STL
41 #include <memory>
42 
43 // Qt
44 #include <QMenu>
45 #include <QWidget>
46 
49  m_dataset(dt),
50  m_geomPropertyName(geomPropertyName),
51  m_datasource(ds),
52  m_checked(false)
53 {
54  if(ds == 0 && dt->getCatalog())
55  m_datasource = dt->getCatalog()->getDataSource();
56 }
57 
59 {
60 }
61 
63 {
64  return 1;
65 }
66 
67 QVariant te::qt::widgets::DataSetItem::data(int column, int role) const
68 {
69  if(role == Qt::DecorationRole)
70  {
71  if((m_dataset->getCategory() == te::da::TABLE_TYPE) && m_dataset->hasGeom())
72  return QVariant(QIcon::fromTheme("dataset-geotable"));
73  else if((m_dataset->getCategory() == te::da::TABLE_TYPE) && !m_dataset->hasGeom())
74  return QVariant(QIcon::fromTheme("dataset-table"));
75  else if((m_dataset->getCategory() == te::da::VIEW_TYPE) && m_dataset->hasGeom())
76  return QVariant(QIcon::fromTheme("dataset-geoview"));
77  else if((m_dataset->getCategory() == te::da::VIEW_TYPE) && !m_dataset->hasGeom())
78  return QVariant(QIcon::fromTheme("dataset-view"));
79  else if((m_dataset->getCategory() == te::da::REGULAR_FILE_TYPE) && m_dataset->hasGeom())
80  return QVariant(QIcon::fromTheme("dataset-geofile"));
81  else if((m_dataset->getCategory() == te::da::REGULAR_FILE_TYPE) && !m_dataset->hasGeom())
82  return QVariant(QIcon::fromTheme("dataset-file"));
83  else
84  return QVariant(QIcon::fromTheme("dataset"));
85  }
86 
87  if(role == Qt::DisplayRole)
88  {
89  if(!m_dataset->getTitle().empty())
90  return QVariant((m_dataset->getTitle() + " (" + m_geomPropertyName+ ")").c_str());
91  else
92  return QVariant((m_dataset->getName() + " (" + m_geomPropertyName+ ")").c_str());
93  }
94 
95  if(role == Qt::CheckStateRole)
96  return QVariant(m_checked ? Qt::Checked : Qt::Unchecked);
97 
98  return QVariant();
99 }
100 
101 QMenu* te::qt::widgets::DataSetItem::getMenu(QWidget* parent) const
102 {
103  QMenu* m = new QMenu(parent);
104 
105  QAction* aOpenDataSet = m->addAction(tr("&Open dataset"));
106 
107  connect(aOpenDataSet, SIGNAL(triggered()), this, SLOT(openDataSet()));
108 
109  return m;
110 }
111 
113 {
114  if(!children().empty())
115  return false;
116 
117  return hasChildren();
118 }
119 
121 {
122  return Qt::ItemIsUserCheckable;
123 }
124 
126 {
127  if(m_dataset.get() == 0)
128  return;
129 
130  //if(!m_dataset->isFullLoaded() && (m_datasource != 0))
131  // te::da::LoadFull(m_dataset.get(), m_datasource);
132 
133  if(m_dataset->size() != 0)
134  new PropertyGroupItem(this);
135 
136  if((!m_dataset->getNumberOfCheckConstraints() != 0) ||
137  (!m_dataset->getNumberOfUniqueKeys() != 0) ||
138  (!m_dataset->getPrimaryKey() != 0))
139  new ConstraintsItem(this);
140 
141  if(m_dataset->getNumberOfIndexes() != 0)
142  new IndexGroupItem(this);
143 }
144 
146 {
147  if(m_dataset.get() == 0)
148  return false;
149 
150  if(m_dataset->size() != 0)
151  return true;
152 
153  if(m_datasource == 0)
154  return false;
155 
156  return true; // assume at least one property will exist! otherwise we need to use catalog loader!
157 }
158 
159 bool te::qt::widgets::DataSetItem::setData(const QVariant& value, int role)
160 {
161  if(role == Qt::CheckStateRole)
162  {
163  m_checked = value.toBool();
164 
165  DataSetGroupItem* p = dynamic_cast<DataSetGroupItem*>(parent());
166 
167  p->checkState();
168 
169  return true;
170  }
171 
172  return false;
173 }
174 
176 {
177  return m_dataset;
178 }
179 
181 {
182  return m_geomPropertyName;
183 }
184 
186 {
187  return m_datasource;
188 }
189 
191 {
192  return m_checked;
193 }
A class that represents a dataset in a TreeModel.
boost::shared_ptr< DataSetType > DataSetTypePtr
Definition: DataSetType.h:653
te::da::DataSource * m_datasource
Definition: DataSetItem.h:86
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
Definition: DataSource.h:118
A class used to group a set of properties from a dataset in a TreeModel.
QMenu * getMenu(QWidget *parent=0) const
const std::string & getGeomPropertyName() const
QVariant data(int column, int role) const
Definition: DataSetItem.cpp:67
Qt::ItemFlags flags() const
bool setData(const QVariant &value, int role=Qt::EditRole)
const te::da::DataSetTypePtr & getDataSet() const
te::da::DataSource * getDataSource() const
DataSetItem(const te::da::DataSetTypePtr &dt, const std::string &geomPropertyName, te::da::DataSource *ds=0, AbstractDataSourceTreeItem *parent=0)
Constructor.
Definition: DataSetItem.cpp:47
A class used to group a set of indexes from a dataset in a TreeModel.
A class used to group the set of constraints of a dataset in a TreeModel.