All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
WMSLayerSelector.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/wms/qt/WMSLayerSelector.cpp
22 
23  \brief A simple widget that allows the selection of datasets from a given WMS server.
24 */
25 
26 // TerraLib
27 #include "../../common/Translator.h"
28 #include "../../dataaccess/datasource/DataSource.h"
29 #include "../../dataaccess/datasource/DataSourceManager.h"
30 #include "../../maptools/DataSetLayer.h"
31 #include "../../qt/widgets/dataset/selector/DataSetSelectorDialog.h"
32 #include "../../qt/widgets/layer/utils/DataSet2Layer.h"
33 #include "../Exception.h"
34 #include "../WMS2Layer.h"
35 #include "WMSLayerSelector.h"
36 
37 // STL
38 #include <algorithm>
39 #include <iterator>
40 #include <memory>
41 
42 te::wms::WMSLayerSelector::WMSLayerSelector(QWidget* parent, Qt::WindowFlags f)
43  : te::qt::widgets::AbstractLayerSelector(parent, f)
44 {
45 }
46 
48 {
49 }
50 
51 void te::wms::WMSLayerSelector::set(const std::list<te::da::DataSourceInfoPtr>& datasources)
52 {
53  m_datasources = datasources;
54 }
55 
56 std::list<te::map::AbstractLayerPtr> te::wms::WMSLayerSelector::getLayers()
57 {
58  std::list<te::map::AbstractLayerPtr> layers;
59 
60  for(std::list<te::da::DataSourceInfoPtr>::iterator it = m_datasources.begin(); it != m_datasources.end(); ++it)
61  {
62  te::da::DataSourcePtr datasource = te::da::DataSourceManager::getInstance().find((*it)->getId());
63 
64  if(datasource.get() == 0)
65  {
66  datasource = te::da::DataSourceManager::getInstance().get((*it)->getId(), (*it)->getAccessDriver(), (*it)->getConnInfo());
67 
68  if(datasource.get() == 0)
69  throw Exception(TE_TR("Could not retrieve the data source instance!"));
70  }
71 
72  if(!datasource->isOpened())
73  datasource->open();
74 
75  std::auto_ptr<te::qt::widgets::DataSetSelectorDialog> ldialog(new te::qt::widgets::DataSetSelectorDialog(static_cast<QWidget*>(parent())));
76 
77  ldialog->set(*it, true);
78 
79  int retval = ldialog->exec();
80 
81  if(retval == QDialog::Rejected)
82  continue;
83 
84  std::list<te::da::DataSetTypePtr> datasets = ldialog->getCheckedDataSets();
85 
86  std::transform(datasets.begin(), datasets.end(), std::back_inserter(layers), WMS2Layer((*it)->getId()));
87  }
88 
89  return layers;
90 }
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1435
WMSLayerSelector(QWidget *parent=0, Qt::WindowFlags f=0)
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
void set(const std::list< te::da::DataSourceInfoPtr > &datasources)
std::list< te::map::AbstractLayerPtr > getLayers()
A simple widget that allows the selection of datasets from a given WMS server.