27 #include "../../../dataaccess/dataset/DataSetAdapter.h"
28 #include "../../../dataaccess/dataset/DataSetType.h"
29 #include "../../../dataaccess/dataset/DataSetTypeConverter.h"
30 #include "../../../dataaccess/dataset/PrimaryKey.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/utils/Utils.h"
36 #include "../../../datatype/Property.h"
37 #include "../../../datatype/DateTimeProperty.h"
38 #include "../../../datatype/NumericProperty.h"
39 #include "../../../datatype/SimpleProperty.h"
40 #include "../../../datatype/StringProperty.h"
41 #include "../../../geometry/GeometryProperty.h"
42 #include "../../../memory/DataSet.h"
43 #include "../property/DataSetAdapterWidget.h"
44 #include "../srs/SRSManagerDialog.h"
45 #include "../table/DataSetTableView.h"
48 #include "ui_DataPropertiesWidgetForm.h"
53 #include <QFileDialog>
55 #include <QMessageBox>
58 #include <boost/filesystem.hpp>
59 #include <boost/lexical_cast.hpp>
60 #include <boost/uuid/random_generator.hpp>
61 #include <boost/uuid/uuid_io.hpp>
68 typeMap.insert(std::map<int, std::string>::value_type(
te::dt::ARRAY_TYPE, QObject::tr(
"Array").toStdString()));
69 typeMap.insert(std::map<int, std::string>::value_type(
te::dt::BYTE_ARRAY_TYPE, QObject::tr(
"Byte Array").toStdString()));
70 typeMap.insert(std::map<int, std::string>::value_type(
te::dt::DATETIME_TYPE, QObject::tr(
"Date and Time").toStdString()));
71 typeMap.insert(std::map<int, std::string>::value_type(
te::dt::DOUBLE_TYPE, QObject::tr(
"Double").toStdString()));
72 typeMap.insert(std::map<int, std::string>::value_type(
te::dt::GEOMETRY_TYPE, QObject::tr(
"Geometry").toStdString()));
73 typeMap.insert(std::map<int, std::string>::value_type(
te::dt::INT32_TYPE, QObject::tr(
"Int 32").toStdString()));
74 typeMap.insert(std::map<int, std::string>::value_type(
te::dt::NUMERIC_TYPE, QObject::tr(
"Numeric").toStdString()));
75 typeMap.insert(std::map<int, std::string>::value_type(
te::dt::STRING_TYPE, QObject::tr(
"String").toStdString()));
137 for(std::map<int, std::string>::iterator it = typeMap.begin(); it != typeMap.end(); ++it)
139 box->addItem(QString::fromStdString(it->second), QVariant(it->first));
144 : QWidget(parent, f),
145 m_ui(new Ui::DataPropertiesWidgetForm)
156 QGridLayout* dataPreviewLayout =
new QGridLayout(
m_ui->m_dataPreviewFrame);
157 dataPreviewLayout->addWidget(
m_tblView.get());
158 dataPreviewLayout->setContentsMargins(0, 0, 0, 0);
160 m_tblView->setAlternatingRowColors(
true);
161 m_tblView->verticalHeader()->setVisible(
false);
162 m_tblView->setSelectionMode(QAbstractItemView::NoSelection);
164 m_ui->m_dataPropertiesTableWidget->setSelectionMode(QAbstractItemView::NoSelection);
167 m_ui->m_imgLabel->setPixmap(QIcon::fromTheme(
"tabular-import-hint").pixmap(112,48));
168 m_ui->m_sridPushButton->setIcon(QIcon::fromTheme(
"srs"));
191 for (
int i = 0; i < m_ui->m_dataPropertiesTableWidget->rowCount(); ++i)
193 if(dynamic_cast<QCheckBox*>(m_ui->m_dataPropertiesTableWidget->cellWidget(i, 0))->isChecked())
195 QComboBox* box =
dynamic_cast<QComboBox*
>(m_ui->m_dataPropertiesTableWidget->cellWidget(i, 1));
196 int type = box->itemData(box->currentIndex()).toInt();
198 m_dsConverter->
add(m_dataType->getProperty(i)->getName(),
getConvertedproperty(m_dataType->getProperty(i)->getName(), type));
202 std::vector<te::dt::Property*> props = pkIn->getProperties();
204 for(std::size_t t= 0; t < props.size(); ++t)
206 if(props[t]->getName() == m_dataType->getProperty(i)->getName())
219 if(m_ui->m_geometryGroupBox->isCheckable() && m_ui->m_geometryGroupBox->isChecked())
223 std::vector<std::string> names;
224 names.push_back(m_ui->m_xAxisComboBox->currentText().toStdString());
225 names.push_back(m_ui->m_yAxisComboBox->currentText().toStdString());
229 m_dsConverter->add(names, newGeom,
"XYToPointConverter");
234 if(gp && !m_ui->m_sridLineEdit->text().isEmpty())
235 gp->
setSRID(boost::lexical_cast<int>(m_ui->m_sridLineEdit->text().trimmed().toStdString()));
238 return m_dsConverter;
243 return m_dataSet.get();
248 return m_dataType.get();
253 return m_dataSource.get();
260 QString fileName = QFileDialog::getOpenFileName(
this, tr(
"Open Textual File"),
te::qt::widgets::GetFilePathFromSettings(
"tabular"), tr(
"Comma Separated Value (*.csv *.CSV);; dBASE (*.dbf *.DBF)"),
261 0, QFileDialog::ReadOnly);
263 if(fileName.isEmpty())
266 QFileInfo info(fileName);
271 std::string ogrInfo(
"connection_string=" + fileName.toStdString());
272 std::map<std::string, std::string> connInfo;
273 connInfo[
"URI"] = fileName.toStdString();
275 boost::filesystem::path uri(fileName.toStdString());
276 std::string file = uri.stem().string();
279 static boost::uuids::basic_random_generator<boost::mt19937> gen;
280 boost::uuids::uuid u = gen();
283 dsInfo->setConnInfo(connInfo);
284 dsInfo->setId(boost::uuids::to_string(u));
285 dsInfo->setTitle(fileName.toStdString());
286 dsInfo->setDescription(
"");
287 dsInfo->setAccessDriver(
"OGR");
288 dsInfo->setType(
"OGR");
293 m_dataSource->setConnectionInfo(dsInfo->getConnInfo());
295 m_dataSource->setId(boost::uuids::to_string(u));
296 m_dataSource->open();
299 m_dataSet = m_dataSource->getDataSet(file);
300 std::vector<std::string> datasetNames = m_dataSource->getDataSetNames();
302 if(!datasetNames.empty())
303 m_dataType = m_dataSource->getDataSetType(datasetNames[0]);
306 QMessageBox::critical(
this, tr(
"Error"),tr(
"The file could not be read!"));
310 m_ui->m_inputDataLineEdit->setText(fileName);
316 std::vector<std::size_t> properties;
317 for(std::size_t i = 0; i < m_dataSet->getNumProperties(); ++i)
318 properties.push_back(i);
321 std::auto_ptr<te::mem::DataSet> memFeature((
new te::mem::DataSet(*m_dataSet.get(), properties, 5)));
323 m_tblView->setDataSet(memFeature.release(), m_dataSource->getEncoding());
324 m_tblView->resizeColumnsToContents();
327 m_ui->m_dataPropertiesTableWidget->setRowCount(0);
330 for(
size_t t = 0; t < m_dataType->size(); ++t)
332 int newrow = m_ui->m_dataPropertiesTableWidget->rowCount();
333 m_ui->m_dataPropertiesTableWidget->insertRow(newrow);
336 std::string propName = m_dataType->getProperty(t)->getName();
339 QCheckBox* impCheck =
new QCheckBox();
340 impCheck->setText(QString::fromStdString(propName));
341 impCheck->setCheckState(Qt::Checked);
344 connect(impCheck, SIGNAL(stateChanged (
int )),
this, SLOT(onGeomPropertyChecked(
int)));
346 m_ui->m_dataPropertiesTableWidget->setCellWidget(newrow, 0, impCheck);
349 QComboBox* typeCB =
new QComboBox();
351 typeCB->setCurrentIndex(typeCB->findText(m_typeMap[m_dataType->getProperty(t)->getType()].c_str()));
353 m_mapper->setMapping(typeCB, newrow);
354 connect(typeCB, SIGNAL(currentIndexChanged (
int)), m_mapper, SLOT(map()));
356 m_ui->m_dataPropertiesTableWidget->setCellWidget(newrow, 1, typeCB);
359 if(m_dataType->hasGeom())
363 if(gp && gp->
getName() == propName)
367 m_ui->m_sridLineEdit->setText(srid);
369 typeCB->setEnabled(
false);
381 for(std::size_t t= 0; t < props.size(); ++t)
383 if(props[t]->getName() == propName)
385 typeCB->setEnabled(
false);
386 impCheck->setEnabled(
false);
393 m_ui->m_dataPropertiesTableWidget->resizeColumnsToContents();
394 m_ui->m_dataPropertiesTableWidget->resizeRowsToContents();
395 #if (QT_VERSION >= 0x050000)
396 m_ui->m_dataPropertiesTableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
398 m_ui->m_dataPropertiesTableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
402 m_ui->m_xAxisComboBox->clear();
403 m_ui->m_yAxisComboBox->clear();
405 if(m_dataType->hasGeom())
407 m_ui->m_geometryGroupBox->setCheckable(
false);
408 m_ui->m_xAxisComboBox->setEnabled(
false);
409 m_ui->m_yAxisComboBox->setEnabled(
false);
410 m_ui->m_geometryGroupBox->setChecked(
true);
414 m_ui->m_geometryGroupBox->setCheckable(
true);
415 m_ui->m_xAxisComboBox->setEnabled(
true);
416 m_ui->m_yAxisComboBox->setEnabled(
true);
417 m_ui->m_geometryGroupBox->setChecked(
false);
421 for(
size_t t = 0; t < m_dataType->size(); ++t)
423 std::string propName = m_dataType->getProperty(t)->getName();
424 int type = m_dataType->getProperty(t)->getType();
428 m_ui->m_xAxisComboBox->addItem(QString::fromStdString(propName));
429 m_ui->m_yAxisComboBox->addItem(QString::fromStdString(propName));
434 catch(
const std::exception& e)
436 QMessageBox::warning(
this, tr(
"Tabular File"), e.what());
443 srsDialog.setWindowTitle(tr(
"Choose the SRS"));
445 if(srsDialog.exec() != QDialog::Rejected)
448 m_ui->m_sridLineEdit->setText(QString::number(srid.first));
454 if(checked == Qt::Unchecked)
456 m_ui->m_geometryGroupBox->setCheckable(
true);
457 m_ui->m_xAxisComboBox->setEnabled(
true);
458 m_ui->m_yAxisComboBox->setEnabled(
true);
459 m_ui->m_geometryGroupBox->setChecked(
true);
463 m_ui->m_geometryGroupBox->setCheckable(
false);
464 m_ui->m_xAxisComboBox->setEnabled(
false);
465 m_ui->m_yAxisComboBox->setEnabled(
false);
466 m_ui->m_geometryGroupBox->setChecked(
false);
473 QCheckBox* check =
dynamic_cast<QCheckBox*
>(m_ui->m_dataPropertiesTableWidget->cellWidget(row, 0));
474 QComboBox* box =
dynamic_cast<QComboBox*
>(m_ui->m_dataPropertiesTableWidget->cellWidget(row, 1));
475 std::string propName = check->text().toStdString();
476 int type = box->itemData(box->currentIndex()).toInt();
479 int xyAxis = m_ui->m_xAxisComboBox->findText(QString::fromStdString(propName));
487 m_ui->m_xAxisComboBox->addItem(QString::fromStdString(propName));
488 m_ui->m_yAxisComboBox->addItem(QString::fromStdString(propName));
495 m_ui->m_xAxisComboBox->removeItem(xyAxis);
496 m_ui->m_yAxisComboBox->removeItem(xyAxis);
void setAutoNumber(bool a)
It tells if the property is an autonumber or not.
void add(te::dt::Property *p)
It adds a property to the list of properties of the primary key.
void setSRID(int srid)
It sets the spatial reference system identifier associated to this property.
void setGeometryType(GeomType t)
It sets the geometry subtype.
An atomic property like an integer or double.
A class that models the description of a dataset.
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that take part of the primary key.
An converter for DataSetType.
The type for arbitrary precison numbers, like numeric(p, q).
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
int getSRID() const
It returns the spatial reference system identifier associated to this property.
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
static std::auto_ptr< DataSource > make(const std::string &dsType)
The type for string types: FIXED_STRING, VAR_STRING or STRING.
A dataset is the unit of information manipulated by the data access module of TerraLib.
It describes a primary key (pk) constraint.
The type for date and time types: date, date period, date duration, time duration, time instant, time period, time instant with time zone or time period with time zone.
A class that represents a data source component.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
const std::string & getName() const
It returns the property name.