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