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 "../../../se/Utils.h"
42 #include "../table/DataSetTableView.h"
45 #include "ui_TableLinkDialogForm.h"
48 #include <boost/uuid/random_generator.hpp>
49 #include <boost/uuid/uuid_io.hpp>
52 #include <QMessageBox>
59 m_ui(new Ui::TableLinkDialogForm)
62 m_ui->m_dataToolButton->setIcon(QIcon::fromTheme(
"view-data-table"));
63 m_ui->m_dataToolButton->setToolTip(tr(
"View dataset rows"));
64 m_ui->m_advancedToolButton->setIcon(QIcon::fromTheme(
"preferences-system"));
65 m_ui->m_advancedToolButton->setToolTip(tr(
"View advanced options"));
69 QGridLayout* tabularLayout =
new QGridLayout(
m_ui->m_tabularFrame);
71 tabularLayout->setContentsMargins(0, 0, 0, 0);
75 m_tabularView->setSelectionMode(QAbstractItemView::NoSelection);
77 m_ui->m_dataPreviewGroupBox->hide();
81 m_ui->m_tabularFrame->hide();
82 m_ui->m_helpPushButton->setPageReference(
"widgets/external_table/table_link_dialog.html");
85 m_ui->m_advancedToolButton->hide();
101 m_ui->m_dataSet1LineEdit->setText(QString::fromStdString(m_inputLayer->getDataSetName()));
104 if(!m_ds->isOpened())
112 size_t pos = m_inputLayer->getDataSetName().find(
".");
113 std::string inputAlias = m_inputLayer->getDataSetName().substr(pos + 1, m_inputLayer->getDataSetName().size() - 1);
115 if(pos != std::string::npos)
116 inputAlias = m_inputLayer->getDataSetName().substr(pos + 1, m_inputLayer->getDataSetName().size() - 1);
118 inputAlias = m_inputLayer->getDataSetName();
142 from->push_back(getJoin());
152 static boost::uuids::basic_random_generator<boost::mt19937> gen;
153 boost::uuids::uuid u = gen();
154 std::string
id = boost::uuids::to_string(u);
156 std::string title = m_ui->m_layerTitleLineEdit->text().toStdString();
159 layer->setDataSourceId(m_ds->getId());
160 layer->setRendererType(
"QUERY_LAYER_RENDERER");
162 layer->computeExtent();
165 std::auto_ptr<const te::map::LayerSchema> schema(layer->getSchema());
177 QApplication::setOverrideCursor(Qt::WaitCursor);
179 std::string dsId = m_ds->getId();
181 std::vector<std::string> datasetNames;
185 for (
size_t i = 0; i < datasetNames.size(); i++)
187 if(datasetNames[i] != m_inputLayer->getDataSetName())
188 m_ui->m_dataSet2ComboBox->addItem(QString::fromStdString(datasetNames[i]));
191 std::string DsName = m_ui->m_dataSet2ComboBox->currentText().toStdString();
192 size_t pos = DsName.find(
".");
193 if(pos != std::string::npos)
194 m_ui->m_dataSetAliasLineEdit->setText(QString::fromStdString(DsName.substr(pos + 1, DsName.size() - 1)));
196 m_ui->m_dataSetAliasLineEdit->setText(QString::fromStdString(DsName));
198 QApplication::restoreOverrideCursor();
204 int index = m_ui->m_dataset1ColumnComboBox->currentIndex();
205 m_ui->m_dataset1ColumnComboBox->clear();
206 m_ui->m_dataset2ColumnComboBox->clear();
208 m_fieldsDialog->clearInputValues();
209 m_fieldsDialog->clearOutputValues();
212 std::vector<std::string> datasetNames = m_ds->getDataSetNames();
213 std::vector<std::pair<std::string, std::string> > dataSetSelecteds;
214 std::string inputAlias;
215 size_t pos = m_inputLayer->getDataSetName().find(
".");
217 if(pos != std::string::npos)
218 inputAlias = m_inputLayer->getDataSetName().substr(pos + 1, m_inputLayer->getDataSetName().size() - 1);
220 inputAlias = m_inputLayer->getDataSetName();
222 dataSetSelecteds.push_back(std::make_pair(m_inputLayer->getDataSetName(), inputAlias));
223 dataSetSelecteds.push_back(std::make_pair(m_ui->m_dataSet2ComboBox->currentText().toStdString(), m_ui->m_dataSetAliasLineEdit->text().toStdString()));
225 std::vector<std::string> propertyNames;
226 std::vector<std::string> fixedProperties;
229 for(
size_t t = 0; t < dataSetSelecteds.size(); ++t)
232 std::string alias = dataSetSelecteds[t].second;
235 std::string dataSetName = dataSetSelecteds[t].first;
238 std::auto_ptr<te::da::DataSetType> dsType(0);
241 std::vector<std::size_t> dataSetProperties;
244 for(
unsigned int i = 0; i < datasetNames.size(); ++i)
246 if(datasetNames[i] == dataSetName)
248 dsType = m_ds->getDataSetType(datasetNames[i]);
261 for(
size_t i = 0; i < dsType->size(); ++i)
263 std::string propName = dsType->getProperty(i)->
getName();
264 std::string fullName = alias +
"." + propName;
266 std::auto_ptr<te::da::DataSet> dataSet = m_ds->getDataSet(alias);
268 dataSetProperties.push_back(i);
271 fixedProperties.push_back(fullName);
273 propertyNames.push_back(fullName);
276 m_ui->m_dataset1ColumnComboBox->addItem(QString::fromStdString(fullName), QVariant(dsType->getProperty(i)->getType()));
279 m_ui->m_dataset2ColumnComboBox->addItem(QString::fromStdString(fullName), QVariant(dsType->getProperty(i)->getType()));
281 if(i == dsType->size() - 1)
284 m_tabularView->setDataSet(
new te::mem::DataSet(*dataSet.get(), dataSetProperties, 5), m_ds->getEncoding());
285 m_tabularView->resizeColumnsToContents();
293 m_ui->m_dataset1ColumnComboBox->setCurrentIndex(index);
296 m_fieldsDialog->setLeftLabel(
"Non-selected fields");
297 m_fieldsDialog->setRightLabel(
"Selected fields");
298 m_fieldsDialog->setOutputValues(propertyNames);
299 m_fieldsDialog->setFixedOutputValues(fixedProperties,
"geometry");
304 if(QDialog::Accepted == r)
307 dsv1 = m_ui->m_dataset1ColumnComboBox->itemData(m_ui->m_dataset1ColumnComboBox->currentIndex());
308 dsv2 = m_ui->m_dataset2ColumnComboBox->itemData(m_ui->m_dataset2ColumnComboBox->currentIndex());
312 QMessageBox::warning(
this, tr(
"Tabular File"),
"The types of the selected columns do not match.");
317 QMessageBox::warning(
this, tr(
"Tabular File"),
"The types of the selected columns must be either an integer or a string.");
335 if(m_ds->getType() ==
"OGR")
337 QMessageBox::information(
this, tr(
"Table link error"),
338 tr(
"This function is not available for the selected datasource"));
339 return QDialog::Rejected;
341 else if(!m_ds->getDataSetType(m_inputLayer->getDataSetName())->getPrimaryKey())
343 QMessageBox::information(
this, tr(
"Table link error"),
344 tr(
"This function is not available for datasets without a primary key"));
345 return QDialog::Rejected;
348 return QDialog::exec();
353 std::string DsName = m_ui->m_dataSet2ComboBox->currentText().toStdString();
354 size_t pos = DsName.find(
".");
355 if(pos != std::string::npos)
356 m_ui->m_dataSetAliasLineEdit->setText(QString::fromStdString(DsName.substr(pos + 1, DsName.size() - 1)));
358 m_ui->m_dataSetAliasLineEdit->setText(QString::fromStdString(DsName));
365 if(m_ui->m_tabularFrame->isHidden())
367 m_tabularView->show();
368 m_ui->m_tabularFrame->show();
369 m_ui->m_dataPreviewGroupBox->show();
373 m_ui->m_tabularFrame->hide();
374 m_tabularView->hide();
375 m_ui->m_dataPreviewGroupBox->hide();
381 int res = m_fieldsDialog->exec();
382 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.
A Qt Dialog that allows users to modify which fields will be included in 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.
A Qt dialog that allows users to create a new query layer based on the information of two distinct da...