27 #include "../../../dataaccess/dataset/PrimaryKey.h"
28 #include "../../../dataaccess/datasource/DataSourceManager.h"
29 #include "../../../dataaccess/Enums.h"
30 #include "../../../dataaccess/query/BinaryFunction.h"
31 #include "../../../dataaccess/query/DataSetName.h"
32 #include "../../../dataaccess/query/Expression.h"
33 #include "../../../dataaccess/query/Field.h"
34 #include "../../../dataaccess/query/Join.h"
35 #include "../../../dataaccess/query/JoinConditionOn.h"
36 #include "../../../dataaccess/query/PropertyName.h"
37 #include "../../../dataaccess/utils/Utils.h"
38 #include "../../../geometry/GeometryProperty.h"
39 #include "../../../maptools/QueryLayer.h"
40 #include "../../../memory/DataSet.h"
41 #include "../../../qt/widgets/utils/ScopedCursor.h"
42 #include "../../../se/Utils.h"
43 #include "../table/DataSetTableView.h"
46 #include "ui_TableLinkDialogForm.h"
49 #include <boost/uuid/random_generator.hpp>
50 #include <boost/uuid/uuid_io.hpp>
53 #include <QMessageBox>
60 m_ui(new
Ui::TableLinkDialogForm)
63 m_ui->m_dataToolButton->setIcon(QIcon::fromTheme(
"view-data-table"));
64 m_ui->m_dataToolButton->setToolTip(tr(
"View dataset rows"));
65 m_ui->m_advancedToolButton->setIcon(QIcon::fromTheme(
"preferences-system"));
66 m_ui->m_advancedToolButton->setToolTip(tr(
"View advanced options"));
70 QGridLayout* tabularLayout =
new QGridLayout(
m_ui->m_tabularFrame);
72 tabularLayout->setContentsMargins(0, 0, 0, 0);
76 m_tabularView->setSelectionMode(QAbstractItemView::NoSelection);
78 m_ui->m_dataPreviewGroupBox->hide();
82 m_ui->m_tabularFrame->hide();
83 m_ui->m_helpPushButton->setPageReference(
"widgets/external_table/table_link_dialog.html");
86 m_ui->m_advancedToolButton->hide();
102 m_ui->m_dataSet1LineEdit->setText(QString::fromStdString(m_inputLayer->getDataSetName()));
105 if(!m_ds->isOpened())
113 size_t pos = m_inputLayer->getDataSetName().find(
".");
114 std::string inputAlias = m_inputLayer->getDataSetName().substr(pos + 1, m_inputLayer->getDataSetName().size() - 1);
116 if(pos != std::string::npos)
117 inputAlias = m_inputLayer->getDataSetName().substr(pos + 1, m_inputLayer->getDataSetName().size() - 1);
119 inputAlias = m_inputLayer->getDataSetName();
143 from->push_back(getJoin());
155 static boost::uuids::basic_random_generator<boost::mt19937> gen;
156 boost::uuids::uuid u = gen();
157 std::string
id = boost::uuids::to_string(u);
159 std::string title = m_ui->m_layerTitleLineEdit->text().toStdString();
162 layer->setDataSourceId(m_ds->getId());
163 layer->setRendererType(
"QUERY_LAYER_RENDERER");
165 layer->computeExtent();
168 std::auto_ptr<const te::map::LayerSchema> schema(layer->getSchema());
182 std::string dsId = m_ds->getId();
184 std::vector<std::string> datasetNames;
188 for (
size_t i = 0; i < datasetNames.size(); i++)
190 if(datasetNames[i] != m_inputLayer->getDataSetName())
191 m_ui->m_dataSet2ComboBox->addItem(QString::fromStdString(datasetNames[i]));
194 std::string DsName = m_ui->m_dataSet2ComboBox->currentText().toStdString();
195 size_t pos = DsName.find(
".");
196 if(pos != std::string::npos)
197 m_ui->m_dataSetAliasLineEdit->setText(QString::fromStdString(DsName.substr(pos + 1, DsName.size() - 1)));
199 m_ui->m_dataSetAliasLineEdit->setText(QString::fromStdString(DsName));
207 int index = m_ui->m_dataset1ColumnComboBox->currentIndex();
208 m_ui->m_dataset1ColumnComboBox->clear();
209 m_ui->m_dataset2ColumnComboBox->clear();
211 m_fieldsDialog->clearInputValues();
212 m_fieldsDialog->clearOutputValues();
215 std::vector<std::string> datasetNames = m_ds->getDataSetNames();
216 std::vector<std::pair<std::string, std::string> > dataSetSelecteds;
217 std::string inputAlias;
218 size_t pos = m_inputLayer->getDataSetName().find(
".");
220 if(pos != std::string::npos)
221 inputAlias = m_inputLayer->getDataSetName().substr(pos + 1, m_inputLayer->getDataSetName().size() - 1);
223 inputAlias = m_inputLayer->getDataSetName();
225 dataSetSelecteds.push_back(std::make_pair(m_inputLayer->getDataSetName(), inputAlias));
226 dataSetSelecteds.push_back(std::make_pair(m_ui->m_dataSet2ComboBox->currentText().toStdString(), m_ui->m_dataSetAliasLineEdit->text().toStdString()));
228 std::vector<std::string> propertyNames;
229 std::vector<std::string> fixedProperties;
232 for(
size_t t = 0; t < dataSetSelecteds.size(); ++t)
235 std::string alias = dataSetSelecteds[t].second;
238 std::string dataSetName = dataSetSelecteds[t].first;
241 std::auto_ptr<te::da::DataSetType> dsType(0);
244 std::vector<std::size_t> dataSetProperties;
247 for(
unsigned int i = 0; i < datasetNames.size(); ++i)
249 if(datasetNames[i] == dataSetName)
251 dsType = m_ds->getDataSetType(datasetNames[i]);
264 for(
size_t i = 0; i < dsType->size(); ++i)
266 std::string propName = dsType->getProperty(i)->
getName();
267 std::string fullName = alias +
"." + propName;
270 fixedProperties.push_back(fullName);
272 propertyNames.push_back(fullName);
275 m_ui->m_dataset1ColumnComboBox->addItem(QString::fromStdString(fullName), QVariant(dsType->getProperty(i)->getType()));
278 m_ui->m_dataset2ColumnComboBox->addItem(QString::fromStdString(fullName), QVariant(dsType->getProperty(i)->getType()));
285 m_ui->m_dataset1ColumnComboBox->setCurrentIndex(index);
288 m_fieldsDialog->setLeftLabel(
"Non-selected fields");
289 m_fieldsDialog->setRightLabel(
"Selected fields");
290 m_fieldsDialog->setOutputValues(propertyNames);
291 m_fieldsDialog->setFixedOutputValues(fixedProperties,
"geometry");
296 if(QDialog::Accepted == r)
299 dsv1 = m_ui->m_dataset1ColumnComboBox->itemData(m_ui->m_dataset1ColumnComboBox->currentIndex());
300 dsv2 = m_ui->m_dataset2ColumnComboBox->itemData(m_ui->m_dataset2ColumnComboBox->currentIndex());
301 std::string title = m_ui->m_layerTitleLineEdit->text().toStdString();
305 QMessageBox::warning(
this, tr(
"Tabular File"),
"The types of the selected columns do not match.");
310 QMessageBox::warning(
this, tr(
"Tabular File"),
"The types of the selected columns must be either an integer or a string.");
313 else if (title.empty())
315 QMessageBox::warning(
this, tr(
"Tabular File"),
"The new layer must have a title.");
333 if(m_ds->getType() ==
"OGR")
335 QMessageBox::information(
this, tr(
"Table link error"),
336 tr(
"This function is not available for the selected datasource"));
337 return QDialog::Rejected;
339 else if(!m_ds->getDataSetType(m_inputLayer->getDataSetName())->getPrimaryKey())
341 QMessageBox::information(
this, tr(
"Table link error"),
342 tr(
"This function is not available for datasets without a primary key"));
343 return QDialog::Rejected;
346 return QDialog::exec();
351 std::string DsName = m_ui->m_dataSet2ComboBox->currentText().toStdString();
352 size_t pos = DsName.find(
".");
353 if(pos != std::string::npos)
354 m_ui->m_dataSetAliasLineEdit->setText(QString::fromStdString(DsName.substr(pos + 1, DsName.size() - 1)));
356 m_ui->m_dataSetAliasLineEdit->setText(QString::fromStdString(DsName));
359 m_ui->m_tabularFrame->hide();
360 m_tabularView->hide();
361 m_ui->m_dataPreviewGroupBox->hide();
366 std::string aux = m_ui->m_dataset2ColumnComboBox->currentText().toStdString();
367 std::string alias =
"";
368 size_t pos = aux.find(
".");
370 if (pos != std::string::npos)
371 alias = aux.substr(0, pos);
376 std::auto_ptr<te::da::DataSetType> dsType(0);
377 dsType = m_ds->getDataSetType(alias);
381 std::auto_ptr<te::da::DataSet> dataSet = m_ds->getDataSet(alias);
384 std::vector<std::size_t> dataSetProperties;
386 for (
size_t i = 0; i < dsType->size(); ++i)
388 dataSetProperties.push_back(i);
392 m_tabularView->setDataSet(
new te::mem::DataSet(*dataSet.get(), dataSetProperties, 5), m_ds->getEncoding());
393 m_tabularView->resizeColumnsToContents();
395 if(m_ui->m_tabularFrame->isHidden())
397 m_tabularView->show();
398 m_ui->m_tabularFrame->show();
399 m_ui->m_dataPreviewGroupBox->show();
403 m_ui->m_tabularFrame->hide();
404 m_tabularView->hide();
405 m_ui->m_dataPreviewGroupBox->hide();
411 int res = m_fieldsDialog->exec();
412 if(res != QDialog::Accepted)
void setSRID(int srid)
It sets the spatial reference system identifier associated to this property.
A class that models the name of a dataset used in a From clause.
A class that models the name of any property of an object.
bool has(const te::dt::Property *p) const
It verifies if Property is associated to the primary key.
A layer resulting from a query.
This is an abstract class that models a query expression.
TESEEXPORT Style * CreateFeatureTypeStyle(const te::gm::GeomType &geomType)
Try creates an appropriate feature type style based on given geometry type.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
boost::ptr_vector< Field > Fields
Fields is just a boost::ptr_vector of Field pointers.
JoinType
The type of join in a query.
const Fields * getFields() const
It returns the list of output expressions used to form the result set.
A Join clause combines two FromItems.
TEDATAACCESSEXPORT void GetDataSetNames(std::vector< std::string > &datasetNames, const std::string &datasourceId)
A Select models a query to be used when retrieving data from a DataSource.
boost::ptr_vector< FromItem > From
It models the FROM clause for a query.
It describes a primary key (pk) constraint.
JoinConditionOn is a boolean expression and it specifies which items in a join are considered to matc...
A layer with reference to a dataset.
boost::intrusive_ptr< QueryLayer > QueryLayerPtr
virtual const std::string & getName() const
It returns the constraint name.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
A base class for binary functions.