mnt/qt/LayerSearchDialog.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/mnt/qt/LayerSearchDialog.cpp
22 
23 \brief A dialog for Layer Search
24 */
25 
26 //terralib
27 #include "LayerSearchDialog.h"
28 #include "ui_LayerSearchDialogForm.h"
29 
30 #include "../../dataaccess/datasource/DataSourceInfoManager.h"
31 #include "../../dataaccess/utils/Utils.h"
32 #include "../../geometry/GeometryProperty.h"
33 
34 // Qt
35 #include <QFileDialog>
36 #include <QMessageBox>
37 
38 
39 te::mnt::LayerSearchDialog::LayerSearchDialog(QWidget* parent, Qt::WindowFlags f, bool mnt)
40 : QDialog(parent, f),
41 m_ui(new Ui::MNTLayerSearchDialogForm)
42 {
43  // add controls
44  m_ui->setupUi(this);
45 
46  //signals
47 
48  connect(m_ui->m_startsRadioButton, SIGNAL(toggled(bool)), this, SLOT(onstartsEnabled(bool)));
49  connect(m_ui->m_endsRadioButton, SIGNAL(toggled(bool)), this, SLOT(onendsEnabled(bool)));
50  connect(m_ui->m_containsRadioButton, SIGNAL(toggled(bool)), this, SLOT(oncontainsEnabled(bool)));
51  connect(m_ui->m_equalsRadioButton, SIGNAL(toggled(bool)), this, SLOT(onequalsEnabled(bool)));
52  connect(m_ui->m_nameLineEdit, SIGNAL(editingFinished()), this, SLOT(onnameLineEditEditingFinished()));
53 
54  connect(m_ui->m_isolinesRadioButton, SIGNAL(toggled(bool)), this, SLOT(onisolinesEnabled(bool)));
55  connect(m_ui->m_samplesRadioButton, SIGNAL(toggled(bool)), this, SLOT(onsamplesEnabled(bool)));
56  connect(m_ui->m_gridRadioButton, SIGNAL(toggled(bool)), this, SLOT(ongridEnabled(bool)));
57  connect(m_ui->m_tinRadioButton, SIGNAL(toggled(bool)), this, SLOT(ontinEnabled(bool)));
58  connect(m_ui->m_othersRadioButton, SIGNAL(toggled(bool)), this, SLOT(onothersEnabled(bool)));
59  connect(m_ui->m_allRadioButton, SIGNAL(toggled(bool)), this, SLOT(onallEnabled(bool)));
60 
61  connect(m_ui->m_layersTable, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(onOkPushButtonClicked()));
62 
63  connect(m_ui->m_okPushButton, SIGNAL(clicked()), this, SLOT(onOkPushButtonClicked()));
64  connect(m_ui->m_cancelPushButton, SIGNAL(clicked()), this, SLOT(onCancelPushButtonClicked()));
65 
66  m_ui->m_helpPushButton->setNameSpace("dpi.inpe.br.plugins");
67  m_ui->m_helpPushButton->setPageReference("plugins/mnt/DTM_LayerSearch.html");
68 
69  if (mnt)
70  m_geom_name << "Samples" << "Isolines" << "TIN" << "Undefined" << "Grid";
71  else
72  m_geom_name << "Points" << "Lines" << "Polygons" << "Undefined" << "Raster";
73 
74 }
75 
77 
78 void te::mnt::LayerSearchDialog::setLayers(std::list<te::map::AbstractLayerPtr> layers)
79 {
80  m_layers = layers;
81  m_ui->m_layersTable->clear();
82 
83  std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
84 
85  int i = 1; //to starts from 1 in interface, but real index is 0
86 
87  while (it != m_layers.end())
88  {
89  if (it->get())
90  {
91  QTreeWidgetItem* item = new QTreeWidgetItem(m_ui->m_layersTable);
92  item->setData(0, Qt::DisplayRole, i);
93  //layer name
94  item->setText(1, it->get()->getTitle().c_str());
95 
96  std::unique_ptr<te::da::DataSetType> dsType(it->get()->getSchema());
97  //layer type
98  if (dsType->hasRaster())
99  item->setText(2, m_geom_name.at(4));
100  else if (dsType->hasGeom())
101  {
102  item->setText(2, GetGeometryName(te::da::GetFirstGeomProperty(dsType.get())->getGeometryType()));
103  }
104  else
105  item->setText(2, "");
106 
107  // Get the data souce info
108  te::da::DataSourceInfoPtr info = te::da::DataSourceInfoManager::getInstance().get(it->get()->getDataSourceId());
109  item->setText(3, info->getConnInfoAsString().c_str());
110  }
111  ++it;
112  ++i;
113  }
114  m_ui->m_layersTable->resizeColumnToContents(0);
115  m_ui->m_layersTable->resizeColumnToContents(1);
116  m_ui->m_layersTable->resizeColumnToContents(2);
117  m_ui->m_layersTable->resizeColumnToContents(3);
118  m_ui->m_layersTable->sortItems(0, Qt::AscendingOrder);
119 
120 }
121 
122 void te::mnt::LayerSearchDialog::setActive(const QList<mntType> &types)
123 {
124  m_ui->m_isolinesRadioButton->setDisabled(true);
125  m_ui->m_samplesRadioButton->setDisabled(true);
126  m_ui->m_gridRadioButton->setDisabled(true);
127  m_ui->m_tinRadioButton->setDisabled(true);
128  m_ui->m_othersRadioButton->setDisabled(true);
129  m_ui->m_allRadioButton->setDisabled(true);
130 
131  for (int i = 0; i < types.size(); i++)
132  {
133  mntType t = types.at(i);
134  switch (t)
135  {
136  case SAMPLE:
137  m_ui->m_samplesRadioButton->setDisabled(false);
138  m_ui->m_samplesRadioButton->setChecked(true);
139  break;
140  case ISOLINE:
141  m_ui->m_isolinesRadioButton->setDisabled(false);
142  m_ui->m_isolinesRadioButton->setChecked(true);
143  break;
144  case GRID:
145  m_ui->m_gridRadioButton->setDisabled(false);
146  m_ui->m_gridRadioButton->setChecked(true);
147  break;
148  case TIN:
149  m_ui->m_tinRadioButton->setDisabled(false);
150  m_ui->m_tinRadioButton->setChecked(true);
151  break;
152  case OTHER:
153  m_ui->m_othersRadioButton->setDisabled(false);
154  m_ui->m_othersRadioButton->setChecked(true);
155  }
156  }
157 
158  if (types.size() < 2)
159  m_ui->m_represbuttonGroup->setVisible(false);
160  else
161  {
162  m_ui->m_represbuttonGroup->setVisible(true);
163  m_ui->m_allRadioButton->setDisabled(false);
164  }
165 
166 }
167 
169 {
170  return m_selectLayer;
171 }
172 
173 
175 {
176  switch (t)
177  {
178  case te::gm::PointType:
179  case te::gm::PointZType:
180  case te::gm::PointZMType:
181  case te::gm::PointMType:
186  return m_geom_name.at(0);
187 
196  return m_geom_name.at(1);
197 
198  case te::gm::PolygonType:
210  return m_geom_name.at(2);
211 
212  case te::gm::TINType:
214  case te::gm::TINZType:
217  return m_geom_name.at(2);
218  default:
219  return m_geom_name.at(3);
220  }
221 }
222 
224 {
225  if (m_namefilter.isEmpty() && m_geomfilter.isEmpty())
226  {
227  QTreeWidgetItemIterator it(m_ui->m_layersTable);
228  while (*it) {
229  (*it)->setHidden(false);
230  ++it;
231  }
232  return;
233  }
234 
235  QTreeWidgetItemIterator it(m_ui->m_layersTable);
236  while (*it) {
237  (*it)->setHidden(true);
238  ++it;
239  }
240 
241  QList<QTreeWidgetItem *> select_itens1 = m_namefilter.isEmpty() ? m_ui->m_layersTable->findItems("*", Qt::MatchWildcard, 1) : \
242  m_ui->m_layersTable->findItems(m_namefilter, m_matchflags, 1);
243  QList<QTreeWidgetItem *> select_itens2 = m_geomfilter.isEmpty() ? m_ui->m_layersTable->findItems("*", Qt::MatchWildcard, 2) : \
244  m_ui->m_layersTable->findItems(m_geomfilter, Qt::MatchRegExp, 2);
245  for (int i = 0; i < select_itens1.size(); i++)
246  {
247  QTreeWidgetItem *item = select_itens1.at(i);
248  if (select_itens2.contains(item))
249  item->setHidden(false);
250  }
251 }
252 
254 {
255  m_matchflags = Qt::MatchStartsWith;
256  ApplyFilter();
257 }
258 
260 {
261  m_matchflags = Qt::MatchEndsWith;
262  ApplyFilter();
263 
264 }
265 
267 {
268  m_matchflags = Qt::MatchContains;
269  ApplyFilter();
270 }
271 
273 {
274  m_matchflags = Qt::MatchExactly;
275  ApplyFilter();
276 }
277 
279 {
280  m_namefilter = m_ui->m_nameLineEdit->text();
281  ApplyFilter();
282 }
283 
285 {
286  m_geomfilter = m_geom_name.at(1);
287  ApplyFilter();
288 }
289 
291 {
292  m_geomfilter = m_geom_name.at(0);
293  ApplyFilter();
294 }
295 
297 {
298  m_geomfilter = m_geom_name.at(4);
299  ApplyFilter();
300 }
301 
303 {
304  m_geomfilter = m_geom_name.at(2);
305  ApplyFilter();
306 }
307 
309 {
310  m_geomfilter = m_geom_name.at(3);
311  ApplyFilter();
312 }
313 
315 {
316  if (!flag)
317  return;
318 
319  m_geomfilter.clear();
320  bool vazio = true;
321  if (m_ui->m_isolinesRadioButton->isEnabled())
322  {
323  m_geomfilter = m_geom_name.at(1);
324  vazio = false;
325  }
326 
327  if (m_ui->m_samplesRadioButton->isEnabled())
328  {
329  if (!vazio)
330  m_geomfilter += "|";
331  m_geomfilter += m_geom_name.at(0);
332  vazio = false;
333 
334  }
335  if (m_ui->m_gridRadioButton->isEnabled())
336  {
337  if (!vazio)
338  m_geomfilter += "|";
339  m_geomfilter += m_geom_name.at(4);
340  vazio = false;
341  }
342  if (m_ui->m_tinRadioButton->isEnabled())
343  {
344  if (!vazio)
345  m_geomfilter += "|";
346  m_geomfilter += m_geom_name.at(2);
347  vazio = false;
348  }
349  if (m_ui->m_othersRadioButton->isEnabled())
350  {
351  if (!vazio)
352  m_geomfilter += "|";
353  m_geomfilter += m_geom_name.at(3);
354  vazio = false;
355  }
356 
357  ApplyFilter();
358 }
359 
361 {
362  QTreeWidgetItem* item = m_ui->m_layersTable->currentItem();
363  if (!item)
364  return;
365 
366  m_selectlayer_index = item->data(0, Qt::DisplayRole).toInt() - 1; //because adds 1 to display from 1 and not from 0
367  std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
368  for (int i = 0; i < m_selectlayer_index; i++)
369  it++;
370  if (it != m_layers.end())
371  m_selectLayer = *it;
372  else
373  m_selectLayer = nullptr;
374 
375  accept();
376 
377 }
378 
380 {
381  reject();
382 }
383 
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
te::map::AbstractLayerPtr m_selectLayer
Selected Layer.
A dialog Layer Search.
static DataSourceInfoManager & getInstance()
It returns a reference to the singleton instance.
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
te::map::AbstractLayerPtr getLayer()
std::list< te::map::AbstractLayerPtr > m_layers
List of layers.
const QString & GetGeometryName(te::gm::GeomType t)
void setActive(const QList< mntType > &types)
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
std::unique_ptr< Ui::MNTLayerSearchDialogForm > m_ui
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
LayerSearchDialog(QWidget *parent=0, Qt::WindowFlags f=0, bool mnt=true)
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr