27 #include "../../../dataaccess/dataset/DataSetAdapter.h"
28 #include "../../../dataaccess/dataset/PrimaryKey.h"
29 #include "../../../dataaccess/dataset/DataSetTypeConverter.h"
30 #include "../../../dataaccess/datasource/DataSourceFactory.h"
31 #include "../../../dataaccess/datasource/DataSourceInfo.h"
32 #include "../../../dataaccess/datasource/DataSourceInfoManager.h"
33 #include "../../../dataaccess/datasource/DataSourceManager.h"
34 #include "../../../dataaccess/utils/Utils.h"
35 #include "../../../geometry/GeometryProperty.h"
36 #include "../../../maptools/DataSetLayer.h"
37 #include "../../widgets/datasource/selector/DataSourceExplorerDialog.h"
38 #include "../../widgets/srs/SRSManagerDialog.h"
40 #include "ui_DirectExchangerDialogForm.h"
43 #include <QtGui/QFileDialog>
44 #include <QtGui/QMessageBox>
47 #include <boost/filesystem.hpp>
48 #include <boost/lexical_cast.hpp>
49 #include <boost/uuid/random_generator.hpp>
50 #include <boost/uuid/uuid_io.hpp>
58 m_ui(new Ui::DirectExchangerDialogForm)
64 m_ui->m_imgLabel->setPixmap(QIcon::fromTheme(
"data-exchange-direct-hint").pixmap(112,48));
65 m_ui->m_dsToolButton->setIcon(QIcon::fromTheme(
"datasource"));
74 m_ui->m_helpPushButton->setPageReference(
"widgets/exchanger_direct/exchanger_direct.html");
91 m_ui->m_inputLayerComboBox->clear();
93 std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
95 while(it != m_layers.end())
99 std::auto_ptr<te::da::DataSetType> dsType = l->getSchema();
101 if(dsType.get() && dsType->hasGeom())
102 m_ui->m_inputLayerComboBox->addItem(l->getTitle().c_str(), QVariant::fromValue(l));
107 if(m_ui->m_inputLayerComboBox->count() > 0)
109 QString s = m_ui->m_inputLayerComboBox->currentText();
111 onInputLayerActivated(s);
114 if(m_ui->m_inputLayerComboBox->count() > 1)
115 m_ui->m_inputLayerComboBox->setEnabled(
true);
120 m_ui->m_outputDataSourceComboBox->clear();
122 std::vector<te::da::DataSourceInfoPtr> datasources;
126 for(std::size_t i = 0; i < datasources.size(); ++i)
130 if(datasource.get() == 0)
133 const std::string& title = datasource->getTitle();
135 m_ui->m_outputDataSourceComboBox->addItem(title.c_str(), QVariant::fromValue(datasource));
141 int idxLayer = m_ui->m_inputLayerComboBox->currentIndex();
145 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Input layer not selected."));
149 QVariant varLayer = m_ui->m_inputLayerComboBox->itemData(idxLayer, Qt::UserRole);
154 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Error getting selected layer."));
158 if(m_ui->m_dataSetLineEdit->text().isEmpty())
160 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Output File Name not defined."));
167 std::auto_ptr<te::da::DataSetType> dsType = layer->getSchema();
170 std::map<std::string, std::string> connInfo;
171 connInfo[
"URI"] = m_ui->m_dataSetLineEdit->text().toStdString();
174 dsOGR->setConnectionInfo(connInfo);
181 boost::filesystem::path uri(m_ui->m_dataSetLineEdit->text().toStdString());
183 std::string val = uri.stem().string();
188 std::map<std::string,std::string> nopt;
190 std::auto_ptr<te::da::DataSet> dataset = layer->getData();
192 dsOGR->createDataSet(dsTypeResult, nopt);
196 dsAdapter->setSRID(layer->getSRID());
198 if(dataset->moveBeforeFirst())
199 dsOGR->add(dsTypeResult->getName(), dsAdapter.get(), dsOGR->getConnectionInfo());
203 QMessageBox::information(
this, tr(
"Exchanger"), tr(
"Layer exported successfully."));
205 catch(
const std::exception& e)
207 QString errMsg(tr(
"Error during exchanger. The reported error is: %1"));
209 errMsg = errMsg.arg(e.what());
211 QMessageBox::information(
this, tr(
"Exchanger"), errMsg);
221 int idxLayer = m_ui->m_inputLayerComboBox->currentIndex();
225 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Input layer not selected."));
229 QVariant varLayer = m_ui->m_inputLayerComboBox->itemData(idxLayer, Qt::UserRole);
234 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Error getting selected layer."));
238 int idxDataSource = m_ui->m_outputDataSourceComboBox->currentIndex();
242 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Output data source not selected."));
246 QVariant varDataSource = m_ui->m_outputDataSourceComboBox->itemData(idxDataSource, Qt::UserRole);
251 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Error getting selected data source."));
255 if(m_ui->m_dataSetLineEdit->text().isEmpty())
257 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Data Set name not defined."));
264 std::auto_ptr<te::da::DataSetType> dsType = layer->getSchema();
272 dsTypeResult->
setName(m_ui->m_dataSetLineEdit->text().toStdString());
275 if(m_ui->m_spatialIndexCheckBox->isChecked())
283 std::string name = m_ui->m_dataSetLineEdit->text().toStdString() +
"_" + p->
getName() +
"_idx";
294 if(dsType->getPrimaryKey())
298 std::string name = m_ui->m_dataSetLineEdit->text().toStdString() +
"_" + dsType->getPrimaryKey()->getName() +
"_pk";
302 std::vector<te::dt::Property*> props = dsType->getPrimaryKey()->getProperties();
304 for(
size_t t = 0; t < props.size(); ++ t)
313 std::map<std::string,std::string> nopt;
315 std::auto_ptr<te::da::DataSet> dataset = layer->getData();
317 targetDSPtr->createDataSet(dsTypeResult, nopt);
321 dsAdapter->setSRID(layer->getSRID());
323 if(dataset->moveBeforeFirst())
324 targetDSPtr->add(dsTypeResult->getName(), dsAdapter.get(), targetDSPtr->getConnectionInfo());
326 QMessageBox::information(
this, tr(
"Exchanger"), tr(
"Layer exported successfully."));
328 catch(
const std::exception& e)
330 QString errMsg(tr(
"Error during exchanger. The reported error is: %1"));
332 errMsg = errMsg.arg(e.what());
334 QMessageBox::information(
this, tr(
"Exchanger"), errMsg);
344 QString value = m_ui->m_dsTypeComboBox->itemData(index).toString();
346 m_outputDataSourceType = value.toStdString();
348 if(m_outputDataSourceType ==
"POSTGIS")
350 m_exchangeToFile =
false;
352 m_ui->m_outputDataSourceComboBox->setEnabled(
true);
353 m_ui->m_dsToolButton->setEnabled(
true);
354 m_ui->m_dataSetLineEdit->clear();
355 m_ui->m_dataSetLineEdit->setEnabled(
true);
356 m_ui->m_dirToolButton->setEnabled(
false);
357 m_ui->m_spatialIndexCheckBox->setEnabled(
true);
358 m_ui->m_spatialIndexCheckBox->setChecked(
true);
362 else if(m_outputDataSourceType ==
"ADO")
364 m_exchangeToFile =
false;
366 m_ui->m_outputDataSourceComboBox->setEnabled(
true);
367 m_ui->m_dsToolButton->setEnabled(
true);
368 m_ui->m_dataSetLineEdit->clear();
369 m_ui->m_dataSetLineEdit->setEnabled(
true);
370 m_ui->m_dirToolButton->setEnabled(
false);
371 m_ui->m_spatialIndexCheckBox->setEnabled(
false);
372 m_ui->m_spatialIndexCheckBox->setChecked(
false);
376 else if(m_outputDataSourceType ==
"OGR")
378 m_exchangeToFile =
true;
380 m_ui->m_outputDataSourceComboBox->clear();
381 m_ui->m_outputDataSourceComboBox->setEnabled(
false);
382 m_ui->m_dsToolButton->setEnabled(
false);
383 m_ui->m_dataSetLineEdit->clear();
384 m_ui->m_dataSetLineEdit->setEnabled(
false);
385 m_ui->m_dirToolButton->setEnabled(
true);
386 m_ui->m_spatialIndexCheckBox->setEnabled(
false);
387 m_ui->m_spatialIndexCheckBox->setChecked(
false);
393 onDataSourceTypeActivated(m_ui->m_dsTypeComboBox->currentIndex());
395 if(m_ui->m_dataSetLineEdit->isEnabled())
396 m_ui->m_dataSetLineEdit->setText(value);
401 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save as..."),
402 QString(), tr(
"Shapefile (*.shp *.SHP);;Mapinfo File (*.mif *.MIF);;KML (*.kml *.KML);;GeoJSON (*.geojson *.GEOJSON);;GML (*.gml *.GML);;DXF (*.dxf *.DXF);;DGN (*.dgn *.DGN);;"),0, QFileDialog::DontConfirmOverwrite);
404 if (fileName.isEmpty())
407 m_ui->m_dataSetLineEdit->setText(fileName);
424 res = exchangeToFile();
426 res = exchangeToDatabase();
434 m_ui->m_dsTypeComboBox->clear();
436 m_ui->m_dsTypeComboBox->addItem(QIcon::fromTheme(
"datasource-postgis"), tr(
"PostGIS"), QVariant(
"POSTGIS"));
437 m_ui->m_dsTypeComboBox->addItem(QIcon::fromTheme(
"datasource-ado"), tr(
"Microsoft Access"), QVariant(
"ADO"));
438 m_ui->m_dsTypeComboBox->addItem(QIcon::fromTheme(
"datasource-ogr"), tr(
"File - OGR Formats"), QVariant(
"OGR"));
It describes an index associated to a DataSetType.
void onInputLayerActivated(QString value)
void onDirToolButtonClicked()
An converter for DataSetType.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
void setName(const std::string &name)
It sets the index name.
It describes a primary key (pk) constraint.
const std::string & getName() const
It returns the property name.
void onDataSoruceToolButtonClicked()
static std::auto_ptr< DataSource > make(const std::string &dsType)
bool exchangeToDatabase()
std::string m_outputDataSourceType
void setName(const std::string &name)
It sets the property name.
virtual void setName(const std::string &name)
It sets the constraint name.
A dialog for selecting a data source.
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr)
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used.
void setOutputDataSources()
boost::shared_ptr< DataSource > DataSourcePtr
A direct exchanger dialog for ADO, POSTGIS and SHP data sources.
std::auto_ptr< Ui::DirectExchangerDialogForm > m_ui
void add(te::dt::Property *p)
It adds the property to the list of properties of the index.
void setDataSources()
Set the list of data sources that can be used.
A class that models the description of a dataset.
DataSetType * getResult() const
void setIndexType(IndexType t)
It sets the index type.
void onDataSourceTypeActivated(int index)
void add(te::dt::Property *p)
It adds a property to the list of properties of the primary key.
It models a property definition.
te::dt::Property * clone() const
It returns a clone of the object.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
static DataSourceInfoManager & getInstance()
It returns a reference to the singleton instance.
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
void onOkPushButtonClicked()
DirectExchangerDialog(QWidget *parent=0, Qt::WindowFlags f=0)
virtual Property * clone() const =0
It returns a clone of the object.
TEDATAACCESSEXPORT DataSetAdapter * CreateAdapter(DataSet *ds, DataSetTypeConverter *converter, bool isOwner=false)