All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ConfigInputAddressDialog.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/addressgeocoding/ImportTableDialog.cpp
22 
23  \brief A dialog to import table with address to geocoding operation
24 */
25 
26 // TerraLib
27 #include "../../common/Logger.h"
28 #include "../../common/progress/ProgressManager.h"
29 #include "../../common/Translator.h"
30 #include "../../common/STLUtils.h"
31 #include "../../dataaccess/dataset/DataSetType.h"
32 #include "../../dataaccess/dataset/ObjectIdSet.h"
33 #include "../../dataaccess/datasource/DataSourceCapabilities.h"
34 #include "../../dataaccess/datasource/DataSourceInfo.h"
35 #include "../../dataaccess/datasource/DataSourceInfoManager.h"
36 #include "../../dataaccess/datasource/DataSourceFactory.h"
37 #include "../../dataaccess/datasource/DataSourceManager.h"
38 #include "../../dataaccess/utils/Utils.h"
39 #include "../../datatype/Enums.h"
40 #include "../../datatype/Property.h"
41 #include "../../maptools/AbstractLayer.h"
42 #include "../../qt/af/Utils.h"
43 #include "../../qt/widgets/datasource/selector/DataSourceSelectorDialog.h"
44 #include "../../qt/widgets/layer/utils/DataSet2Layer.h"
45 #include "../../qt/widgets/progress/ProgressViewerDialog.h"
46 #include "../../statistics/core/Utils.h"
47 #include "../Config.h"
48 #include "../Exception.h"
50 #include "ui_ConfigInputAddressDialogForm.h"
51 
52 // Qt
53 #include <QFileDialog>
54 #include <QMessageBox>
55 #include <QSettings>
56 
57 // Boost
58 #include <boost/algorithm/string.hpp>
59 #include <boost/filesystem.hpp>
60 #include <boost/uuid/random_generator.hpp>
61 #include <boost/uuid/uuid_io.hpp>
62 
64  : QDialog(parent, f),
65  m_ui(new Ui::ConfigInputAddressDialogForm)
66 {
67 // add controls
68  m_ui->setupUi(this);
69 
70  connect(m_ui->m_helpPushButton, SIGNAL(clicked()), this, SLOT(onHelpPushButtonClicked()));
71  connect(m_ui->m_okPushButton, SIGNAL(clicked()), this, SLOT(onOkPushButtonClicked()));
72  connect(m_ui->m_cancelPushButton, SIGNAL(clicked()), this, SLOT(onCancelPushButtonClicked()));
73 
74  std::string fileName;
75  std::string streetName;
76 }
77 
79 {
80 }
81 
83 {
84  return m_dataSource;
85 }
86 
88 {
89  m_dataSource = dataSource;
90  std::vector<std::string> names = m_dataSource->getDataSetNames();
91 
92  m_ui->m_inputAddressLineEdit->clear();
93  m_ui->m_inputAddressLineEdit->setText(QString(names[0].c_str()));
94 
95  m_ui->m_sTypeComboBox->clear();
96  m_ui->m_sTitleComboBox->clear();
97  m_ui->m_sNameComboBox->clear();
98  m_ui->m_sNumberComboBox->clear();
99  m_ui->m_sNeighborhoodComboBox->clear();
100  m_ui->m_sPostalCodeComboBox->clear();
101 
102  m_ui->m_sTypeComboBox->addItem("");
103  m_ui->m_sTitleComboBox->addItem("");
104  m_ui->m_sNameComboBox->addItem("");
105  m_ui->m_sNumberComboBox->addItem("");
106  m_ui->m_sNeighborhoodComboBox->addItem("");
107  m_ui->m_sPostalCodeComboBox->addItem("");
108 
109  std::auto_ptr<te::da::DataSetType> dsType = m_dataSource->getDataSetType(names[0]);
110  std::vector<te::dt::Property*> propsVec = dsType->getProperties();
111 
112  for(std::size_t i = 0; i < propsVec.size(); ++i)
113  {
114  int type = propsVec[i]->getType();
115  if(type == te::dt::INT16_TYPE || type == te::dt::INT32_TYPE || type == te::dt::INT64_TYPE || type == te::dt::DOUBLE_TYPE )
116  {
117  m_ui->m_sNumberComboBox->addItem(QString(propsVec[i]->getName().c_str()));
118  }
119  else
120  {
121  m_ui->m_sTypeComboBox->addItem(QString(propsVec[i]->getName().c_str()));
122  m_ui->m_sTitleComboBox->addItem(QString(propsVec[i]->getName().c_str()));
123  m_ui->m_sNameComboBox->addItem(QString(propsVec[i]->getName().c_str()));
124  m_ui->m_sNeighborhoodComboBox->addItem(QString(propsVec[i]->getName().c_str()));
125  m_ui->m_sPostalCodeComboBox->addItem(QString(propsVec[i]->getName().c_str()));
126  }
127  }
128 }
129 
131 {
132  return m_ui->m_inputAddressLineEdit->text().toStdString();
133 }
134 
136 {
137  return m_ui->m_sTypeComboBox->currentText().toStdString();
138 }
139 
141 {
142  m_ui->m_sTypeComboBox->setCurrentIndex(m_ui->m_sTypeComboBox->findText(streetType.c_str()));
143 }
144 
146 {
147  return m_ui->m_sTitleComboBox->currentText().toStdString();
148 }
149 
151 {
152  m_ui->m_sTitleComboBox->setCurrentIndex(m_ui->m_sTitleComboBox->findText(streetTitle.c_str()));
153 }
154 
156 {
157  return m_ui->m_sNameComboBox->currentText().toStdString();
158 }
159 
161 {
162  m_ui->m_sNameComboBox->setCurrentIndex(m_ui->m_sNameComboBox->findText(streetName.c_str()));
163 }
164 
166 {
167  return m_ui->m_sNumberComboBox->currentText().toStdString();
168 }
169 
171 {
172  m_ui->m_sNumberComboBox->setCurrentIndex(m_ui->m_sNumberComboBox->findText(streetNumber.c_str()));
173 }
174 
176 {
177  return m_ui->m_sNeighborhoodComboBox->currentText().toStdString();
178 }
179 
181 {
182  m_ui->m_sNeighborhoodComboBox->setCurrentIndex(m_ui->m_sNeighborhoodComboBox->findText(streetNeighborhood.c_str()));
183 }
184 
186 {
187  return m_ui->m_sPostalCodeComboBox->currentText().toStdString();
188 }
189 
191 {
192  m_ui->m_sPostalCodeComboBox->setCurrentIndex(m_ui->m_sPostalCodeComboBox->findText(streetPostalCode.c_str()));
193 }
194 
196 {
197  QMessageBox::information(this, "Help", "Under development");
198 }
199 
201 {
202  std::map<std::string, std::string> connInfo = m_dataSource->getConnectionInfo();
203  std::map<std::string, std::string>::iterator it = connInfo.begin();
204 
205  std::vector<std::string>dsNames = m_dataSource->getDataSetNames();
206 
207  std::map<std::string, std::string> addressConfig;
208  addressConfig.insert(std::pair<std::string,std::string>("fileName", dsNames[0]));
209  addressConfig.insert(std::pair<std::string,std::string>("filePath", it->second));
210  addressConfig.insert(std::pair<std::string,std::string>("streetType", m_ui->m_sTypeComboBox->currentText().toStdString()));
211  addressConfig.insert(std::pair<std::string,std::string>("streetTitle", m_ui->m_sTitleComboBox->currentText().toStdString()));
212  addressConfig.insert(std::pair<std::string,std::string>("streetName", m_ui->m_sNameComboBox->currentText().toStdString()));
213  addressConfig.insert(std::pair<std::string,std::string>("number", m_ui->m_sNumberComboBox->currentText().toStdString()));
214  addressConfig.insert(std::pair<std::string,std::string>("neighborhood", m_ui->m_sNeighborhoodComboBox->currentText().toStdString()));
215  addressConfig.insert(std::pair<std::string,std::string>("postalCode", m_ui->m_sPostalCodeComboBox->currentText().toStdString()));
216 
217  AddAddressConfigToSettings(addressConfig);
218 
219  this->accept();
220 }
221 
223 {
224  reject();
225 }
226 
227 void te::addressgeocoding::ConfigInputAddressDialog::AddAddressConfigToSettings(std::map<std::string, std::string> addressConfig)
228 {
229  QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
230 
231  sett.beginGroup("Address Geocoding");
232 
233  AddAddressConfigItens(addressConfig, sett);
234 
235  sett.endGroup();
236 }
237 
238 void te::addressgeocoding::ConfigInputAddressDialog::AddAddressConfigItens(std::map<std::string, std::string> addressConfig, QSettings& sett)
239 {
240  std::map<std::string, std::string>::iterator it = addressConfig.begin();
241 
242  sett.beginGroup(it->second.c_str());
243 
244  while(it != addressConfig.end())
245  {
246  sett.setValue(it->first.c_str(), it->second.c_str());
247  ++it;
248  }
249 
250  sett.endGroup();
251 
252 }
253 
255  std::string streetType,
256  std::string streetTitle,
257  std::string streetName,
258  std::string number,
259  std::string neighborhood,
260  std::string postalCode)
261 {
262  QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
263 
264  QString key1 = "Address Geocoding/filePath";
265  QString key2 = "Address Geocoding/streetType";
266  QString key3 = "Address Geocoding/streetTitle";
267  QString key4 = "Address Geocoding/streetName";
268  QString key5 = "Address Geocoding/number";
269  QString key6 = "Address Geocoding/neighborhood";
270  QString key7 = "Address Geocoding/postalCode";
271 
272  sett.setValue(key1, filePath.c_str());
273  sett.setValue(key2, streetType.c_str());
274  sett.setValue(key3, streetTitle.c_str());
275  sett.setValue(key4, streetName.c_str());
276  sett.setValue(key5, number.c_str());
277  sett.setValue(key6, neighborhood.c_str());
278  sett.setValue(key7, postalCode.c_str());
279 }
280 
282  std::string& streetType,
283  std::string& streetTitle,
284  std::string& streetName,
285  std::string& number,
286  std::string& neighborhood,
287  std::string& postalCode)
288 {
289  QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
290 
291  std::string key1 = "Address Geocoding/filePath";
292  std::string key2 = "Address Geocoding/streetType";
293  std::string key3 = "Address Geocoding/streetTitle";
294  std::string key4 = "Address Geocoding/streetName";
295  std::string key5 = "Address Geocoding/number";
296  std::string key6 = "Address Geocoding/neighborhood";
297  std::string key7 = "Address Geocoding/postalCode";
298 
299  filePath = sett.value(key1.c_str()).toString().toStdString();
300  streetType = sett.value(key2.c_str()).toString().toStdString();
301  streetTitle = sett.value(key3.c_str()).toString().toStdString();
302  streetName = sett.value(key4.c_str()).toString().toStdString();
303  number = sett.value(key5.c_str()).toString().toStdString();
304  neighborhood = sett.value(key5.c_str()).toString().toStdString();
305  postalCode = sett.value(key6.c_str()).toString().toStdString();
306 }
307 
309 {
310 
311 }
void RemoveAddressConfigFromSettings(const QString &path, const QString &typeFile)
ConfigInputAddressDialog(QWidget *parent=0, Qt::WindowFlags f=0)
std::auto_ptr< Ui::ConfigInputAddressDialogForm > m_ui
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1435
void setDataSource(te::da::DataSourcePtr dataSource)
void AddAddressConfigItens(std::map< std::string, std::string > addressConfig, QSettings &sett)
void setStreetPostalCode(std::string streetPostalCode)
void setStreetNeighborhood(std::string streetNeighborhood)
void AddAddressConfigToSettings(std::map< std::string, std::string > addressConfig)
A dialog to import table with address to geocoding operation.
void GetAddressConfigToSettings(std::string &filePath, std::string &streetType, std::string &streetTitle, std::string &streetName, std::string &number, std::string &neighborhood, std::string &postalCode)