27 #include "../../../core/translator/Translator.h" 28 #include "../../../dataaccess/dataset/PrimaryKey.h" 29 #include "../../../dataaccess/datasource/DataSourceManager.h" 30 #include "../../../dataaccess/Enums.h" 31 #include "../../../dataaccess/query/BinaryFunction.h" 32 #include "../../../dataaccess/query/DataSetName.h" 33 #include "../../../dataaccess/query/Expression.h" 34 #include "../../../dataaccess/query/Field.h" 35 #include "../../../dataaccess/query/Join.h" 36 #include "../../../dataaccess/query/JoinConditionOn.h" 37 #include "../../../dataaccess/query/PropertyName.h" 38 #include "../../../dataaccess/utils/Utils.h" 39 #include "../../../geometry/GeometryProperty.h" 40 #include "../../../maptools/QueryLayer.h" 41 #include "../../../memory/DataSet.h" 42 #include "../../../qt/widgets/utils/ScopedCursor.h" 43 #include "../../../se/Utils.h" 44 #include "../table/DataSetTableView.h" 47 #include "ui_TableLinkDialogForm.h" 50 #include <boost/uuid/random_generator.hpp> 51 #include <boost/uuid/uuid_io.hpp> 54 #include <QMessageBox> 61 m_ui(new
Ui::TableLinkDialogForm)
64 m_ui->m_dataToolButton->setIcon(QIcon::fromTheme(
"view-data-table"));
65 m_ui->m_dataToolButton->setToolTip(tr(
"View dataset rows"));
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();
78 m_ui->m_helpPushButton->setPageReference(
"widgets/external_table/table_link_dialog.html");
92 m_ui->m_dataSet1LineEdit->setText(QString::fromUtf8(
m_inputLayer->getDataSetName().c_str()));
106 if(pos != std::string::npos)
134 fields->push_back(f);
140 fields->push_back(f);
159 static boost::uuids::basic_random_generator<boost::mt19937> gen;
160 boost::uuids::uuid u = gen();
161 std::string
id = boost::uuids::to_string(u);
163 std::string title =
m_ui->m_layerTitleLineEdit->text().toUtf8().data();
166 layer->setDataSourceId(
m_ds->getId());
168 layer->setRendererType(
"QUERY_LAYER_RENDERER");
172 std::unique_ptr<const te::map::LayerSchema> schema(layer->getSchema());
177 layer->computeExtent();
190 std::string dsId =
m_ds->getId();
192 std::vector<std::string> datasetNames;
196 for (
size_t i = 0; i < datasetNames.size(); i++)
201 if((datasetNames[i] !=
m_inputLayer->getDataSetName()) && (!dataType->hasGeom()))
202 m_ui->m_dataSet2ComboBox->addItem(QString::fromUtf8(datasetNames[i].c_str()));
205 if (
m_ui->m_dataSet2ComboBox->count() == 0)
211 std::string DsName =
m_ui->m_dataSet2ComboBox->currentText().toUtf8().data();
212 size_t pos = DsName.find(
".");
213 if(pos != std::string::npos)
214 m_ui->m_dataSetAliasLineEdit->setText(QString::fromUtf8(DsName.substr(pos + 1, DsName.size() - 1).c_str()));
216 m_ui->m_dataSetAliasLineEdit->setText(QString::fromUtf8(DsName.c_str()));
227 int index =
m_ui->m_dataset1ColumnComboBox->currentIndex();
228 m_ui->m_dataset1ColumnComboBox->clear();
229 m_ui->m_dataset2ColumnComboBox->clear();
232 std::vector<std::string> datasetNames =
m_ds->getDataSetNames();
233 std::vector<std::pair<std::string, std::string> > dataSetSelecteds;
234 std::string inputAlias;
237 if(pos != std::string::npos)
242 dataSetSelecteds.push_back(std::make_pair(
m_inputLayer->getDataSetName(), inputAlias));
243 dataSetSelecteds.push_back(std::make_pair(
m_ui->m_dataSet2ComboBox->currentText().toUtf8().data(),
m_ui->m_dataSetAliasLineEdit->text().toUtf8().data()));
246 std::set<std::string> propertyNames;
249 for(
size_t t = 0; t < dataSetSelecteds.size(); ++t)
252 std::string alias = dataSetSelecteds[t].second;
255 std::string dataSetName = dataSetSelecteds[t].first;
258 std::unique_ptr<te::da::DataSetType> dsType;
260 for(
unsigned int i = 0; i < datasetNames.size(); ++i)
262 if(datasetNames[i] == dataSetName)
264 dsType =
m_ds->getDataSetType(datasetNames[i]);
277 for(
size_t i = 0; i < dsType->size(); ++i)
280 std::string propName = curProp->
getName();
281 std::string fullName = alias +
"." + propName;
282 bool isNew = propertyNames.find(propName) == propertyNames.end();
285 propertyNames.insert(propName);
287 if (pk->
has(dsType->getProperty(i)) || !isNew)
293 m_ui->m_dataset1ColumnComboBox->addItem(QString::fromUtf8(fullName.c_str()), QVariant(dsType->getProperty(i)->getType()));
296 m_ui->m_dataset2ColumnComboBox->addItem(QString::fromUtf8(fullName.c_str()), QVariant(dsType->getProperty(i)->getType()));
303 m_ui->m_dataset1ColumnComboBox->setCurrentIndex(index);
308 if(QDialog::Accepted == r)
311 dsv1 =
m_ui->m_dataset1ColumnComboBox->itemData(
m_ui->m_dataset1ColumnComboBox->currentIndex());
312 dsv2 =
m_ui->m_dataset2ColumnComboBox->itemData(
m_ui->m_dataset2ColumnComboBox->currentIndex());
313 std::string title =
m_ui->m_layerTitleLineEdit->text().toUtf8().data();
317 QMessageBox::warning(
this, tr(
"Tabular File"),
"The types of the selected columns do not match.");
322 QMessageBox::warning(
this, tr(
"Tabular File"),
"The types of the selected columns must be either an integer or a string.");
325 else if (title.empty())
327 QMessageBox::warning(
this, tr(
"Tabular File"),
"The new layer must have a title.");
345 if (
m_ds->getType() ==
"ADO")
347 QMessageBox::information(
this, tr(
"Table link error"),
348 tr(
"This function is not available for the selected datasource"));
349 return QDialog::Rejected;
351 else if(!
m_ds->getDataSetType(
m_inputLayer->getDataSetName())->getPrimaryKey())
353 QMessageBox::information(
this, tr(
"Table link error"),
354 tr(
"This function is not available for datasets without a primary key"));
355 return QDialog::Rejected;
358 return QDialog::exec();
363 std::string DsName =
m_ui->m_dataSet2ComboBox->currentText().toUtf8().data();
364 size_t pos = DsName.find(
".");
365 if(pos != std::string::npos)
366 m_ui->m_dataSetAliasLineEdit->setText(QString::fromUtf8(DsName.substr(pos + 1, DsName.size() - 1).c_str()));
368 m_ui->m_dataSetAliasLineEdit->setText(QString::fromUtf8(DsName.c_str()));
371 m_ui->m_tabularFrame->hide();
373 m_ui->m_dataPreviewGroupBox->hide();
378 std::string aux =
m_ui->m_dataset2ColumnComboBox->currentText().toUtf8().data();
380 size_t pos = aux.find(
".");
382 if (pos != std::string::npos)
383 alias = aux.substr(0, pos);
388 std::unique_ptr<te::da::DataSetType> dsType;
389 dsType =
m_ds->getDataSetType(alias);
393 std::unique_ptr<te::da::DataSet> dataSet =
m_ds->getDataSet(alias);
396 std::vector<std::size_t> dataSetProperties;
398 for (
size_t i = 0; i < dsType->size(); ++i)
400 dataSetProperties.push_back(i);
407 if(
m_ui->m_tabularFrame->isHidden())
410 m_ui->m_tabularFrame->show();
411 m_ui->m_dataPreviewGroupBox->show();
415 m_ui->m_tabularFrame->hide();
417 m_ui->m_dataPreviewGroupBox->hide();
The Field class can be used to model an expression that takes part of the output items of a SELECT...
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.
#define TE_TR(message)
It marks a string in order to get translated.
It models a property definition.
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.
A Join clause combines two FromItems.
TEDATAACCESSEXPORT void GetDataSetNames(std::vector< std::string > &datasetNames, const std::string &datasourceId)
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
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...
TEDATAACCESSEXPORT DataSetType * GetDataSetType(const std::string &name, const std::string &datasourceId)
A layer with reference to a dataset.
boost::intrusive_ptr< QueryLayer > QueryLayerPtr
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
A base class for binary functions.
const std::string & getName() const
It returns the property name.