IndexWidget.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/IndexWidget.cpp
22 
23  \brief This file has the IndexWidget class.
24 */
25 
26 // TerraLib
27 #include "../../../dataaccess/dataset/DataSetType.h"
28 #include "../../../dataaccess/dataset/Index.h"
29 #include "../utils/DoubleListWidget.h"
30 #include "IndexWidget.h"
31 #include "ui_DoubleListWidgetForm.h"
32 #include "ui_IndexWidgetForm.h"
33 
34 // Qt
35 #include <QGridLayout>
36 #include <QMessageBox>
37 
39  : QWidget(parent, f),
40  m_ui(new Ui::IndexWidgetForm)
41 {
42  m_ui->setupUi(this);
43 
44  //set index types
45  m_ui->m_typeComboBox->addItem(tr("B Tree"), te::da::B_TREE_TYPE);
46  m_ui->m_typeComboBox->addItem(tr("R Tree"), te::da::R_TREE_TYPE);
47  m_ui->m_typeComboBox->addItem(tr("Quad Tree"), te::da::QUAD_TREE_TYPE);
48  m_ui->m_typeComboBox->addItem(tr("Hash"), te::da::HASH_TYPE);
49 
50 
51 //add double list widget to this form
52  m_doubleListWidget = new DoubleListWidget(m_ui->m_widget);
53  m_doubleListWidget->getForm()->m_leftItemsLabel->setText(tr("Available Properties"));
54  m_doubleListWidget->getForm()->m_rightItemsLabel->setText(tr("Selected Properties"));
55 
56  QGridLayout* layout = new QGridLayout(m_ui->m_widget);
57  layout->addWidget(m_doubleListWidget);
58 
59 //set properties names
60  m_dsType = dsType;
61 
62  if(m_dsType)
63  {
64  std::vector<std::string> propValues;
65 
66  for(size_t t = 0; t < m_dsType->getProperties().size(); ++t)
67  {
68  propValues.push_back(m_dsType->getProperty(t)->getName());
69  }
70 
72  }
73 }
74 
76 
77 Ui::IndexWidgetForm* te::qt::widgets::IndexWidget::getForm() const
78 {
79  return m_ui.get();
80 }
81 
83 {
84  //get index name
85  if(m_ui->m_nameLineEdit->text().isEmpty())
86  {
87  return nullptr;
88  }
89 
90  std::string indexName = m_ui->m_nameLineEdit->text().toUtf8().data();
91 
92  //get index type
93  int currIndex = m_ui->m_typeComboBox->currentIndex();
94  int indexType = m_ui->m_typeComboBox->itemData(currIndex).toInt();
95 
96  te::da::IndexType idxType = (te::da::IndexType)indexType;
97 
98  //get index properties
99  std::vector<std::string> vec = m_doubleListWidget->getOutputValues();
100 
101  if(vec.empty())
102  {
103  return nullptr;
104  }
105 
106  //create index
108 
109  idx->setName(indexName);
110  idx->setIndexType(idxType);
111 
112  for(size_t t = 0; t < vec.size(); ++t)
113  {
115 
116  idx->add(p);
117  }
118 
119  return idx;
120 }
121 
123 {
124  //get index name
125  if(m_ui->m_nameLineEdit->text().isEmpty())
126  {
127  QMessageBox::warning(this, tr("Warning"), tr("Index name not defined."));
128  return false;
129  }
130 
131  //get index properties
132  std::vector<std::string> vec = m_doubleListWidget->getOutputValues();
133 
134  if(vec.empty())
135  {
136  QMessageBox::warning(this, tr("Warning"), tr("No property selected."));
137  return false;
138  }
139 
140  return true;
141 }
142 
144 {
145  if(!idx)
146  return;
147 
148  m_ui->m_nameLineEdit->setText(idx->getName().c_str());
149 
150  m_ui->m_typeComboBox->setCurrentIndex(idx->getIndexType());
151 
152  std::vector<te::dt::Property*> idxProps = idx->getProperties();
153  std::vector<std::string> idxPropsStr;
154  for(std::size_t i = 0; i < idxProps.size(); ++i)
155  {
156  idxPropsStr.push_back(idxProps[i]->getName());
157  }
158 
159  std::vector<te::dt::Property*> dtProps = m_dsType->getProperties();
160  std::vector<std::string> dtPropsStr;
161  for(std::size_t i = 0; i < dtProps.size(); ++i)
162  {
163  std::string propStr = dtProps[i]->getName();
164 
165  if(std::find(idxPropsStr.begin(), idxPropsStr.end(), propStr) != idxPropsStr.end())
166  continue;
167 
168  dtPropsStr.push_back(propStr);
169  }
170 
171  m_doubleListWidget->setInputValues(dtPropsStr);
172  m_doubleListWidget->setOutputValues(idxPropsStr);
173 }
Property * getProperty(std::size_t i) const
It returns the i-th property.
std::unique_ptr< Ui::IndexWidgetForm > m_ui
Definition: IndexWidget.h:89
std::vector< std::string > getOutputValues()
A class that models the description of a dataset.
Definition: DataSetType.h:72
void setIndexType(IndexType t)
It sets the index type.
void add(te::dt::Property *p)
It adds the property to the list of properties of the index.
bool checkParameters()
Check the interface parameters.
virtual Property * clone() const =0
It returns a clone of the object.
te::da::Index * getIndex()
It returns the Index DataSet class object.
Definition: IndexWidget.cpp:82
It models a property definition.
Definition: Property.h:59
This file has the IndexWidget class.
te::da::DataSetType * m_dsType
Definition: IndexWidget.h:91
te::qt::widgets::DoubleListWidget * m_doubleListWidget
Definition: IndexWidget.h:90
void setInputValues(std::vector< std::string > values)
const std::vector< Property * > & getProperties() const
It returns the list of properties describing the CompositeProperty.
void setIndex(te::da::Index *idx)
te::gm::Polygon * p
IndexWidget(te::da::DataSetType *dsType, QWidget *parent=0, Qt::WindowFlags f=0)
Definition: IndexWidget.cpp:38
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that take part of the index.
Ui::DoubleListWidgetForm * getForm() const
void setName(const std::string &name)
It sets the index name.
void setOutputValues(std::vector< std::string > values)
IndexType getIndexType() const
It gets the index type.
It describes an index associated to a DataSetType.
Ui::IndexWidgetForm * getForm() const
Definition: IndexWidget.cpp:77
const std::string & getName() const
It returns the property name.
Definition: Property.h:127
const std::string & getName() const
It returns the index name.