All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GroupingWidget.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/se/GroupingWidget.cpp
22 
23  \brief A widget used to build a grouping.
24 */
25 
26 // TerraLib
27 #include "../../../color/ColorBar.h"
28 #include "../../../common/Globals.h"
29 #include "../../../common/STLUtils.h"
30 #include "../../../dataaccess/dataset/DataSet.h"
31 #include "../../../dataaccess/dataset/DataSetType.h"
32 #include "../../../dataaccess/query/OrderByItem.h"
33 #include "../../../dataaccess/utils/Utils.h"
34 #include "../../../geometry/GeometryProperty.h"
35 #include "../../../maptools/Enums.h"
36 #include "../../../maptools/Grouping.h"
37 #include "../../../maptools/GroupingAlgorithms.h"
38 #include "../../../maptools/GroupingItem.h"
39 #include "../../../maptools/Utils.h"
40 #include "../../../maptools/QueryLayer.h"
41 #include "../../../se/SymbolizerColorFinder.h"
42 #include "../../../se/Utils.h"
43 #include "../colorbar/ColorBar.h"
44 #include "../colorbar/ColorCatalogWidget.h"
45 #include "../se/LineSymbolizerWidget.h"
46 #include "../se/PointSymbolizerWidget.h"
47 #include "../se/PolygonSymbolizerWidget.h"
48 #include "../se/SymbologyPreview.h"
49 #include "GroupingWidget.h"
50 #include "ui_GroupingWidgetForm.h"
51 
52 // STL
53 #include <cassert>
54 
55 // QT
56 #include <QDialogButtonBox>
57 #include <QMessageBox>
58 
59 #define MAX_SLICES 200
60 #define PRECISION 15
61 #define NO_TITLE "No Value"
62 
64 
65 te::qt::widgets::GroupingWidget::GroupingWidget(QWidget* parent, Qt::WindowFlags f)
66  : QWidget(parent, f),
67  m_ui(new Ui::GroupingWidgetForm),
68  m_cb(0)
69 {
70  m_ui->setupUi(this);
71 
72  QGridLayout* l = new QGridLayout(m_ui->m_colorBarWidget);
73  l->setContentsMargins(0,0,0,0);
74  m_colorBar = new te::qt::widgets::ColorCatalogWidget(m_ui->m_colorBarWidget);
75  l->addWidget(m_colorBar);
76 
77 //connects
78  connect(m_colorBar, SIGNAL(colorBarChanged()), this, SLOT(onColorBarChanged()));
79  connect(m_ui->m_typeComboBox, SIGNAL(activated(int)), this, SLOT(onTypeComboBoxActivated(int)));
80  connect(m_ui->m_attrComboBox, SIGNAL(activated(int)), this, SLOT(onAttrComboBoxActivated(int)));
81  connect(m_ui->m_applyPushButton, SIGNAL(clicked()), this, SLOT(onApplyPushButtonClicked()));
82  connect(m_ui->m_tableWidget, SIGNAL(itemDoubleClicked(QTableWidgetItem*)), this, SLOT(onTableWidgetItemDoubleClicked(QTableWidgetItem*)));
83  connect(m_ui->m_importPushButton, SIGNAL(clicked()), this, SLOT(onImportPushButtonClicked()));
84 
85  //m_importGroupingGroupBox
86  initialize();
87 }
88 
90 {
91  delete m_cb;
92 
93  te::common::FreeContents(m_legend);
94  m_legend.clear();
95 }
96 
97 std::auto_ptr<te::map::Grouping> te::qt::widgets::GroupingWidget::getGrouping()
98 {
99  if(m_ui->m_importGroupBox->isChecked())
100  {
101  QVariant varLayer = m_ui->m_layersComboBox->itemData(m_ui->m_layersComboBox->currentIndex(), Qt::UserRole);
102  te::map::AbstractLayerPtr layer = varLayer.value<te::map::AbstractLayerPtr>();
103 
104  te::map::Grouping* ref = layer->getGrouping();
105 
106  std::auto_ptr<te::map::Grouping> group(new te::map::Grouping(*ref));
107 
108  return group;
109  }
110 
111  std::string attr = m_ui->m_attrComboBox->currentText().toStdString();
112  int attrIdx = m_ui->m_attrComboBox->currentIndex();
113  int attrType = m_ui->m_attrComboBox->itemData(attrIdx).toInt();
114 
115  int index = m_ui->m_typeComboBox->currentIndex();
116  int type = m_ui->m_typeComboBox->itemData(index).toInt();
117 
118  std::auto_ptr<te::map::Grouping> group(new te::map::Grouping(attr, (te::map::GroupingType)type));
119 
120  group->setPropertyType(attrType);
121 
122  group->setNumSlices(m_ui->m_slicesSpinBox->value());
123 
124  group->setPrecision(m_ui->m_precSpinBox->value());
125 
126  group->setStdDeviation(m_ui->m_stdDevDoubleSpinBox->value());
127 
128  std::vector<te::map::GroupingItem*> groupingItems;
129  for(std::size_t t = 0; t < m_legend.size(); ++t)
130  {
131  te::map::GroupingItem* gi = new te::map::GroupingItem(*m_legend[t]);
132 
133  groupingItems.push_back(gi);
134  }
135  group->setGroupingItems(groupingItems);
136 
137  group->setSummary(m_ui->m_summaryComboBox->currentText().toStdString());
138 
139  return group;
140 }
141 
143 {
144  // create color bar
145  m_colorBar->getColorBar()->setHeight(20);
146  m_colorBar->getColorBar()->setScaleVisible(false);
147 
148  // fill grouping type combo box
149  m_ui->m_typeComboBox->addItem(tr("Equal Steps"), te::map::EQUAL_STEPS);
150  m_ui->m_typeComboBox->addItem(tr("Quantil"), te::map::QUANTIL);
151  m_ui->m_typeComboBox->addItem(tr("Standard Deviation"), te::map::STD_DEVIATION);
152  m_ui->m_typeComboBox->addItem(tr("Unique Value"), te::map::UNIQUE_VALUE);
153 
154  onTypeComboBoxActivated(0);
155 
156  //set number of slices
157  m_ui->m_slicesSpinBox->setMinimum(1);
158  m_ui->m_slicesSpinBox->setMaximum(MAX_SLICES);
159  m_ui->m_slicesSpinBox->setValue(5);
160  m_ui->m_slicesSpinBox->setSingleStep(1);
161 
162  //set standard deviation values
163  m_ui->m_stdDevDoubleSpinBox->setMinimum(0.25);
164  m_ui->m_stdDevDoubleSpinBox->setMaximum(1.0);
165  m_ui->m_stdDevDoubleSpinBox->setValue(0.5);
166  m_ui->m_stdDevDoubleSpinBox->setSingleStep(0.25);
167 
168  //set number of precision
169  m_ui->m_precSpinBox->setMinimum(1);
170  m_ui->m_precSpinBox->setMaximum(PRECISION);
171  m_ui->m_precSpinBox->setValue(6);
172  m_ui->m_precSpinBox->setSingleStep(1);
173 
174  //adjust table
175  m_ui->m_tableWidget->resizeColumnsToContents();
176 #if (QT_VERSION >= 0x050000)
177  m_ui->m_tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
178 #else
179  m_ui->m_tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
180 #endif
181 
182  m_manual = false;
183 }
184 
186 {
187  disconnect(m_ui->m_tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(onTableWidgetItemChanged(QTableWidgetItem*)));
188 
189  m_ui->m_tableWidget->setRowCount(0);
190 
191  int index = m_ui->m_typeComboBox->currentIndex();
192  int type = m_ui->m_typeComboBox->itemData(index).toInt();
193 
194  if(type == te::map::EQUAL_STEPS || type == te::map::QUANTIL || type == te::map::STD_DEVIATION)
195  {
196  QStringList list;
197  list.append(tr("Symbol"));
198  list.append(tr("Title"));
199  list.append(tr("Min"));
200  list.append(tr("Max"));
201  list.append(tr("Count"));
202 
203  m_ui->m_tableWidget->setColumnCount(5);
204  m_ui->m_tableWidget->setHorizontalHeaderLabels(list);
205  }
206  else if(type == te::map::UNIQUE_VALUE)
207  {
208  QStringList list;
209  list.append(tr("Symbol"));
210  list.append(tr("Title"));
211  list.append(tr("Value"));
212  list.append(tr("Count"));
213 
214  m_ui->m_tableWidget->setColumnCount(4);
215  m_ui->m_tableWidget->setHorizontalHeaderLabels(list);
216  }
217 
218  te::color::ColorBar* cb = 0;
219 
220  if(loadColorBar)
221  {
222  if(!m_legend.empty() && !m_legend[0]->getSymbolizers().empty() && !m_legend[m_legend.size() - 1]->getSymbolizers().empty())
223  {
225 
226  scf.find(m_legend[0]->getSymbolizers()[0]);
227  te::color::RGBAColor initColor = scf.getColor();
228 
229  scf.find(m_legend[m_legend.size() - 1]->getSymbolizers()[0]);
230  te::color::RGBAColor endColor = scf.getColor();
231 
232  cb = new te::color::ColorBar(initColor, endColor, 256);
233  }
234  }
235 
236  int count = 0;
237 
238  for(std::size_t t = 0; t < m_legend.size(); ++t)
239  {
240  te::map::GroupingItem* gi = m_legend[t];
241 
242  int newrow = m_ui->m_tableWidget->rowCount();
243  m_ui->m_tableWidget->insertRow(newrow);
244 
245  //symbol
246  {
247  const std::vector<te::se::Symbolizer*>& ss = gi->getSymbolizers();
248  QPixmap pix = te::qt::widgets::SymbologyPreview::build(ss, QSize(24, 24));
249  QIcon icon(pix);
250  QTableWidgetItem* item = new QTableWidgetItem(icon, "");
251  item->setFlags(Qt::ItemIsEnabled);
252  m_ui->m_tableWidget->setItem(newrow, 0, item);
253  }
254 
255  //title
256  {
257  QTableWidgetItem* item = new QTableWidgetItem(QString::fromStdString(gi->getTitle()));
258  item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable);
259  m_ui->m_tableWidget->setItem(newrow, 1, item);
260  }
261 
262  if(loadColorBar)
263  {
264  if(count != 0 && count != m_legend.size() - 1)
265  {
266  double pos = (1. / (m_legend.size() - 1)) * count;
267 
268  if(!gi->getSymbolizers().empty())
269  {
271 
272  scf.find(gi->getSymbolizers()[0]);
273 
274  te::color::RGBAColor color = scf.getColor();
275 
276  if(cb)
277  cb->addColor(color, pos);
278  }
279  }
280  }
281 
282  ++count;
283 
284  if(type == te::map::EQUAL_STEPS || type == te::map::QUANTIL || type == te::map::STD_DEVIATION)
285  {
286  if(gi->getTitle() != NO_TITLE)
287  {
288  //Min
289  {
290  QTableWidgetItem* item = new QTableWidgetItem(QString::fromStdString(gi->getLowerLimit()));
291  item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable);
292  m_ui->m_tableWidget->setItem(newrow, 2, item);
293  }
294 
295  //Max
296  {
297  QTableWidgetItem* item = new QTableWidgetItem(QString::fromStdString(gi->getUpperLimit()));
298  item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable);
299  m_ui->m_tableWidget->setItem(newrow, 3, item);
300  }
301  }
302 
303  //Count
304  QTableWidgetItem* item = new QTableWidgetItem(QString::number(gi->getCount()));
305  item->setFlags(Qt::ItemIsEnabled);
306  m_ui->m_tableWidget->setItem(newrow, 4, item);
307 
308  }
309  else if(type == te::map::UNIQUE_VALUE)
310  {
311  if(gi->getTitle() != NO_TITLE)
312  {
313  //Value
314  QTableWidgetItem* item = new QTableWidgetItem(QString::fromStdString(gi->getValue()));
315  item->setFlags(Qt::ItemIsEnabled);
316  m_ui->m_tableWidget->setItem(newrow, 2, item);
317  }
318 
319  //Count
320  QTableWidgetItem* item = new QTableWidgetItem(QString::number(gi->getCount()));
321  item->setFlags(Qt::ItemIsEnabled);
322  m_ui->m_tableWidget->setItem(newrow, 3, item);
323 
324  }
325  }
326 
327  if(cb)
328  {
329  disconnect(m_colorBar, SIGNAL(colorBarChanged()), this, SLOT(onColorBarChanged()));
330 
332  cbW->setColorBar(cb);
333 
334  connect(m_colorBar, SIGNAL(colorBarChanged()), this, SLOT(onColorBarChanged()));
335  }
336 
337  m_ui->m_tableWidget->resizeColumnsToContents();
338 #if (QT_VERSION >= 0x050000)
339  m_ui->m_tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
340 #else
341  m_ui->m_tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
342 #endif
343 
344  connect(m_ui->m_tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(onTableWidgetItemChanged(QTableWidgetItem*)));
345 }
346 
348 {
349  listAttributes();
350 }
351 
353 {
354  te::map::Grouping* grouping = m_layer->getGrouping();
355 
356  setGrouping(grouping);
357 
358  emit applyPushButtonClicked();
359 }
360 
362 {
363  if(!grouping)
364  return;
365 
366  //type
367  te::map::GroupingType type = grouping->getType();
368 
369  for(int i = 0; i < m_ui->m_typeComboBox->count(); ++i)
370  {
371  if(type == m_ui->m_typeComboBox->itemData(i).toInt())
372  {
373  m_ui->m_typeComboBox->setCurrentIndex(i);
374 
375  onTypeComboBoxActivated(i);
376 
377  break;
378  }
379  }
380 
381  //attr name
382  std::string attrName = grouping->getPropertyName();
383 
384  for(int i = 0; i < m_ui->m_attrComboBox->count(); ++i)
385  {
386  if(attrName == m_ui->m_attrComboBox->itemText(i).toStdString())
387  {
388  m_ui->m_attrComboBox->setCurrentIndex(i);
389  break;
390  }
391  }
392 
393  //precision
394  size_t prec = grouping->getPrecision();
395 
396  m_ui->m_precSpinBox->setValue((int)prec);
397 
398  //slices
399  size_t slices = grouping->getNumSlices();
400 
401  m_ui->m_slicesSpinBox->setValue((int)slices);
402 
403  //std dev
404  float stdDev = grouping->getStdDeviation();
405 
406  m_ui->m_stdDevDoubleSpinBox->setValue((double)stdDev);
407 
408  //grouping items
409  te::common::FreeContents(m_legend);
410  m_legend.clear();
411 
412  for(size_t t = 0; t < grouping->getGroupingItems().size(); ++t)
413  {
415 
416  m_legend.push_back(gi);
417  }
418 
419  updateUi(true);
420 
421  onApplyPushButtonClicked();
422 }
423 
425 {
426  if(m_manual)
427  {
428  int reply = QMessageBox::question(this, tr("Classification"), tr("Manual changes will be lost. Continue?"), QMessageBox::Yes | QMessageBox::Cancel);
429 
430  if(reply != QMessageBox::Yes)
431  return;
432  }
433 
434  int index = m_ui->m_typeComboBox->currentIndex();
435 
436  int type = m_ui->m_typeComboBox->itemData(index).toInt();
437  int slices = m_ui->m_slicesSpinBox->value();
438  int prec = m_ui->m_precSpinBox->value();
439  double stdDev = m_ui->m_stdDevDoubleSpinBox->value();
440 
441  std::string attr = m_ui->m_attrComboBox->currentText().toStdString();
442  int attrIdx = m_ui->m_attrComboBox->currentIndex();
443  int attrType = m_ui->m_attrComboBox->itemData(attrIdx).toInt();
444 
445  te::common::FreeContents(m_legend);
446  m_legend.clear();
447 
448  std::string mean = "";
449 
450  int nullValues = 0;
451 
452  bool update = false;
453 
454  if(type == te::map::EQUAL_STEPS)
455  {
456  std::vector<double> vec;
457 
458  getDataAsDouble(vec, attr, attrType, nullValues);
459 
460  te::map::GroupingByEqualSteps(vec.begin(), vec.end(), slices, m_legend, prec);
461 
462  buildSymbolizer(mean);
463 
464  createDoubleNullGroupingItem(nullValues);
465  }
466  else if(type == te::map::QUANTIL)
467  {
468  std::vector<double> vec;
469 
470  getDataAsDouble(vec, attr, attrType, nullValues);
471 
472  te::map::GroupingByQuantil(vec.begin(), vec.end(), slices, m_legend, prec);
473 
474  buildSymbolizer(mean);
475 
476  createDoubleNullGroupingItem(nullValues);
477  }
478  else if(type == te::map::STD_DEVIATION)
479  {
480  std::vector<double> vec;
481 
482  getDataAsDouble(vec, attr, attrType, nullValues);
483 
484  te::map::GroupingByStdDeviation(vec.begin(), vec.end(), stdDev, m_legend, mean, prec);
485 
486  buildSymbolizer(mean);
487 
488  createDoubleNullGroupingItem(nullValues);
489 
490  update = false;
491  }
492  else if(type == te::map::UNIQUE_VALUE)
493  {
494  std::vector<std::string> vec;
495 
496  getDataAsString(vec, attr, nullValues);
497 
498  te::map::GroupingByUniqueValues(vec, attrType, m_legend, prec);
499 
500  buildSymbolizer(mean);
501 
502  createStringNullGroupingItem(nullValues);
503  }
504 
505  updateUi(update);
506 
507  m_manual = false;
508 
509  emit applyPushButtonClicked();
510 }
511 
513 {
514  int type = m_ui->m_typeComboBox->itemData(idx).toInt();
515 
516  if(type == te::map::EQUAL_STEPS)
517  {
518  m_ui->m_slicesSpinBox->setEnabled(true);
519  m_ui->m_precSpinBox->setEnabled(true);
520  m_ui->m_stdDevDoubleSpinBox->setEnabled(false);
521  }
522  else if(type == te::map::QUANTIL)
523  {
524  m_ui->m_slicesSpinBox->setEnabled(true);
525  m_ui->m_precSpinBox->setEnabled(true);
526  m_ui->m_stdDevDoubleSpinBox->setEnabled(false);
527  }
528  else if(type == te::map::STD_DEVIATION)
529  {
530  m_ui->m_slicesSpinBox->setEnabled(false);
531  m_ui->m_precSpinBox->setEnabled(true);
532  m_ui->m_stdDevDoubleSpinBox->setEnabled(true);
533  }
534  else if(type == te::map::UNIQUE_VALUE)
535  {
536  m_ui->m_slicesSpinBox->setEnabled(false);
537  m_ui->m_precSpinBox->setEnabled(true);
538  m_ui->m_stdDevDoubleSpinBox->setEnabled(false);
539  }
540 
541  if(m_layer.get())
542  listAttributes();
543 }
544 
546 {
547 // int attrType = m_ui->m_attrComboBox->itemData(idx).toInt();
548 }
549 
551 {
552  if(m_layer.get())
553  {
554  buildSymbolizer();
555 
556  updateUi();
557  }
558 }
559 
561 {
562  int index = m_ui->m_typeComboBox->currentIndex();
563  int type = m_ui->m_typeComboBox->itemData(index).toInt();
564 
565  int curRow = m_ui->m_tableWidget->currentRow();
566  int curCol = m_ui->m_tableWidget->currentColumn();
567 
568  QString str = item->text();
569 
570  if(curCol == 1) // title
571  {
572  m_legend[curRow]->setTitle(str.toStdString());
573 
574  m_manual = true;
575  }
576  else if(curCol == 2 || curCol == 3) // min and max
577  {
578  if(type == te::map::EQUAL_STEPS || type == te::map::QUANTIL || type == te::map::STD_DEVIATION)
579  {
580  bool ok = false;
581 
582  str.toDouble(&ok);
583 
584  if(!ok)
585  {
586  if(curCol == 2)
587  item->setText(m_legend[curRow]->getLowerLimit().c_str());
588  else if(curCol ==3)
589  item->setText(m_legend[curRow]->getUpperLimit().c_str());
590  }
591  else
592  {
593  if(curCol == 2)
594  m_legend[curRow]->setLowerLimit(item->text().toStdString());
595  else if(curCol ==3)
596  m_legend[curRow]->setUpperLimit(item->text().toStdString());
597 
598  m_manual = true;
599  }
600  }
601  }
602 }
603 
605 {
606  int curRow = m_ui->m_tableWidget->currentRow();
607  int curCol = m_ui->m_tableWidget->currentColumn();
608 
609  if(curCol == 0)
610  {
611  te::map::GroupingItem* gi = m_legend[curRow];
612 
613  std::vector<te::se::Symbolizer*> symbVec = gi->getSymbolizers();
614 
615  QDialog* dialog = new QDialog(this);
616  QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom, dialog);
617 
618  QDialogButtonBox* bbox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, dialog);
619 
620  QWidget* symbWidget = 0;
621 
622  if(symbVec[0]->getType() == "PolygonSymbolizer")
623  {
624  symbWidget = new te::qt::widgets::PolygonSymbolizerWidget(dialog);
626  polygonSymbolizerWidget->setSymbolizer((te::se::PolygonSymbolizer*)symbVec[0]);
627  }
628  else if(symbVec[0]->getType() == "LineSymbolizer")
629  {
630  symbWidget = new te::qt::widgets::LineSymbolizerWidget(dialog);
632  lineSymbolizerWidget->setSymbolizer((te::se::LineSymbolizer*)symbVec[0]);
633  }
634  else if(symbVec[0]->getType() == "PointSymbolizer")
635  {
636  symbWidget = new te::qt::widgets::PointSymbolizerWidget(dialog);
638  pointSymbolizerWidget->setSymbolizer((te::se::PointSymbolizer*)symbVec[0]);
639  }
640 
641  layout->addWidget(symbWidget);
642  layout->addWidget(bbox);
643 
644  connect(bbox, SIGNAL(accepted()), dialog, SLOT(accept()));
645  connect(bbox, SIGNAL(rejected()), dialog, SLOT(reject()));
646 
647  if(dialog->exec() == QDialog::Rejected)
648  {
649  delete dialog;
650  return;
651  }
652 
653  if(symbVec[0]->getType() == "PolygonSymbolizer")
654  {
655  symbVec.clear();
657  symbVec.push_back(polygonSymbolizerWidget->getSymbolizer());
658  }
659  else if(symbVec[0]->getType() == "LineSymbolizer")
660  {
661  symbVec.clear();
663  symbVec.push_back(lineSymbolizerWidget->getSymbolizer());
664  }
665  else if(symbVec[0]->getType() == "PointSymbolizer")
666  {
667  symbVec.clear();
669  symbVec.push_back(pointSymbolizerWidget->getSymbolizer());
670  }
671 
672  gi->setSymbolizers(symbVec);
673 
674  QPixmap pix = te::qt::widgets::SymbologyPreview::build(symbVec, QSize(24, 24));
675  QIcon icon(pix);
676 
677  QTableWidgetItem* newItem = new QTableWidgetItem(icon, "");
678  newItem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled);
679 
680  m_ui->m_tableWidget->setItem(curRow, 0, newItem);
681 
682  delete dialog;
683 
684  updateUi(true);
685 
686  emit applyPushButtonClicked();
687  }
688 }
689 
690 
691 void te::qt::widgets::GroupingWidget::getDataAsDouble(std::vector<double>& vec, const std::string& attrName, const int& dataType, int& nullValues)
692 {
693  assert(m_layer.get());
694 
695  if(te::da::HasLinkedTable(m_layer->getSchema().get()))
696  {
697  getLinkedDataAsDouble(vec, attrName, dataType, nullValues);
698  return;
699  }
700 
701  std::auto_ptr<te::map::LayerSchema> dsType(m_layer->getSchema());
702 
703  std::size_t idx;
704 
705  for(std::size_t t = 0; t < dsType->getProperties().size(); ++t)
706  {
707  if(dsType->getProperty(t)->getName() == attrName)
708  {
709  idx = t;
710  break;
711  }
712  }
713 
714  std::auto_ptr<te::da::DataSet> ds(m_layer->getData());
715 
716  ds->moveBeforeFirst();
717 
718  while(ds->moveNext())
719  {
720  if(ds->isNull(idx))
721  {
722  ++nullValues;
723  continue;
724  }
725 
726  if(dataType == te::dt::INT16_TYPE)
727  vec.push_back((double)ds->getInt16(idx));
728  else if(dataType == te::dt::INT32_TYPE)
729  vec.push_back((double)ds->getInt32(idx));
730  else if(dataType == te::dt::INT64_TYPE)
731  vec.push_back((double)ds->getInt64(idx));
732  else if(dataType == te::dt::FLOAT_TYPE)
733  vec.push_back((double)ds->getFloat(idx));
734  else if(dataType == te::dt::DOUBLE_TYPE)
735  vec.push_back(ds->getDouble(idx));
736  else if(dataType == te::dt::NUMERIC_TYPE)
737  {
738  QString strNum = ds->getNumeric(idx).c_str();
739 
740  bool ok = false;
741 
742  double value = strNum.toDouble(&ok);
743 
744  if(ok)
745  vec.push_back(value);
746  }
747  }
748 }
749 
750 void te::qt::widgets::GroupingWidget::getLinkedDataAsDouble(std::vector<double>& vec, const std::string& attrName, const int& dataType, int& nullValues)
751 {
752  assert(m_layer.get());
753 
754  std::auto_ptr<te::map::LayerSchema> dsType(m_layer->getSchema());
755 
756  std::string function = m_ui->m_summaryComboBox->currentText().toStdString();
757  std::vector<std::string> poid;
758  size_t pksize = 0;
759  te::map::QueryLayer* qlayer = 0;
760  te::da::Select* select = 0;
761 
762  // make sorting by object id
763  qlayer = dynamic_cast<te::map::QueryLayer*>(m_layer.get());
764  select = dynamic_cast<te::da::Select*>(qlayer->getQuery()->clone());
765  te::da::Select* selectaux = dynamic_cast<te::da::Select*>(select->clone());
766  te::da::OrderBy* orderBy = new te::da::OrderBy;
767 
768  std::vector<te::dt::Property*> props = dsType->getPrimaryKey()->getProperties();
769  while(++pksize < props.size())
770  {
771  poid.push_back(props[pksize-1]->getName());
772  if(props[pksize-1]->getDatasetName() != props[pksize]->getDatasetName())
773  break;
774  }
775 
776  for(size_t i = 0; i < pksize; ++i)
777  orderBy->push_back(new te::da::OrderByItem(poid[i]));
778 
779  selectaux->setOrderBy(orderBy);
780  qlayer->setQuery(selectaux);
781 
782  std::size_t idx;
783 
784  for(std::size_t t = 0; t < dsType->getProperties().size(); ++t)
785  {
786  if(dsType->getProperty(t)->getName() == attrName)
787  {
788  idx = t;
789  break;
790  }
791  }
792 
793  std::vector<std::string> pkdata(pksize), pkdataaux(pksize);
794  std::auto_ptr<te::da::DataSet> ds(m_layer->getData());
795  qlayer->setQuery(select);
796 
797  bool nullValue = false;
798  std::vector<double> values;
799  bool isBegin = true;
800  ds->moveBeforeFirst();
801 
802  while(ds->moveNext())
803  {
804  if(pksize)
805  {
806  // it is linked. Remove redundancies.
807  size_t i;
808  for(i = 0; i < pksize; ++i)
809  {
810  pkdata[i] = ds->getAsString(poid[i]);
811  if(isBegin)
812  {
813  isBegin = false;
814  pkdataaux[i] = ds->getAsString(poid[i]);
815  }
816  }
817 
818  for(i = 0; i < pksize; ++i)
819  {
820  if(pkdata[i] != pkdataaux[i])
821  {
822  pkdataaux = pkdata;
823  break;
824  }
825  }
826  if(i == pksize) // it is the same object
827  {
828  if(nullValue == false)
829  {
830  if(ds->isNull(idx))
831  nullValue = true;
832  else
833  {
834  if(dataType == te::dt::INT16_TYPE)
835  values.push_back((double)ds->getInt16(idx));
836  else if(dataType == te::dt::INT32_TYPE)
837  values.push_back((double)ds->getInt32(idx));
838  else if(dataType == te::dt::INT64_TYPE)
839  values.push_back((double)ds->getInt64(idx));
840  else if(dataType == te::dt::FLOAT_TYPE)
841  values.push_back((double)ds->getFloat(idx));
842  else if(dataType == te::dt::DOUBLE_TYPE)
843  values.push_back(ds->getDouble(idx));
844  else if(dataType == te::dt::NUMERIC_TYPE)
845  {
846  QString strNum = ds->getNumeric(idx).c_str();
847 
848  bool ok = false;
849 
850  double value = strNum.toDouble(&ok);
851 
852  if(ok)
853  values.push_back(value);
854  }
855  }
856  }
857  continue;
858  // read other values
859  }
860  else // it is other object
861  {
862  // sumarize value according to the required summarization
863  if(nullValue)
864  ++nullValues;
865  else
866  vec.push_back(te::da::GetSummarizedValue(values, function));
867 
868  nullValue = false;
869  values.clear();
870 
871  // get new value
872  if(ds->isNull(idx))
873  nullValue = true;
874  else
875  {
876  if(dataType == te::dt::INT16_TYPE)
877  values.push_back((double)ds->getInt16(idx));
878  else if(dataType == te::dt::INT32_TYPE)
879  values.push_back((double)ds->getInt32(idx));
880  else if(dataType == te::dt::INT64_TYPE)
881  values.push_back((double)ds->getInt64(idx));
882  else if(dataType == te::dt::FLOAT_TYPE)
883  values.push_back((double)ds->getFloat(idx));
884  else if(dataType == te::dt::DOUBLE_TYPE)
885  values.push_back(ds->getDouble(idx));
886  else if(dataType == te::dt::NUMERIC_TYPE)
887  {
888  QString strNum = ds->getNumeric(idx).c_str();
889 
890  bool ok = false;
891 
892  double value = strNum.toDouble(&ok);
893 
894  if(ok)
895  values.push_back(value);
896  }
897  }
898  }
899  }
900  }
901  // sumarize value according to the required summarization
902  if(nullValue)
903  ++nullValues;
904  else
905  vec.push_back(te::da::GetSummarizedValue(values, function));
906  values.clear();
907 }
908 
909 void te::qt::widgets::GroupingWidget::getDataAsString(std::vector<std::string>& vec, const std::string& attrName, int& nullValues)
910 {
911  assert(m_layer.get());
912 
913  if(te::da::HasLinkedTable(m_layer->getSchema().get()))
914  {
915  getLinkedDataAsString(vec, attrName, nullValues);
916  return;
917  }
918 
919  std::auto_ptr<te::map::LayerSchema> dsType(m_layer->getSchema());
920 
921  std::size_t idx;
922 
923  for(std::size_t t = 0; t < dsType->getProperties().size(); ++t)
924  {
925  if(dsType->getProperty(t)->getName() == attrName)
926  {
927  idx = t;
928  break;
929  }
930  }
931 
932  std::auto_ptr<te::da::DataSet> ds(m_layer->getData());
933 
934  ds->moveBeforeFirst();
935 
936  while(ds->moveNext())
937  {
938  if(!ds->isNull(idx))
939  vec.push_back(ds->getAsString(idx));
940  else
941  ++nullValues;
942  }
943 }
944 
945 void te::qt::widgets::GroupingWidget::getLinkedDataAsString(std::vector<std::string>& vec, const std::string& attrName, int& nullValues)
946 {
947  assert(m_layer.get());
948 
949  std::auto_ptr<te::map::LayerSchema> dsType(m_layer->getSchema());
950 
951  std::string function = m_ui->m_summaryComboBox->currentText().toStdString();
952  std::vector<std::string> poid;
953  size_t pksize = 0;
954  te::map::QueryLayer* qlayer = 0;
955  te::da::Select* select = 0;
956 
957  // make sorting by object id
958  qlayer = dynamic_cast<te::map::QueryLayer*>(m_layer.get());
959  select = dynamic_cast<te::da::Select*>(qlayer->getQuery()->clone());
960  te::da::Select* selectaux = dynamic_cast<te::da::Select*>(select->clone());
961  te::da::OrderBy* orderBy = new te::da::OrderBy;
962 
963  std::vector<te::dt::Property*> props = dsType->getPrimaryKey()->getProperties();
964  while(++pksize < props.size())
965  {
966  poid.push_back(props[pksize-1]->getName());
967  if(props[pksize-1]->getDatasetName() != props[pksize]->getDatasetName())
968  break;
969  }
970 
971  for(size_t i = 0; i < pksize; ++i)
972  orderBy->push_back(new te::da::OrderByItem(poid[i]));
973 
974  selectaux->setOrderBy(orderBy);
975  qlayer->setQuery(selectaux);
976 
977  std::size_t idx;
978 
979  for(std::size_t t = 0; t < dsType->getProperties().size(); ++t)
980  {
981  if(dsType->getProperty(t)->getName() == attrName)
982  {
983  idx = t;
984  break;
985  }
986  }
987 
988  std::vector<std::string> pkdata(pksize), pkdataaux(pksize);
989  std::auto_ptr<te::da::DataSet> ds(m_layer->getData());
990  qlayer->setQuery(select);
991 
992  bool nullValue = false;
993  std::vector<std::string> values;
994  bool isBegin = true;
995  ds->moveBeforeFirst();
996 
997  while(ds->moveNext())
998  {
999  if(pksize)
1000  {
1001  // it is linked. Remove redundancies.
1002  size_t i;
1003  for(i = 0; i < pksize; ++i)
1004  {
1005  pkdata[i] = ds->getAsString(poid[i]);
1006  if(isBegin)
1007  {
1008  isBegin = false;
1009  pkdataaux[i] = ds->getAsString(poid[i]);
1010  }
1011  }
1012 
1013  for(i = 0; i < pksize; ++i)
1014  {
1015  if(pkdata[i] != pkdataaux[i])
1016  {
1017  pkdataaux = pkdata;
1018  break;
1019  }
1020  }
1021  if(i == pksize) // it is the same object
1022  {
1023  if(nullValue == false)
1024  {
1025  if(ds->isNull(idx))
1026  nullValue = true;
1027  else
1028  values.push_back(ds->getAsString(idx));
1029  }
1030  continue;
1031  // read other values
1032  }
1033  else // it is other object
1034  {
1035  // sumarize value according to the required summarization
1036  if(nullValue)
1037  ++nullValues;
1038  else
1039  vec.push_back(te::da::GetSummarizedValue(values, function));
1040 
1041  nullValue = false;
1042  values.clear();
1043 
1044  // get new value
1045  if(ds->isNull(idx))
1046  nullValue = true;
1047  else
1048  values.push_back(ds->getAsString(idx));
1049  }
1050  }
1051  }
1052  // sumarize value according to the required summarization
1053  if(nullValue)
1054  ++nullValues;
1055  else
1056  vec.push_back(te::da::GetSummarizedValue(values, function));
1057  values.clear();
1058 }
1059 
1061 {
1062  if(count == 0)
1063  return;
1064 
1065  te::map::GroupingItem* legendItem = new te::map::GroupingItem;
1068  legendItem->setTitle(NO_TITLE);
1069  legendItem->setCount(count);
1070 
1071  int geomType = getGeometryType();
1072  std::vector<te::se::Symbolizer*> symbVec;
1074  symbVec.push_back(s);
1075  legendItem->setSymbolizers(symbVec);
1076 
1077  m_legend.push_back(legendItem);
1078 }
1079 
1081 {
1082  if(count == 0)
1083  return;
1084 
1085  te::map::GroupingItem* legendItem = new te::map::GroupingItem;
1087  legendItem->setTitle(NO_TITLE);
1088  legendItem->setCount(count);
1089 
1090  int geomType = getGeometryType();
1091  std::vector<te::se::Symbolizer*> symbVec;
1093  symbVec.push_back(s);
1094  legendItem->setSymbolizers(symbVec);
1095 
1096  m_legend.push_back(legendItem);
1097 }
1098 
1100 {
1101  assert(m_layer.get());
1102 
1103  return te::map::GetGeomType(m_layer);
1104 }
1105 
1107 {
1108  delete m_cb;
1109 
1110  m_cb = m_colorBar->getColorBar()->getColorBar();
1111 
1112  int legendSize = m_legend.size();
1113 
1114  std::vector<te::color::RGBAColor> colorVec;
1115 
1116  if(meanTitle.empty())
1117  {
1118  colorVec = m_cb->getSlices(legendSize);
1119  }
1120  else
1121  {
1122  int beforeMean = 0;
1123  int afterMean = 0;
1124  int meanIdx = 0;
1125 
1126  for(size_t t = 0; t < m_legend.size(); ++t)
1127  {
1128  if(m_legend[t]->getTitle() != meanTitle)
1129  {
1130  beforeMean++;
1131  }
1132  else
1133  {
1134  meanIdx = t;
1135  afterMean = m_legend.size() - t - 1;
1136  break;
1137  }
1138  }
1139 
1140  std::vector<te::color::RGBAColor> lowerColorVec = m_cb->getLowerMeanSlices(beforeMean);
1141  te::color::RGBAColor meanColor = m_cb->getMeanSlice();
1142  std::vector<te::color::RGBAColor> upperColorVec = m_cb->getUpperMeanSlices(afterMean);
1143 
1144  for(size_t t = 0; t < lowerColorVec.size(); ++t)
1145  colorVec.push_back(lowerColorVec[t]);
1146 
1147  colorVec.push_back(meanColor);
1148 
1149  for(size_t t = 0; t < upperColorVec.size(); ++t)
1150  colorVec.push_back(upperColorVec[t]);
1151  }
1152 
1153  if(colorVec.size() != m_legend.size())
1154  return;
1155 
1156  int geomType = getGeometryType();
1157 
1158  for(size_t t = 0; t < colorVec.size(); ++t)
1159  {
1160  std::vector<te::se::Symbolizer*> symbVec;
1161 
1162  te::se::Symbolizer* s = te::se::CreateSymbolizer((te::gm::GeomType)geomType, colorVec[t].getColor());
1163 
1164  symbVec.push_back(s);
1165 
1166  m_legend[t]->setSymbolizers(symbVec);
1167  }
1168 }
1169 
1171 {
1172  QString curValue = m_ui->m_attrComboBox->currentText();
1173 
1174  m_ui->m_attrComboBox->clear();
1175 
1176  std::auto_ptr<te::map::LayerSchema> dsType(m_layer->getSchema());
1177 
1178  //grouping type
1179  int index = m_ui->m_typeComboBox->currentIndex();
1180  int type = m_ui->m_typeComboBox->itemData(index).toInt();
1181 
1182  if(type == te::map::EQUAL_STEPS ||type == te::map::QUANTIL || type == te::map::STD_DEVIATION)
1183  {
1184  for(size_t t = 0; t < dsType->getProperties().size(); ++t)
1185  {
1186  te::dt::Property* p = dsType->getProperty(t);
1187 
1188  int dataType = p->getType();
1189 
1190  switch(dataType)
1191  {
1192  case te::dt::INT16_TYPE:
1193  case te::dt::INT32_TYPE:
1194  case te::dt::INT64_TYPE:
1195  case te::dt::FLOAT_TYPE:
1196  case te::dt::DOUBLE_TYPE:
1197  case te::dt::NUMERIC_TYPE:
1198  m_ui->m_attrComboBox->addItem(p->getName().c_str(), p->getType());
1199 
1200  default:
1201  continue;
1202  }
1203  }
1204  }
1205  else if(type == te::map::UNIQUE_VALUE)
1206  {
1207  for(size_t t = 0; t < dsType->getProperties().size(); ++t)
1208  {
1209  te::dt::Property* p = dsType->getProperty(t);
1210 
1211  int dataType = p->getType();
1212 
1213  switch(dataType)
1214  {
1215  case te::dt::INT16_TYPE:
1216  case te::dt::INT32_TYPE:
1217  case te::dt::INT64_TYPE:
1218  case te::dt::FLOAT_TYPE:
1219  case te::dt::DOUBLE_TYPE:
1220  case te::dt::NUMERIC_TYPE:
1221  case te::dt::STRING_TYPE:
1222  m_ui->m_attrComboBox->addItem(p->getName().c_str(), p->getType());
1223 
1224  default:
1225  continue;
1226  }
1227  }
1228  }
1229 
1230  if(curValue.isEmpty() == false)
1231  {
1232  int idx = m_ui->m_attrComboBox->findText(curValue);
1233 
1234  if(idx != -1)
1235  m_ui->m_attrComboBox->setCurrentIndex(idx);
1236  }
1237 }
1238 
1239 void te::qt::widgets::GroupingWidget::setLayers(te::map::AbstractLayerPtr selectedLayer, std::vector<te::map::AbstractLayerPtr> allLayers)
1240 {
1241  m_layer = selectedLayer;
1242 
1243  //set data type
1244  setDataSetType();
1245 
1246  //set grouping
1247  setGrouping();
1248 
1249  //Adjusting summary options
1250  m_ui->m_summaryComboBox->clear();
1251  if(te::da::HasLinkedTable(m_layer->getSchema().get()))
1252  {
1253  m_ui->m_summaryComboBox->addItem("MIN");
1254  m_ui->m_summaryComboBox->addItem("MAX");
1255  m_ui->m_summaryComboBox->addItem("SUM");
1256  m_ui->m_summaryComboBox->addItem("AVERAGE");
1257  m_ui->m_summaryComboBox->addItem("MEDIAN");
1258  m_ui->m_summaryComboBox->addItem("STDDEV");
1259  m_ui->m_summaryComboBox->addItem("VARIANCE");
1260 
1261  if(m_layer->getGrouping())
1262  {
1263  int index = m_ui->m_summaryComboBox->findText(QString::fromStdString(m_layer->getGrouping()->getSummary()));
1264  m_ui->m_summaryComboBox->setCurrentIndex(index);
1265  }
1266 
1267  m_ui->m_summaryComboBox->setEnabled(true);
1268  m_ui->m_summaryComboBox->show();
1269  m_ui->m_summaryLabel->show();
1270  }
1271  else
1272  {
1273  m_ui->m_summaryComboBox->addItem("NONE");
1274  m_ui->m_summaryComboBox->setEnabled(false);
1275  m_ui->m_summaryComboBox->hide();
1276  m_ui->m_summaryLabel->hide();
1277  }
1278 
1279  for(std::size_t i = 0; i < allLayers.size(); ++i)
1280  {
1281  if(!allLayers[i]->isValid())
1282  continue;
1283 
1284  std::auto_ptr<te::da::DataSetType> dt(allLayers[i]->getSchema());
1285 
1286  if(dt->hasGeom() && allLayers[i]->getGrouping() && allLayers[i]->getId() != selectedLayer->getId())
1287  {
1288  m_ui->m_layersComboBox->addItem(allLayers[i]->getTitle().c_str(), QVariant::fromValue(allLayers[i]));
1289  }
1290  }
1291 }
1292 
1294 {
1295  if(m_ui->m_layersComboBox->currentText() == "")
1296  {
1297  QMessageBox::warning(this, tr("Grouping"), tr("There are no other layers with Grouping!"));
1298  return;
1299  }
1300 
1301  if(m_manual)
1302  {
1303  int reply = QMessageBox::question(this, tr("Grouping"), tr("Manual changes will be lost. Continue?"), QMessageBox::Yes | QMessageBox::Cancel);
1304 
1305  if(reply != QMessageBox::Yes)
1306  return;
1307  }
1308 
1309  QVariant varLayer = m_ui->m_layersComboBox->itemData(m_ui->m_layersComboBox->currentIndex(), Qt::UserRole);
1310  te::map::AbstractLayerPtr layer = varLayer.value<te::map::AbstractLayerPtr>();
1311 
1312  te::map::Grouping* ref = layer->getGrouping();
1313 
1314  std::auto_ptr<te::da::DataSetType> dt = m_layer->getSchema();
1315 
1316  std::vector<te::dt::Property*> props = dt->getProperties();
1317 
1318  bool isValid = false;
1319  for(std::size_t i = 0; i < props.size(); ++i)
1320  {
1321  te::dt::Property* prop = props[i];
1322  if((te::common::Convert2UCase(prop->getName()) == te::common::Convert2UCase(ref->getPropertyName())) && (prop->getType() == ref->getPropertyType()))
1323  {
1324  isValid = true;
1325  break;
1326  }
1327  }
1328 
1329  if(!isValid)
1330  {
1331  QString err = tr("There is no grouping that can be imported!\nThe layer must have an attribute with the same name of the attribute used to make the reference layer grouping: ");
1332  err.append(ref->getPropertyName().c_str());
1333  QMessageBox::warning(this, tr("Grouping"), err);
1334  return;
1335  }
1336 
1337  te::map::Grouping* newGrouping = new te::map::Grouping(*ref);
1338 
1339  setGrouping(newGrouping);
1340 
1341  updateUi(true);
1342 
1343  m_manual = false;
1344 
1345  emit applyPushButtonClicked();
1346 }
void createStringNullGroupingItem(int count)
void setValue(const std::string &value)
It sets value of the legend item.
void onTableWidgetItemChanged(QTableWidgetItem *item)
std::auto_ptr< te::map::Grouping > getGrouping()
const double getStdDeviation() const
It gets the standard deviation used in the Standard Deviation grouping.
Definition: Grouping.cpp:120
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Definition: Enums.h:41
A widget used to build a point symbolizer element.
A PolygonSymbolizer is used to draw a polygon (or other area-type geometries), including filling its ...
TESEEXPORT Symbolizer * CreateSymbolizer(const te::gm::GeomType &geomType)
Try creates an appropriate symbolizer based on given geometry type.
Definition: Utils.cpp:220
const std::string & getValue() const
It gets the value of the legend item.
TEDATAACCESSEXPORT bool HasLinkedTable(te::da::DataSetType *type)
It checks if the datasettype has a linked table.
Definition: Utils.cpp:1175
const size_t getPrecision() const
It gets the precision used for the property values.
Definition: Grouping.cpp:100
A Symbolizer describes how a feature is to appear on a map.
Definition: Symbolizer.h:80
#define PRECISION
std::string getPropertyName() const
It gets the property name whose values will be grouped.
Definition: Grouping.cpp:68
void setSymbolizer(const te::se::PointSymbolizer *symb)
Sets a point symbolizer element to this widget.
TEMAPEXPORT te::gm::GeomType GetGeomType(const te::map::AbstractLayerPtr &layer)
It gets the geometry type of the given layer.
Definition: Utils.cpp:748
void addColor(const RGBAColor &color, const double &pos)
It adds a color in the color bar.
Definition: ColorBar.cpp:264
A widget used to build a line symbolizer element.
boost::ptr_vector< OrderByItem > OrderBy
A class that can be used to model an ORDER BY clause.
Definition: OrderBy.h:37
std::string Convert2UCase(const std::string &value)
It converts a string to upper case.
Definition: StringUtils.h:163
A PointSymbolizer specifies the rendering of a graphic Symbolizer at a point.
A layer resulting from a query.
Definition: QueryLayer.h:50
void setTitle(const std::string &title)
It sets the title of the legend item.
void GroupingByEqualSteps(iterator begin, iterator end, int nSteps, std::vector< te::map::GroupingItem * > &legend, int precision=0, bool countElements=true)
It groups the values defined by a range of iterators using the equal steps algorithm.
It models a property definition.
Definition: Property.h:59
void setColorBar(te::color::ColorBar *cb)
It sets the color bar.
Definition: ColorBar.cpp:108
#define MAX_SLICES
te::se::Symbolizer * getSymbolizer() const
Gets the configured point symbolizer element.
void GroupingByStdDeviation(iterator begin, iterator end, double nDevs, std::vector< te::map::GroupingItem * > &legend, std::string &meanTitle, int precision=0, bool countElements=true)
It groups the values defined by a range of iterators using the standard deviation algorithm...
This class contains the parameters needed for grouping the values of a Property.
Definition: Grouping.h:59
std::auto_ptr< Ui::GroupingWidgetForm > m_ui
Widget form.
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr)
A GroupingItem contains information about a grouping item associated to a layer.
Definition: GroupingItem.h:48
GroupingWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a basic fill widget which is a child of parent, with widget flags set to f...
It QWidget implementation of color bar.
Definition: ColorBar.h:67
TEDATAACCESSEXPORT double GetSummarizedValue(std::vector< double > &values, const std::string &summary)
It gets the summarized value.
Definition: Utils.cpp:1196
te::se::Symbolizer * getSymbolizer() const
Gets the configured line symbolizer element.
te::da::Select * getQuery() const
Definition: QueryLayer.cpp:340
Query * clone() const
It creates a new copy of this query.
Definition: Select.cpp:424
void setOrderBy(OrderBy *o)
It sets the list of expressions used to sort the output result.
Definition: Select.cpp:977
void buildSymbolizer(std::string meanTitle="")
void GroupingByQuantil(iterator begin, iterator end, int nSteps, std::vector< te::map::GroupingItem * > &legend, int precision=0, bool countElements=true)
It groups the values defined by a range of iterators using the quantil algorithm. ...
A Select models a query to be used when retrieving data from a DataSource.
Definition: Select.h:65
A Symbology Enconding visitor that finds a color given a symbolizer element. If you want to use this ...
void initialize()
Internal method to initialize the widget (e.g.: color, combos, icons, etc.)
A widget used to build a polygon symbolizer element.
void onTableWidgetItemDoubleClicked(QTableWidgetItem *item)
void createDoubleNullGroupingItem(int count)
int getType() const
It returns the property data type.
Definition: Property.h:161
void find(const te::se::Symbolizer *symbolizer)
It find the color based on given symbolizer.
const std::vector< te::map::GroupingItem * > & getGroupingItems() const
It gets the vector of grouping items.
Definition: Grouping.cpp:130
GroupingType
The grouping type associated to the layer.
Definition: Enums.h:150
void getLinkedDataAsString(std::vector< std::string > &vec, const std::string &attrName, int &nullValues)
void updateUi(bool loadColorBar=false)
Updates the widget form based on internal fill element.
const std::string & getUpperLimit() const
It gets the upper limit value of the legend item.
TEMAPEXPORT void GroupingByUniqueValues(std::vector< std::string > &inputValues, int dataType, std::vector< te::map::GroupingItem * > &legend, int precision)
It groups the values using the unique value algorithm.
#define NO_TITLE
void setCount(std::size_t count)
It It sets the number of objects whose values are between the lower and upper limits.
void setQuery(te::da::Select *s)
Definition: QueryLayer.cpp:345
void getLinkedDataAsDouble(std::vector< double > &vec, const std::string &attrName, const int &dataType, int &nullValues)
void getDataAsString(std::vector< std::string > &vec, const std::string &attrName, int &nullValues)
void setLayers(te::map::AbstractLayerPtr selectedLayer, std::vector< te::map::AbstractLayerPtr > allLayers)
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
te::color::ColorBar * getColorBar()
It returns the colorbar.
Definition: ColorBar.cpp:117
void setUpperLimit(const std::string &to)
It sets the upper limit value of the legend item.
const GroupingType getType() const
It gets the grouping type.
Definition: Grouping.cpp:90
void setSymbolizer(const te::se::PolygonSymbolizer *symb)
Sets a polygon symbolizer element to this widget.
It models the concept of color bar.
Definition: ColorBar.h:49
void getDataAsDouble(std::vector< double > &vec, const std::string &attrName, const int &dataType, int &nullValues)
A widget used to build a grouping.
A LineSymbolizer is used to style a stroke along a linear geometry type, such as a string of line seg...
const size_t getNumSlices() const
It gets the number of slices used in the Equal Steps and Quantil groupings.
Definition: Grouping.cpp:110
std::size_t getCount() const
It gets the number of objects whose values are between the lower and upper limits.
A class that can be used in an ORDER BY clause to sort the items of a resulting query.
Definition: OrderByItem.h:53
te::qt::widgets::ColorCatalogWidget * m_colorBar
Widget used to pick a color.
std::string getTitle()
It gets the title of the legend item.
const std::string & getLowerLimit() const
It gets the lower limit value of the legend item.
te::color::RGBAColor getColor()
Get the color.
const std::vector< te::se::Symbolizer * > & getSymbolizers() const
It gets the symbolizer of the legend item.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
Definition: BoostUtils.h:55
static QPixmap build(const te::se::Symbolizer *symb, const QSize &size)
Generates the preview of given symbolizer element.
te::se::Symbolizer * getSymbolizer() const
Gets the configured polygon symbolizer element.
void setSymbolizer(const te::se::LineSymbolizer *symb)
Sets a line symbolizer element to this widget.
void setSymbolizers(const std::vector< te::se::Symbolizer * > &symbolizers)
It sets the symbolizers of the legend item.
static const std::string sm_nanStr
Not a number string value.
Definition: Globals.h:56
const std::string & getName() const
It returns the property name.
Definition: Property.h:127
void setLowerLimit(const std::string &from)
It sets the lower limit value of the legend item.