All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
UniquekeyConstraintWidget.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/property/UniqueKeyConstraintWidget.cpp
22 
23  \brief This file has the UniqueKeyConstraintWidget class.
24 */
25 
26 // TerraLib
27 #include "../../../dataaccess/dataset/DataSetType.h"
28 #include "../../../dataaccess/dataset/UniqueKey.h"
29 #include "../utils/DoubleListWidget.h"
31 #include "ui_ConstraintWidgetForm.h"
32 #include "ui_DoubleListWidgetForm.h"
33 
34 
35 //Qt
36 #include <QWidget>
37 
38 
40  : ConstraintWidget(dsType, parent, f)
41 {
42 }
43 
45 {
46 }
47 
49 {
50 //get index name
51  if(m_ui->m_nameLineEdit->text().isEmpty())
52  {
53  return 0;
54  }
55 
56  std::string constraintName = m_ui->m_nameLineEdit->text().toStdString();
57 
58  //get properties
59  std::vector<std::string> vec = m_doubleListWidget->getOutputValues();
60 
61  if(vec.empty())
62  {
63  return 0;
64  }
65 
66  //create constraint
67  te::da::UniqueKey* uk = new te::da::UniqueKey(m_dsType);
68 
69  uk->setName(constraintName);
70 
71  for(size_t t = 0; t < vec.size(); ++t)
72  {
73  te::dt::Property* p = m_dsType->getProperty(vec[t])->clone();
74 
75  uk->add(p);
76  }
77 
78  return uk;
79 }
80 
82 {
83  if(!constraint)
84  return;
85 
86  te::da::UniqueKey* uk = dynamic_cast<te::da::UniqueKey*>(constraint);
87 
88  if(!uk)
89  return;
90 
91  m_ui->m_nameLineEdit->setText(uk->getName().c_str());
92 
93  std::vector<te::dt::Property*> ukProps = uk->getProperties();
94  std::vector<std::string> ukPropsStr;
95  for(std::size_t i = 0; i < ukProps.size(); ++i)
96  {
97  ukPropsStr.push_back(ukProps[i]->getName());
98  }
99 
100  std::vector<te::dt::Property*> dtProps = m_dsType->getProperties();
101  std::vector<std::string> dtPropsStr;
102  for(std::size_t i = 0; i < dtProps.size(); ++i)
103  {
104  std::string propStr = dtProps[i]->getName();
105 
106  if(std::find(ukPropsStr.begin(), ukPropsStr.end(), propStr) != ukPropsStr.end())
107  continue;
108 
109  dtPropsStr.push_back(propStr);
110  }
111 
112  m_doubleListWidget->setInputValues(dtPropsStr);
113  m_doubleListWidget->setOutputValues(ukPropsStr);
114 
115 }
virtual void setName(const std::string &name)
It sets the constraint name.
Definition: Constraint.h:126
void add(te::dt::Property *p)
It adds the property to the list of properties that participates in the unique key.
Definition: UniqueKey.h:124
virtual void setConstraint(te::da::Constraint *constraint)
virtual te::da::Constraint * getConstraint()
It returns the Constraint DataSet class object.
A class that models the description of a dataset.
Definition: DataSetType.h:72
virtual Property * clone() const =0
It returns a clone of the object.
This virtual class is used to define a Constraint DataSet class object.
It models a property definition.
Definition: Property.h:59
This file has the UniqueKeyConstraintWidget class.
It describes a unique key (uk) constraint.
Definition: UniqueKey.h:53
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that form the unique key.
Definition: UniqueKey.h:110
virtual const std::string & getName() const
It returns the constraint name.
Definition: Constraint.h:119
UniqueKeyConstraintWidget(te::da::DataSetType *dsType, QWidget *parent=0, Qt::WindowFlags f=0)