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) 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::auto_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 {
85  delete m_dataPropertiesWidget;
86 }
87 
89 {
90  te::qt::widgets::ScopedCursor c(Qt::WaitCursor);
91 
92  static boost::uuids::basic_random_generator<boost::mt19937> gen;
93  boost::uuids::uuid u = gen();
94  std::string id = boost::uuids::to_string(u);
95 
96  if(m_dataPropertiesWidget->getDataSetType())
97  {
98  std::string title = m_dataPropertiesWidget->getDataSetType()->getTitle().empty() ? m_dataPropertiesWidget->getDataSetType()->getName() : m_dataPropertiesWidget->getDataSetType()->getTitle();
99  m_DataSetAdapterLayer = new te::map::DataSetAdapterLayer(id, title);
100  m_DataSetAdapterLayer->setDataSetName(m_dataPropertiesWidget->getDataSetType()->getName());
101  m_DataSetAdapterLayer->setDataSourceId(m_dataPropertiesWidget->getDataSource()->getId());
102  m_DataSetAdapterLayer->setVisibility(te::map::NOT_VISIBLE);
103  m_DataSetAdapterLayer->setRendererType("ABSTRACT_LAYER_RENDERER");
104  m_DataSetAdapterLayer->setConverter(m_dataPropertiesWidget->getConverter());
105 
106  if(m_DataSetAdapterLayer->getConverter()->getResult()->hasGeom())
107  {
108  te::gm::GeometryProperty* gp = te::da::GetFirstGeomProperty(m_DataSetAdapterLayer->getConverter()->getResult());
109  std::auto_ptr<te::gm::Envelope> mbr(te::da::GetExtent(m_DataSetAdapterLayer->getDataSetName(), gp->getName(), m_DataSetAdapterLayer->getDataSourceId()));
110 
111  //Checking if it was possible to obtain an envelope
112  if(!mbr.get())
113  m_DataSetAdapterLayer->setExtent(computeDataSetEnvelope(m_DataSetAdapterLayer->getData(), gp->getName())); //Build an envelope
114  else
115  m_DataSetAdapterLayer->setExtent(*(mbr.release())); // using the envelope obtained by common means
116 
117  m_DataSetAdapterLayer->setSRID(gp->getSRID());
118  m_DataSetAdapterLayer->setStyle(te::se::CreateFeatureTypeStyle(gp->getGeometryType()));
119  }
120 
121  this->accept();
122  }
123  else
124  this->reject();
125 }
126 
128 {
129  return m_DataSetAdapterLayer;
130 }
Geometric property.
TEDATAACCESSEXPORT te::gm::Envelope * GetExtent(const std::string &datasetName, const std::string &propertyName, const std::string &datasourceId)
Definition: Utils.cpp:136
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:557
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:104
te::gm::Envelope & computeDataSetEnvelope(std::auto_ptr< te::da::DataSet > dataset, const std::string &propertyName)
An object that when created shows a cursor during its scope.
Definition: ScopedCursor.h:48
const std::string & getName() const
It returns the property name.
Definition: Property.h:127