All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
UniqueKeyItem.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/UniqueKeyItem.cpp
22 
23  \brief A class that represents a unique key in a TreeModel.
24 */
25 
26 // TerraLib
27 #include "../../../../common/Translator.h"
28 #include "../../../../dataaccess/dataset/UniqueKey.h"
29 #include "../../Exception.h"
30 #include "PropertyItem.h"
31 #include "UniqueKeyItem.h"
32 
33 // Qt
34 #include <QMenu>
35 #include <QWidget>
36 
39  m_uk(uk)
40 {
41 }
42 
44 {
45  //if(m_uk && (m_uk->getDataSetType() == 0))
46  // delete m_uk;
47 }
48 
50 {
51  return 1;
52 }
53 
54 QVariant te::qt::widgets::UniqueKeyItem::data(int /*column*/, int role) const
55 {
56  if(role == Qt::DecorationRole)
57  return QVariant(QIcon::fromTheme("unique"));
58 
59  if(role == Qt::DisplayRole)
60  return QVariant(m_uk->getName().c_str());
61 
62  return QVariant();
63 }
64 
65 QMenu* te::qt::widgets::UniqueKeyItem::getMenu(QWidget* parent) const
66 {
67  QMenu* m = new QMenu(parent);
68 
69  QAction* aOpenUniqueKey = m->addAction(tr("&Open unique-key"));
70 
71  connect(aOpenUniqueKey, SIGNAL(triggered()), this, SLOT(openUniqueKey()));
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  const std::size_t nproperties = m_uk->getProperties().size();
92 
93  for(std::size_t i = 0; i < nproperties; ++i)
94  new PropertyItem(m_uk->getProperties()[i], this);
95 }
96 
98 {
99  return !m_uk->getProperties().empty();
100 }
101 
102 bool te::qt::widgets::UniqueKeyItem::setData(const QVariant& /*value*/, int /*role*/)
103 {
104  return false;
105 }
106 
108 {
109  return m_uk;
110 }
111 
A class that represents a unique key in a TreeModel.
bool setData(const QVariant &value, int role=Qt::EditRole)
Qt::ItemFlags flags() const
QMenu * getMenu(QWidget *parent=0) const
QVariant data(int column, int role) const
It describes a unique key (uk) constraint.
Definition: UniqueKey.h:53
UniqueKeyItem(te::da::UniqueKey *uk, AbstractDataSourceTreeItem *parent)
Constructor.
te::da::UniqueKey * getUniqueKey() const
A class that represents a dataset in a TreeModel.