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 
41  m_minRasterBandsDefined = false;
42  m_maxRasterBandsDefined = false;
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 Ui::LayerSearchWidgetForm* te::qt::widgets::LayerSearchWidget::getForm() const
54 {
55  return m_ui.get();
56 }
57 
59 {
60  if(flag == true)
61  {
62  m_ui->m_treeWidget->setSelectionMode(QAbstractItemView::MultiSelection);
63  }
64  else
65  {
66  m_ui->m_treeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
67  }
68 }
69 
70 std::list<te::map::AbstractLayerPtr> te::qt::widgets::LayerSearchWidget::getSelecteds() const
71 {
72  std::list<te::map::AbstractLayerPtr> list;
73 
74  QList<QTreeWidgetItem*> sel = m_ui->m_treeWidget->selectedItems();
75 
76  QList<QTreeWidgetItem*>::iterator it = sel.begin();
77 
78  while(it != sel.end())
79  {
80  QTreeWidgetItem* item = *it;
81 
82  QVariant v = item->data(0, Qt::UserRole);
83 
85 
86  list.push_back(l);
87 
88  ++it;
89  }
90 
91  return list;
92 }
93 
94 void te::qt::widgets::LayerSearchWidget::setList(std::list<te::map::AbstractLayerPtr>& layerList)
95 {
96  m_layerList = layerList;
97 
99 }
100 
102 {
103  m_ui->m_repRstRadioButton->setChecked(true);
104 
105  m_ui->m_filterByRepGroupBox->setEnabled(false);
106 
107  onFilter();
108 }
109 
111 {
112  m_ui->m_repGeomRadioButton->setChecked(true);
113 
114  m_ui->m_filterByRepGroupBox->setEnabled(false);
115 
116  onFilter();
117 }
118 
120 {
121  m_ui->m_repAllRadioButton->setChecked(true);
122 
123  m_ui->m_filterByRepGroupBox->setEnabled(false);
124 
125  onFilter();
126 }
127 
129 {
130  m_minRasterBandsValue = value;
131 
133 
134  onFilter();
135 }
136 
138 {
139  m_maxRasterBandsValue = value;
140 
142 
143  onFilter();
144 }
145 
146 void te::qt::widgets::LayerSearchWidget::fillTreeView(std::list<te::map::AbstractLayerPtr>& layerList)
147 {
148  std::list<te::map::AbstractLayerPtr>::iterator it = layerList.begin();
149 
150  while(it != layerList.end())
151  {
153 
154  QTreeWidgetItem* item = new QTreeWidgetItem(m_ui->m_treeWidget);
155  //layer name
156  item->setText(0, l->getTitle().c_str());
157  item->setIcon(0, QIcon::fromTheme("layer"));
158  item->setData(0, Qt::UserRole, QVariant::fromValue(l));
159 
160  //layer parent
161  te::map::AbstractLayer* lParent = dynamic_cast<te::map::AbstractLayer*>(l->getParent());
162 
163  if(lParent)
164  item->setText(1, lParent->getTitle().c_str());
165  else
166  item->setText(1, "");
167 
168  //layer type
169  item->setText(2, l->getType().c_str());
170 
171  if (it == layerList.begin())
172  m_ui->m_treeWidget->setItemSelected(item, true);
173 
174  ++it;
175  }
176 
177 //fix columns sizes
178  m_ui->m_treeWidget->resizeColumnToContents(0);
179  m_ui->m_treeWidget->resizeColumnToContents(2);
180 
181  m_ui->m_treeWidget->expandAll();
182 }
183 
184 void te::qt::widgets::LayerSearchWidget::filter(const QList<QTreeWidgetItem*>& items)
185 {
186  QTreeWidgetItemIterator it(m_ui->m_treeWidget);
187 
188  while(*it)
189  {
190  QTreeWidgetItem* layerItem = *it;
191  bool hide = items.indexOf(layerItem) == -1;
192  layerItem->setHidden(hide);
193 
194  ++it;
195  }
196 
197  update();
198 }
199 
201 {
202  QString str = m_ui->m_nameLineEdit->text();
203 
204  QList<QTreeWidgetItem*> items = m_ui->m_treeWidget->findItems(str, Qt::MatchContains | Qt::MatchRecursive, 0);
205 
206  QList<QTreeWidgetItem*> result;
207 
208  for(int i = 0; i < items.size(); ++i)
209  {
210  QTreeWidgetItem* item = items.at(i);
211 
212  QVariant v = item->data(0, Qt::UserRole);
213 
215 
216  std::unique_ptr<te::da::DataSetType> dsType = l->getSchema();
217 
218  if(m_ui->m_repAllRadioButton->isChecked())
219  {
220  result.push_back(item);
221  }
222  else if(m_ui->m_repGeomRadioButton->isChecked())
223  {
224  if(dsType.get() && dsType->hasGeom())
225  result.push_back(item);
226  }
227  else if(m_ui->m_repRstRadioButton->isChecked())
228  {
229  if(dsType.get() && dsType->hasRaster())
230  {
231  //check if has band restriction
233  {
234  std::unique_ptr<te::da::DataSet> ds = l->getData();
235 
236  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
237 
238  std::unique_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
239 
241  {
242  if(inputRst->getNumberOfBands() >= m_minRasterBandsValue && inputRst->getNumberOfBands() <= m_maxRasterBandsValue)
243  {
244  result.push_back(item);
245  }
246  }
247  else if(m_minRasterBandsDefined)
248  {
249  if(inputRst->getNumberOfBands() >= m_minRasterBandsValue)
250  {
251  result.push_back(item);
252  }
253  }
254  else if(m_minRasterBandsDefined)
255  {
256  if(inputRst->getNumberOfBands() <= m_maxRasterBandsValue)
257  {
258  result.push_back(item);
259  }
260  }
261  }
262  else
263  {
264  result.push_back(item);
265  }
266  }
267  }
268  }
269 
270  filter(result);
271 }
272 
This is the base class for layers.
Definition: AbstractLayer.h:77
std::list< te::map::AbstractLayerPtr > getSelecteds() const
virtual const std::string & getTitle() const
It returns the layer title.
static te::dt::Date ds(2010, 01, 01)
void fillTreeView(std::list< te::map::AbstractLayerPtr > &layerList)
Ui::LayerSearchWidgetForm * getForm() const
std::list< te::map::AbstractLayerPtr > m_layerList
URI C++ Library.
Definition: Attributes.h:37
void filter(const QList< QTreeWidgetItem * > &items)
void setMinRasterBands(std::size_t value)
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr) te
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)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
std::unique_ptr< Ui::LayerSearchWidgetForm > m_ui