DirectExchangerDialog.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/exchanger/DirectExchangerDialog.h
22 
23  \brief A direct exchanger dialog for ADO, POSTGIS and SHP data sources
24 */
25 
26 // TerraLib
27 #include "../../../common/StringUtils.h"
28 #include "../../../dataaccess/dataset/DataSetAdapter.h"
29 #include "../../../dataaccess/dataset/PrimaryKey.h"
30 #include "../../../dataaccess/dataset/DataSetTypeConverter.h"
31 #include "../../../dataaccess/datasource/DataSourceFactory.h"
32 #include "../../../dataaccess/datasource/DataSourceInfo.h"
33 #include "../../../dataaccess/datasource/DataSourceInfoManager.h"
34 #include "../../../dataaccess/datasource/DataSourceManager.h"
35 #include "../../../dataaccess/datasource/DataSourceTransactor.h"
36 #include "../../../dataaccess/utils/Utils.h"
37 #include "../../../geometry/GeometryProperty.h"
38 #include "../../../maptools/DataSetLayer.h"
39 #include "../../../srs/Config.h"
40 #include "../../widgets/datasource/selector/DataSourceExplorerDialog.h"
41 #include "../../widgets/datasource/core/DataSourceType.h"
42 #include "../../widgets/datasource/core/DataSourceTypeManager.h"
43 #include "../../widgets/srs/SRSManagerDialog.h"
44 #include "DirectExchangerDialog.h"
45 #include "ui_DirectExchangerDialogForm.h"
46 
47 // Qt
48 #include <QFileDialog>
49 #include <QMessageBox>
50 
51 // Boost
52 #include <boost/algorithm/string/replace.hpp>
53 #include <boost/filesystem.hpp>
54 #include <boost/lexical_cast.hpp>
55 #include <boost/uuid/random_generator.hpp>
56 #include <boost/uuid/uuid_io.hpp>
57 
58 
61 
62 te::qt::widgets::DirectExchangerDialog::DirectExchangerDialog(QWidget* parent, Qt::WindowFlags f)
63  : QDialog(parent, f),
64  m_ui(new Ui::DirectExchangerDialogForm)
65 {
66 // setup widget
67  m_ui->setupUi(this);
68 
69 // add icons
70  m_ui->m_imgLabel->setPixmap(QIcon::fromTheme("data-exchange-direct-hint").pixmap(112,48));
71  m_ui->m_dsToolButton->setIcon(QIcon::fromTheme("datasource"));
72 
73 //connectors
74  connect(m_ui->m_okPushButton, SIGNAL(clicked()), this, SLOT(onOkPushButtonClicked()));
75  connect(m_ui->m_dirToolButton, SIGNAL(clicked()), this, SLOT(onDirToolButtonClicked()));
76  connect(m_ui->m_dsToolButton, SIGNAL(clicked()), this, SLOT(onDataSoruceToolButtonClicked()));
77  connect(m_ui->m_dsTypeComboBox, SIGNAL(activated(int)), this, SLOT(onDataSourceTypeActivated(int)));
78  connect(m_ui->m_inputLayerComboBox, SIGNAL(activated(QString)), this, SLOT(onInputLayerActivated(QString)));
79  connect(m_ui->m_outputSRIDToolButton, SIGNAL(clicked()), SLOT(onOutputLayerSRSTriggered()));
80 
81  m_ui->m_outputSRIDToolButton->setIcon(QIcon::fromTheme("srs"));
82  m_ui->m_helpPushButton->setPageReference("widgets/exchanger_direct/exchanger_direct.html");
83 
84  //starup interface
85  m_outputDataSourceType = "";
86  m_exchangeToFile = false;
87  m_lastDsType = "";
88 
89  setOutputDataSources();
90 }
91 
93 
94 void te::qt::widgets::DirectExchangerDialog::setLayers(std::list<te::map::AbstractLayerPtr> layers)
95 {
96  m_layers = layers;
97 
98  m_ui->m_inputLayerComboBox->clear();
99 
100  std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
101 
102  while(it != m_layers.end())
103  {
105 
106  std::unique_ptr<te::da::DataSetType> dsType = l->getSchema();
107 
108  if(dsType.get() && !dsType->hasRaster())
109  m_ui->m_inputLayerComboBox->addItem(l->getTitle().c_str(), QVariant::fromValue(l));
110 
111  ++it;
112  }
113 
114  if(m_ui->m_inputLayerComboBox->count() > 0)
115  {
116  QString s = m_ui->m_inputLayerComboBox->currentText();
117 
119  }
120 
121  if(m_ui->m_inputLayerComboBox->count() > 1)
122  m_ui->m_inputLayerComboBox->setEnabled(true);
123 }
124 
126 {
127  m_lastDsType = dataSource;
128 }
129 
131 {
132  m_ui->m_outputDataSourceComboBox->clear();
133 
134  std::vector<te::da::DataSourceInfoPtr> datasources;
135 
137 
138  for(std::size_t i = 0; i < datasources.size(); ++i)
139  {
140  const te::da::DataSourceInfoPtr& datasource = datasources[i];
141 
142  if(datasource.get() == nullptr)
143  continue;
144 
145  const std::string& title = datasource->getTitle();
146 
147  m_ui->m_outputDataSourceComboBox->addItem(title.c_str(), QVariant::fromValue(datasource));
148  }
149 }
150 
152 {
153  int idxLayer = m_ui->m_inputLayerComboBox->currentIndex();
154 
155  if(idxLayer == -1)
156  {
157  QMessageBox::warning(this, tr("Warning"), tr("Input layer not selected."));
158  return false;
159  }
160 
161  QVariant varLayer = m_ui->m_inputLayerComboBox->itemData(idxLayer, Qt::UserRole);
162  te::map::AbstractLayerPtr layer = varLayer.value<te::map::AbstractLayerPtr>();
163 
164  if(!layer.get())
165  {
166  QMessageBox::warning(this, tr("Warning"), tr("Error getting selected layer."));
167  return false;
168  }
169 
170  if(m_ui->m_dataSetLineEdit->text().isEmpty())
171  {
172  QMessageBox::warning(this, tr("Warning"), tr("Output File Name not defined."));
173  return false;
174  }
175 
176  //get srid information
177  int inputSRID = m_ui->m_inputSRIDLineEdit->text().toInt();
178 
179  int outputSRID = m_ui->m_outputSRIDLineEdit->text().toInt();
180 
181  try
182  {
183  //create adapter
184  std::unique_ptr<te::da::DataSetType> dsType = layer->getSchema();
185 
186  QFileInfo fileInfo(m_ui->m_dataSetLineEdit->text());
187 
188  //create data source
189  std::string connInfo("file://" + std::string(fileInfo.absoluteFilePath().toUtf8().data()));
190 
191  if (fileInfo.suffix().toUtf8().data() == std::string("csv"))
192  connInfo += "?GEOMETRY=AS_WKT";
193 
194  if (connInfo.find("(") != std::string::npos || connInfo.find(")") != std::string::npos)
195  {
196  throw te::common::Exception(tr("The output name has invalid characters (parentheses).\nRemoves these characters to perform the operation.").toUtf8());
197  }
198 
199  std::unique_ptr<te::da::DataSource> dsOGR = te::da::DataSourceFactory::make(m_outputDataSourceType, connInfo);
200 
201  if (dsOGR.get() == nullptr)
202  throw te::common::Exception(tr("Output invalid.").toUtf8());
203 
204  dsOGR->open();
205 
206  te::da::DataSetTypeConverter* converter = new te::da::DataSetTypeConverter(dsType.get(), dsOGR->getCapabilities(), dsOGR->getEncoding());
207 
208  te::da::AssociateDataSetTypeConverterSRID(converter, inputSRID, outputSRID);
209 
210  te::da::DataSetType* dsTypeResult = converter->getResult();
211 
212  boost::filesystem::path uri(m_ui->m_dataSetLineEdit->text().toUtf8().data());
213 
214  std::string val = uri.stem().string();
215 
216  dsTypeResult->setName(val);
217 
218  // Check dataset name
219  if(!dsOGR->isDataSetNameValid(dsTypeResult->getName()))
220  {
221  int r = QMessageBox::question(this, tr("Exchanger"), tr("Layer name invalid for output datasource. Would you like to normalize the name?"), QMessageBox::Yes, QMessageBox::No);
222 
223  if(r == QMessageBox::Yes)
224  {
225  bool aux;
226  std::string newName = te::common::ReplaceSpecialChars(dsTypeResult->getName(), aux);
227  dsTypeResult->setName(newName);
228  }
229  else
230  {
231  throw te::common::Exception(tr("Layer name invalid for output datasource!").toUtf8().data());
232  }
233  }
234 
235  // Check properties names
236  std::vector<te::dt::Property* > props = dsTypeResult->getProperties();
237  std::map<std::size_t, std::string> invalidNames;
238  for(std::size_t i = 0; i < props.size(); ++i)
239  {
240  if(!dsOGR->isPropertyNameValid(props[i]->getName()))
241  {
242  invalidNames[i] = props[i]->getName();
243  }
244  }
245 
246  if(!invalidNames.empty())
247  {
248  int r = QMessageBox::question(this, tr("Exchanger"), tr("Some property name is invalid for output datasource. Would you like to normalize the name?"), QMessageBox::Yes, QMessageBox::No);
249 
250  if(r == QMessageBox::Yes)
251  {
252  std::map<std::size_t, std::string>::iterator it = invalidNames.begin();
253 
254  while(it != invalidNames.end())
255  {
256  bool aux;
257  std::string newName = te::common::ReplaceSpecialChars(it->second, aux);
258 
259  props[it->first]->setName(newName);
260 
261  ++it;
262  }
263  }
264  else
265  {
266  QString err(tr("Some property name is invalid for output datasource:\n\n"));
267 
268  std::map<std::size_t, std::string>::iterator it = invalidNames.begin();
269 
270  while(it != invalidNames.end())
271  {
272  err.append(" - ");
273  err.append(it->second.c_str());
274 
275  ++it;
276  }
277 
278  throw te::common::Exception(err.toUtf8().data());
279  }
280  }
281 
282  //exchange
283  std::map<std::string,std::string> nopt;
284 
285  std::unique_ptr<te::da::DataSet> dataset = layer->getData();
286 
287  dsOGR->createDataSet(dsTypeResult, nopt);
288 
289  std::unique_ptr<te::da::DataSetAdapter> dsAdapter(te::da::CreateAdapter(dataset.get(), converter));
290 
291  if(dataset->moveBeforeFirst())
292  dsOGR->add(dsTypeResult->getName(), dsAdapter.get(), nopt);
293 
294  dsOGR->close();
295 
296  QMessageBox::information(this, tr("Exchanger"), tr("Layer exported successfully."));
297  }
298  catch(const std::exception& e)
299  {
300  QString errMsg(tr("Error during exchanger. The reported error is: %1"));
301 
302  errMsg = errMsg.arg(e.what());
303 
304  QMessageBox::information(this, tr("Exchanger"), errMsg);
305 
306  return false;
307  }
308  catch (...)
309  {
310  QString errMsg(tr("Error during exchanger."));
311 
312  QMessageBox::information(this, tr("Exchanger"), errMsg);
313 
314  return false;
315  }
316 
317  return true;
318 }
319 
321 {
322  int idxLayer = m_ui->m_inputLayerComboBox->currentIndex();
323 
324  if(idxLayer == -1)
325  {
326  QMessageBox::warning(this, tr("Warning"), tr("Input layer not selected."));
327  return false;
328  }
329 
330  QVariant varLayer = m_ui->m_inputLayerComboBox->itemData(idxLayer, Qt::UserRole);
331  te::map::AbstractLayerPtr layer = varLayer.value<te::map::AbstractLayerPtr>();
332 
333  if(!layer.get())
334  {
335  QMessageBox::warning(this, tr("Warning"), tr("Error getting selected layer."));
336  return false;
337  }
338 
339  int idxDataSource = m_ui->m_outputDataSourceComboBox->currentIndex();
340 
341  if(idxLayer == -1)
342  {
343  QMessageBox::warning(this, tr("Warning"), tr("Output data source not selected."));
344  return false;
345  }
346 
347  QVariant varDataSource = m_ui->m_outputDataSourceComboBox->itemData(idxDataSource, Qt::UserRole);
348  te::da::DataSourceInfoPtr dsInfo = varDataSource.value<te::da::DataSourceInfoPtr>();
349 
350  if(!dsInfo.get())
351  {
352  QMessageBox::warning(this, tr("Warning"), tr("Error getting selected data source."));
353  return false;
354  }
355 
356  if(m_ui->m_dataSetLineEdit->text().isEmpty())
357  {
358  QMessageBox::warning(this, tr("Warning"), tr("Data Set name not defined."));
359  return false;
360  }
361 
362  //get srid information
363  int inputSRID = m_ui->m_inputSRIDLineEdit->text().toInt();
364 
365  int outputSRID = m_ui->m_outputSRIDLineEdit->text().toInt();
366 
367  std::unique_ptr<te::da::DataSourceTransactor> transactor;
368 
369  try
370  {
371  setCursor(Qt::WaitCursor);
372 
373  //create adapter
374  std::unique_ptr<te::da::DataSetType> dsType = layer->getSchema();
375 
376  bool isLinked = te::da::HasLinkedTable(dsType.get());
377 
378  if (isLinked)
379  {
380  te::da::PrimaryKey* pk = dsType->getPrimaryKey();
381 
382  if (pk)
383  {
384  std::vector<te::dt::Property*> props = pk->getProperties();
385 
386  for (size_t t = 0; t < props.size(); ++t)
387  {
388  std::vector<std::string> tokens;
389  te::common::Tokenize(props[t]->getName(), tokens, ".");
390 
391  size_t tkSize = tokens.size();
392  props[t]->setName(tokens[tkSize - 1]);
393 
394  te::dt::SimpleProperty* p = dynamic_cast<te::dt::SimpleProperty*>(props[t]);
395 
396  if (p)
397  {
398  p->setRequired(false);
399  p->setAutoNumber(false);
400  p->setDefaultValue(nullptr);
401  }
402  }
403 
404  dsType->setPrimaryKey(nullptr);
405  }
406  }
407 
408  te::da::DataSourcePtr targetDSPtr = te::da::DataSourceManager::getInstance().get(dsInfo->getId(), dsInfo->getType(), dsInfo->getConnInfo());
409 
410  if (!targetDSPtr->isOpened())
411  targetDSPtr->open();
412 
413  transactor = targetDSPtr->getTransactor();
414 
415  te::da::DataSetTypeConverter* converter = new te::da::DataSetTypeConverter(dsType.get(), targetDSPtr->getCapabilities(), targetDSPtr->getEncoding());
416 
417  te::da::AssociateDataSetTypeConverterSRID(converter, inputSRID, outputSRID);
418 
419  te::da::DataSetType* dsTypeResult = converter->getResult();
420 
421  dsTypeResult->setName(m_ui->m_dataSetLineEdit->text().toUtf8().data());
422 
423  // Check dataset name
424  if(!targetDSPtr->isDataSetNameValid(dsTypeResult->getName()))
425  {
426  int r = QMessageBox::question(this, tr("Exchanger"), tr("Layer name invalid for output datasource. Would you like to normalize the name?"), QMessageBox::Yes, QMessageBox::No);
427 
428  if(r == QMessageBox::Yes)
429  {
430  bool aux;
431  std::string newName = te::common::ReplaceSpecialChars(dsTypeResult->getName(), aux);
432  dsTypeResult->setName(newName);
433  }
434  else
435  {
436  throw te::common::Exception(tr("Layer name invalid for output datasource!").toUtf8().data());
437  }
438  }
439 
440  // Check properties names
441  std::vector<te::dt::Property* > props = dsTypeResult->getProperties();
442  std::map<std::size_t, std::string> invalidNames;
443  for(std::size_t i = 0; i < props.size(); ++i)
444  {
445  if(!targetDSPtr->isPropertyNameValid(props[i]->getName()))
446  {
447  invalidNames[i] = props[i]->getName();
448  }
449  }
450 
451  if(!invalidNames.empty())
452  {
453  int r = QMessageBox::question(this, tr("Exchanger"), tr("Some property name is invalid for output datasource. Would you like to normalize the name?"), QMessageBox::Yes, QMessageBox::No);
454 
455  if(r == QMessageBox::Yes)
456  {
457  std::map<std::size_t, std::string>::iterator it = invalidNames.begin();
458 
459  while(it != invalidNames.end())
460  {
461  bool aux;
462  std::string newName = te::common::ReplaceSpecialChars(it->second, aux);
463 
464  props[it->first]->setName(newName);
465 
466  ++it;
467  }
468  }
469  else
470  {
471  QString err(tr("Some property name is invalid for output datasource:\n\n"));
472 
473  std::map<std::size_t, std::string>::iterator it = invalidNames.begin();
474 
475  while(it != invalidNames.end())
476  {
477  err.append(" - ");
478  err.append(it->second.c_str());
479 
480  ++it;
481  }
482 
483  throw te::common::Exception(err.toUtf8().data());
484  }
485  }
486 
487  //fix repeated names
488  std::set<std::string> names;
489 
490  props = dsTypeResult->getProperties();
491 
492  for (std::size_t i = 0; i < props.size(); ++i)
493  {
494  //check if the property name its duplicated
495  std::string propName = props[i]->getName();
496 
497  int count = 1;
498  while (names.find(te::common::Convert2UCase(propName)) != names.end())
499  {
500  propName += "_";
501  propName += te::common::Convert2String(count);
502  }
503 
504  names.insert(te::common::Convert2UCase(propName));
505 
506  props[i]->setName(propName);
507  }
508 
509  //create index
510  if(m_ui->m_spatialIndexCheckBox->isChecked())
511  {
513 
514  if(p)
515  {
516  te::da::Index* idx = new te::da::Index(dsTypeResult);
517 
518  std::string name = std::string(m_ui->m_dataSetLineEdit->text().toUtf8().data()) + "_" + p->getName() + "_idx";
519 
520  boost::replace_all(name, ".", "_");
521 
522  idx->setName(name);
524 
525  te::dt::Property* pClone = p->clone();
526 
527  idx->add(pClone);
528  }
529  }
530 
531  if (!isLinked)
532  {
533  //create primary key
534  if (dsType->getPrimaryKey())
535  {
536  te::da::PrimaryKey* pk = new te::da::PrimaryKey(dsTypeResult);
537 
538  std::string name = std::string(m_ui->m_dataSetLineEdit->text().toUtf8().data()) + "_" + dsType->getPrimaryKey()->getName() + "_pk";
539 
540  boost::replace_all(name, ".", "_");
541 
542  pk->setName(name);
543 
544  std::vector<te::dt::Property*> props = dsType->getPrimaryKey()->getProperties();
545 
546  for (size_t t = 0; t < props.size(); ++t)
547  {
548  te::dt::Property* p = props[t]->clone();
549 
550  pk->add(p);
551  }
552  }
553  }
554 
555  //exchange
556  std::map<std::string,std::string> nopt;
557 
558  std::unique_ptr<te::da::DataSet> dataset = layer->getData();
559 
560  transactor->begin();
561 
562  transactor->createDataSet(dsTypeResult, nopt);
563 
564  std::unique_ptr<te::da::DataSetAdapter> dsAdapter(te::da::CreateAdapter(dataset.get(), converter));
565 
566  if(dataset->moveBeforeFirst())
567  transactor->add(dsTypeResult->getName(), dsAdapter.get(), nopt);
568 
569  if (isLinked)
570  {
571  std::string name = std::string(m_ui->m_dataSetLineEdit->text().toUtf8().data()) + "_id";
572 
574  p->setAutoNumber(true);
575 
576  transactor->addProperty(dsTypeResult->getName(), p);
577 
578  te::da::PrimaryKey* pk = new te::da::PrimaryKey(dsTypeResult);
579 
580  name += "_pk";
581 
582  boost::replace_all(name, ".", "_");
583 
584  pk->setName(name);
585 
586  pk->add(p);
587 
588  transactor->addPrimaryKey(dsTypeResult->getName(), pk);
589  }
590 
591  transactor->commit();
592 
593  setCursor(Qt::ArrowCursor);
594  QMessageBox::information(this, tr("Exchanger"), tr("Layer exported successfully."));
595  }
596  catch(const std::exception& e)
597  {
598  setCursor(Qt::ArrowCursor);
599 
600  if (transactor.get())
601  transactor->rollBack();
602 
603  QString errMsg(tr("Error during exchanger. The reported error is: %1"));
604 
605  errMsg = errMsg.arg(e.what());
606 
607  QMessageBox::information(this, tr("Exchanger"), errMsg);
608 
609  return false;
610  }
611 
612  return true;
613 }
614 
616 {
617  QString value = m_ui->m_dsTypeComboBox->itemData(index).toString();
618 
619  m_outputDataSourceType = value.toUtf8().data();
620 
621  if(m_outputDataSourceType == "POSTGIS")
622  {
623  m_exchangeToFile = false;
624 
625  m_ui->m_outputDataSourceComboBox->setEnabled(true);
626  m_ui->m_dsToolButton->setEnabled(true);
627  m_ui->m_dataSetLineEdit->clear();
628  m_ui->m_dataSetLineEdit->setEnabled(true);
629  m_ui->m_dirToolButton->setEnabled(false);
630  m_ui->m_spatialIndexCheckBox->setEnabled(true);
631  m_ui->m_spatialIndexCheckBox->setChecked(true);
632 
633  setDataSources();
634  }
635  else if(m_outputDataSourceType == "ADO")
636  {
637  m_exchangeToFile = false;
638 
639  m_ui->m_outputDataSourceComboBox->setEnabled(true);
640  m_ui->m_dsToolButton->setEnabled(true);
641  m_ui->m_dataSetLineEdit->clear();
642  m_ui->m_dataSetLineEdit->setEnabled(true);
643  m_ui->m_dirToolButton->setEnabled(false);
644  m_ui->m_spatialIndexCheckBox->setEnabled(false);
645  m_ui->m_spatialIndexCheckBox->setChecked(false);
646 
647  setDataSources();
648  }
649  else if(m_outputDataSourceType == "OGR")
650  {
651  m_exchangeToFile = true;
652 
653  m_ui->m_outputDataSourceComboBox->clear();
654  m_ui->m_outputDataSourceComboBox->setEnabled(false);
655  m_ui->m_dsToolButton->setEnabled(false);
656  m_ui->m_dataSetLineEdit->clear();
657  m_ui->m_dataSetLineEdit->setEnabled(false);
658  m_ui->m_dirToolButton->setEnabled(true);
659  m_ui->m_spatialIndexCheckBox->setEnabled(false);
660  m_ui->m_spatialIndexCheckBox->setChecked(false);
661  }
662 }
663 
665 {
666  onDataSourceTypeActivated(m_ui->m_dsTypeComboBox->currentIndex());
667 
668  if(m_ui->m_dataSetLineEdit->isEnabled())
669  m_ui->m_dataSetLineEdit->setText(value);
670 
671  QVariant varLayer = m_ui->m_inputLayerComboBox->itemData(m_ui->m_inputLayerComboBox->currentIndex(), Qt::UserRole);
672  te::map::AbstractLayerPtr layer = varLayer.value<te::map::AbstractLayerPtr>();
673 
674  if (!layer.get())
675  {
676  QMessageBox::warning(this, tr("Warning"), tr("Error getting selected layer."));
677  return;
678  }
679 
680  int inputSRID = layer->getSRID();
681 
682  m_ui->m_inputSRIDLineEdit->setText(QString::number(inputSRID));
683  m_ui->m_outputSRIDLineEdit->setText(QString::number(inputSRID));
684 
685  if (inputSRID == TE_UNKNOWN_SRS)
686  {
687  m_ui->m_outputSRIDLineEdit->setEnabled(false);
688  m_ui->m_outputSRIDToolButton->setEnabled(false);
689  }
690  else
691  {
692  m_ui->m_outputSRIDLineEdit->setEnabled(true);
693  m_ui->m_outputSRIDToolButton->setEnabled(true);
694  }
695 }
696 
698 {
699  QString fileName = QFileDialog::getSaveFileName(this, tr("Save as..."),
700  QString(), tr("Shapefile (*.shp *.SHP);;Mapinfo File (*.mif *.MIF);;KML (*.kml *.KML);;GeoJSON (*.geojson *.GEOJSON);;GML (*.gml *.GML);;DXF (*.dxf *.DXF);;DGN (*.dgn *.DGN);; CSV (*.csv *.CSV);;"), nullptr, QFileDialog::DontConfirmOverwrite);
701 
702  if (fileName.isEmpty())
703  return;
704 
705  m_ui->m_dataSetLineEdit->setText(fileName);
706 }
707 
709 {
710  std::unique_ptr<te::qt::widgets::DataSourceExplorerDialog> dExplorer(new te::qt::widgets::DataSourceExplorerDialog(this));
711 
712  if(!m_lastDsType.empty())
713  dExplorer->setDataSourceToUse(m_lastDsType.c_str());
714 
715  dExplorer->exec();
716 
717  setDataSources();
718 }
719 
721 {
722  if (m_ui->m_outputSRIDLineEdit->text().isEmpty())
723  {
724  QMessageBox::warning(this, tr("Warning"), tr("Output Layer SRID not defined."));
725  return;
726  }
727 
728  int inputSRID = m_ui->m_inputSRIDLineEdit->text().toInt();
729  int outputSRID = m_ui->m_outputSRIDLineEdit->text().toInt();
730 
731  if (inputSRID != outputSRID && outputSRID == TE_UNKNOWN_SRS)
732  {
733  QMessageBox::warning(this, tr("Warning"), tr("Invalid output Layer SRID."));
734  return;
735  }
736 
737  if (inputSRID != outputSRID && inputSRID == TE_UNKNOWN_SRS)
738  {
739  QMessageBox::warning(this, tr("Warning"), tr("Invalid input Layer SRID."));
740  return;
741  }
742 
743  bool res = false;
744 
745  if(m_exchangeToFile)
746  res = exchangeToFile();
747  else
748  res = exchangeToDatabase();
749 
750  if(res)
751  accept();
752 }
753 
755 {
756  m_ui->m_dsTypeComboBox->clear();
757 
758  // add the list of data sources available in the system
759  std::map<std::string, DataSourceType*>::const_iterator it = DataSourceTypeManager::getInstance().begin();
760  std::map<std::string, DataSourceType*>::const_iterator itend = DataSourceTypeManager::getInstance().end();
761 
762  while (it != itend)
763  {
764  std::string dataSourceName = it->first;
765 
766  if (dataSourceName == "POSTGIS" || dataSourceName == "ADO" || dataSourceName == "OGR")
767  {
768  QIcon icon = it->second->getIcon(DataSourceType::ICON_DATASOURCE_SMALL);
769  QString title = QString::fromUtf8(it->second->getTitle().c_str());
770 
771  m_ui->m_dsTypeComboBox->addItem(icon, title, QVariant(dataSourceName.c_str()));
772  }
773 
774  ++it;
775  }
776 }
777 
779 {
780  te::qt::widgets::SRSManagerDialog srsDialog(this);
781  srsDialog.setWindowTitle(tr("Choose the SRS"));
782 
783  if (srsDialog.exec() == QDialog::Rejected)
784  return;
785 
786  std::pair<int, std::string> srid = srsDialog.getSelectedSRS();
787 
788  m_ui->m_outputSRIDLineEdit->setText(QString::number(srid.first));
789 }
virtual void setName(const std::string &name)
It sets the constraint name.
Definition: Constraint.h:126
void setAutoNumber(bool a)
It tells if the property is an autonumber or not.
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr) Q_DECLARE_METATYPE(te
void setDataSources()
Set the list of data sources that can be used.
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
Geometric property.
void add(te::dt::Property *p)
It adds a property to the list of properties of the primary key.
Definition: PrimaryKey.h:123
std::unique_ptr< Ui::DirectExchangerDialogForm > m_ui
A dialog for selecting a data source.
An atomic property like an integer or double.
boost::shared_ptr< DataSource > DataSourcePtr
TEDATAACCESSEXPORT void AssociateDataSetTypeConverterSRID(DataSetTypeConverter *converter, const int &inputSRID, const int &outputSRID=TE_UNKNOWN_SRS)
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
TEDATAACCESSEXPORT bool HasLinkedTable(te::da::DataSetType *type)
It checks if the datasettype has a linked table.
A class that models the description of a dataset.
Definition: DataSetType.h:72
void setIndexType(IndexType t)
It sets the index type.
std::string Convert2UCase(const std::string &value)
It converts a string to upper case.
Definition: StringUtils.h:168
void add(te::dt::Property *p)
It adds the property to the list of properties of the index.
te::dt::Property * clone() const
It returns a clone of the object.
std::string ReplaceSpecialChars(const std::string &str, bool &changed)
It replace special characters of a string.
Definition: StringUtils.h:376
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 setDefaultValue(std::string *d)
It sets the default value associated to the property, or NULL if none is associated.
virtual te::dt::AbstractData * clone() const
It clones the linestring.
An converter for DataSetType.
void Tokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" ")
It tokenizes a given string with a delimiter of your own choice.
Definition: StringUtils.h:221
void setName(const std::string &name)
It sets the property name.
Definition: Property.h:137
const std::vector< Property * > & getProperties() const
It returns the list of properties describing the CompositeProperty.
static DataSourceInfoManager & getInstance()
It returns a reference to the singleton instance.
URI C++ Library.
Definition: Attributes.h:37
te::gm::Polygon * p
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used.
A direct exchanger dialog for ADO, POSTGIS and SHP data sources.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
void setLastDataSource(std::string dataSource)
Function used to set the last data source used.
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52
void setRequired(bool r)
It tells if the property is required or not.
std::list< te::map::AbstractLayerPtr > m_layers
void setName(const std::string &name)
It sets the index name.
std::string Convert2String(boost::int16_t value)
It converts a short integer value to a string.
Definition: StringUtils.h:56
A dialog used to build a SRSManagerDialog element.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
TEDATAACCESSEXPORT DataSetAdapter * CreateAdapter(DataSet *ds, DataSetTypeConverter *converter, bool isOwner=false)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
const std::pair< int, std::string > & getSelectedSRS() const
Returns the selected SRS in the window.
It describes an index associated to a DataSetType.
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
const std::string & getName() const
It returns the property name.
Definition: Property.h:127