qt/widgets/datasource/explorer/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 "../../../../core/translator/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_datasource(ds),
50  m_checked(false),
51  m_name(name)
52 {
53 }
54 
56 
58 {
59  return 1;
60 }
61 
62 QVariant te::qt::widgets::DataSetItem::data(int /*column*/, int role) const
63 {
64  if(role == Qt::DisplayRole)
65  {
66  return QVariant((m_name).c_str());
67  }
68 
69  if(role == Qt::CheckStateRole)
70  return QVariant(m_checked ? Qt::Checked : Qt::Unchecked);
71 
72  return QVariant();
73 }
74 
76 {
77  QMenu* m = new QMenu(parent);
78 
79  QAction* aOpenDataSet = m->addAction(tr("&Open dataset"));
80 
81  connect(aOpenDataSet, SIGNAL(triggered()), this, SLOT(openDataSet()));
82 
83  return m;
84 }
85 
87 {
88  if(!children().empty())
89  return false;
90 
91  return hasChildren();
92 }
93 
95 {
96  return Qt::ItemIsUserCheckable;
97 }
98 
100 {
101  if(!m_dataset.get())
102  m_dataset.reset(m_datasource->getDataSetType(m_name).release());
103 
104  if (!m_dataset.get())
105  return;
106 
107  if(m_dataset->size() != 0)
108  new PropertyGroupItem(this);
109 
110  if ((m_dataset->getNumberOfCheckConstraints() != 0) ||
111  (m_dataset->getNumberOfUniqueKeys() != 0) ||
112  (m_dataset->getPrimaryKey() != nullptr))
113  new ConstraintsItem(this);
114 
115  if(m_dataset->getNumberOfIndexes() != 0)
116  new IndexGroupItem(this);
117 }
118 
120 {
121  if(m_datasource == nullptr)
122  return false;
123 
124  return true; // assume at least one property will exist! otherwise we need to use catalog loader!
125 }
126 
127 bool te::qt::widgets::DataSetItem::setData(const QVariant& value, int role)
128 {
129  if(role == Qt::CheckStateRole)
130  {
131  m_checked = value.toBool();
132 
133  DataSetGroupItem* p = dynamic_cast<DataSetGroupItem*>(parent());
134 
135  p->checkState();
136 
137  return true;
138  }
139 
140  return false;
141 }
142 
144 {
145  if (!m_dataset.get())
146  m_dataset.reset(m_datasource->getDataSetType(m_name).release());
147 
148  return m_dataset;
149 }
150 
152 {
153  if(!m_dataset.get())
154  m_dataset.reset(m_datasource->getDataSetType(m_name).release());
155 
157  if (geomProp)
158  return geomProp->getName();
159 
160  return "";
161 }
162 
164 {
165  return m_datasource;
166 }
167 
169 {
170  return m_checked;
171 }
A class that represents a dataset in a TreeModel.
boost::shared_ptr< DataSetType > DataSetTypePtr
Definition: DataSetType.h:653
static te::dt::Date ds(2010, 01, 01)
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
It models a property definition.
Definition: Property.h:59
DataSetItem(const std::string &name, te::da::DataSource *ds, AbstractDataSourceTreeItem *parent=0)
Constructor.
te::gm::Polygon * p
bool setData(const QVariant &value, int role=Qt::EditRole)
virtual std::unique_ptr< te::da::DataSetType > getDataSetType(const std::string &name)
It gets information about the given dataset.
A class used to group a set of properties from a dataset in a TreeModel.
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.
TEDATAACCESSEXPORT te::dt::Property * GetFirstSpatialProperty(const DataSetType *dt)
const std::string & getName() const
It returns the property name.
Definition: Property.h:127