LayerSelectorWidget.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/search/LayerSelectorWidget.cpp
22 
23  \brief This file has the LayerSelectorWidget class.
24 */
25 
26 // TerraLib
27 #include "LayerSearchDialog.h"
28 #include "LayerSearchWidget.h"
29 #include "LayerSelectorWidget.h"
30 #include "ui_LayerSelectorWidgetForm.h"
31 
33 
34 te::qt::widgets::LayerSelectorWidget::LayerSelectorWidget(QWidget* parent, Qt::WindowFlags f)
35  : QWidget(parent, f),
36  m_ui(new Ui::LayerSelectorWidgetForm)
37 {
38 //build form
39  m_ui->setupUi(this);
40 
41  m_ui->m_layerSearchToolButton->setIcon(QIcon::fromTheme("zoom"));
42 
43  m_layerSearchDlg.reset( new te::qt::widgets::LayerSearchDialog(this));
44 
45  m_layerSearchDlg->getWidget()->enableMultiSelection(false);
46 
47 //connects
48  connect(m_ui->m_layerSearchToolButton, SIGNAL(clicked()), this, SLOT(onLayerSearchToolButtonClicked()));
49  connect(m_ui->m_layerComboBox, SIGNAL(activated(int)), this, SLOT(onLayerComboBoxActivated(int)));
50 }
51 
53 
54 Ui::LayerSelectorWidgetForm* te::qt::widgets::LayerSelectorWidget::getForm() const
55 {
56  return m_ui.get();
57 }
58 
59 void te::qt::widgets::LayerSelectorWidget::setList(std::list<te::map::AbstractLayerPtr>& layerList, FilterOptions fo)
60 {
61  m_layerSearchDlg->getWidget()->setList(layerList);
62 
63  m_layerList = layerList;
64 
65  //fill combo
66  m_ui->m_layerComboBox->clear();
67 
68  if(fo == NO_FILTER)
69  filterAll();
70  else if(fo == FILTER_BY_GEOM)
72  else if(fo == FILTER_BY_RASTER)
74 
75  if(m_ui->m_layerComboBox->count() != 0)
77 }
78 
80 {
81  m_layerSearchDlg->getWidget()->filterOnlyByRaster();
82 
83  std::list<te::map::AbstractLayerPtr>::iterator it = m_layerList.begin();
84 
85  while(it != m_layerList.end())
86  {
88 
89  std::unique_ptr<te::da::DataSetType> dsType = l->getSchema();
90 
91  if(dsType.get() && dsType->hasRaster())
92  m_ui->m_layerComboBox->addItem(it->get()->getTitle().c_str(), QVariant::fromValue(l));
93 
94  ++it;
95  }
96 }
97 
99 {
100  m_layerSearchDlg->getWidget()->filterOnlyByGeom();
101 
102  std::list<te::map::AbstractLayerPtr>::iterator it = m_layerList.begin();
103 
104  while(it != m_layerList.end())
105  {
107 
108  std::unique_ptr<te::da::DataSetType> dsType = l->getSchema();
109 
110  if(dsType.get() && dsType->hasGeom())
111  m_ui->m_layerComboBox->addItem(it->get()->getTitle().c_str(), QVariant::fromValue(l));
112 
113  ++it;
114  }
115 }
116 
118 {
119  m_layerSearchDlg->getWidget()->filterAll();
120 
121  std::list<te::map::AbstractLayerPtr>::iterator it = m_layerList.begin();
122 
123  while(it != m_layerList.end())
124  {
126 
127  m_ui->m_layerComboBox->addItem(it->get()->getTitle().c_str(), QVariant::fromValue(l));
128 
129  ++it;
130  }
131 }
132 
134 {
135  if(m_layerSearchDlg->exec() == QDialog::Accepted)
136  {
137  std::list<te::map::AbstractLayerPtr> list = m_layerSearchDlg->getWidget()->getSelecteds();
138 
139  if(!list.empty())
140  {
141  te::map::AbstractLayerPtr layer = *list.begin();
142 
143  //set layer in combo
144  int size = m_ui->m_layerComboBox->count();
145 
146  for(int i = 0; i < size; ++i)
147  {
148  QVariant varLayer = m_ui->m_layerComboBox->itemData(i, Qt::UserRole);
150 
151  if(layer == l)
152  {
153  m_ui->m_layerComboBox->setCurrentIndex(i);
154 
156 
157  break;
158  }
159  }
160  }
161  }
162 }
163 
165 {
166  QVariant varLayer = m_ui->m_layerComboBox->itemData(index, Qt::UserRole);
168 
169  emit layerSelected(l);
170 }
Ui::LayerSelectorWidgetForm * getForm() const
std::unique_ptr< Ui::LayerSelectorWidgetForm > m_ui
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr) te
std::unique_ptr< LayerSearchDialog > m_layerSearchDlg
This class is a dialog for the LayerSearchWidget.
std::list< te::map::AbstractLayerPtr > m_layerList
URI C++ Library.
Definition: Attributes.h:37
This file has the LayerSelectorWidget class.
This file defines the LayerSearchWidget class.
void layerSelected(te::map::AbstractLayerPtr l)
void setList(std::list< te::map::AbstractLayerPtr > &layerList, FilterOptions fo=NO_FILTER)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr