All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ConstraintsItem.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/ConstraintsItem.h
22 
23  \brief A class used to group the set of constraints of a dataset in a TreeModel.
24 */
25 
26 // TerraLib
27 #include "../../../../common/Translator.h"
28 #include "../../../../dataaccess/dataset/DataSetType.h"
29 #include "../../../../dataaccess/datasource/DataSource.h"
30 #include "../../../../dataaccess/datasource/DataSourceCatalog.h"
31 #include "../../../../dataaccess/utils/Utils.h"
32 #include "../../../../datatype/Property.h"
33 #include "../../Exception.h"
34 #include "DataSetItem.h"
35 #include "CheckConstraintItem.h"
36 #include "ConstraintsItem.h"
37 #include "PrimaryKeyItem.h"
38 #include "PropertyItem.h"
39 #include "UniqueKeyItem.h"
40 
41 // STL
42 #include <memory>
43 
44 // Qt
45 #include <QMenu>
46 #include <QWidget>
47 
50 {
51 }
52 
54 {
55 }
56 
58 {
59  return 1;
60 }
61 
62 QVariant te::qt::widgets::ConstraintsItem::data(int /*column*/, int role) const
63 {
64  if(role == Qt::DecorationRole)
65  return QVariant(QIcon::fromTheme("constraints"));
66 
67  if(role == Qt::DisplayRole)
68  return QVariant(QString("constraints"));
69 
70  return QVariant();
71 }
72 
73 QMenu* te::qt::widgets::ConstraintsItem::getMenu(QWidget* parent) const
74 {
75  QMenu* m = new QMenu(parent);
76 
77  QAction* aOpenProperties = m->addAction(tr("&Open constraints"));
78 
79  connect(aOpenProperties, SIGNAL(triggered()), this, SLOT(openProperties()));
80 
81  return m;
82 }
83 
85 {
86  if(!children().empty())
87  return false;
88 
89  return hasChildren();
90 }
91 
93 {
94  return Qt::NoItemFlags;
95 }
96 
98 {
99  if(parent() == 0)
100  return;
101 
102 // if parent is a dataset item we can get more data otherwise we can do nothing
103  DataSetItem* parentItem = dynamic_cast<DataSetItem*>(parent());
104 
105  if(parentItem == 0)
106  return;
107 
108  const te::da::DataSetTypePtr& dt = parentItem->getDataSet();
109 
110  if(dt.get() == 0)
111  return;
112 
113  //if(!dt->isFullLoaded() && (parentItem->getDataSource() != 0))
114  // te::da::LoadFull(dt.get(), parentItem->getDataSource());
115 
116  if(dt->getPrimaryKey() != 0)
117  new PrimaryKeyItem(dt->getPrimaryKey(), this);
118 
119  const std::size_t nuks = dt->getNumberOfUniqueKeys();
120 
121  for(std::size_t i = 0; i < nuks; ++i)
122  new UniqueKeyItem(dt->getUniqueKey(i), this);
123 
124  const std::size_t nccs = dt->getNumberOfCheckConstraints();
125 
126  for(std::size_t i = 0; i < nccs; ++i)
127  new CheckConstraintItem(dt->getCheckConstraint(i), this);
128 }
129 
131 {
132  if(parent() == 0)
133  return false;
134 
135  DataSetItem* parentItem = dynamic_cast<DataSetItem*>(parent());
136 
137  if(parentItem == 0)
138  return false;
139 
140  const te::da::DataSetTypePtr& dt = parentItem->getDataSet();
141 
142  if(dt.get() == 0)
143  return false;
144 
145  //if(!dt->isFullLoaded() && (parentItem->getDataSource() != 0))
146  // te::da::LoadFull(dt.get(), parentItem->getDataSource());
147 
148  return (dt->getPrimaryKey() != 0) ||
149  (dt->getNumberOfUniqueKeys() != 0) ||
150  (dt->getNumberOfCheckConstraints() != 0);
151 }
152 
153 bool te::qt::widgets::ConstraintsItem::setData(const QVariant& /*value*/, int /*role*/)
154 {
155  return false;
156 }
157 
A class that represents a dataset in a TreeModel.
A class that represents a unique key in a TreeModel.
boost::shared_ptr< DataSetType > DataSetTypePtr
Definition: DataSetType.h:653
QVariant data(int column, int role) const
bool setData(const QVariant &value, int role=Qt::EditRole)
A class that represents a check-constraint in a TreeModel.
QMenu * getMenu(QWidget *parent=0) const
const te::da::DataSetTypePtr & getDataSet() const
A class that represents a primary key in a TreeModel.
A class used to group the set of constraints of a dataset in a TreeModel.
ConstraintsItem(AbstractDataSourceTreeItem *parent)
A class that represents a dataset in a TreeModel.