All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OGRConnector.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/plugins/datasource/ogr/OGRConnector.cpp
22 
23  \brief OGR connector implementation for the Qt data source widget.
24 */
25 
26 // TerraLib
27 #include "../../../../dataaccess/datasource/DataSource.h"
28 #include "../../../../dataaccess/datasource/DataSourceManager.h"
29 #include "../../../../dataaccess/datasource/DataSourceInfoManager.h"
30 #include "OGRConnector.h"
31 #include "OGRConnectorDialog.h"
32 
33 // Boost
34 #include <boost/uuid/random_generator.hpp>
35 #include <boost/uuid/uuid_io.hpp>
36 #include <boost/filesystem.hpp>
37 
38 // Qt
39 #include <QFileDialog>
40 #include <QMessageBox>
41 
42 te::qt::plugins::ogr::OGRConnector::OGRConnector(QWidget* parent, Qt::WindowFlags f)
43  : te::qt::widgets::AbstractDataSourceConnector(parent, f)
44 {
45 }
46 
48 {
49 }
50 
51 void te::qt::plugins::ogr::OGRConnector::connect(std::list<te::da::DataSourceInfoPtr>& datasources)
52 {
53  std::auto_ptr<OGRConnectorDialog> cdialog(new OGRConnectorDialog(static_cast<QWidget*>(parent())));
54 
55  int retval = cdialog->exec();
56 
57  if(retval == QDialog::Rejected)
58  return;
59 
60  te::da::DataSourceInfoPtr ds = cdialog->getDataSource();
61 
62  if(ds.get() != 0)
63  {
65  datasources.push_back(ds);
66 
67  te::da::DataSourcePtr driver = cdialog->getDriver();
68 
70  }
71 }
72 
73 void te::qt::plugins::ogr::OGRConnector::create(std::list<te::da::DataSourceInfoPtr>& datasources)
74 {
75  QMessageBox::warning(this,
76  tr("TerraLib Qt Components"),
77  tr("Not implemented yet!\nWe will provide it soon!"));
78 }
79 
80 void te::qt::plugins::ogr::OGRConnector::update(std::list<te::da::DataSourceInfoPtr>& datasources)
81 {
82  for(std::list<te::da::DataSourceInfoPtr>::iterator it = datasources.begin(); it != datasources.end(); ++it)
83  {
84  if(it->get() == 0)
85  continue;
86 
87  std::auto_ptr<OGRConnectorDialog> cdialog(new OGRConnectorDialog(static_cast<QWidget*>(parent())));
88 
89  cdialog->set(*it);
90 
91  int retval = cdialog->exec();
92 
93  if(retval == QDialog::Rejected)
94  continue;
95 
96 // don't forget to replace the driver
97  te::da::DataSourcePtr driver = cdialog->getDriver();
98 
99  if(driver.get() != 0)
100  {
101  if(te::da::DataSourceManager::getInstance().find(driver->getId()) != 0)
102  te::da::DataSourceManager::getInstance().detach(driver->getId());
103 
105  }
106  }
107 }
108 
109 void te::qt::plugins::ogr::OGRConnector::remove(std::list<te::da::DataSourceInfoPtr>& datasources)
110 {
111  for(std::list<te::da::DataSourceInfoPtr>::iterator it = datasources.begin(); it != datasources.end(); ++it)
112  {
113  if(it->get() == 0)
114  continue;
115 
116 // first remove driver
118 
119  if(rds.get())
120  {
122  rds.reset();
123  }
124 
125 // then remove data source
126  te::da::DataSourceInfoManager::getInstance().remove((*it)->getId());
127  }
128 }
129 
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1435
void update(std::list< te::da::DataSourceInfoPtr > &datasources)
void create(std::list< te::da::DataSourceInfoPtr > &datasources)
OGR connector implementation for the Qt data source widget.
void remove(std::list< te::da::DataSourceInfoPtr > &datasources)
OGRConnector(QWidget *parent=0, Qt::WindowFlags f=0)
static DataSourceInfoManager & getInstance()
It returns a reference to the singleton instance.
A dialog window for showing the OGR connector widget.
void connect(std::list< te::da::DataSourceInfoPtr > &datasources)
A dialog window for showing the OGR connector widget.
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr