PrimaryKeyConstraintWidget.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/PrimaryKeyConstraintWidget.cpp
22 
23  \brief This file has the PrimaryKeyConstraintWidget class.
24 */
25 
26 // TerraLib
27 #include "../../../dataaccess/dataset/DataSetType.h"
28 #include "../../../dataaccess/dataset/PrimaryKey.h"
29 #include "../utils/DoubleListWidget.h"
31 #include "ui_ConstraintWidgetForm.h"
32 #include "ui_DoubleListWidgetForm.h"
33 
34 //Qt
35 #include <QWidget>
36 
37 
39  : ConstraintWidget(dsType, parent, f)
40 {
41 }
42 
44  default;
45 
47 {
48 //get index name
49  if(m_ui->m_nameLineEdit->text().isEmpty())
50  {
51  return nullptr;
52  }
53 
54  std::string constraintName = m_ui->m_nameLineEdit->text().toUtf8().data();
55 
56  //get properties
57  std::vector<std::string> vec = m_doubleListWidget->getOutputValues();
58 
59  if(vec.empty())
60  {
61  return nullptr;
62  }
63 
64  //create constraint
66 
67  pk->setName(constraintName);
68 
69  for(size_t t = 0; t < vec.size(); ++t)
70  {
72 
73  pk->add(p);
74  }
75 
76  return pk;
77 }
78 
80 {
81  if(!constraint)
82  return;
83 
84  te::da::PrimaryKey* pk = dynamic_cast<te::da::PrimaryKey*>(constraint);
85 
86  if(!pk)
87  return;
88 
89  m_ui->m_nameLineEdit->setText(pk->getName().c_str());
90 
91  std::vector<te::dt::Property*> pkProps = pk->getProperties();
92  std::vector<std::string> pkPropsStr;
93  for(std::size_t i = 0; i < pkProps.size(); ++i)
94  {
95  pkPropsStr.push_back(pkProps[i]->getName());
96  }
97 
98  std::vector<te::dt::Property*> dtProps = m_dsType->getProperties();
99  std::vector<std::string> dtPropsStr;
100  for(std::size_t i = 0; i < dtProps.size(); ++i)
101  {
102  std::string propStr = dtProps[i]->getName();
103 
104  if(std::find(pkPropsStr.begin(), pkPropsStr.end(), propStr) != pkPropsStr.end())
105  continue;
106 
107  dtPropsStr.push_back(propStr);
108  }
109 
110  m_doubleListWidget->setInputValues(dtPropsStr);
111  m_doubleListWidget->setOutputValues(pkPropsStr);
112 
113 }
114 
virtual void setName(const std::string &name)
It sets the constraint name.
Definition: Constraint.h:126
Property * getProperty(std::size_t i) const
It returns the i-th property.
virtual te::da::Constraint * getConstraint()
It returns the Constraint DataSet class object.
void add(te::dt::Property *p)
It adds a property to the list of properties of the primary key.
Definition: PrimaryKey.h:123
std::vector< std::string > getOutputValues()
te::qt::widgets::DoubleListWidget * m_doubleListWidget
A class that models the description of a dataset.
Definition: DataSetType.h:72
This virtual class is used to define a Constraint DataSet class object.
virtual Property * clone() const =0
It returns a clone of the object.
It models a property definition.
Definition: Property.h:59
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that take part of the primary key.
Definition: PrimaryKey.h:109
void setInputValues(std::vector< std::string > values)
This file has the PrimaryKeyConstraintWidget class.
const std::vector< Property * > & getProperties() const
It returns the list of properties describing the CompositeProperty.
te::gm::Polygon * p
virtual void setConstraint(te::da::Constraint *constraint)
std::unique_ptr< Ui::ConstraintWidgetForm > m_ui
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52
void setOutputValues(std::vector< std::string > values)
virtual const std::string & getName() const
It returns the constraint name.
Definition: Constraint.h:119
PrimaryKeyConstraintWidget(te::da::DataSetType *dsType, QWidget *parent=0, Qt::WindowFlags f=0)