src/terralib/ws/ogc/wms/qt/WMSConnector.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 // TerraLib
21 #include "WMSConnector.h"
22 #include "WMSConnectorDialog.h"
23 #include "../../../../dataaccess/datasource/DataSource.h"
24 #include "../../../../dataaccess/datasource/DataSourceManager.h"
25 #include "../../../../dataaccess/datasource/DataSourceInfoManager.h"
26 
27 // Boost
28 #include <boost/uuid/random_generator.hpp>
29 #include <boost/uuid/uuid_io.hpp>
30 #include <boost/filesystem.hpp>
31 
32 // Qt
33 #include <QFileDialog>
34 #include <QMessageBox>
35 
37  : te::qt::widgets::AbstractDataSourceConnector(parent, f)
38 {
39 }
40 
42 
43 void te::ws::ogc::wms::qt::WMSConnector::connect(std::list<te::da::DataSourceInfoPtr> &datasources)
44 {
45  std::unique_ptr<WMSConnectorDialog> cdialog(new WMSConnectorDialog(static_cast<QWidget*>(parent())));
46 
47  int retval = cdialog->exec();
48 
49  if(retval == QDialog::Rejected)
50  return;
51 
52  te::da::DataSourceInfoPtr ds = cdialog->getDataSource();
53 
54  if(ds.get() != nullptr)
55  {
57  datasources.push_back(ds);
58 
59  te::da::DataSourceManager::getInstance().make(ds->getId(), ds->getType(), ds->getConnInfo());
60  }
61 }
62 
64  std::list<te::da::DataSourceInfoPtr> & /*datasources*/)
65 {
66  QMessageBox::information(this,tr("TerraLib Qt Components"), tr("The WMS data access driver not support creation operation."));
67 }
68 
69 void te::ws::ogc::wms::qt::WMSConnector::update(std::list<te::da::DataSourceInfoPtr> &datasources)
70 {
71  for(std::list<te::da::DataSourceInfoPtr>::iterator it = datasources.begin(); it != datasources.end(); ++it)
72  {
73  if(it->get() == nullptr)
74  continue;
75 
76  std::unique_ptr<WMSConnectorDialog> cdialog(new WMSConnectorDialog(static_cast<QWidget*>(parent())));
77 
78  cdialog->set(*it);
79 
80  int retval = cdialog->exec();
81 
82  if(retval == QDialog::Rejected)
83  continue;
84 
85  // Don't forget to replace the driver
86  te::da::DataSourcePtr driver = cdialog->getDriver();
87 
88  if(driver.get() != nullptr)
89  {
90  if(te::da::DataSourceManager::getInstance().find(driver->getId()) != nullptr)
91  te::da::DataSourceManager::getInstance().detach(driver->getId());
92 
94  }
95  }
96 }
97 
98 void te::ws::ogc::wms::qt::WMSConnector::remove(std::list<te::da::DataSourceInfoPtr> &datasources)
99 {
100  for(std::list<te::da::DataSourceInfoPtr>::iterator it = datasources.begin(); it != datasources.end(); ++it)
101  {
102  if(it->get() == nullptr)
103  continue;
104 
105  // First remove driver
107 
108  if(rds.get())
109  {
111  rds.reset();
112  }
113 
114  // Then remove data source
115  te::da::DataSourceInfoManager::getInstance().remove((*it)->getId());
116  }
117 }
WMSConnector(QWidget *parent=0, Qt::WindowFlags f=0)
A dialog window for showing the WMS connector widget.
boost::shared_ptr< DataSource > DataSourcePtr
void update(std::list< te::da::DataSourceInfoPtr > &datasources)
OGC Web Map Service (WMS) connector implementation for the Qt data source widget. ...
static te::dt::Date ds(2010, 01, 01)
A dialog window for showing the WMS connector widget.
static DataSourceInfoManager & getInstance()
It returns a reference to the singleton instance.
URI C++ Library.
Definition: Attributes.h:37
void create(std::list< te::da::DataSourceInfoPtr > &datasources)
void remove(std::list< te::da::DataSourceInfoPtr > &datasources)
void connect(std::list< te::da::DataSourceInfoPtr > &datasources)
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr