29 #include "../../../dataaccess/dataset/DataSet.h" 30 #include "../../../dataaccess/dataset/DataSetType.h" 31 #include "../../../dataaccess/query/SQLDialect.h" 32 #include "../../../dataaccess/datasource/DataSourceManager.h" 35 #include "../../../dataaccess/utils/Utils.h" 36 #include "../utils/DoubleListWidget.h" 37 #include "ui_DoubleListWidgetForm.h" 38 #include "ui_QueryBuilderWizardForm.h" 42 #include <QMessageBox> 47 m_ui(new
Ui::QueryBuilderWizardForm)
58 m_ui->m_addDataSetPushButton->setIcon(QIcon::fromTheme(
"list-add"));
59 m_ui->m_removeDataSetPushButton->setIcon(QIcon::fromTheme(
"list-remove"));
61 m_ui->m_addWhereClausePushButton->setIcon(QIcon::fromTheme(
"list-add"));
62 m_ui->m_removeWhereClausePushButton->setIcon(QIcon::fromTheme(
"list-remove"));
64 m_ui->m_addOrderPushButton->setIcon(QIcon::fromTheme(
"list-add"));
65 m_ui->m_removeOrderPushButton->setIcon(QIcon::fromTheme(
"list-remove"));
69 m_propertyList->getForm()->m_leftItemsLabel->setText(tr(
"Available Properties"));
70 m_propertyList->getForm()->m_rightItemsLabel->setText(tr(
"Used Properties"));
75 m_groupByList->getForm()->m_leftItemsLabel->setText(tr(
"Available Properties"));
76 m_groupByList->getForm()->m_rightItemsLabel->setText(tr(
"Used Properties"));
99 if(currentPage() ==
m_ui->m_dataSourceWizardPage)
103 else if(currentPage() ==
m_ui->m_dataSetWizardPage)
107 else if(currentPage() ==
m_ui->m_propertyWizardPage)
111 else if(currentPage() ==
m_ui->m_whereClauseWizardPage)
115 else if(currentPage() ==
m_ui->m_groupByWizardPage)
119 else if(currentPage() ==
m_ui->m_orderByWizardPage)
135 list.push_back(it->first.c_str());
140 m_ui->m_dataSourceComboBox->clear();
141 m_ui->m_dataSourceComboBox->addItems(list);
146 std::string dsId =
m_ui->m_dataSourceComboBox->currentText().toUtf8().data();
148 std::vector<std::string> datasetNames;
154 for(
size_t t = 0; t < datasetNames.size(); ++t)
156 list.push_back(datasetNames[t].c_str());
159 m_ui->m_dataSetComboBox->clear();
160 m_ui->m_dataSetComboBox->addItems(list);
162 if(datasetNames.empty() ==
false)
169 std::string dsId =
m_ui->m_dataSourceComboBox->currentText().toUtf8().data();
171 std::vector<std::string> datasetNames = ds->getDataSetNames();
173 int row =
m_ui->m_dataSetTableWidget->rowCount();
175 std::vector<std::string> inputProperties;
179 for(
int i = 0; i < row; ++i)
182 QTableWidgetItem* itemAlias =
m_ui->m_dataSetTableWidget->item(i, 1);
183 std::string alias = itemAlias->text().toUtf8().data();
186 QTableWidgetItem* itemDataSet =
m_ui->m_dataSetTableWidget->item(i, 0);
187 std::string dataSetName = itemDataSet->text().toUtf8().data();
190 std::unique_ptr<te::da::DataSetType> dsType;
191 for(
unsigned int i = 0; i < datasetNames.size(); ++i)
193 if(datasetNames[i] == dataSetName)
194 dsType = ds->getDataSetType(datasetNames[i]);
199 for(
size_t t = 0; t < dsType->size(); ++t)
201 std::string propName = dsType->getProperty(t)->getName();
202 std::string fullName = alias +
"." + propName;
204 inputProperties.push_back(fullName);
205 list.push_back(fullName.c_str());
214 m_ui->m_restrictValueComboBox->clear();
215 m_ui->m_restrictValueComboBox->addItems(list);
217 m_ui->m_valuePropertyComboBox->clear();
218 m_ui->m_valuePropertyComboBox->addItems(list);
220 m_ui->m_orderPropertyComboBox->clear();
221 m_ui->m_orderPropertyComboBox->addItems(list);
237 m_ui->m_OperatorComboBox->clear();
243 m_ui->m_OperatorComboBox->addItem(it->right.c_str());
256 m_ui->m_connectorComboBox->clear();
258 boost::bimap<int, std::string>::left_const_iterator it;
260 m_ui->m_connectorComboBox->addItem(it->second.c_str());
262 m_ui->m_connectorComboBox->addItem(it->second.c_str());
264 m_ui->m_connectorComboBox->addItem(it->second.c_str());
266 m_ui->m_connectorComboBox->addItem(it->second.c_str());
268 m_ui->m_connectorComboBox->addItem(it->second.c_str());
276 m_ui->m_orderComboBox->clear();
278 boost::bimap<int, std::string>::iterator it =
m_bimapOrder.begin();
282 m_ui->m_orderComboBox->addItem(it->right.c_str());
289 if(
m_ui->m_dataSourceComboBox->currentText().isEmpty())
291 QMessageBox::warning(
this, tr(
"Query Builder"), tr(
"Data Source not selected."));
304 int numRows =
m_ui->m_dataSetTableWidget->rowCount();
308 QMessageBox::warning(
this, tr(
"Query Builder"), tr(
"No Data Set selected."));
323 QMessageBox::warning(
this, tr(
"Query Builder"), tr(
"No Property selected."));
332 int numRows =
m_ui->m_whereClauseTableWidget->rowCount();
336 QMessageBox::warning(
this, tr(
"Query Builder"), tr(
"No Where Clause defined."));
360 std::string dataSourceName = value.toUtf8().data();
367 if(value.isEmpty() ==
false)
368 m_ui->m_dataSetAliasLineEdit->setText(value);
373 if(
m_ui->m_dataSetComboBox->currentText().isEmpty())
375 QMessageBox::warning(
this, tr(
"Query Builder"), tr(
"Data Set not selected."));
379 if(
m_ui->m_dataSetAliasLineEdit->text().isEmpty())
381 QMessageBox::warning(
this, tr(
"Query Builder"), tr(
"Data Set Alias not defined."));
385 std::string dataSetName =
m_ui->m_dataSetComboBox->currentText().toUtf8().data();
386 std::string aliasName =
m_ui->m_dataSetAliasLineEdit->text().toUtf8().data();
388 int newrow =
m_ui->m_dataSetTableWidget->rowCount();
391 for(
int i = 0; i < newrow; ++i)
393 QTableWidgetItem* itemName =
m_ui->m_dataSetTableWidget->item(i, 1);
395 if(itemName->text().toUtf8().data() == aliasName)
397 QMessageBox::warning(
this, tr(
"Query Builder"), tr(
"Data Set Alias already defined."));
403 m_ui->m_dataSetTableWidget->insertRow(newrow);
405 QTableWidgetItem* itemDataSet =
new QTableWidgetItem(QString::fromUtf8(dataSetName.c_str()));
406 m_ui->m_dataSetTableWidget->setItem(newrow, 0, itemDataSet);
408 QTableWidgetItem* itemAlias =
new QTableWidgetItem(QString::fromUtf8(aliasName.c_str()));
409 m_ui->m_dataSetTableWidget->setItem(newrow, 1, itemAlias);
411 m_ui->m_dataSetTableWidget->resizeColumnToContents(0);
416 int row =
m_ui->m_dataSetTableWidget->currentRow();
419 m_ui->m_dataSetTableWidget->removeRow(row);
421 m_ui->m_dataSetTableWidget->resizeColumnToContents(0);
426 if(
m_ui->m_restrictValueComboBox->currentText().isEmpty())
428 QMessageBox::warning(
this, tr(
"Query Builder"), tr(
"Restrict value not defined."));
432 if(
m_ui->m_valuePropertyRadioButton->isChecked() ==
false &&
433 m_ui->m_valueValueRadioButton->isChecked() ==
false)
435 if(
m_ui->m_valueValueComboBox->currentText().isEmpty())
437 QMessageBox::warning(
this, tr(
"Query Builder"), tr(
"Value not defined."));
442 if(
m_ui->m_valueValueRadioButton->isChecked())
444 if(
m_ui->m_valueValueComboBox->currentText().isEmpty())
446 QMessageBox::warning(
this, tr(
"Query Builder"), tr(
"Value not defined."));
451 int newrow =
m_ui->m_whereClauseTableWidget->rowCount();
453 std::string restrictValue =
m_ui->m_restrictValueComboBox->currentText().toUtf8().data();
454 std::string operatorStr =
m_ui->m_OperatorComboBox->currentText().toUtf8().data();
455 std::string connector =
m_ui->m_connectorComboBox->currentText().toUtf8().data();
457 std::string valueStr;
458 if(
m_ui->m_valuePropertyRadioButton->isChecked())
459 valueStr =
m_ui->m_valuePropertyComboBox->currentText().toUtf8().data();
460 else if(
m_ui->m_valueValueRadioButton->isChecked())
461 valueStr =
m_ui->m_valueValueComboBox->currentText().toUtf8().data();
464 m_ui->m_whereClauseTableWidget->insertRow(newrow);
466 QTableWidgetItem* itemProperty =
new QTableWidgetItem(QString::fromUtf8(restrictValue.c_str()));
467 m_ui->m_whereClauseTableWidget->setItem(newrow, 0, itemProperty);
469 QTableWidgetItem* itemOperator =
new QTableWidgetItem(QString::fromUtf8(operatorStr.c_str()));
470 m_ui->m_whereClauseTableWidget->setItem(newrow, 1, itemOperator);
472 QTableWidgetItem* itemValue =
new QTableWidgetItem(QString::fromUtf8(valueStr.c_str()));
473 m_ui->m_whereClauseTableWidget->setItem(newrow, 2, itemValue);
475 QTableWidgetItem* itemConnector =
new QTableWidgetItem(QString::fromUtf8(connector.c_str()));
476 m_ui->m_whereClauseTableWidget->setItem(newrow, 3, itemConnector);
478 m_ui->m_whereClauseTableWidget->resizeColumnsToContents();
483 int row =
m_ui->m_whereClauseTableWidget->currentRow();
486 m_ui->m_whereClauseTableWidget->removeRow(row);
488 m_ui->m_whereClauseTableWidget->resizeColumnsToContents();
493 if(
m_ui->m_orderPropertyComboBox->currentText().isEmpty())
495 QMessageBox::warning(
this, tr(
"Query Builder"), tr(
"Property value not defined."));
499 int newrow =
m_ui->m_orderTableWidget->rowCount();
501 std::string propertyValue =
m_ui->m_orderPropertyComboBox->currentText().toUtf8().data();
502 std::string order =
m_ui->m_orderComboBox->currentText().toUtf8().data();
505 m_ui->m_orderTableWidget->insertRow(newrow);
507 QTableWidgetItem* itemProperty =
new QTableWidgetItem(QString::fromUtf8(propertyValue.c_str()));
508 m_ui->m_orderTableWidget->setItem(newrow, 0, itemProperty);
510 QTableWidgetItem* itemOrder =
new QTableWidgetItem(QString::fromUtf8(order.c_str()));
511 m_ui->m_orderTableWidget->setItem(newrow, 1, itemOrder);
513 m_ui->m_orderTableWidget->resizeColumnsToContents();
518 int row =
m_ui->m_orderTableWidget->currentRow();
521 m_ui->m_orderTableWidget->removeRow(row);
523 m_ui->m_orderTableWidget->resizeColumnsToContents();
std::map< std::string, DataSourcePtr >::iterator iterator
boost::shared_ptr< DataSource > DataSourcePtr
static te::dt::Date ds(2010, 01, 01)
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
TEDATAACCESSEXPORT void GetDataSetNames(std::vector< std::string > &datasetNames, const std::string &datasourceId)
A Qt dialog that allows users to create query builder based on TerraLib query framework.