All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DataPropertiesDialog.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2010-2013 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 "../../../se/FeatureTypeStyle.h"
36 #include "../../../se/Utils.h"
37 #include "DataPropertiesDialog.h"
38 #include "DataPropertiesWidget.h"
39 #include "ui_DataPropertiesDialogForm.h"
40 #include "ui_DataPropertiesWidgetForm.h"
41 
42 // Boost
43 #include <boost/uuid/random_generator.hpp>
44 #include <boost/uuid/uuid_io.hpp>
45 
46 //Utility functions used mianly to pupulate ui elements.
47 te::gm::Envelope& computeDataSetEnvelope(std::auto_ptr<te::da::DataSet> dataset,
48  const std::string& propertyName)
49 {
50  te::gm::Envelope* result = new te::gm::Envelope;
51 
52  while(dataset->moveNext())
53  {
54  te::gm::Geometry* geom = dataset->getGeometry(propertyName).release();
55  assert(geom);
56  result->Union(*geom->getMBR());
57  }
58  return *result;
59 }
60 
62  : QDialog(parent, f),
63  m_ui(new Ui::DataPropertiesDialogForm)
64 {
65  m_ui->setupUi(this);
66 
67  // data properties Widget
69 
70  // Adjusting...
71  QGridLayout* layout = new QGridLayout(m_ui->m_dataWidgetFrame);
72  layout->addWidget(m_dataPropertiesWidget);
73  layout->setContentsMargins(0,0,0,0);
74  this->layout()->setSizeConstraint(QLayout::SetFixedSize);
75 
76 // connect signal and slots
77  connect(m_ui->m_okPushButton, SIGNAL(clicked()), this, SLOT(onOkPushButtonClicked()));
78 
79  m_ui->m_helpPushButton->setPageReference("widgets/external_table/external_table.html");
80 }
81 
83 {
84  delete m_dataPropertiesWidget;
85 }
86 
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 
93  if(m_dataPropertiesWidget->getDataSetType())
94  {
95  std::string title = m_dataPropertiesWidget->getDataSetType()->getTitle().empty() ? m_dataPropertiesWidget->getDataSetType()->getName() : m_dataPropertiesWidget->getDataSetType()->getTitle();
96  m_DataSetAdapterLayer = new te::map::DataSetAdapterLayer(id, title);
97  m_DataSetAdapterLayer->setDataSetName(m_dataPropertiesWidget->getDataSetType()->getName());
98  m_DataSetAdapterLayer->setDataSourceId(m_dataPropertiesWidget->getDataSource()->getId());
99  m_DataSetAdapterLayer->setVisibility(te::map::NOT_VISIBLE);
100  m_DataSetAdapterLayer->setRendererType("ABSTRACT_LAYER_RENDERER");
101  m_DataSetAdapterLayer->setConverter(m_dataPropertiesWidget->getConverter());
102 
103  if(m_DataSetAdapterLayer->getConverter()->getResult()->hasGeom())
104  {
105  te::gm::GeometryProperty* gp = te::da::GetFirstGeomProperty(m_DataSetAdapterLayer->getConverter()->getResult());
106  std::auto_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());
115  m_DataSetAdapterLayer->setStyle(te::se::CreateFeatureTypeStyle(gp->getGeometryType()));
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)
Definition: Utils.cpp:133
DataPropertiesDialog(QWidget *parent=0, Qt::WindowFlags f=0)
Constructor.
A class to represent a chart display.
DatapPropertiesWidget * m_dataPropertiesWidget
The widget used to import and configure a textual file.
std::auto_ptr< Ui::DataPropertiesDialogForm > m_ui
The dialog form.
void Union(const Envelope &rhs)
It updates the envelop with coordinates of another envelope.
Definition: Envelope.h:555
TESEEXPORT Style * CreateFeatureTypeStyle(const te::gm::GeomType &geomType)
Try creates an appropriate feature type style based on given geometry type.
Definition: Utils.cpp:284
A layer with reference to a DataSetTypeConverter.
int getSRID() const
It returns the spatial reference system identifier associated to this property.
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
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.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
Definition: Utils.cpp:508
A class used to configure the properties of a new textual file based layer.
const Envelope * getMBR() const
It returns the minimum bounding rectangle for the geometry in an internal representation.
Definition: Geometry.cpp:103
te::gm::Envelope & computeDataSetEnvelope(std::auto_ptr< te::da::DataSet > dataset, const std::string &propertyName)
const std::string & getName() const
It returns the property name.
Definition: Property.h:126