All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
IndexGroupItem.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/IndexGroupItem.cpp
22 
23  \brief A class used to group a set of indexes from a dataset in a TreeModel.
24 */
25 
26 // TerraLib
27 #include "../../../../common/STLUtils.h"
28 #include "../../../../common/Translator.h"
29 #include "../../../../dataaccess/dataset/DataSetType.h"
30 #include "../../../../dataaccess/dataset/Index.h"
31 #include "../../../../dataaccess/datasource/DataSource.h"
32 #include "../../../../dataaccess/utils/Utils.h"
33 #include "../../Exception.h"
34 #include "DataSetItem.h"
35 #include "IndexGroupItem.h"
36 #include "IndexItem.h"
37 
38 // Qt
39 #include <QMenu>
40 #include <QWidget>
41 
44 {
45 }
46 
48 {
49 }
50 
52 {
53  return 1;
54 }
55 
56 QVariant te::qt::widgets::IndexGroupItem::data(int /*column*/, int role) const
57 {
58  if(role == Qt::DecorationRole)
59  return QVariant(QIcon::fromTheme("indexes"));
60 
61  if(role == Qt::DisplayRole)
62  return QVariant(QString("indexes"));
63 
64  return QVariant();
65 }
66 
67 QMenu* te::qt::widgets::IndexGroupItem::getMenu(QWidget* parent) const
68 {
69  QMenu* m = new QMenu(parent);
70 
71  QAction* aOpenIndexes = m->addAction(tr("&Open indexes"));
72 
73  connect(aOpenIndexes, SIGNAL(triggered()), this, SLOT(openIndexes()));
74 
75  return m;
76 }
77 
79 {
80  if(!children().empty())
81  return false;
82 
83  return hasChildren();
84 }
85 
87 {
88  return Qt::NoItemFlags;
89 }
90 
92 {
93  if(parent() == 0)
94  return;
95 
96  DataSetItem* parentItem = dynamic_cast<DataSetItem*>(parent());
97 
98  if(parentItem == 0)
99  return;
100 
101  const te::da::DataSetTypePtr& dt = parentItem->getDataSet();
102 
103  if(dt.get() == 0)
104  return;
105 
106  //if(!dt->isFullLoaded() && (parentItem->getDataSource() != 0))
107  // te::da::LoadFull(dt.get(), parentItem->getDataSource());
108 
109 // create new items
110  const std::size_t nidxs = dt->getNumberOfIndexes();
111 
112  for(std::size_t i = 0; i < nidxs; ++i)
113  new IndexItem(dt->getIndex(i), this);
114 }
115 
117 {
118  if(parent() == 0)
119  return false;
120 
121  DataSetItem* parentItem = dynamic_cast<DataSetItem*>(parent());
122 
123  if(parentItem == 0)
124  return false;
125 
126  const te::da::DataSetTypePtr& dt = parentItem->getDataSet();
127 
128  if(dt == 0)
129  return false;
130 
131  //if(!dt->isFullLoaded() && (parentItem->getDataSource() != 0))
132  // te::da::LoadFull(dt.get(), parentItem->getDataSource());
133 
134  //return (dt->isFullLoaded() && (dt->getNumberOfIndexes() != 0));
135  return dt->getNumberOfIndexes() != 0;
136 }
137 
138 bool te::qt::widgets::IndexGroupItem::setData(const QVariant& /*value*/, int /*role*/)
139 {
140  return false;
141 }
142 
A class that represents a dataset in a TreeModel.
boost::shared_ptr< DataSetType > DataSetTypePtr
Definition: DataSetType.h:653
IndexGroupItem(AbstractDataSourceTreeItem *parent)
Qt::ItemFlags flags() const
QMenu * getMenu(QWidget *parent=0) const
bool setData(const QVariant &value, int role=Qt::EditRole)
A class that represents an index in a TreeModel.
const te::da::DataSetTypePtr & getDataSet() const
A class used to group a set of indexes from a dataset in a TreeModel.
QVariant data(int column, int role) const