All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DataSetCategoryItem.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/DataSetCategoryItem.cpp
22 
23  \brief A class used to group a set of dataset items in a DataSourceTreeModel.
24 */
25 
26 // TerraLib
27 #include "../../../../common/STLUtils.h"
28 #include "../../../../common/Translator.h"
29 #include "../../../../dataaccess/Enums.h"
30 #include "../../../../dataaccess/dataset/DataSetType.h"
31 #include "../../../../dataaccess/datasource/DataSource.h"
32 //#include "../../../../dataaccess/datasource/DataSourceCatalog.h"
33 //#include "../../../../dataaccess/datasource/DataSourceCatalogLoader.h"
34 #include "../../../../dataaccess/datasource/DataSourceManager.h"
35 #include "../../../../dataaccess/datasource/DataSourceInfo.h"
36 //#include "../../../../dataaccess/datasource/DataSourceTransactor.h"
37 #include "../../../../dataaccess/utils/Utils.h"
38 #include "../../Exception.h"
39 #include "DataSetCategoryItem.h"
40 #include "DataSetItem.h"
41 #include "DataSourceItem.h"
42 
43 // STL
44 #include <memory>
45 
46 // Qt
47 #include <QMenu>
48 #include <QMessageBox>
49 #include <QWidget>
50 
53  m_ds(ds),
54  m_checked(false),
55  m_isInvalid(false),
56  m_category(category)
57 {
58 }
59 
61 {
62 }
63 
65 {
66  return 1;
67 }
68 
69 QVariant te::qt::widgets::DataSetCategoryItem::data(int /*column*/, int role) const
70 {
71  if(role == Qt::DecorationRole)
72  return QVariant(QIcon::fromTheme(te::da::GetDataSetCategoryName(m_category).c_str()));
73 
74  if(role == Qt::DisplayRole)
75  return QVariant(QString(te::da::GetDataSetCategoryName(m_category).c_str()));
76 
77  if(role == Qt::CheckStateRole)
78  return QVariant(m_checked ? Qt::Checked : Qt::Unchecked);
79 
80  return QVariant();
81 }
82 
83 QMenu* te::qt::widgets::DataSetCategoryItem::getMenu(QWidget* parent) const
84 {
85  QMenu* m = new QMenu(parent);
86 
87  QAction* aOpenDataSets = m->addAction(tr("&Open datasets"));
88 
89  connect(aOpenDataSets, SIGNAL(triggered()), this, SLOT(openDataSets()));
90 
91  return m;
92 }
93 
95 {
96  if(!children().empty ())
97  return false;
98 
99  return hasChildren();
100 }
101 
103 {
104  return Qt::ItemIsUserCheckable;
105 }
106 
108 {
109  if(m_ds == 0)
110  return;
111 
112  te::da::DataSourcePtr ds = te::da::DataSourceManager::getInstance().get(m_ds->getId(), m_ds->getAccessDriver(), m_ds->getConnInfo());
113 
114  if(ds.get() == 0)
115  return;
116 
117  std::vector<std::string> datasetNames = ds->getDataSetNames();
118 
119  const std::size_t ndatasets = datasetNames.size();
120 
121  for(std::size_t i = 0; i < ndatasets; ++i)
122  {
123  //te::da::DataSetTypePtr dt(new te::da::DataSetType(datasetNames[i]));
124  te::da::DataSetTypePtr dt(ds->getDataSetType(datasetNames[i].c_str()).release());
125 
126  for(std::size_t i = 0; i < dt->size(); ++i)
127  {
128  if(dt->getCategory() == m_category)
129  {
130  te::dt::Property* p = dt->getProperty(i);
131  if(p->getType() == te::dt::GEOMETRY_TYPE || dt->getProperty(i)->getType() == te::dt::RASTER_TYPE)
132  new DataSetItem(dt, p->getName(), ds.get(), this);
133  }
134  }
135  }
136 }
137 
139 {
140  if(m_isInvalid)
141  return false;
142 
143  if(m_ds.get() == 0)
144  return false;
145 
146  try
147  {
148  te::da::DataSourcePtr ds = te::da::DataSourceManager::getInstance().get(m_ds->getId(), m_ds->getAccessDriver(), m_ds->getConnInfo());
149 
150  if(ds.get() == 0)
151  return false;
152 
153  return ds->hasDataSets();
154  }
155  catch(...)
156  {
157  m_isInvalid = true;
158  throw;
159  }
160 }
161 
162 bool te::qt::widgets::DataSetCategoryItem::setData(const QVariant& value, int role)
163 {
164  if(role == Qt::CheckStateRole)
165  {
166  m_checked = value.toBool();
167  return true;
168  }
169 
170  return false;
171 }
172 
174 {
175  return m_checked;
176 }
177 
A class that represents a dataset in a TreeModel.
boost::shared_ptr< DataSetType > DataSetTypePtr
Definition: DataSetType.h:653
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1435
A class used to group a set of dataset items in a DataSourceTreeModel.
TEDATAACCESSEXPORT std::string GetDataSetCategoryName(int category)
Definition: Utils.cpp:164
It models a property definition.
Definition: Property.h:59
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
bool setData(const QVariant &value, int role=Qt::EditRole)
QMenu * getMenu(QWidget *parent=0) const
int getType() const
It returns the property data type.
Definition: Property.h:161
A class that represents a data source in a DataSourceTreeModel.
QVariant data(int column, int role) const
DataSetCategoryItem(const te::da::DataSourceInfoPtr &ds, int category, AbstractDataSourceTreeItem *parent=0)
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
const std::string & getName() const
It returns the property name.
Definition: Property.h:127