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 "../../../../core/translator/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 
50 {
51  return 1;
52 }
53 
54 QVariant te::qt::widgets::IndexGroupItem::data(int /*column*/, int role) const
55 {
56  if(role == Qt::DecorationRole)
57  return QVariant(QIcon::fromTheme("indexes"));
58 
59  if(role == Qt::DisplayRole)
60  return QVariant(QString("indexes"));
61 
62  return QVariant();
63 }
64 
66 {
67  QMenu* m = new QMenu(parent);
68 
69  QAction* aOpenIndexes = m->addAction(tr("&Open indexes"));
70 
71  connect(aOpenIndexes, SIGNAL(triggered()), this, SLOT(openIndexes()));
72 
73  return m;
74 }
75 
77 {
78  if(!children().empty())
79  return false;
80 
81  return hasChildren();
82 }
83 
85 {
86  return Qt::NoItemFlags;
87 }
88 
90 {
91  if(parent() == nullptr)
92  return;
93 
94  DataSetItem* parentItem = dynamic_cast<DataSetItem*>(parent());
95 
96  if(parentItem == nullptr)
97  return;
98 
99  const te::da::DataSetTypePtr& dt = parentItem->getDataSet();
100 
101  if(dt.get() == nullptr)
102  return;
103 
104  //if(!dt->isFullLoaded() && (parentItem->getDataSource() != 0))
105  // te::da::LoadFull(dt.get(), parentItem->getDataSource());
106 
107 // create new items
108  const std::size_t nidxs = dt->getNumberOfIndexes();
109 
110  for(std::size_t i = 0; i < nidxs; ++i)
111  new IndexItem(dt->getIndex(i), this);
112 }
113 
115 {
116  if(parent() == nullptr)
117  return false;
118 
119  DataSetItem* parentItem = dynamic_cast<DataSetItem*>(parent());
120 
121  if(parentItem == nullptr)
122  return false;
123 
124  const te::da::DataSetTypePtr& dt = parentItem->getDataSet();
125 
126  if(dt == nullptr)
127  return false;
128 
129  //if(!dt->isFullLoaded() && (parentItem->getDataSource() != 0))
130  // te::da::LoadFull(dt.get(), parentItem->getDataSource());
131 
132  //return (dt->isFullLoaded() && (dt->getNumberOfIndexes() != 0));
133  return dt->getNumberOfIndexes() != 0;
134 }
135 
136 bool te::qt::widgets::IndexGroupItem::setData(const QVariant& /*value*/, int /*role*/)
137 {
138  return false;
139 }
140 
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
static te::dt::TimeDuration dt(20, 30, 50, 11)
QMenu * getMenu(QWidget *parent=0) const
bool setData(const QVariant &value, int role=Qt::EditRole)
A class that represents an index in a TreeModel.
A class used to group a set of indexes from a dataset in a TreeModel.
QVariant data(int column, int role) const