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").toUtf8().data()));
69 typeMap.insert(std::map<int, std::string>::value_type(
te::dt::BYTE_ARRAY_TYPE, QObject::tr(
"Byte Array").toUtf8().data()));
70 typeMap.insert(std::map<int, std::string>::value_type(
te::dt::DATETIME_TYPE, QObject::tr(
"Date and Time").toUtf8().data()));
71 typeMap.insert(std::map<int, std::string>::value_type(
te::dt::DOUBLE_TYPE, QObject::tr(
"Double").toUtf8().data()));
72 typeMap.insert(std::map<int, std::string>::value_type(
te::dt::GEOMETRY_TYPE, QObject::tr(
"Geometry").toUtf8().data()));
73 typeMap.insert(std::map<int, std::string>::value_type(
te::dt::INT32_TYPE, QObject::tr(
"Int 32").toUtf8().data()));
74 typeMap.insert(std::map<int, std::string>::value_type(
te::dt::INT64_TYPE, QObject::tr(
"Int 64").toUtf8().data()));
75 typeMap.insert(std::map<int, std::string>::value_type(
te::dt::NUMERIC_TYPE, QObject::tr(
"Numeric").toUtf8().data()));
76 typeMap.insert(std::map<int, std::string>::value_type(
te::dt::STRING_TYPE, QObject::tr(
"String").toUtf8().data()));
129 newProperty =
nullptr;
138 for(std::map<int, std::string>::iterator it = typeMap.begin(); it != typeMap.end(); ++it)
140 box->addItem(QString::fromUtf8(it->second.c_str()), QVariant(it->first));
146 m_ui(new
Ui::DataPropertiesWidgetForm)
157 QGridLayout* dataPreviewLayout =
new QGridLayout(
m_ui->m_dataPreviewFrame);
158 dataPreviewLayout->addWidget(
m_tblView.get());
159 dataPreviewLayout->setContentsMargins(0, 0, 0, 0);
161 m_tblView->setAlternatingRowColors(
true);
162 m_tblView->verticalHeader()->setVisible(
false);
163 m_tblView->setSelectionMode(QAbstractItemView::NoSelection);
165 m_ui->m_dataPropertiesTableWidget->setSelectionMode(QAbstractItemView::NoSelection);
168 m_ui->m_imgLabel->setPixmap(QIcon::fromTheme(
"tabular-import-hint").pixmap(112,48));
169 m_ui->m_sridPushButton->setIcon(QIcon::fromTheme(
"srs"));
189 std::unique_ptr<te::da::DataSetTypeConverter> result = std::move(
m_dsConverter);
194 for (
int i = 0; i <
m_ui->m_dataPropertiesTableWidget->rowCount(); ++i)
196 if(dynamic_cast<QCheckBox*>(
m_ui->m_dataPropertiesTableWidget->cellWidget(i, 0))->isChecked())
198 QComboBox* box =
dynamic_cast<QComboBox*
>(
m_ui->m_dataPropertiesTableWidget->cellWidget(i, 1));
199 int type = box->itemData(box->currentIndex()).toInt();
204 std::vector<te::dt::Property*> props = pkIn->getProperties();
206 for(std::size_t t= 0; t < props.size(); ++t)
208 if(props[t]->getName() ==
m_dataType->getProperty(i)->getName())
221 if(
m_ui->m_geometryGroupBox->isCheckable() &&
m_ui->m_geometryGroupBox->isChecked())
225 std::vector<std::string> names;
226 names.push_back(
m_ui->m_xAxisComboBox->currentText().toUtf8().data());
227 names.push_back(
m_ui->m_yAxisComboBox->currentText().toUtf8().data());
231 result->add(names, newGeom,
"XYToPointConverter");
236 if(gp && !
m_ui->m_sridLineEdit->text().isEmpty())
237 gp->
setSRID(boost::lexical_cast<int>(
m_ui->m_sridLineEdit->text().trimmed().toUtf8().data()));
256 QString fileName = QFileDialog::getOpenFileName(
this, tr(
"Open Textual File"),
te::qt::widgets::GetFilePathFromSettings(
"tabular"), tr(
"Comma Separated Value (*.csv *.CSV);; dBASE (*.dbf *.DBF)"),
257 nullptr, QFileDialog::ReadOnly);
259 if(fileName.isEmpty())
262 QFileInfo info(fileName);
267 std::string ogrInfo(
"connection_string=" + std::string(fileName.toUtf8().data()));
268 const std::string connInfo(
"file://" + std::string(fileName.toUtf8().data()));
270 boost::filesystem::path uri(fileName.toUtf8().data());
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.toUtf8().data());
281 dsInfo->setDescription(
"");
282 dsInfo->setAccessDriver(
"OGR");
283 dsInfo->setType(
"OGR");
301 std::unique_ptr<te::da::DataSet> dataset =
m_dataSource->getDataSet(file);
302 std::vector<std::string> datasetNames =
m_dataSource->getDataSetNames();
304 if(!datasetNames.empty())
308 QMessageBox::critical(
this, tr(
"Error"),tr(
"The file could not be read!"));
312 m_ui->m_inputDataLineEdit->setText(fileName);
318 std::vector<std::size_t> properties;
319 for (std::size_t i = 0; i < dataset->getNumProperties(); ++i)
320 properties.push_back(i);
323 std::unique_ptr<te::mem::DataSet> memFeature;
325 size_t count = dataset->size();
329 memFeature.reset((
new te::mem::DataSet(*dataset.get(), properties, count)));
331 m_tblView->setDataSet(memFeature.release());
335 m_ui->m_dataPropertiesTableWidget->setRowCount(0);
338 for(
size_t t = 0; t <
m_dataType->size(); ++t)
344 int newrow =
m_ui->m_dataPropertiesTableWidget->rowCount();
345 m_ui->m_dataPropertiesTableWidget->insertRow(newrow);
348 std::string propName =
m_dataType->getProperty(t)->getName();
351 QCheckBox* impCheck =
new QCheckBox();
352 impCheck->setText(QString::fromUtf8(propName.c_str()));
353 impCheck->setCheckState(Qt::Checked);
355 m_ui->m_dataPropertiesTableWidget->setCellWidget(newrow, 0, impCheck);
358 QComboBox* typeCB =
new QComboBox();
360 typeCB->setCurrentIndex(typeCB->findText(
m_typeMap[
m_dataType->getProperty(t)->getType()].c_str()));
362 m_mapper->setMapping(typeCB, newrow);
363 connect(typeCB, SIGNAL(currentIndexChanged (
int)),
m_mapper, SLOT(map()));
365 m_ui->m_dataPropertiesTableWidget->setCellWidget(newrow, 1, typeCB);
374 for(std::size_t t= 0; t < props.size(); ++t)
376 if(props[t]->getName() == propName)
378 typeCB->setEnabled(
false);
379 impCheck->setEnabled(
false);
386 m_ui->m_dataPropertiesTableWidget->resizeColumnsToContents();
387 m_ui->m_dataPropertiesTableWidget->resizeRowsToContents();
388 #if (QT_VERSION >= 0x050000) 389 m_ui->m_dataPropertiesTableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
391 m_ui->m_dataPropertiesTableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
395 m_ui->m_xAxisComboBox->clear();
396 m_ui->m_yAxisComboBox->clear();
397 m_ui->m_xAxisComboBox->setEnabled(
true);
398 m_ui->m_yAxisComboBox->setEnabled(
true);
399 m_ui->m_geometryGroupBox->setCheckable(
true);
400 m_ui->m_geometryGroupBox->setChecked(
false);
403 for(
size_t t = 0; t <
m_dataType->size(); ++t)
405 std::string propName =
m_dataType->getProperty(t)->getName();
406 int type =
m_dataType->getProperty(t)->getType();
410 m_ui->m_xAxisComboBox->addItem(QString::fromUtf8(propName.c_str()));
411 m_ui->m_yAxisComboBox->addItem(QString::fromUtf8(propName.c_str()));
416 catch(
const std::exception& e)
418 QMessageBox::warning(
this, tr(
"Tabular File"), e.what());
425 srsDialog.setWindowTitle(tr(
"Choose the SRS"));
427 if(srsDialog.exec() != QDialog::Rejected)
430 m_ui->m_sridLineEdit->setText(QString::number(srid.first));
437 QCheckBox* check =
dynamic_cast<QCheckBox*
>(
m_ui->m_dataPropertiesTableWidget->cellWidget(row, 0));
438 QComboBox* box =
dynamic_cast<QComboBox*
>(
m_ui->m_dataPropertiesTableWidget->cellWidget(row, 1));
439 std::string propName = check->text().toUtf8().data();
440 int type = box->itemData(box->currentIndex()).toInt();
443 int xyAxis =
m_ui->m_xAxisComboBox->findText(QString::fromUtf8(propName.c_str()));
451 m_ui->m_xAxisComboBox->addItem(QString::fromUtf8(propName.c_str()));
452 m_ui->m_yAxisComboBox->addItem(QString::fromUtf8(propName.c_str()));
459 m_ui->m_xAxisComboBox->removeItem(xyAxis);
460 m_ui->m_yAxisComboBox->removeItem(xyAxis);
void setAutoNumber(bool a)
It tells if the property is an autonumber or not.
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
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...
static DataSourceInfoManager & getInstance()
It returns a reference to the singleton instance.
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)
file(WRITE ${CMAKE_BINARY_DIR}/config_qhelp.cmake"configure_file (${TERRALIB_ABSOLUTE_ROOT_DIR}/doc/qhelp/help.qhcp.in ${CMAKE_BINARY_DIR}/share/terraview/help/help.qhcp @ONLY)") add_custom_command(OUTPUT del_dir COMMAND $
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr