27 #include "../../../common/StringUtils.h" 28 #include "../../../dataaccess/dataset/DataSet.h" 29 #include "../../../dataaccess/dataset/DataSetType.h" 30 #include "../../../dataaccess/dataset/ObjectIdSet.h" 31 #include "../../../dataaccess/datasource/DataSourceCapabilities.h" 32 #include "../../../dataaccess/query/FunctionNames.h" 33 #include "../../../dataaccess/query/QueryCapabilities.h" 34 #include "../../../dataaccess/query_h.h" 35 #include "../../../dataaccess/utils/Utils.h" 36 #include "../../../maptools/DataSetLayer.h" 37 #include "../../../maptools/QueryLayer.h" 38 #include "../../../geometry/GeometryProperty.h" 39 #include "../../../se/Utils.h" 40 #include "../layer/explorer/LayerItemView.h" 41 #include "../layer/explorer/TreeItem.h" 42 #include "../utils/ColorPickerToolButton.h" 45 #include "ui_QueryDialogForm.h" 48 #include <QGridLayout> 49 #include <QMessageBox> 52 #include <boost/uuid/random_generator.hpp> 53 #include <boost/uuid/uuid_io.hpp> 61 te::qt::widgets::QueryDialog::QueryDialog(
QWidget* parent, Qt::WindowFlags f)
63 m_ui(new
Ui::QueryDialogForm)
68 QGridLayout* layout =
new QGridLayout(m_ui->m_widget);
70 layout->addWidget(m_whereClauseWidget.get());
71 layout->setContentsMargins(0, 0, 0, 0);
75 m_colorPicker->setFixedSize(70, 24);
76 m_colorPicker->setColor(QColor(255, 255, 0, 128));
79 QGridLayout* colorPickerLayout =
new QGridLayout(m_ui->m_colorPickerFrame);
80 colorPickerLayout->setContentsMargins(0, 0, 0, 0);
81 colorPickerLayout->addWidget(m_colorPicker);
84 connect(m_ui->m_inputLayerComboBox, SIGNAL(activated(QString)),
this, SLOT(onInputLayerActivated(QString)));
85 connect(m_ui->m_applyPushButton, SIGNAL(clicked()),
this, SLOT(onApplyPushButtonClicked()));
86 connect(m_ui->m_createLayerPushButton, SIGNAL(clicked()),
this, SLOT(onCreateLayerPushButtonClicked()));
89 m_ui->m_helpPushButton->setPageReference(
"widgets/query/query_dialog.html");
98 m_ui->m_inputLayerComboBox->clear();
100 std::list<te::map::AbstractLayerPtr>::iterator it = layerList.begin();
102 while(it != layerList.end())
106 std::unique_ptr<te::da::DataSetType> dsType = l->getSchema();
108 if(dsType->hasGeom())
109 m_ui->m_inputLayerComboBox->addItem(l->getTitle().c_str(), QVariant::fromValue(l));
114 if(
m_ui->m_inputLayerComboBox->count() > 0)
116 QString s =
m_ui->m_inputLayerComboBox->currentText();
124 for(
int i = 0; i <
m_ui->m_inputLayerComboBox->count(); ++i)
126 QVariant varLayer =
m_ui->m_inputLayerComboBox->itemData(i, Qt::UserRole);
131 m_ui->m_inputLayerComboBox->setCurrentIndex(i);
136 if(
m_ui->m_inputLayerComboBox->count() > 0)
138 QString s =
m_ui->m_inputLayerComboBox->currentText();
146 if(value.empty() ==
false)
148 std::string dataSetName = value;
149 std::string aliasName = value;
151 size_t pos = dataSetName.find(
".");
153 if(pos != std::string::npos)
155 aliasName = dataSetName.substr(pos + 1, dataSetName.size() - 1);
179 m_ui->m_inputLayerComboBox->addItem(layer->getTitle().c_str(), QVariant::fromValue(layer));
181 int curIdx =
m_ui->m_inputLayerComboBox->currentIndex();
183 QVariant varLayer =
m_ui->m_inputLayerComboBox->itemData(curIdx, Qt::UserRole);
188 QString s =
m_ui->m_inputLayerComboBox->currentText();
201 int curIdx =
m_ui->m_inputLayerComboBox->currentIndex();
203 for(
int i = 0; i <
m_ui->m_inputLayerComboBox->count(); ++i)
205 QVariant varLayer =
m_ui->m_inputLayerComboBox->itemData(i, Qt::UserRole);
210 m_ui->m_inputLayerComboBox->removeItem(i);
214 if(
m_ui->m_inputLayerComboBox->count() != 0)
216 m_ui->m_inputLayerComboBox->setCurrentIndex(0);
218 QString s =
m_ui->m_inputLayerComboBox->currentText();
239 int idxLayer =
m_ui->m_inputLayerComboBox->currentIndex();
241 QVariant varLayer =
m_ui->m_inputLayerComboBox->itemData(idxLayer, Qt::UserRole);
246 std::string dataSourceName = layer->getDataSourceId();
250 if(!dsPtr->isOpened())
256 std::vector<std::string> vecOperators;
257 std::vector<std::string> vecSpatialOperators;
258 std::vector<std::string> vecConnectors;
263 std::set<std::string>::iterator it;
268 vecOperators.push_back(*it);
275 vecOperators.push_back(*it);
284 vecSpatialOperators.push_back(*it);
291 vecSpatialOperators.clear();
307 vecConnectors.push_back(*it);
314 std::unique_ptr<te::da::DataSetType> dsType = layer->getSchema();
316 std::string dsName = dsType->getName();
319 std::vector<std::pair<std::string, std::string> > list;
320 list.push_back(std::pair<std::string, std::string>(dsName, aliasName));
325 std::vector<std::string> inputProperties;
326 std::vector<std::string> geomProperties;
328 for(
size_t i = 0; i < dsType->size(); ++i)
330 std::string propName = dsType->getProperty(i)->getName();
333 geomProperties.push_back(propName);
335 inputProperties.push_back(propName);
346 if (wh ==
nullptr || wh->
getExp() ==
nullptr)
348 QMessageBox::information(
this, tr(
"Query"), tr(
"Add a restriction expression first."));
353 int index =
m_ui->m_inputLayerComboBox->currentIndex();
355 QVariant varLayer =
m_ui->m_inputLayerComboBox->itemData(index, Qt::UserRole);
359 std::unique_ptr<te::da::DataSetType> schema = layer->getSchema();
361 std::vector<std::string> tokens;
366 if (tokens.size() > 1)
369 alias = schema->getName();
373 static boost::uuids::basic_random_generator<boost::mt19937> gen;
374 boost::uuids::uuid u = gen();
375 std::string
id = boost::uuids::to_string(u);
378 aLayer->setDataSourceId(layer->getDataSourceId());
387 std::vector<te::dt::Property*> props = schema->getProperties();
397 from->push_back(fromItem);
421 if(wh ==
nullptr || wh->
getExp() ==
nullptr)
423 QMessageBox::information(
this, tr(
"Query"), tr(
"Add a restriction expression first."));
428 int index =
m_ui->m_inputLayerComboBox->currentIndex();
430 QVariant varLayer =
m_ui->m_inputLayerComboBox->itemData(index, Qt::UserRole);
439 setCursor(Qt::WaitCursor);
445 std::unique_ptr<const te::map::LayerSchema> schema(layer->getSchema());
448 std::unique_ptr<te::da::DataSet> dataset = layer->getData(e);
449 assert(dataset.get());
451 if(
m_ui->m_newSelRadioButton->isChecked())
454 dataset->moveBeforeFirst();
459 layer->clearSelected();
464 else if(
m_ui->m_addSelRadioButton->isChecked())
467 dataset->moveBeforeFirst();
479 setCursor(Qt::ArrowCursor);
481 QMessageBox::information(
this, tr(
"Query"), tr(
"Query executed with successfully."));
483 catch(std::exception& e)
485 setCursor(Qt::ArrowCursor);
486 QMessageBox::information(
this, tr(
"Query"), e.what());
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
const std::set< std::string > & getComparsionOperators() const
An abstract class that models a source of data in a query.
The Field class can be used to model an expression that takes part of the output items of a SELECT...
static const std::string sm_ST_Equals
A class that models the name of a dataset used in a From clause.
static const std::string sm_ST_Overlaps
boost::shared_ptr< DataSource > DataSourcePtr
static const std::string sm_ST_Touches
static const std::string sm_ST_Intersects
virtual Expression * clone() const =0
It creates a new copy of this expression.
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
const std::set< std::string > & getArithmeticOperators() const
A layer resulting from a query.
void setExpression(te::da::Expression *expression, bool isClauseIn)
It set the expression that can be used to retrieve the data set that contains the all indentified ele...
static const std::string sm_ST_Contains
const QueryCapabilities & getQueryCapabilities() const
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.
const std::set< std::string > & getLogicalOperators() const
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr) te
void Tokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" ")
It tokenizes a given string with a delimiter of your own choice.
void setRendererType(const std::string &t)
static const std::string sm_ST_Crosses
A class that informs the query support of a given data source.
int getSRID() const
It returns the spatial reference system identifier associated to this property.
This class represents a set of unique ids created in the same context. i.e. from the same data set...
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
boost::ptr_vector< Field > Fields
Fields is just a boost::ptr_vector of Field pointers.
A class that can be used to model a filter expression that can be applied to a query.
static const std::string sm_ST_EnvelopeIntersects
Expression * getExp() const
TEDATAACCESSEXPORT ObjectIdSet * GenerateOIDSet(DataSet *dataset, const DataSetType *type)
A Select models a query to be used when retrieving data from a DataSource.
const std::set< std::string > & getSpatialTopologicOperators() const
boost::ptr_vector< FromItem > From
It models the FROM clause for a query.
This file defines a class for a Query Dialog Dialog.
static const std::string sm_ST_Disjoint
virtual void setSRID(int srid)
It sets the Spatial Reference System ID associated to the Layer.
void setQuery(te::da::Select *s)
static const std::string sm_ST_Within
virtual void setStyle(te::se::Style *style)
It sets the Style associated to the layer.
A layer with reference to a dataset.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr