DataSourceItem.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/DataSourceItem.cpp
22 
23  \brief A class that represents a data source in a DataSourceTreeModel.
24 */
25 
26 // TerraLib
27 #include "../../../../core/translator/Translator.h"
28 #include "../../../../dataaccess/datasource/DataSource.h"
29 #include "../../../../dataaccess/datasource/DataSourceManager.h"
30 #include "../../Exception.h"
31 #include "DataSetGroupItem.h"
32 #include "DataSourceItem.h"
33 
34 // Qt
35 #include <QMenu>
36 #include <QWidget>
37 
40  m_ds(ds)
41 {
42 }
43 
45 
47 {
48  return 1;
49 }
50 
51 QVariant te::qt::widgets::DataSourceItem::data(int /*column*/, int role) const
52 {
53  if(role == Qt::DecorationRole)
54  {
56 
57  if(ds == nullptr || !ds->isOpened())
58  return QVariant(QIcon::fromTheme("closed-datasource"));
59  else
60  return QVariant(QIcon::fromTheme("datasource"));
61  }
62 
63  if(role == Qt::DisplayRole)
64  return QVariant(QString::fromUtf8(m_ds->getTitle().c_str()));
65 
66  return QVariant();
67 }
68 
70 {
71  QMenu* m = new QMenu(parent);
72 
73  QAction* aOpenDataSource = m->addAction(tr("&Open data source"));
74 
75  connect(aOpenDataSource, SIGNAL(triggered()), this, SLOT(openDataSource()));
76 
77  return m;
78 }
79 
81 {
82  if(m_ds.get() == nullptr)
83  return false;
84 
85  if(!children().empty())
86  return false;
87 
88  return true;
89 }
90 
92 {
93  return Qt::NoItemFlags;
94 }
95 
97 {
98  if(m_ds.get() == nullptr)
99  return;
100 
101  new DataSetGroupItem(m_ds, this); // add a child item
102 }
103 
105 {
106  //return !children().empty();
107  return true;
108 }
109 
110 bool te::qt::widgets::DataSourceItem::setData(const QVariant& /*value*/, int /*role*/)
111 {
112  return false;
113 }
114 
116 {
117  return m_ds;
118 }
QMenu * getMenu(QWidget *parent=0) const
boost::shared_ptr< DataSource > DataSourcePtr
Qt::ItemFlags flags() const
QVariant data(int column, int role) const
te::da::DataSourceInfoPtr m_ds
te::da::DataSourceInfoPtr getDataSource() const
static te::dt::Date ds(2010, 01, 01)
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
DataSourceItem(const te::da::DataSourceInfoPtr &ds, AbstractDataSourceTreeItem *parent=0)
A class that represents a data source in a DataSourceTreeModel.
bool setData(const QVariant &value, int role=Qt::EditRole)
A class used to group a set of dataset items in a DataSourceTreeModel.
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr