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 "../../../../core/translator/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  default;
62 
64 {
65  return 1;
66 }
67 
68 QVariant te::qt::widgets::DataSetCategoryGroupItem::data(int /*column*/, int role) const
69 {
70  if(role == Qt::DecorationRole)
71  return QVariant(QIcon::fromTheme("datasets"));
72 
73  if(role == Qt::DisplayRole)
74  return QVariant(QString("datasets"));
75 
76  if(role == Qt::CheckStateRole)
77  return QVariant(m_checked ? Qt::Checked : Qt::Unchecked);
78 
79  return QVariant();
80 }
81 
83 {
84  QMenu* m = new QMenu(parent);
85 
86  QAction* aOpenDataSets = m->addAction(tr("&Open datasets"));
87 
88  connect(aOpenDataSets, SIGNAL(triggered()), this, SLOT(openDataSets()));
89 
90  return m;
91 }
92 
94 {
95  if(!children().empty ())
96  return false;
97 
98  return hasChildren();
99 }
100 
102 {
103  return Qt::ItemIsUserCheckable;
104 }
105 
107 {
108  if(m_ds == nullptr)
109  return;
110 
120 }
121 
123 {
124  if(m_isInvalid)
125  return false;
126 
127  if(m_ds.get() == nullptr)
128  return false;
129 
130  try
131  {
132  te::da::DataSourcePtr ds = te::da::DataSourceManager::getInstance().get(m_ds->getId(), m_ds->getAccessDriver(), m_ds->getConnInfo());
133 
134  if(ds.get() == nullptr)
135  return false;
136 
137  return ds->hasDataSets();
138  }
139  catch(...)
140  {
141  m_isInvalid = true;
142  throw;
143  }
144 }
145 
146 bool te::qt::widgets::DataSetCategoryGroupItem::setData(const QVariant& value, int role)
147 {
148  if(role == Qt::CheckStateRole)
149  {
150  m_checked = value.toBool();
151  return true;
152  }
153 
154  return false;
155 }
156 
158 {
159  return m_checked;
160 }
161 
A class that represents a dataset in a TreeModel.
bool setData(const QVariant &value, int role=Qt::EditRole)
boost::shared_ptr< DataSource > DataSourcePtr
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 te::dt::Date ds(2010, 01, 01)
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