All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
38 te::qt::widgets::IndexWidget::IndexWidget(te::da::DataSetType* dsType, QWidget* parent, Qt::WindowFlags f)
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 }
78 
79 Ui::IndexWidgetForm* te::qt::widgets::IndexWidget::getForm() const
80 {
81  return m_ui.get();
82 }
83 
85 {
86  //get index name
87  if(m_ui->m_nameLineEdit->text().isEmpty())
88  {
89  return 0;
90  }
91 
92  std::string indexName = m_ui->m_nameLineEdit->text().toStdString();
93 
94  //get index type
95  int currIndex = m_ui->m_typeComboBox->currentIndex();
96  int indexType = m_ui->m_typeComboBox->itemData(currIndex).toInt();
97 
98  te::da::IndexType idxType = (te::da::IndexType)indexType;
99 
100  //get index properties
101  std::vector<std::string> vec = m_doubleListWidget->getOutputValues();
102 
103  if(vec.empty())
104  {
105  return 0;
106  }
107 
108  //create index
109  te::da::Index* idx = new te::da::Index(m_dsType);
110 
111  idx->setName(indexName);
112  idx->setIndexType(idxType);
113 
114  for(size_t t = 0; t < vec.size(); ++t)
115  {
116  te::dt::Property* p = m_dsType->getProperty(vec[t])->clone();
117 
118  idx->add(p);
119  }
120 
121  return idx;
122 }
123 
125 {
126  //get index name
127  if(m_ui->m_nameLineEdit->text().isEmpty())
128  {
129  QMessageBox::warning(this, tr("Warning"), tr("Index name not defined."));
130  return false;
131  }
132 
133  //get index properties
134  std::vector<std::string> vec = m_doubleListWidget->getOutputValues();
135 
136  if(vec.empty())
137  {
138  QMessageBox::warning(this, tr("Warning"), tr("No property selected."));
139  return false;
140  }
141 
142  return true;
143 }
144 
146 {
147  if(!idx)
148  return;
149 
150  m_ui->m_nameLineEdit->setText(idx->getName().c_str());
151 
152  m_ui->m_typeComboBox->setCurrentIndex(idx->getIndexType());
153 
154  std::vector<te::dt::Property*> idxProps = idx->getProperties();
155  std::vector<std::string> idxPropsStr;
156  for(std::size_t i = 0; i < idxProps.size(); ++i)
157  {
158  idxPropsStr.push_back(idxProps[i]->getName());
159  }
160 
161  std::vector<te::dt::Property*> dtProps = m_dsType->getProperties();
162  std::vector<std::string> dtPropsStr;
163  for(std::size_t i = 0; i < dtProps.size(); ++i)
164  {
165  std::string propStr = dtProps[i]->getName();
166 
167  if(std::find(idxPropsStr.begin(), idxPropsStr.end(), propStr) != idxPropsStr.end())
168  continue;
169 
170  dtPropsStr.push_back(propStr);
171  }
172 
173  m_doubleListWidget->setInputValues(dtPropsStr);
174  m_doubleListWidget->setOutputValues(idxPropsStr);
175 }
Property * getProperty(std::size_t i) const
It returns the i-th property.
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.
void setIndexType(IndexType t)
It sets the index type.
Definition: Index.h:176
void add(te::dt::Property *p)
It adds the property to the list of properties of the index.
Definition: Index.h:197
std::auto_ptr< Ui::IndexWidgetForm > m_ui
Definition: IndexWidget.h:87
bool checkParameters()
Check the interface parameters.
te::da::Index * getIndex()
It returns the Index DataSet class object.
Definition: IndexWidget.cpp:84
It models a property definition.
Definition: Property.h:59
This file has the IndexWidget class.
te::da::DataSetType * m_dsType
Definition: IndexWidget.h:89
te::qt::widgets::DoubleListWidget * m_doubleListWidget
Definition: IndexWidget.h:88
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)
IndexType
Index type.
Definition: Enums.h:107
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.
Definition: Index.h:183
Ui::DoubleListWidgetForm * getForm() const
void setName(const std::string &name)
It sets the index name.
Definition: Index.h:162
IndexType getIndexType() const
It gets the index type.
Definition: Index.h:169
It describes an index associated to a DataSetType.
Definition: Index.h:54
Ui::IndexWidgetForm * getForm() const
Definition: IndexWidget.cpp:79
const std::string & getName() const
It returns the property name.
Definition: Property.h:127
const std::string & getName() const
It returns the index name.
Definition: Index.h:155