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_dataType.get();
248 return m_dataSource.get();
255 QString fileName = QFileDialog::getOpenFileName(
this, tr(
"Open Textual File"),
te::qt::widgets::GetFilePathFromSettings(
"tabular"), tr(
"Comma Separated Value (*.csv *.CSV);; dBASE (*.dbf *.DBF)"),
256 0, QFileDialog::ReadOnly);
258 if(fileName.isEmpty())
261 QFileInfo info(fileName);
266 std::string ogrInfo(
"connection_string=" + fileName.toStdString());
267 std::map<std::string, std::string> connInfo;
268 connInfo[
"URI"] = fileName.toStdString();
270 boost::filesystem::path uri(fileName.toStdString());
271 std::string file = uri.stem().string();
274 static boost::uuids::basic_random_generator<boost::mt19937> gen;
275 boost::uuids::uuid u = gen();
278 dsInfo->setConnInfo(connInfo);
279 dsInfo->setId(boost::uuids::to_string(u));
280 dsInfo->setTitle(fileName.toStdString());
281 dsInfo->setDescription(
"");
282 dsInfo->setAccessDriver(
"OGR");
283 dsInfo->setType(
"OGR");
288 m_dataSource->setConnectionInfo(dsInfo->getConnInfo());
290 m_dataSource->setId(boost::uuids::to_string(u));
291 m_dataSource->open();
294 std::auto_ptr<te::da::DataSet> dataset = m_dataSource->getDataSet(file);
295 std::vector<std::string> datasetNames = m_dataSource->getDataSetNames();
297 if(!datasetNames.empty())
298 m_dataType = m_dataSource->getDataSetType(datasetNames[0]);
301 QMessageBox::critical(
this, tr(
"Error"),tr(
"The file could not be read!"));
305 m_ui->m_inputDataLineEdit->setText(fileName);
311 std::vector<std::size_t> properties;
312 for (std::size_t i = 0; i < dataset->getNumProperties(); ++i)
313 properties.push_back(i);
316 std::auto_ptr<te::mem::DataSet> memFeature((
new te::mem::DataSet(*dataset.get(), properties, 5)));
318 m_tblView->setDataSet(memFeature.release(), m_dataSource->getEncoding());
319 m_tblView->resizeColumnsToContents();
322 m_ui->m_dataPropertiesTableWidget->setRowCount(0);
325 for(
size_t t = 0; t < m_dataType->size(); ++t)
327 int newrow = m_ui->m_dataPropertiesTableWidget->rowCount();
328 m_ui->m_dataPropertiesTableWidget->insertRow(newrow);
331 std::string propName = m_dataType->getProperty(t)->getName();
334 QCheckBox* impCheck =
new QCheckBox();
335 impCheck->setText(QString::fromStdString(propName));
336 impCheck->setCheckState(Qt::Checked);
339 connect(impCheck, SIGNAL(stateChanged (
int )),
this, SLOT(onGeomPropertyChecked(
int)));
341 m_ui->m_dataPropertiesTableWidget->setCellWidget(newrow, 0, impCheck);
344 QComboBox* typeCB =
new QComboBox();
346 typeCB->setCurrentIndex(typeCB->findText(m_typeMap[m_dataType->getProperty(t)->getType()].c_str()));
348 m_mapper->setMapping(typeCB, newrow);
349 connect(typeCB, SIGNAL(currentIndexChanged (
int)), m_mapper, SLOT(map()));
351 m_ui->m_dataPropertiesTableWidget->setCellWidget(newrow, 1, typeCB);
354 if(m_dataType->hasGeom())
358 if(gp && gp->
getName() == propName)
362 m_ui->m_sridLineEdit->setText(srid);
364 typeCB->setEnabled(
false);
376 for(std::size_t t= 0; t < props.size(); ++t)
378 if(props[t]->getName() == propName)
380 typeCB->setEnabled(
false);
381 impCheck->setEnabled(
false);
388 m_ui->m_dataPropertiesTableWidget->resizeColumnsToContents();
389 m_ui->m_dataPropertiesTableWidget->resizeRowsToContents();
390 #if (QT_VERSION >= 0x050000)
391 m_ui->m_dataPropertiesTableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
393 m_ui->m_dataPropertiesTableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
397 m_ui->m_xAxisComboBox->clear();
398 m_ui->m_yAxisComboBox->clear();
400 if(m_dataType->hasGeom())
402 m_ui->m_geometryGroupBox->setCheckable(
false);
403 m_ui->m_xAxisComboBox->setEnabled(
false);
404 m_ui->m_yAxisComboBox->setEnabled(
false);
405 m_ui->m_geometryGroupBox->setChecked(
true);
409 m_ui->m_geometryGroupBox->setCheckable(
true);
410 m_ui->m_xAxisComboBox->setEnabled(
true);
411 m_ui->m_yAxisComboBox->setEnabled(
true);
412 m_ui->m_geometryGroupBox->setChecked(
false);
416 for(
size_t t = 0; t < m_dataType->size(); ++t)
418 std::string propName = m_dataType->getProperty(t)->getName();
419 int type = m_dataType->getProperty(t)->getType();
423 m_ui->m_xAxisComboBox->addItem(QString::fromStdString(propName));
424 m_ui->m_yAxisComboBox->addItem(QString::fromStdString(propName));
429 catch(
const std::exception& e)
431 QMessageBox::warning(
this, tr(
"Tabular File"), e.what());
438 srsDialog.setWindowTitle(tr(
"Choose the SRS"));
440 if(srsDialog.exec() != QDialog::Rejected)
443 m_ui->m_sridLineEdit->setText(QString::number(srid.first));
449 if(checked == Qt::Unchecked)
451 m_ui->m_geometryGroupBox->setCheckable(
true);
452 m_ui->m_xAxisComboBox->setEnabled(
true);
453 m_ui->m_yAxisComboBox->setEnabled(
true);
454 m_ui->m_geometryGroupBox->setChecked(
true);
458 m_ui->m_geometryGroupBox->setCheckable(
false);
459 m_ui->m_xAxisComboBox->setEnabled(
false);
460 m_ui->m_yAxisComboBox->setEnabled(
false);
461 m_ui->m_geometryGroupBox->setChecked(
false);
468 QCheckBox* check =
dynamic_cast<QCheckBox*
>(m_ui->m_dataPropertiesTableWidget->cellWidget(row, 0));
469 QComboBox* box =
dynamic_cast<QComboBox*
>(m_ui->m_dataPropertiesTableWidget->cellWidget(row, 1));
470 std::string propName = check->text().toStdString();
471 int type = box->itemData(box->currentIndex()).toInt();
474 int xyAxis = m_ui->m_xAxisComboBox->findText(QString::fromStdString(propName));
482 m_ui->m_xAxisComboBox->addItem(QString::fromStdString(propName));
483 m_ui->m_yAxisComboBox->addItem(QString::fromStdString(propName));
490 m_ui->m_xAxisComboBox->removeItem(xyAxis);
491 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.
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.