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) 2011-2012 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 "ui_LayerSearchWidgetForm.h"
28 #include "LayerSearchWidget.h"
29 
31 
32 te::qt::widgets::LayerSearchWidget::LayerSearchWidget(QWidget* parent, Qt::WindowFlags f)
33  : QWidget(parent, f),
34  m_ui(new Ui::LayerSearchWidgetForm)
35 {
36 // add controls
37  m_ui->setupUi(this);
38 
39 //connect
40  connect(m_ui->m_nameLineEdit, SIGNAL(textChanged(const QString&)), SLOT(onFilter()));
41  connect(m_ui->m_repAllRadioButton, SIGNAL(clicked(bool)), SLOT(onFilter()));
42  connect(m_ui->m_repGeomRadioButton, SIGNAL(clicked(bool)), SLOT(onFilter()));
43  connect(m_ui->m_repRstRadioButton, SIGNAL(clicked(bool)), SLOT(onFilter()));
44 }
45 
47 {
48 }
49 
50 Ui::LayerSearchWidgetForm* te::qt::widgets::LayerSearchWidget::getForm() const
51 {
52  return m_ui.get();
53 }
54 
56 {
57  if(flag == true)
58  {
59  m_ui->m_treeWidget->setSelectionMode(QAbstractItemView::MultiSelection);
60  }
61  else
62  {
63  m_ui->m_treeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
64  }
65 }
66 
67 std::list<te::map::AbstractLayerPtr> te::qt::widgets::LayerSearchWidget::getSelecteds() const
68 {
69  std::list<te::map::AbstractLayerPtr> list;
70 
71  QList<QTreeWidgetItem*> sel = m_ui->m_treeWidget->selectedItems();
72 
73  QList<QTreeWidgetItem*>::iterator it = sel.begin();
74 
75  while(it != sel.end())
76  {
77  QTreeWidgetItem* item = *it;
78 
79  QVariant v = item->data(0, Qt::UserRole);
80 
82 
83  list.push_back(l);
84 
85  ++it;
86  }
87 
88  return list;
89 }
90 
91 void te::qt::widgets::LayerSearchWidget::setList(std::list<te::map::AbstractLayerPtr>& layerList)
92 {
93  m_layerList = layerList;
94 
95  fillTreeView(m_layerList);
96 }
97 
99 {
100  m_ui->m_repRstRadioButton->setChecked(true);
101 
102  m_ui->m_filterByRepGroupBox->setEnabled(false);
103 
104  onFilter();
105 }
106 
108 {
109  m_ui->m_repGeomRadioButton->setChecked(true);
110 
111  m_ui->m_filterByRepGroupBox->setEnabled(false);
112 
113  onFilter();
114 }
115 
117 {
118  m_ui->m_repAllRadioButton->setChecked(true);
119 
120  m_ui->m_filterByRepGroupBox->setEnabled(false);
121 
122  onFilter();
123 }
124 
125 void te::qt::widgets::LayerSearchWidget::fillTreeView(std::list<te::map::AbstractLayerPtr>& layerList)
126 {
127  std::list<te::map::AbstractLayerPtr>::iterator it = layerList.begin();
128 
129  while(it != layerList.end())
130  {
132 
133  QTreeWidgetItem* item = new QTreeWidgetItem(m_ui->m_treeWidget);
134  item->setText(0, l->getTitle().c_str());
135  item->setIcon(0, QIcon::fromTheme("layer"));
136  item->setData(0, Qt::UserRole, QVariant::fromValue(l));
137  item->setText(1, l->getId().c_str());
138  item->setText(2, l->getType().c_str());
139 
140  ++it;
141  }
142 
143 //fix columns sizes
144  m_ui->m_treeWidget->resizeColumnToContents(0);
145  m_ui->m_treeWidget->resizeColumnToContents(2);
146 
147  m_ui->m_treeWidget->expandAll();
148 }
149 
150 void te::qt::widgets::LayerSearchWidget::filter(const QList<QTreeWidgetItem*>& items)
151 {
152  QTreeWidgetItemIterator it(m_ui->m_treeWidget);
153 
154  while(*it)
155  {
156  QTreeWidgetItem* layerItem = *it;
157  bool hide = items.indexOf(layerItem) == -1;
158  layerItem->setHidden(hide);
159 
160  ++it;
161  }
162 
163  update();
164 }
165 
167 {
168  QString str = m_ui->m_nameLineEdit->text();
169 
170  QList<QTreeWidgetItem*> items = m_ui->m_treeWidget->findItems(str, Qt::MatchContains | Qt::MatchRecursive, 0);
171 
172  QList<QTreeWidgetItem*> result;
173 
174  for(int i = 0; i < items.size(); ++i)
175  {
176  QTreeWidgetItem* item = items.at(i);
177 
178  QVariant v = item->data(0, Qt::UserRole);
179 
181 
182  std::auto_ptr<te::da::DataSetType> dsType = l->getSchema();
183 
184  if(m_ui->m_repAllRadioButton->isChecked())
185  {
186  result.push_back(item);
187  }
188  else if(m_ui->m_repGeomRadioButton->isChecked())
189  {
190  if(dsType.get() && dsType->hasGeom())
191  result.push_back(item);
192  }
193  else if(m_ui->m_repRstRadioButton->isChecked())
194  {
195  if(dsType.get() && dsType->hasRaster())
196  result.push_back(item);
197  }
198  }
199 
200  filter(result);
201 }
202 
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr)
std::list< te::map::AbstractLayerPtr > getSelecteds() const
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)
LayerSearchWidget(QWidget *parent=0, Qt::WindowFlags f=0)
This file defines the LayerSearchWidget class.
void setList(std::list< te::map::AbstractLayerPtr > &layerList)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr