All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 "../../../../common/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 {
46 }
47 
49 {
50  return 1;
51 }
52 
53 QVariant te::qt::widgets::DataSourceItem::data(int /*column*/, int role) const
54 {
55  if(role == Qt::DecorationRole)
56  {
58 
59  if(ds == 0 || !ds->isOpened())
60  return QVariant(QIcon::fromTheme("closed-datasource"));
61  else
62  return QVariant(QIcon::fromTheme("datasource"));
63  }
64 
65  if(role == Qt::DisplayRole)
66  return QVariant(QString::fromStdString(m_ds->getTitle()));
67 
68  return QVariant();
69 }
70 
71 QMenu* te::qt::widgets::DataSourceItem::getMenu(QWidget* parent) const
72 {
73  QMenu* m = new QMenu(parent);
74 
75  QAction* aOpenDataSource = m->addAction(tr("&Open data source"));
76 
77  connect(aOpenDataSource, SIGNAL(triggered()), this, SLOT(openDataSource()));
78 
79  return m;
80 }
81 
83 {
84  if(m_ds.get() == 0)
85  return false;
86 
87  if(!children().empty())
88  return false;
89 
90  return true;
91 }
92 
94 {
95  return Qt::NoItemFlags;
96 }
97 
99 {
100  if(m_ds.get() == 0)
101  return;
102 
103  new DataSetGroupItem(m_ds, this); // add a child item
104 }
105 
107 {
108  //return !children().empty();
109  return true;
110 }
111 
112 bool te::qt::widgets::DataSourceItem::setData(const QVariant& /*value*/, int /*role*/)
113 {
114  return false;
115 }
116 
118 {
119  return m_ds;
120 }
QMenu * getMenu(QWidget *parent=0) const
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1435
Qt::ItemFlags flags() const
QVariant data(int column, int role) const
te::da::DataSourceInfoPtr getDataSource() const
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