All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
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 
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 }
55 
56 Ui::LayerSelectorWidgetForm* te::qt::widgets::LayerSelectorWidget::getForm() const
57 {
58  return m_ui.get();
59 }
60 
61 void te::qt::widgets::LayerSelectorWidget::setList(std::list<te::map::AbstractLayerPtr>& layerList, FilterOptions fo)
62 {
63  m_layerSearchDlg->getWidget()->setList(layerList);
64 
65  m_layerList = layerList;
66 
67  //fill combo
68  m_ui->m_layerComboBox->clear();
69 
70  if(fo == NO_FILTER)
71  filterAll();
72  else if(fo == FILTER_BY_GEOM)
73  filterOnlyByGeom();
74  else if(fo == FILTER_BY_RASTER)
75  filterOnlyByRaster();
76 
77  if(m_ui->m_layerComboBox->count() != 0)
78  onLayerComboBoxActivated(0);
79 }
80 
82 {
83  m_layerSearchDlg->getWidget()->filterOnlyByRaster();
84 
85  std::list<te::map::AbstractLayerPtr>::iterator it = m_layerList.begin();
86 
87  while(it != m_layerList.end())
88  {
90 
91  std::auto_ptr<te::da::DataSetType> dsType = l->getSchema();
92 
93  if(dsType.get() && dsType->hasRaster())
94  m_ui->m_layerComboBox->addItem(it->get()->getTitle().c_str(), QVariant::fromValue(l));
95 
96  ++it;
97  }
98 }
99 
101 {
102  m_layerSearchDlg->getWidget()->filterOnlyByGeom();
103 
104  std::list<te::map::AbstractLayerPtr>::iterator it = m_layerList.begin();
105 
106  while(it != m_layerList.end())
107  {
109 
110  std::auto_ptr<te::da::DataSetType> dsType = l->getSchema();
111 
112  if(dsType.get() && dsType->hasGeom())
113  m_ui->m_layerComboBox->addItem(it->get()->getTitle().c_str(), QVariant::fromValue(l));
114 
115  ++it;
116  }
117 }
118 
120 {
121  m_layerSearchDlg->getWidget()->filterAll();
122 
123  std::list<te::map::AbstractLayerPtr>::iterator it = m_layerList.begin();
124 
125  while(it != m_layerList.end())
126  {
128 
129  m_ui->m_layerComboBox->addItem(it->get()->getTitle().c_str(), QVariant::fromValue(l));
130 
131  ++it;
132  }
133 }
134 
136 {
137  if(m_layerSearchDlg->exec() == QDialog::Accepted)
138  {
139  std::list<te::map::AbstractLayerPtr> list = m_layerSearchDlg->getWidget()->getSelecteds();
140 
141  if(!list.empty())
142  {
143  te::map::AbstractLayerPtr layer = *list.begin();
144 
145  //set layer in combo
146  int size = m_ui->m_layerComboBox->count();
147 
148  for(int i = 0; i < size; ++i)
149  {
150  QVariant varLayer = m_ui->m_layerComboBox->itemData(i, Qt::UserRole);
152 
153  if(layer == l)
154  {
155  m_ui->m_layerComboBox->setCurrentIndex(i);
156 
157  onLayerComboBoxActivated(i);
158 
159  break;
160  }
161  }
162  }
163  }
164 }
165 
167 {
168  QVariant varLayer = m_ui->m_layerComboBox->itemData(index, Qt::UserRole);
170 
171  emit layerSelected(l);
172 }
Ui::LayerSelectorWidgetForm * getForm() const
std::auto_ptr< LayerSearchDialog > m_layerSearchDlg
This class is a dialog for the LayerSearchWidget.
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr)
std::auto_ptr< Ui::LayerSelectorWidgetForm > m_ui
This file has the LayerSelectorWidget class.
This file defines the LayerSearchWidget class.
LayerSelectorWidget(QWidget *parent=0, Qt::WindowFlags f=0)
void setList(std::list< te::map::AbstractLayerPtr > &layerList, FilterOptions fo=NO_FILTER)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr