All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DataSetCategoryGroupItem.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/DataSetCategoryGroupItem.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"
40 #include "DataSetCategoryItem.h"
41 #include "DataSetItem.h"
42 #include "DataSourceItem.h"
43 
44 // STL
45 #include <memory>
46 
47 // Qt
48 #include <QMenu>
49 #include <QMessageBox>
50 #include <QWidget>
51 
54  m_ds(ds),
55  m_checked(false),
56  m_isInvalid(false)
57 {
58 }
59 
61 {
62 }
63 
65 {
66  return 1;
67 }
68 
69 QVariant te::qt::widgets::DataSetCategoryGroupItem::data(int /*column*/, int role) const
70 {
71  if(role == Qt::DecorationRole)
72  return QVariant(QIcon::fromTheme("datasets"));
73 
74  if(role == Qt::DisplayRole)
75  return QVariant(QString("datasets"));
76 
77  if(role == Qt::CheckStateRole)
78  return QVariant(m_checked ? Qt::Checked : Qt::Unchecked);
79 
80  return QVariant();
81 }
82 
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  new DataSetCategoryItem(m_ds, te::da::TABLE_TYPE, this);
113  new DataSetCategoryItem(m_ds, te::da::VIEW_TYPE, this);
114  new DataSetCategoryItem(m_ds, te::da::QUERY_TYPE, this);
115  new DataSetCategoryItem(m_ds, te::da::INDEX_TYPE, this);
117  new DataSetCategoryItem(m_ds, te::da::TRIGGER_TYPE, this);
121 }
122 
124 {
125  if(m_isInvalid)
126  return false;
127 
128  if(m_ds.get() == 0)
129  return false;
130 
131  try
132  {
133  te::da::DataSourcePtr ds = te::da::DataSourceManager::getInstance().get(m_ds->getId(), m_ds->getAccessDriver(), m_ds->getConnInfo());
134 
135  if(ds.get() == 0)
136  return false;
137 
138  return ds->hasDataSets();
139  }
140  catch(...)
141  {
142  m_isInvalid = true;
143  throw;
144  }
145 }
146 
147 bool te::qt::widgets::DataSetCategoryGroupItem::setData(const QVariant& value, int role)
148 {
149  if(role == Qt::CheckStateRole)
150  {
151  m_checked = value.toBool();
152  return true;
153  }
154 
155  return false;
156 }
157 
159 {
160  return m_checked;
161 }
162 
A class that represents a dataset in a TreeModel.
bool setData(const QVariant &value, int role=Qt::EditRole)
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1435
A class used to group a set of dataset items in a DataSourceTreeModel.
A class used to group a set of dataset items in a DataSourceTreeModel.
QVariant data(int column, int role) const
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
DataSetCategoryGroupItem(const te::da::DataSourceInfoPtr &ds, AbstractDataSourceTreeItem *parent=0)
A class that represents a data source in a DataSourceTreeModel.
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr