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 "../table/DataSetTableView.h"
48 #include "ui_DataPropertiesWidgetForm.h"
52 #include <QtGui/QComboBox>
53 #include <QtCore/QFileInfo>
54 #include <QtGui/QFileDialog>
55 #include <QtGui/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()));
71 typeMap.insert(std::map<int, std::string>::value_type(
te::dt::BYTE_ARRAY_TYPE, QObject::tr(
"Byte Array").toStdString()));
74 typeMap.insert(std::map<int, std::string>::value_type(
te::dt::DATETIME_TYPE, QObject::tr(
"Date and Time").toStdString()));
75 typeMap.insert(std::map<int, std::string>::value_type(
te::dt::DOUBLE_TYPE, QObject::tr(
"Double").toStdString()));
77 typeMap.insert(std::map<int, std::string>::value_type(
te::dt::GEOMETRY_TYPE, QObject::tr(
"Geometry").toStdString()));
79 typeMap.insert(std::map<int, std::string>::value_type(
te::dt::INT32_TYPE, QObject::tr(
"Int 32").toStdString()));
81 typeMap.insert(std::map<int, std::string>::value_type(
te::dt::NUMERIC_TYPE, QObject::tr(
"Numeric").toStdString()));
82 typeMap.insert(std::map<int, std::string>::value_type(
te::dt::STRING_TYPE, QObject::tr(
"String").toStdString()));
148 for(std::map<int, std::string>::iterator it = typeMap.begin(); it != typeMap.end(); ++it)
150 box->addItem(QString::fromStdString(it->second), QVariant(it->first));
155 : QWidget(parent, f),
156 m_ui(new Ui::DataPropertiesWidgetForm)
167 QGridLayout* dataPreviewLayout =
new QGridLayout(
m_ui->m_dataPreviewFrame);
168 dataPreviewLayout->addWidget(
m_tblView.get());
169 dataPreviewLayout->setContentsMargins(0, 0, 0, 0);
171 m_tblView->setAlternatingRowColors(
true);
172 m_tblView->verticalHeader()->setVisible(
false);
173 m_tblView->setSelectionMode(QAbstractItemView::NoSelection);
175 m_ui->m_dataPropertiesTableWidget->setSelectionMode(QAbstractItemView::NoSelection);
178 m_ui->m_imgLabel->setPixmap(QIcon::fromTheme(
"tabular-import-hint").pixmap(112,48));
179 m_ui->m_sridPushButton->setIcon(QIcon::fromTheme(
"srs"));
195 if(m_ui->m_geometryGroupBox->isCheckable() && m_ui->m_geometryGroupBox->isChecked())
199 std::vector<std::string> names;
200 names.push_back(m_ui->m_xAxisComboBox->currentText().toStdString());
201 names.push_back(m_ui->m_yAxisComboBox->currentText().toStdString());
205 m_dsConverter->add(names, newGeom,
"XYToPointConverter");
212 for (
int i = 0; i < m_ui->m_dataPropertiesTableWidget->rowCount(); ++i)
214 if(dynamic_cast<QCheckBox*>(m_ui->m_dataPropertiesTableWidget->cellWidget(i, 0))->isChecked())
216 QComboBox* box =
dynamic_cast<QComboBox*
>(m_ui->m_dataPropertiesTableWidget->cellWidget(i, 1));
217 int type = box->itemData(box->currentIndex()).toInt();
219 m_dsConverter->
add(m_dataType->getProperty(i)->getName(),
getConvertedproperty(m_dataType->getProperty(i)->getName(), type));
223 std::vector<te::dt::Property*> props = pkIn->getProperties();
225 for(std::size_t t= 0; t < props.size(); ++t)
227 if(props[t]->getName() == m_dataType->getProperty(i)->getName())
242 if(gp && !m_ui->m_sridLineEdit->text().isEmpty())
243 gp->
setSRID(boost::lexical_cast<int>(m_ui->m_sridLineEdit->text().trimmed().toStdString()));
246 return m_dsConverter;
251 return m_dataSet.get();
256 return m_dataType.get();
261 return m_dataSource.get();
266 QString fileName = QFileDialog::getOpenFileName(
this, tr(
"Open Textual File"),
te::qt::widgets::GetFilePathFromSettings(
"tabular"), tr(
"Comma Separated Value (*.csv *.CSV);; dBASE (*.dbf *.dbf)"),
267 0, QFileDialog::ReadOnly);
269 if(fileName.isEmpty())
272 QFileInfo info(fileName);
276 m_ui->m_inputDataLineEdit->setText(fileName);
279 std::string ogrInfo(
"connection_string=" + fileName.toStdString());
280 std::map<std::string, std::string> connInfo;
281 connInfo[
"URI"] = fileName.toStdString();
283 boost::filesystem::path uri(m_ui->m_inputDataLineEdit->text().toStdString());
284 std::string file = uri.stem().string();
287 static boost::uuids::basic_random_generator<boost::mt19937> gen;
288 boost::uuids::uuid u = gen();
291 dsInfo->setConnInfo(connInfo);
292 dsInfo->setId(boost::uuids::to_string(u));
293 dsInfo->setTitle(fileName.toStdString());
294 dsInfo->setDescription(
"");
295 dsInfo->setAccessDriver(
"OGR");
296 dsInfo->setType(
"OGR");
301 m_dataSource->setConnectionInfo(dsInfo->getConnInfo());
303 m_dataSource->setId(boost::uuids::to_string(u));
304 m_dataSource->open();
307 m_dataSet = m_dataSource->getDataSet(file);
308 std::vector<std::string> datasetNames = m_dataSource->getDataSetNames();
309 m_dataType = m_dataSource->getDataSetType(datasetNames[0]);
315 std::vector<std::size_t> properties;
316 for(std::size_t i = 0; i < m_dataSet->getNumProperties(); ++i)
317 properties.push_back(i);
320 std::auto_ptr<te::mem::DataSet> memFeature((
new te::mem::DataSet(*m_dataSet.get(), properties, 5)));
322 m_tblView->setDataSet(memFeature.release());
323 m_tblView->resizeColumnsToContents();
326 m_ui->m_dataPropertiesTableWidget->setRowCount(0);
329 for(
size_t t = 0; t < m_dataType->size(); ++t)
331 int newrow = m_ui->m_dataPropertiesTableWidget->rowCount();
332 m_ui->m_dataPropertiesTableWidget->insertRow(newrow);
335 std::string propName = m_dataType->getProperty(t)->getName();
338 QCheckBox* impCheck =
new QCheckBox();
339 impCheck->setText(QString::fromStdString(propName));
340 impCheck->setCheckState(Qt::Checked);
342 m_ui->m_dataPropertiesTableWidget->setCellWidget(newrow, 0, impCheck);
345 QComboBox* typeCB =
new QComboBox();
347 typeCB->setCurrentIndex(typeCB->findText(m_typeMap[m_dataType->getProperty(t)->getType()].c_str()));
349 m_mapper->setMapping(typeCB, newrow);
350 connect(typeCB, SIGNAL(currentIndexChanged (
int)), m_mapper, SLOT(map()));
352 m_ui->m_dataPropertiesTableWidget->setCellWidget(newrow, 1, typeCB);
355 if(m_dataType->hasGeom())
359 if(gp && gp->
getName() == propName)
363 m_ui->m_sridLineEdit->setText(srid);
365 impCheck->setEnabled(
false);
366 typeCB->setEnabled(
false);
378 for(std::size_t t= 0; t < props.size(); ++t)
380 if(props[t]->getName() == propName)
382 typeCB->setEnabled(
false);
383 impCheck->setEnabled(
false);
390 m_ui->m_dataPropertiesTableWidget->resizeColumnsToContents();
391 m_ui->m_dataPropertiesTableWidget->resizeRowsToContents();
392 m_ui->m_dataPropertiesTableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
395 m_ui->m_xAxisComboBox->clear();
396 m_ui->m_yAxisComboBox->clear();
399 if(!m_dataType->hasGeom())
403 m_ui->m_geometryGroupBox->setCheckable(
true);
404 m_ui->m_xAxisComboBox->setEnabled(
true);
405 m_ui->m_yAxisComboBox->setEnabled(
true);
406 m_ui->m_geometryGroupBox->setChecked(
false);
410 for(
size_t t = 0; t < m_dataType->size(); ++t)
412 std::string propName = m_dataType->getProperty(t)->getName();
413 int type = m_dataType->getProperty(t)->getType();
417 m_ui->m_xAxisComboBox->addItem(QString::fromStdString(propName));
418 m_ui->m_yAxisComboBox->addItem(QString::fromStdString(propName));
425 m_ui->m_geometryGroupBox->setCheckable(
false);
426 m_ui->m_xAxisComboBox->setEnabled(
false);
427 m_ui->m_yAxisComboBox->setEnabled(
false);
434 srsDialog.setWindowTitle(tr(
"Choose the SRS"));
436 if(srsDialog.exec() != QDialog::Rejected)
439 m_ui->m_sridLineEdit->setText(QString::number(srid.first));
446 QCheckBox* check =
dynamic_cast<QCheckBox*
>(m_ui->m_dataPropertiesTableWidget->cellWidget(row, 0));
447 QComboBox* box =
dynamic_cast<QComboBox*
>(m_ui->m_dataPropertiesTableWidget->cellWidget(row, 1));
448 std::string propName = check->text().toStdString();
449 int type = box->itemData(box->currentIndex()).toInt();
452 int xyAxis = m_ui->m_xAxisComboBox->findText(QString::fromStdString(propName));
460 m_ui->m_xAxisComboBox->addItem(QString::fromStdString(propName));
461 m_ui->m_yAxisComboBox->addItem(QString::fromStdString(propName));
468 m_ui->m_xAxisComboBox->removeItem(xyAxis);
469 m_ui->m_yAxisComboBox->removeItem(xyAxis);
void setGeometryType(GeomType t)
It sets the geometry subtype.
void fillComboBox(std::map< int, std::string > typeMap, QComboBox *box)
te::da::DataSet * getDataSet()
Returns a pointer to the widget's dataSet.
An atomic property like an integer or double.
An converter for DataSetType.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
te::dt::SimpleProperty * getConvertedproperty(std::string name, int dataType, std::string defaultValue="", bool isRequired=false, bool isAutoNumber=true)
te::da::DataSetType * getDataSetType()
Returns a pointer to the widget's dataSetType.
A class used to configure the properties of a new textual file based layer.
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.
void onSridPushButtonCLicked()
int getSRID() const
It returns the spatial reference system identifier associated to this property.
TEQTWIDGETSEXPORT QString GetFilePathFromSettings(const QString &typeFile)
Returns the value of the last saved file path for the typeFile required.
The type for string types: FIXED_STRING, VAR_STRING or STRING.
A class that represents a data source component.
It describes a primary key (pk) constraint.
TEQTWIDGETSEXPORT void AddFilePathToSettings(const QString &path, const QString &typeFile)
Save last used path in QSettings.
const std::string & getName() const
It returns the property name.
static std::auto_ptr< DataSource > make(const std::string &dsType)
~DatapPropertiesWidget()
Destructor.
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that take part of the primary key.
void buidTypeMap(std::map< int, std::string > &typeMap)
std::auto_ptr< DataSetTableView > m_tblView
The widget used to preview the data of the new dataset.
DatapPropertiesWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Constructor.
A dialog used to build a SRSManagerDialog element.
QSignalMapper * m_mapper
The mapper used to know which property was configured.
void setAutoNumber(bool a)
It tells if the property is an autonumber or not.
te::da::DataSource * getDataSource()
Returns a pointer to the widget's dataSource.
const std::pair< int, std::string > & getSelectedSRS() const
Returns the selected SRS in the window.
A customized table view for te::map::AbstractLayer objects. Uses a te::qt::widgets::DataSetModel as i...
std::auto_ptr< Ui::DataPropertiesWidgetForm > m_ui
The widget's form.
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
A class that models the description of a dataset.
void add(te::dt::Property *p)
It adds a property to the list of properties of the primary key.
A class used to define the DataSetAdapterWidget class.
The type for arbitrary precison numbers, like numeric(p, q).
void onInputDataToolButtonTriggered()
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
std::auto_ptr< te::da::DataSetTypeConverter > getConverter()
Returns a pointer to the generated DataSetTypeConverter.
void setSRID(int srid)
It sets the spatial reference system identifier associated to this property.
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
void onPropertyTypeChanged(int index)
std::map< int, std::string > m_typeMap
A map that correlates a terralib type with a label.
A dataset is the unit of information manipulated by the data access module of TerraLib.