All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HiddenDataSetLayerSelector.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/layer/selector/core/HiddenDataSetLayerSelector.cpp
22 
23  \brief ....
24 */
25 
26 // TerraLib
27 #include "../../../../common/Translator.h"
28 #include "../../../../dataaccess/dataset/DataSetType.h"
29 #include "../../../../dataaccess/datasource/DataSource.h"
30 #include "../../../../dataaccess/datasource/DataSourceManager.h"
31 #include "../../../../dataaccess/utils/Utils.h"
32 #include "../../../../geometry/Envelope.h"
33 #include "../../../../geometry/GeometryProperty.h"
34 #include "../../../../maptools/AbstractLayer.h"
35 #include "../../../../maptools/DataSetLayer.h"
36 #include "../../Exception.h"
37 #include "../utils/DataSet2Layer.h"
39 
40 // STL
41 #include <algorithm>
42 #include <iterator>
43 
45  : AbstractLayerSelector(parent, f)
46 {
47 }
48 
50 {
51 }
52 
53 void te::qt::widgets::HiddenDataSetLayerSelector::set(const std::list<te::da::DataSourceInfoPtr>& datasources)
54 {
55  m_datasources = datasources;
56 }
57 
58 std::list<te::map::AbstractLayerPtr> te::qt::widgets::HiddenDataSetLayerSelector::getLayers()
59 {
60  std::list<te::map::AbstractLayerPtr> layers;
61 
62  for(std::list<te::da::DataSourceInfoPtr>::iterator it = m_datasources.begin(); it != m_datasources.end(); ++it)
63  {
64  te::da::DataSourcePtr datasource = te::da::DataSourceManager::getInstance().find((*it)->getId());
65 
66  if(datasource.get() == 0)
67  {
68  datasource = te::da::DataSourceManager::getInstance().get((*it)->getId(), (*it)->getAccessDriver(), (*it)->getConnInfo());
69 
70  if(datasource.get() == 0)
71  throw Exception(TE_TR("Could not retrieve the data source instance!"));
72  }
73 
74  if(!datasource->isOpened())
75  datasource->open();
76 
77  std::vector<std::string> datasetNames;
78 
79  te::da::GetDataSetNames(datasetNames, datasource->getId());
80 
81  DataSet2Layer converter((*it)->getId());
82 
83  for(std::size_t i = 0; i < datasetNames.size(); ++i)
84  {
85  std::auto_ptr<te::da::DataSetType> dt = datasource->getDataSetType(datasetNames[i]);
86  te::da::DataSetTypePtr dtpt(dt.release());
87  te::map::DataSetLayerPtr layer = converter(dtpt);
88 
89  layers.push_back(layer);
90  }
91  }
92 
93  return layers;
94 }
95 
boost::shared_ptr< DataSetType > DataSetTypePtr
Definition: DataSetType.h:653
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1435
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
An abstract class for layer selection widgets.
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
std::list< te::map::AbstractLayerPtr > getLayers()
TEDATAACCESSEXPORT void GetDataSetNames(std::vector< std::string > &datasetNames, const std::string &datasourceId)
Definition: Utils.cpp:153
boost::intrusive_ptr< DataSetLayer > DataSetLayerPtr
Definition: DataSetLayer.h:171
HiddenDataSetLayerSelector(QWidget *parent=0, Qt::WindowFlags f=0)
void set(const std::list< te::da::DataSourceInfoPtr > &datasources)