All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
LayerSearchWidget.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/LayerSearchWidget.cpp
22 
23  \brief This file defines the LayerSearchWidget class.
24 */
25 
26 // TerraLib
27 #include "../../../../dataaccess/utils/Utils.h"
28 #include "LayerSearchWidget.h"
29 #include "ui_LayerSearchWidgetForm.h"
30 
31 
33 
34 te::qt::widgets::LayerSearchWidget::LayerSearchWidget(QWidget* parent, Qt::WindowFlags f)
35  : QWidget(parent, f),
36  m_ui(new Ui::LayerSearchWidgetForm)
37 {
38 // add controls
39  m_ui->setupUi(this);
40 
43 
44 //connect
45  connect(m_ui->m_nameLineEdit, SIGNAL(textChanged(const QString&)), SLOT(onFilter()));
46  connect(m_ui->m_repAllRadioButton, SIGNAL(clicked(bool)), SLOT(onFilter()));
47  connect(m_ui->m_repGeomRadioButton, SIGNAL(clicked(bool)), SLOT(onFilter()));
48  connect(m_ui->m_repRstRadioButton, SIGNAL(clicked(bool)), SLOT(onFilter()));
49 }
50 
52 {
53 }
54 
55 Ui::LayerSearchWidgetForm* te::qt::widgets::LayerSearchWidget::getForm() const
56 {
57  return m_ui.get();
58 }
59 
61 {
62  if(flag == true)
63  {
64  m_ui->m_treeWidget->setSelectionMode(QAbstractItemView::MultiSelection);
65  }
66  else
67  {
68  m_ui->m_treeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
69  }
70 }
71 
72 std::list<te::map::AbstractLayerPtr> te::qt::widgets::LayerSearchWidget::getSelecteds() const
73 {
74  std::list<te::map::AbstractLayerPtr> list;
75 
76  QList<QTreeWidgetItem*> sel = m_ui->m_treeWidget->selectedItems();
77 
78  QList<QTreeWidgetItem*>::iterator it = sel.begin();
79 
80  while(it != sel.end())
81  {
82  QTreeWidgetItem* item = *it;
83 
84  QVariant v = item->data(0, Qt::UserRole);
85 
87 
88  list.push_back(l);
89 
90  ++it;
91  }
92 
93  return list;
94 }
95 
96 void te::qt::widgets::LayerSearchWidget::setList(std::list<te::map::AbstractLayerPtr>& layerList)
97 {
98  m_layerList = layerList;
99 
100  fillTreeView(m_layerList);
101 }
102 
104 {
105  m_ui->m_repRstRadioButton->setChecked(true);
106 
107  m_ui->m_filterByRepGroupBox->setEnabled(false);
108 
109  onFilter();
110 }
111 
113 {
114  m_ui->m_repGeomRadioButton->setChecked(true);
115 
116  m_ui->m_filterByRepGroupBox->setEnabled(false);
117 
118  onFilter();
119 }
120 
122 {
123  m_ui->m_repAllRadioButton->setChecked(true);
124 
125  m_ui->m_filterByRepGroupBox->setEnabled(false);
126 
127  onFilter();
128 }
129 
131 {
132  m_minRasterBandsValue = value;
133 
134  m_minRasterBandsDefined = true;
135 
136  onFilter();
137 }
138 
140 {
141  m_maxRasterBandsValue = value;
142 
143  m_maxRasterBandsDefined = true;
144 
145  onFilter();
146 }
147 
148 void te::qt::widgets::LayerSearchWidget::fillTreeView(std::list<te::map::AbstractLayerPtr>& layerList)
149 {
150  std::list<te::map::AbstractLayerPtr>::iterator it = layerList.begin();
151 
152  while(it != layerList.end())
153  {
155 
156  QTreeWidgetItem* item = new QTreeWidgetItem(m_ui->m_treeWidget);
157  //layer name
158  item->setText(0, l->getTitle().c_str());
159  item->setIcon(0, QIcon::fromTheme("layer"));
160  item->setData(0, Qt::UserRole, QVariant::fromValue(l));
161 
162  //layer parent
163  te::map::AbstractLayer* lParent = dynamic_cast<te::map::AbstractLayer*>(l->getParent());
164 
165  if(lParent)
166  item->setText(1, lParent->getTitle().c_str());
167  else
168  item->setText(1, "");
169 
170  //layer type
171  item->setText(2, l->getType().c_str());
172 
173  ++it;
174  }
175 
176 //fix columns sizes
177  m_ui->m_treeWidget->resizeColumnToContents(0);
178  m_ui->m_treeWidget->resizeColumnToContents(2);
179 
180  m_ui->m_treeWidget->expandAll();
181 }
182 
183 void te::qt::widgets::LayerSearchWidget::filter(const QList<QTreeWidgetItem*>& items)
184 {
185  QTreeWidgetItemIterator it(m_ui->m_treeWidget);
186 
187  while(*it)
188  {
189  QTreeWidgetItem* layerItem = *it;
190  bool hide = items.indexOf(layerItem) == -1;
191  layerItem->setHidden(hide);
192 
193  ++it;
194  }
195 
196  update();
197 }
198 
200 {
201  QString str = m_ui->m_nameLineEdit->text();
202 
203  QList<QTreeWidgetItem*> items = m_ui->m_treeWidget->findItems(str, Qt::MatchContains | Qt::MatchRecursive, 0);
204 
205  QList<QTreeWidgetItem*> result;
206 
207  for(int i = 0; i < items.size(); ++i)
208  {
209  QTreeWidgetItem* item = items.at(i);
210 
211  QVariant v = item->data(0, Qt::UserRole);
212 
214 
215  std::auto_ptr<te::da::DataSetType> dsType = l->getSchema();
216 
217  if(m_ui->m_repAllRadioButton->isChecked())
218  {
219  result.push_back(item);
220  }
221  else if(m_ui->m_repGeomRadioButton->isChecked())
222  {
223  if(dsType.get() && dsType->hasGeom())
224  result.push_back(item);
225  }
226  else if(m_ui->m_repRstRadioButton->isChecked())
227  {
228  if(dsType.get() && dsType->hasRaster())
229  {
230  //check if has band restriction
231  if(m_minRasterBandsDefined || m_maxRasterBandsDefined)
232  {
233  std::auto_ptr<te::da::DataSet> ds = l->getData();
234 
235  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
236 
237  std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
238 
239  if(m_minRasterBandsDefined && m_maxRasterBandsDefined)
240  {
241  if(inputRst->getNumberOfBands() >= m_minRasterBandsValue && inputRst->getNumberOfBands() <= m_maxRasterBandsValue)
242  {
243  result.push_back(item);
244  }
245  }
246  else if(m_minRasterBandsDefined)
247  {
248  if(inputRst->getNumberOfBands() >= m_minRasterBandsValue)
249  {
250  result.push_back(item);
251  }
252  }
253  else if(m_minRasterBandsDefined)
254  {
255  if(inputRst->getNumberOfBands() <= m_maxRasterBandsValue)
256  {
257  result.push_back(item);
258  }
259  }
260  }
261  else
262  {
263  result.push_back(item);
264  }
265  }
266  }
267  }
268 
269  filter(result);
270 }
271 
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr)
This is the base class for layers.
Definition: AbstractLayer.h:76
std::list< te::map::AbstractLayerPtr > getSelecteds() const
virtual const std::string & getTitle() const
It returns the layer title.
std::auto_ptr< Ui::LayerSearchWidgetForm > m_ui
void fillTreeView(std::list< te::map::AbstractLayerPtr > &layerList)
Ui::LayerSearchWidgetForm * getForm() const
void filter(const QList< QTreeWidgetItem * > &items)
void setMinRasterBands(std::size_t value)
LayerSearchWidget(QWidget *parent=0, Qt::WindowFlags f=0)
This file defines the LayerSearchWidget class.
void setMaxRasterBands(std::size_t value)
void setList(std::list< te::map::AbstractLayerPtr > &layerList)
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
Definition: Utils.cpp:481
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr