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 "../../../../core/translator/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 
56 {
57  return 1;
58 }
59 
60 QVariant te::qt::widgets::ConstraintsItem::data(int /*column*/, int role) const
61 {
62  if(role == Qt::DecorationRole)
63  return QVariant(QIcon::fromTheme("constraints"));
64 
65  if(role == Qt::DisplayRole)
66  return QVariant(QString("constraints"));
67 
68  return QVariant();
69 }
70 
72 {
73  QMenu* m = new QMenu(parent);
74 
75  QAction* aOpenProperties = m->addAction(tr("&Open constraints"));
76 
77  connect(aOpenProperties, SIGNAL(triggered()), this, SLOT(openProperties()));
78 
79  return m;
80 }
81 
83 {
84  if(!children().empty())
85  return false;
86 
87  return hasChildren();
88 }
89 
91 {
92  return Qt::NoItemFlags;
93 }
94 
96 {
97  if(parent() == nullptr)
98  return;
99 
100 // if parent is a dataset item we can get more data otherwise we can do nothing
101  DataSetItem* parentItem = dynamic_cast<DataSetItem*>(parent());
102 
103  if(parentItem == nullptr)
104  return;
105 
106  const te::da::DataSetTypePtr& dt = parentItem->getDataSet();
107 
108  if(dt.get() == nullptr)
109  return;
110 
111  //if(!dt->isFullLoaded() && (parentItem->getDataSource() != 0))
112  // te::da::LoadFull(dt.get(), parentItem->getDataSource());
113 
114  if(dt->getPrimaryKey() != nullptr)
115  new PrimaryKeyItem(dt->getPrimaryKey(), this);
116 
117  const std::size_t nuks = dt->getNumberOfUniqueKeys();
118 
119  for(std::size_t i = 0; i < nuks; ++i)
120  new UniqueKeyItem(dt->getUniqueKey(i), this);
121 
122  const std::size_t nccs = dt->getNumberOfCheckConstraints();
123 
124  for(std::size_t i = 0; i < nccs; ++i)
125  new CheckConstraintItem(dt->getCheckConstraint(i), this);
126 }
127 
129 {
130  if(parent() == nullptr)
131  return false;
132 
133  DataSetItem* parentItem = dynamic_cast<DataSetItem*>(parent());
134 
135  if(parentItem == nullptr)
136  return false;
137 
138  const te::da::DataSetTypePtr& dt = parentItem->getDataSet();
139 
140  if(dt.get() == nullptr)
141  return false;
142 
143  //if(!dt->isFullLoaded() && (parentItem->getDataSource() != 0))
144  // te::da::LoadFull(dt.get(), parentItem->getDataSource());
145 
146  return (dt->getPrimaryKey() != nullptr) ||
147  (dt->getNumberOfUniqueKeys() != 0) ||
148  (dt->getNumberOfCheckConstraints() != 0);
149 }
150 
151 bool te::qt::widgets::ConstraintsItem::setData(const QVariant& /*value*/, int /*role*/)
152 {
153  return false;
154 }
155 
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
A class that represents a dataset in a TreeModel.
static te::dt::TimeDuration dt(20, 30, 50, 11)
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)