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 "../../../../core/translator/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  default;
51 
52 void te::qt::widgets::HiddenDataSetLayerSelector::set(const std::list<te::da::DataSourceInfoPtr>& datasources)
53 {
54  m_datasources = datasources;
55 }
56 
57 std::list<te::map::AbstractLayerPtr> te::qt::widgets::HiddenDataSetLayerSelector::getLayers()
58 {
59  std::list<te::map::AbstractLayerPtr> layers;
60 
61  for(std::list<te::da::DataSourceInfoPtr>::iterator it = m_datasources.begin(); it != m_datasources.end(); ++it)
62  {
63  te::da::DataSourcePtr datasource = te::da::DataSourceManager::getInstance().find((*it)->getId());
64 
65  if(datasource.get() == nullptr)
66  {
67  datasource = te::da::DataSourceManager::getInstance().get((*it)->getId(), (*it)->getAccessDriver(), (*it)->getConnInfo());
68 
69  if(datasource.get() == nullptr)
70  throw Exception(TE_TR("Could not retrieve the data source instance!"));
71  }
72 
73  if(!datasource->isOpened())
74  datasource->open();
75 
76  std::vector<std::string> datasetNames;
77 
78  te::da::GetDataSetNames(datasetNames, datasource->getId());
79 
80  DataSet2Layer converter((*it)->getId());
81 
82  for(std::size_t i = 0; i < datasetNames.size(); ++i)
83  {
84  std::unique_ptr<te::da::DataSetType> dt = datasource->getDataSetType(datasetNames[i]);
85  te::da::DataSetTypePtr dtpt(dt.release());
86  te::map::DataSetLayerPtr layer = converter(dtpt);
87 
88  layers.push_back(layer);
89  }
90  }
91 
92  return layers;
93 }
94 
boost::shared_ptr< DataSetType > DataSetTypePtr
Definition: DataSetType.h:653
boost::shared_ptr< DataSource > DataSourcePtr
Base exception class for plugin module.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
An abstract class for layer selection widgets.
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
static te::dt::TimeDuration dt(20, 30, 50, 11)
std::list< te::map::AbstractLayerPtr > getLayers()
TEDATAACCESSEXPORT void GetDataSetNames(std::vector< std::string > &datasetNames, const std::string &datasourceId)
boost::intrusive_ptr< DataSetLayer > DataSetLayerPtr
Definition: DataSetLayer.h:148
HiddenDataSetLayerSelector(QWidget *parent=0, Qt::WindowFlags f=0)
std::list< te::da::DataSourceInfoPtr > m_datasources
void set(const std::list< te::da::DataSourceInfoPtr > &datasources)