All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PropertyConverterDialog.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/PropertyConverterDialog.cpp
22 
23  \brief A class used to define the PropertyConverterDialog class.
24 */
25 
26 // TerraLib
27 #include "../../../dataaccess/dataset/AttributeConverterManager.h"
28 #include "../../../dataaccess/dataset/DataSetAdapter.h"
29 #include "../../../dataaccess/dataset/DataSetType.h"
30 #include "../../../dataaccess/dataset/DataSetTypeConverter.h"
31 #include "../../../dataaccess/datasource/DataSource.h"
32 #include "../../../dataaccess/datasource/DataSourceCatalog.h"
33 #include "NewPropertyWidget.h"
35 #include "ui_NewPropertyWidgetForm.h"
36 #include "ui_PropertyConverterDialogForm.h"
37 
38 // Qt
39 #include <QMessageBox>
40 #include <QGridLayout>
41 
42 
44  : QDialog(parent, f),
45  m_ui(new Ui::PropertyConverterDialogForm),
46  m_propWidget(0),
47  m_dsType(0)
48 {
49  m_ui->setupUi(this);
50 
51  buidTypeMap();
52 
53  //build form
55 
56  QGridLayout* layout = new QGridLayout(m_ui->m_widget);
57 
58  layout->addWidget(m_propWidget);
59 
60  //connects
61  connect(m_ui->m_okPushButton, SIGNAL(clicked()), this, SLOT(onOkPushButtonClicked()));
62 
63  //get converters types
64  std::vector<std::string> converters;
65  te::da::AttributeConverterManager::getInstance().getConverters(converters);
66 
67  for(std::size_t t = 0; t < converters.size(); ++t)
68  {
69  m_ui->m_comboBox->addItem(converters[t].c_str());
70  }
71 
72  m_ui->m_helpPushButton->setPageReference("widgets/property/property_converter.html");
73 }
74 
76 {
77  m_typeMap.clear();
78 }
79 
81 {
82  assert(dsType);
83 
84  m_dsType = dsType;
85 
86  //fill table with dataset properties
87  for(size_t t = 0; t < m_dsType->size(); ++t)
88  {
89  std::string propName = m_dsType->getProperty(t)->getName();
90 
91  int newrow = m_ui->m_tableWidget->rowCount();
92  m_ui->m_tableWidget->insertRow(newrow);
93 
94  QTableWidgetItem* itemCheck = new QTableWidgetItem();
95  itemCheck->setFlags(Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
96  itemCheck->setCheckState(Qt::Unchecked);
97  m_ui->m_tableWidget->setItem(newrow, 0, itemCheck);
98 
99  QTableWidgetItem* itemName = new QTableWidgetItem(QString::fromStdString(propName));
100  itemName->setFlags(Qt::ItemIsEnabled);
101  m_ui->m_tableWidget->setItem(newrow, 1, itemName);
102 
103  QTableWidgetItem* itemType = new QTableWidgetItem(m_typeMap[m_dsType->getProperty(t)->getType()].c_str());
104  itemType->setFlags(Qt::ItemIsEnabled);
105  m_ui->m_tableWidget->setItem(newrow, 2, itemType);
106  }
107 
108  m_ui->m_tableWidget->resizeColumnsToContents();
109 }
110 
111 void te::qt::widgets::PropertyConverterDialog::set(std::string dataSourceId)
112 {
113  m_propWidget->setDataSourceId(dataSourceId);
114 }
115 
117 {
118  te::dt::SimpleProperty* p = m_propWidget->getProperty();
119  std::vector<std::string> names;
120  std::string converterName = m_ui->m_comboBox->currentText().toStdString();
121 
122  //get selected attributes
123  int row = m_ui->m_tableWidget->rowCount();
124 
125  for(int i = 0; i < row; ++i)
126  {
127  QTableWidgetItem* item = m_ui->m_tableWidget->item(i, 0);
128 
129  if(item && item->checkState() == Qt::Checked)
130  {
131  names.push_back(m_ui->m_tableWidget->item(i, 1)->text().toStdString());
132  }
133  }
134 
135  //adapt
136  converter->add(names, (te::dt::Property*)p, converterName);
137 }
138 
140 {
141  if(m_propWidget->buildProperty() == false)
142  {
143  return;
144  }
145 
146  accept();
147 }
148 
150 {
151  m_typeMap.clear();
152 
153  m_typeMap.insert(std::map<int, std::string>::value_type(te::dt::ARRAY_TYPE, tr("Array").toStdString()));
154  m_typeMap.insert(std::map<int, std::string>::value_type(te::dt::BIT_TYPE, tr("Bit").toStdString()));
155  m_typeMap.insert(std::map<int, std::string>::value_type(te::dt::BOOLEAN_TYPE, tr("Boolean").toStdString()));
156  m_typeMap.insert(std::map<int, std::string>::value_type(te::dt::BYTE_ARRAY_TYPE, tr("Byte Array").toStdString()));
157  m_typeMap.insert(std::map<int, std::string>::value_type(te::dt::CHAR_TYPE, tr("Char").toStdString()));
158  m_typeMap.insert(std::map<int, std::string>::value_type(te::dt::COMPOSITE_TYPE, tr("Composite").toStdString()));
159  m_typeMap.insert(std::map<int, std::string>::value_type(te::dt::DATASET_TYPE, tr("Data Set").toStdString()));
160  m_typeMap.insert(std::map<int, std::string>::value_type(te::dt::DATETIME_TYPE, tr("Date and Time").toStdString()));
161  m_typeMap.insert(std::map<int, std::string>::value_type(te::dt::DOUBLE_TYPE, tr("Double").toStdString()));
162  m_typeMap.insert(std::map<int, std::string>::value_type(te::dt::FLOAT_TYPE, tr("Float").toStdString()));
163  m_typeMap.insert(std::map<int, std::string>::value_type(te::dt::GEOMETRY_TYPE, tr("Geometry").toStdString()));
164  m_typeMap.insert(std::map<int, std::string>::value_type(te::dt::INT16_TYPE, tr("Int 16").toStdString()));
165  m_typeMap.insert(std::map<int, std::string>::value_type(te::dt::INT32_TYPE, tr("Int 32").toStdString()));
166  m_typeMap.insert(std::map<int, std::string>::value_type(te::dt::INT64_TYPE, tr("Int 64").toStdString()));
167  m_typeMap.insert(std::map<int, std::string>::value_type(te::dt::NUMERIC_TYPE, tr("Numeric").toStdString()));
168  m_typeMap.insert(std::map<int, std::string>::value_type(te::dt::RASTER_TYPE, tr("Raster").toStdString()));
169  m_typeMap.insert(std::map<int, std::string>::value_type(te::dt::STRING_TYPE, tr("String").toStdString()));
170  m_typeMap.insert(std::map<int, std::string>::value_type(te::dt::UCHAR_TYPE, tr("U Char").toStdString()));
171  m_typeMap.insert(std::map<int, std::string>::value_type(te::dt::UINT16_TYPE, tr("U Int 16").toStdString()));
172  m_typeMap.insert(std::map<int, std::string>::value_type(te::dt::UINT32_TYPE, tr("U Int 32").toStdString()));
173  m_typeMap.insert(std::map<int, std::string>::value_type(te::dt::UINT64_TYPE, tr("U Int 64").toStdString()));
174 }
Property * getProperty(std::size_t i) const
It returns the i-th property.
An atomic property like an integer or double.
A class that models the description of a dataset.
Definition: DataSetType.h:72
It models a property definition.
Definition: Property.h:59
A class used to define the NewPropertyWidget class.
An converter for DataSetType.
static AttributeConverterManager & getInstance()
It returns a reference to the singleton instance.
PropertyConverterDialog(QWidget *parent=0, Qt::WindowFlags f=0)
void adapt(te::da::DataSetTypeConverter *converter)
void add(const std::string &propertyName, te::dt::Property *p, const std::string &attributeConverterName="GenericAttributeConverter")
It adds a conversions to the given property of the input data set type.
te::qt::widgets::NewPropertyWidget * m_propWidget
A class used to define the PropertyConverterDialog class.
std::auto_ptr< Ui::PropertyConverterDialogForm > m_ui
const std::string & getName() const
It returns the property name.
Definition: Property.h:127