DataPropertiesDialog.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18 */
19 
20 /*!
21  \file terralib/qt/widgets/externalTable/DataPropertiesDialog.h
22 
23  \brief A dialog used to configure the properties of a new textual file based layer
24 */
25 
26 //Terralib
27 #include "../../../dataaccess/dataset/DataSet.h"
28 #include "../../../dataaccess/dataset/DataSetAdapter.h"
29 #include "../../../dataaccess/dataset/DataSetType.h"
30 #include "../../../dataaccess/dataset/DataSetTypeConverter.h"
31 #include "../../../dataaccess/datasource/DataSource.h"
32 #include "../../../dataaccess/utils/Utils.h"
33 #include "../../../geometry/GeometryProperty.h"
34 #include "../../../maptools/DataSetAdapterLayer.h"
35 #include "../../../qt/widgets/utils/ScopedCursor.h"
36 #include "../../../se/FeatureTypeStyle.h"
37 #include "../../../se/Utils.h"
38 #include "DataPropertiesDialog.h"
39 #include "DataPropertiesWidget.h"
40 #include "ui_DataPropertiesDialogForm.h"
41 #include "ui_DataPropertiesWidgetForm.h"
42 
43 // Boost
44 #include <boost/uuid/random_generator.hpp>
45 #include <boost/uuid/uuid_io.hpp>
46 
47 //Utility functions used mianly to pupulate ui elements.
48 te::gm::Envelope& computeDataSetEnvelope(std::unique_ptr<te::da::DataSet> dataset,
49  const std::string& propertyName)
50 {
51  te::gm::Envelope* result = new te::gm::Envelope;
52 
53  while(dataset->moveNext())
54  {
55  te::gm::Geometry* geom = dataset->getGeometry(propertyName).release();
56  assert(geom);
57  result->Union(*geom->getMBR());
58  }
59  return *result;
60 }
61 
63  : QDialog(parent, f),
64  m_ui(new Ui::DataPropertiesDialogForm)
65 {
66  m_ui->setupUi(this);
67 
68  // data properties Widget
70 
71  // Adjusting...
72  QGridLayout* layout = new QGridLayout(m_ui->m_dataWidgetFrame);
73  layout->addWidget(m_dataPropertiesWidget);
74  layout->setContentsMargins(0,0,0,0);
75  this->layout()->setSizeConstraint(QLayout::SetFixedSize);
76 
77 // connect signal and slots
78  connect(m_ui->m_okPushButton, SIGNAL(clicked()), this, SLOT(onOkPushButtonClicked()));
79 
80  m_ui->m_helpPushButton->setPageReference("widgets/external_table/external_table.html");
81 }
82 
84 
86 {
87  te::qt::widgets::ScopedCursor c(Qt::WaitCursor);
88 
89  static boost::uuids::basic_random_generator<boost::mt19937> gen;
90  boost::uuids::uuid u = gen();
91  std::string id = boost::uuids::to_string(u);
92 
94  {
100  m_DataSetAdapterLayer->setRendererType("ABSTRACT_LAYER_RENDERER");
102 
103  if(m_DataSetAdapterLayer->getConverter()->getResult()->hasGeom())
104  {
106  std::unique_ptr<te::gm::Envelope> mbr(te::da::GetExtent(m_DataSetAdapterLayer->getDataSetName(), gp->getName(), m_DataSetAdapterLayer->getDataSourceId()));
107 
108  //Checking if it was possible to obtain an envelope
109  if(!mbr.get())
110  m_DataSetAdapterLayer->setExtent(computeDataSetEnvelope(m_DataSetAdapterLayer->getData(), gp->getName())); //Build an envelope
111  else
112  m_DataSetAdapterLayer->setExtent(*(mbr.release())); // using the envelope obtained by common means
113 
114  m_DataSetAdapterLayer->setSRID(gp->getSRID());
116  }
117 
118  this->accept();
119  }
120  else
121  this->reject();
122 }
123 
125 {
126  return m_DataSetAdapterLayer;
127 }
Geometric property.
TEDATAACCESSEXPORT te::gm::Envelope * GetExtent(const std::string &datasetName, const std::string &propertyName, const std::string &datasourceId)
te::da::DataSetType * getDataSetType()
Returns a pointer to the widget&#39;s dataSetType.
DataPropertiesDialog(QWidget *parent=0, Qt::WindowFlags f=0)
Constructor.
A widget used to configure the properties of a layer based on a tabular file.
DatapPropertiesWidget * m_dataPropertiesWidget
The widget used to import and configure a textual file.
void Union(const Envelope &rhs)
It updates the envelop with coordinates of another envelope.
std::unique_ptr< Ui::DataPropertiesDialogForm > m_ui
The dialog form.
TESEEXPORT Style * CreateFeatureTypeStyle(const te::gm::GeomType &geomType)
Try creates an appropriate feature type style based on given geometry type.
A layer with reference to a DataSetTypeConverter.
int getSRID() const
It returns the spatial reference system identifier associated to this property.
const Envelope * getMBR() const _NOEXCEPT_OP(true)
It returns the minimum bounding rectangle for the geometry in an internal representation.
An Envelope defines a 2D rectangular region.
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
te::map::DataSetAdapterLayerPtr m_DataSetAdapterLayer
The new Layer.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
std::unique_ptr< te::da::DataSetTypeConverter > getConverter()
Returns a pointer to the generated DataSetTypeConverter.
te::map::DataSetAdapterLayerPtr getDataSetAdapterLayer()
Returns a new DataSetAdapterLayer.
boost::intrusive_ptr< DataSetAdapterLayer > DataSetAdapterLayerPtr
A dialog used to configure the properties of a new textual file based layer.
const std::string & getId() const
An identification value for the data source.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
te::gm::Envelope & computeDataSetEnvelope(std::unique_ptr< te::da::DataSet > dataset, const std::string &propertyName)
A class used to configure the properties of a new textual file based layer.
te::da::DataSource * getDataSource()
Returns a pointer to the widget&#39;s dataSource.
An object that when created shows a cursor during its scope.
Definition: ScopedCursor.h:48
const std::string & getTitle() const
A human descriptive title for the DataSetType.
Definition: DataSetType.h:130
const std::string & getName() const
It returns the property name.
Definition: Property.h:127