All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ColorMapWidget.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/ColorMapWidget.cpp
22 
23  \brief A dialog used to build a Color Map element.
24 */
25 
26 // TerraLib
27 
28 #include "../../../color/ColorBar.h"
29 #include "../../../common/STLUtils.h"
30 #include "../../../dataaccess/dataset/DataSet.h"
31 #include "../../../dataaccess/dataset/DataSetType.h"
32 #include "../../../dataaccess/utils/Utils.h"
33 #include "../../../datatype.h"
34 #include "../../../maptools/DataSetLayer.h"
35 #include "../../../maptools/GroupingAlgorithms.h"
36 #include "../../../maptools/RasterLayer.h"
37 #include "../../../fe/Literal.h"
38 #include "../../../raster.h"
39 #include "../../../raster/RasterSummary.h"
40 #include "../../../raster/RasterSummaryManager.h"
41 #include "../../../se/ColorMap.h"
42 #include "../../../se/Categorize.h"
43 #include "../../../se/Enums.h"
44 #include "../../../se/Interpolate.h"
45 #include "../../../se/InterpolationPoint.h"
46 #include "../../../se/ParameterValue.h"
47 #include "../../../se/RasterSymbolizer.h"
48 #include "../../../se/Utils.h"
49 #include "../../widgets/colorbar/ColorBar.h"
50 #include "../../widgets/colorbar/ColorCatalogWidget.h"
51 #include "ColorMapWidget.h"
52 #include "ui_ColorMapWidgetForm.h"
53 
54 // Qt
55 #include <QColorDialog>
56 #include <QMessageBox>
57 #include <QPainter>
58 #include <QValidator>
59 
60 // STL
61 #include <cassert>
62 
64 
65 te::qt::widgets::ColorMapWidget::ColorMapWidget(QWidget* parent, Qt::WindowFlags f)
66  : QWidget(parent, f),
67  m_ui(new Ui::ColorMapWidgetForm),
68  m_cm(0),
69  m_cb(0),
70  m_raster(0)
71 {
72  m_ui->setupUi(this);
73 
74  QGridLayout* l = new QGridLayout(m_ui->m_colorBarWidget);
75  l->setContentsMargins(0,0,0,0);
76  m_colorBar = new te::qt::widgets::ColorCatalogWidget(m_ui->m_colorBarWidget);
77  l->addWidget(m_colorBar);
78 
79  m_ui->m_minValueLineEdit->setValidator(new QDoubleValidator(this));
80  m_ui->m_maxValueLineEdit->setValidator(new QDoubleValidator(this));
81 
82  initialize();
83 
84  // Signals & slots
85  connect(m_colorBar, SIGNAL(colorBarChanged()), this, SLOT(onApplyPushButtonClicked()));
86  connect(m_ui->m_bandComboBox, SIGNAL(activated(QString)), this, SLOT(onBandSelected(QString)));
87  connect(m_ui->m_applyPushButton, SIGNAL(clicked()), this, SLOT(onApplyPushButtonClicked()));
88  connect(m_ui->m_tableWidget, SIGNAL(itemDoubleClicked(QTableWidgetItem*)), this, SLOT(onTableWidgetItemDoubleClicked(QTableWidgetItem*)));
89  connect(m_ui->m_importPushButton, SIGNAL(clicked()), this, SLOT(onImportPushButtonClicked()));
90 }
91 
93 {
94  delete m_cb;
95 
96  delete m_cm;
97 }
98 
100 {
101  assert(r);
102 
103  m_raster = r;
104 
105  int nBands = m_raster->getNumberOfBands();
106 
107  m_ui->m_bandComboBox->clear();
108 
109  for(int i = 0; i < nBands; ++i)
110  {
111  QString strBand;
112  strBand.setNum(i);
113 
114  m_ui->m_bandComboBox->addItem(strBand);
115  }
116 
117  if(nBands > 0)
118  onBandSelected(m_ui->m_bandComboBox->itemText(0));
119 }
120 
122 {
123  assert(cm);
124 
125  m_cm = cm->clone();
126 
127  updateUi(true);
128 }
129 
131 {
132  int index = m_ui->m_transformComboBox->currentIndex();
133 
134  int type = m_ui->m_transformComboBox->itemData(index).toInt();
135 
137  {
138  buildCategorizationMap();
139  }
140  else if(type == te::se::INTERPOLATE_TRANSFORMATION)
141  {
142  buildInterpolationMap();
143  }
144  else if(type == te::se::RECODE_TRANSFORMATION)
145  {
146  buildRecodingMap();
147  }
148 
149  return m_cm->clone();
150 }
151 
153 {
154  if(m_ui->m_bandComboBox->count() != 0)
155  {
156  return m_ui->m_bandComboBox->currentText().toStdString();
157  }
158 
159  return "";
160 }
161 
163 {
164  m_colorBar->getColorBar()->setHeight(20);
165  m_colorBar->getColorBar()->setScaleVisible(false);
166 
167  m_ui->m_transformComboBox->clear();
168 
169  m_ui->m_transformComboBox->addItem(tr("Categorize"), te::se::CATEGORIZE_TRANSFORMATION);
170  m_ui->m_transformComboBox->addItem(tr("Interpolate"), te::se::INTERPOLATE_TRANSFORMATION);
171  //m_ui->m_transformComboBox->addItem(tr("Recode"), te::se::RECODE_TRANSFORMATION);
172 }
173 
175 {
176  m_ui->m_tableWidget->setRowCount(0);
177 
178  if(!m_cm)
179  {
180  return;
181  }
182 
183  te::color::ColorBar* cb = 0;
184 
185  if(m_cm->getCategorize())
186  {
187  for(int i = 0; i < m_ui->m_transformComboBox->count(); ++i)
188  {
189  if(m_ui->m_transformComboBox->itemData(i).toInt() == te::se::CATEGORIZE_TRANSFORMATION)
190  m_ui->m_transformComboBox->setCurrentIndex(i);
191  }
192 
193  std::vector<te::se::ParameterValue*> t = m_cm->getCategorize()->getThresholds();
194  std::vector<te::se::ParameterValue*> tV = m_cm->getCategorize()->getThresholdValues();
195 
196  m_ui->m_slicesSpinBox->setValue(tV.size() - 2);
197 
198  m_ui->m_tableWidget->setRowCount(tV.size() - 2);
199 
200  te::color::RGBAColor initColor(te::se::GetString(tV[1]).c_str());
201  te::color::RGBAColor endColor(te::se::GetString(tV[tV.size() - 2]).c_str());
202 
203  if(loadColorBar)
204  cb = new te::color::ColorBar(initColor, endColor, 256);
205 
206  int count = 0;
207 
208  for(size_t i = 1; i < tV.size() - 1; ++i)
209  {
210  QColor color;
211  std::string lowerLimit = "";
212  std::string upperLimit = "";
213 
214  if(i == 0)
215  {
216  lowerLimit = "...";
217  upperLimit = te::se::GetString(t[i]);
218  color.setNamedColor(te::se::GetString(tV[i]).c_str());
219  }
220  else if(i == tV.size() - 1)
221  {
222  lowerLimit = te::se::GetString(t[i - 1]);
223  upperLimit = "...";
224  color.setNamedColor(te::se::GetString(tV[i]).c_str());
225  }
226  else
227  {
228  lowerLimit = te::se::GetString(t[i - 1]);
229  upperLimit = te::se::GetString(t[i]);
230  color.setNamedColor(te::se::GetString(tV[i]).c_str());
231  }
232 
233  if(loadColorBar)
234  {
235  if(count != 0 && count != tV.size() - 2)
236  {
237  double pos = (1. / (tV.size() - 2)) * count;
238 
239  te::color::RGBAColor color(te::se::GetString(tV[i]).c_str());
240 
241  cb->addColor(color, pos);
242  }
243  }
244 
245  ++count;
246 
247  //color
248  QPixmap pix(24, 24);
249  QPainter p(&pix);
250 
251  p.fillRect(0,0,24, 24, color);
252  p.setBrush(Qt::transparent);
253  p.setPen(Qt::black);
254  p.drawRect(0, 0, 23, 23);
255 
256  QIcon icon(pix);
257 
258  QTableWidgetItem* item = new QTableWidgetItem(pix, "");
259  item->setFlags(Qt::ItemIsEnabled);
260  m_ui->m_tableWidget->setItem(i - 1, 0, item);
261 
262  //value From
263  std::string rangeLower = lowerLimit;
264  QTableWidgetItem* itemRangeLower = new QTableWidgetItem();
265  itemRangeLower->setText(rangeLower.c_str());
266  itemRangeLower->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled|Qt::ItemIsEditable);
267  m_ui->m_tableWidget->setItem(i - 1, 1, itemRangeLower);
268 
269  //value To
270  std::string rangeUpper = upperLimit;
271  QTableWidgetItem* itemRangeUpper = new QTableWidgetItem();
272  itemRangeUpper->setText(rangeUpper.c_str());
273  itemRangeUpper->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled|Qt::ItemIsEditable);
274  m_ui->m_tableWidget->setItem(i - 1, 2, itemRangeUpper);
275 
276  ////label
277  //std::string rangeStr = lowerLimit + " to " + upperLimit;
278  //QTableWidgetItem* itemRangeStr = new QTableWidgetItem();
279  //itemRangeStr->setText(rangeStr.c_str());
280  //itemRangeStr->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled);
281  //m_ui->m_tableWidget->setItem(i - 1, 3, itemRangeStr);
282  }
283  }
284  else if(m_cm->getInterpolate())
285  {
286  for(int i = 0; i < m_ui->m_transformComboBox->count(); ++i)
287  {
288  if(m_ui->m_transformComboBox->itemData(i).toInt() == te::se::INTERPOLATE_TRANSFORMATION)
289  m_ui->m_transformComboBox->setCurrentIndex(i);
290  }
291 
292  std::vector<te::se::InterpolationPoint*> ip = m_cm->getInterpolate()->getInterpolationPoints();
293 
294  m_ui->m_slicesSpinBox->setValue(ip.size() - 1);
295 
296  m_ui->m_tableWidget->setRowCount(ip.size() - 1);
297 
298  te::color::RGBAColor initColor(te::se::GetString(ip[0]->getValue()).c_str());
299  te::color::RGBAColor endColor(te::se::GetString(ip[ip.size() - 1]->getValue()).c_str());
300 
301  if(loadColorBar)
302  cb = new te::color::ColorBar(initColor, endColor, 256);
303 
304  int count = 0;
305 
306  for(size_t i = 0; i < ip.size() - 1; ++i)
307  {
308  QColor color1;
309  QColor color2;
310  QString valStrBegin;
311  QString valStrEnd;
312 
313  te::se::InterpolationPoint* ipItem = ip[i];
314  te::se::InterpolationPoint* ipItem2 = ip[i + 1];
315 
316  color1.setNamedColor(te::se::GetString(ipItem->getValue()).c_str());
317  color2.setNamedColor(te::se::GetString(ipItem2->getValue()).c_str());
318 
319  valStrBegin.setNum(ipItem->getData());
320  valStrEnd.setNum(ipItem2->getData());
321 
322  QString valStr;
323  valStr.append(valStrBegin);
324  valStr.append(" - ");
325  valStr.append(valStrEnd);
326 
327  if(loadColorBar)
328  {
329  if(count != 0 && count != ip.size() - 1)
330  {
331  double pos = (1. / (ip.size() - 1)) * count;
332 
333  te::color::RGBAColor color(te::se::GetString(ipItem->getValue()).c_str());
334 
335  cb->addColor(color, pos);
336  }
337  }
338 
339  ++count;
340 
341  //color
342  QPixmap pix(24, 24);
343  QPainter p(&pix);
344 
345  p.fillRect(0,0,12, 24, color1);
346  p.fillRect(12,0,12, 24, color2);
347  p.setBrush(Qt::transparent);
348  p.setPen(Qt::black);
349  p.drawRect(0, 0, 23, 23);
350 
351  QIcon icon(pix);
352 
353  QTableWidgetItem* item = new QTableWidgetItem(icon, "");
354  //item->setBackgroundColor(color);
355  item->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled);
356  m_ui->m_tableWidget->setItem(i, 0, item);
357 
358  //value lower
359  QTableWidgetItem* itemRangeLower = new QTableWidgetItem();
360  itemRangeLower->setText(valStrBegin);
361  itemRangeLower->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled|Qt::ItemIsEditable);
362  m_ui->m_tableWidget->setItem(i, 1, itemRangeLower);
363 
364  //value upper
365  QTableWidgetItem* itemRangeUpper = new QTableWidgetItem();
366  itemRangeUpper->setText(valStrEnd);
367  itemRangeUpper->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled|Qt::ItemIsEditable);
368  m_ui->m_tableWidget->setItem(i, 2, itemRangeUpper);
369 
370  ////label
371  //QTableWidgetItem* itemRangeStr = new QTableWidgetItem();
372  //itemRangeStr->setText(valStr);
373  //itemRangeStr->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled|Qt::ItemIsEditable);
374  //m_ui->m_tableWidget->setItem(i, 3, itemRangeStr);
375  }
376  }
377 
378  if(cb)
379  {
380  disconnect(m_colorBar, SIGNAL(colorBarChanged()), this, SLOT(onApplyPushButtonClicked()));
381 
383  cbW->setColorBar(cb);
384 
385  connect(m_colorBar, SIGNAL(colorBarChanged()), this, SLOT(onApplyPushButtonClicked()));
386  }
387 
388  m_ui->m_tableWidget->resizeColumnsToContents();
389 #if (QT_VERSION >= 0x050000)
390  m_ui->m_tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
391 #else
392  m_ui->m_tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
393 #endif
394 }
395 
397 {
399 
400  c->setFallbackValue("#000000");
401  c->setLookupValue(new te::se::ParameterValue("Rasterdata"));
402 
403  QColor cWhite(Qt::white);
404  std::string colorWhiteStr = cWhite.name().toLatin1().data();
405 
406  //added dummy color for values < than min values...
407  c->addValue(new te::se::ParameterValue(colorWhiteStr));
408 
409  for(int i = 0; i < m_ui->m_tableWidget->rowCount(); ++i)
410  {
411  QColor color = QColor::fromRgb(m_ui->m_tableWidget->item(i, 0)->icon().pixmap(24, 24).toImage().pixel(1,1));
412 
413  std::string rangeStr = m_ui->m_tableWidget->item(i, 1)->text().toStdString();
414  std::string colorStr = color.name().toStdString();
415 
416  c->addThreshold(new te::se::ParameterValue(rangeStr));
417  c->addValue(new te::se::ParameterValue(colorStr));
418 
419  if(i == m_ui->m_tableWidget->rowCount() - 1)
420  {
421  rangeStr = m_ui->m_tableWidget->item(i, 2)->text().toStdString();
422  c->addThreshold(new te::se::ParameterValue(rangeStr));
423  }
424  }
425 
426  //added dummy color for values > than max values...
427  c->addValue(new te::se::ParameterValue(colorWhiteStr));
428 
430 
431  if(m_cm)
432  {
433  m_cm->setCategorize(c);
434  m_cm->setInterpolate(0);
435  }
436 }
437 /*
438 void te::qt::widgets::ColorMapWidget::buildCategorizationMap()
439 {
440  delete m_cb;
441 
442  m_cb = m_colorBar->getColorBar()->getColorBar();
443 
444  int sliceValue = m_ui->m_slicesSpinBox->value();
445 
446  std::vector<te::color::RGBAColor> colorVec = m_cb->getSlices(sliceValue);
447 
448  std::vector<te::map::GroupingItem*> legVec;
449 
450  std::vector<double> vec;
451  vec.push_back(m_ui->m_minValueLineEdit->text().toDouble());
452  vec.push_back(m_ui->m_maxValueLineEdit->text().toDouble());
453 
454  te::map::GroupingByEqualSteps(vec.begin(), vec.end(), sliceValue, legVec, m_ui->m_precisionSpinBox->value());
455 
456  te::se::Categorize* c = new te::se::Categorize();
457 
458  c->setFallbackValue("#000000");
459  c->setLookupValue(new te::se::ParameterValue("Rasterdata"));
460 
461  QColor cWhite(Qt::white);
462  std::string colorWhiteStr = cWhite.name().toLatin1().data();
463 
464  //added dummy color for values < than min values...
465  c->addValue(new te::se::ParameterValue(colorWhiteStr));
466 
467  for(size_t i = 0; i < colorVec.size(); ++i)
468  {
469  QColor color(colorVec[i].getRed(), colorVec[i].getGreen(), colorVec[i].getBlue(), colorVec[i].getAlpha());
470 
471  std::string rangeStr = legVec[i]->getLowerLimit();
472  std::string colorStr = color.name().toStdString();
473 
474  c->addThreshold(new te::se::ParameterValue(rangeStr));
475  c->addValue(new te::se::ParameterValue(colorStr));
476 
477  if(i == colorVec.size() - 1)
478  {
479  rangeStr = legVec[i]->getUpperLimit();
480  c->addThreshold(new te::se::ParameterValue(rangeStr));
481  }
482  }
483 
484  //added dummy color for values > than max values...
485  c->addValue(new te::se::ParameterValue(colorWhiteStr));
486 
487  c->setThresholdsBelongTo(te::se::Categorize::SUCCEEDING);
488 
489  if(m_cm)
490  {
491  m_cm->setCategorize(c);
492  m_cm->setInterpolate(0);
493  }
494 }
495 */
496 
498 {
499  te::se::Interpolate* interpolate = new te::se::Interpolate();
500 
501  interpolate->setFallbackValue("#000000");
502  interpolate->setLookupValue(new te::se::ParameterValue("Rasterdata"));
504 
505  for(int i = 0; i < m_ui->m_tableWidget->rowCount(); ++i)
506  {
507  QColor color = QColor::fromRgb(m_ui->m_tableWidget->item(i, 0)->icon().pixmap(24, 24).toImage().pixel(1,1));
508 
509  if(i == m_ui->m_tableWidget->rowCount() - 1)
510  {
511  {
512  QString rangeStr = m_ui->m_tableWidget->item(i, 1)->text();
513  std::string colorStr = color.name().toLatin1().data();
514 
516 
517  ip->setData(rangeStr.toDouble());
518  ip->setValue(new te::se::ParameterValue(colorStr));
519 
520  interpolate->add(ip);
521  }
522 
523  {
524  color = QColor::fromRgb(m_ui->m_tableWidget->item(i, 0)->icon().pixmap(24, 24).toImage().pixel(22,1));
525 
526  QString rangeStr = m_ui->m_tableWidget->item(i, 2)->text();
527  std::string colorStr = color.name().toLatin1().data();
528 
530 
531  ip->setData(rangeStr.toDouble());
532  ip->setValue(new te::se::ParameterValue(colorStr));
533 
534  interpolate->add(ip);
535  }
536 
537  }
538  else
539  {
540  QString rangeStr = m_ui->m_tableWidget->item(i, 1)->text();
541  std::string colorStr = color.name().toLatin1().data();
542 
544 
545  ip->setData(rangeStr.toDouble());
546  ip->setValue(new te::se::ParameterValue(colorStr));
547 
548  interpolate->add(ip);
549  }
550  }
551 
552  if(m_cm)
553  {
554  m_cm->setInterpolate(interpolate);
555  m_cm->setCategorize(0);
556  }
557 }
558 
559 /*
560 void te::qt::widgets::ColorMapWidget::buildInterpolationMap()
561 {
562  delete m_cb;
563 
564  m_cb = m_colorBar->getColorBar()->getColorBar();
565 
566  int sliceValue = m_ui->m_slicesSpinBox->value();
567 
568  std::vector<te::color::RGBAColor> colorVec = m_cb->getSlices(sliceValue + 1);
569 
570  std::vector<te::map::GroupingItem*> legVec;
571 
572  std::vector<double> vec;
573  vec.push_back(m_ui->m_minValueLineEdit->text().toDouble());
574  vec.push_back(m_ui->m_maxValueLineEdit->text().toDouble());
575 
576  te::map::GroupingByEqualSteps(vec.begin(), vec.end(), sliceValue, legVec, m_ui->m_precisionSpinBox->value());
577 
578 
579  te::se::Interpolate* interpolate = new te::se::Interpolate();
580 
581  interpolate->setFallbackValue("#000000");
582  interpolate->setLookupValue(new te::se::ParameterValue("Rasterdata"));
583  interpolate->setMethodType(te::se::Interpolate::COLOR);
584 
585 
586  for(size_t i = 0; i < colorVec.size(); ++i)
587  {
588  QColor color(colorVec[i].getRed(), colorVec[i].getGreen(), colorVec[i].getBlue(), colorVec[i].getAlpha());
589 
590  if(i == colorVec.size() - 1)
591  {
592  QString rangeStr = legVec[i - 1]->getUpperLimit().c_str();
593  std::string colorStr = color.name().toLatin1().data();
594 
595  te::se::InterpolationPoint* ip = new te::se::InterpolationPoint();
596 
597  ip->setData(rangeStr.toDouble());
598  ip->setValue(new te::se::ParameterValue(colorStr));
599 
600  interpolate->add(ip);
601  }
602  else
603  {
604  QString rangeStr = legVec[i]->getLowerLimit().c_str();
605  std::string colorStr = color.name().toLatin1().data();
606 
607  te::se::InterpolationPoint* ip = new te::se::InterpolationPoint();
608 
609  ip->setData(rangeStr.toDouble());
610  ip->setValue(new te::se::ParameterValue(colorStr));
611 
612  interpolate->add(ip);
613  }
614  }
615 
616  if(m_cm)
617  {
618  m_cm->setInterpolate(interpolate);
619  m_cm->setCategorize(0);
620  }
621 }
622 */
623 
625 {
626 
627 }
628 
629 
631 {
632  delete m_cb;
633 
634  m_cb = m_colorBar->getColorBar()->getColorBar();
635 
636  int sliceValue = m_ui->m_slicesSpinBox->value();
637 
638  std::vector<te::color::RGBAColor> colorVec;
639 
640  int index = m_ui->m_transformComboBox->currentIndex();
641 
642  int type = m_ui->m_transformComboBox->itemData(index).toInt();
643 
645  {
646  colorVec = m_cb->getSlices(sliceValue);
647  }
648  else if(type == te::se::INTERPOLATE_TRANSFORMATION)
649  {
650  colorVec = m_cb->getSlices(sliceValue + 1);
651  }
652 
653  std::vector<te::map::GroupingItem*> legVec;
654 
655  std::vector<double> vec;
656  vec.push_back(m_ui->m_minValueLineEdit->text().toDouble());
657  vec.push_back(m_ui->m_maxValueLineEdit->text().toDouble());
658 
659  te::map::GroupingByEqualSteps(vec.begin(), vec.end(), sliceValue, legVec, m_ui->m_precisionSpinBox->value());
660 
661  m_ui->m_tableWidget->setRowCount(legVec.size());
662 
663  for(std::size_t t = 0; t < legVec.size(); ++t)
664  {
666  {
667  //color
668  QColor color(colorVec[t].getRed(), colorVec[t].getGreen(), colorVec[t].getBlue(), colorVec[t].getAlpha());
669 
670  QPixmap pix(24, 24);
671  QPainter p(&pix);
672 
673  p.fillRect(0,0,24, 24, color);
674  p.setBrush(Qt::transparent);
675  p.setPen(Qt::black);
676  p.drawRect(0, 0, 23, 23);
677 
678  QIcon icon(pix);
679 
680  QTableWidgetItem* item = new QTableWidgetItem(icon, "");
681  item->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled);
682  m_ui->m_tableWidget->setItem(t, 0, item);
683  }
684  else if(type == te::se::INTERPOLATE_TRANSFORMATION)
685  {
686  QColor color1(colorVec[t].getRed(), colorVec[t].getGreen(), colorVec[t].getBlue(), colorVec[t].getAlpha());
687  QColor color2(colorVec[t + 1].getRed(), colorVec[t + 1].getGreen(), colorVec[t + 1].getBlue(), colorVec[t + 1].getAlpha());
688 
689  QPixmap pix(24, 24);
690  QPainter p(&pix);
691 
692  p.fillRect(0,0,12, 24, color1);
693  p.fillRect(12,0,12, 24, color2);
694 
695  p.setBrush(Qt::transparent);
696  p.setPen(Qt::black);
697  p.drawRect(0, 0, 23, 23);
698 
699  QIcon icon(pix);
700 
701  QTableWidgetItem* item = new QTableWidgetItem(icon, "");
702  item->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled);
703  m_ui->m_tableWidget->setItem(t, 0, item);
704  }
705 
706  //value lower
707  std::string rangeStrLower = legVec[t]->getLowerLimit();
708 
709  QTableWidgetItem* itemRangeLower = new QTableWidgetItem();
710  itemRangeLower->setText(rangeStrLower.c_str());
711  itemRangeLower->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled|Qt::ItemIsEditable);
712  m_ui->m_tableWidget->setItem(t, 1, itemRangeLower);
713 
714  //value upper
715  std::string rangeStrUpper = legVec[t]->getUpperLimit();
716 
717  QTableWidgetItem* itemRangeUpper = new QTableWidgetItem();
718  itemRangeUpper->setText(rangeStrUpper.c_str());
719  itemRangeUpper->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled|Qt::ItemIsEditable);
720  m_ui->m_tableWidget->setItem(t, 2, itemRangeUpper);
721 
722  ////label
723  //std::string valStr = rangeStrLower + " - " + rangeStrUpper;
724 
725  //QTableWidgetItem* itemRangeStr = new QTableWidgetItem();
726  //itemRangeStr->setText(valStr.c_str());
727  //itemRangeStr->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled);
728  //m_ui->m_tableWidget->setItem(t, 3, itemRangeStr);
729  }
730 
731  m_ui->m_tableWidget->resizeColumnsToContents();
732 #if (QT_VERSION >= 0x050000)
733  m_ui->m_tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
734 #else
735  m_ui->m_tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
736 #endif
737 
738  emit applyPushButtonClicked();
739 }
740 
742 {
743  if(value.isEmpty())
744  {
745  return;
746  }
747 
750  const std::complex<double>* cmin = rsMin->at(0).m_minVal;
751  const std::complex<double>* cmax = rsMax->at(0).m_maxVal;
752  double min = cmin->real();
753  double max = cmax->real();
754 
755  QString strMin;
756  strMin.setNum(min);
757  m_ui->m_minValueLineEdit->setText(strMin);
758 
759  QString strMax;
760  strMax.setNum(max);
761  m_ui->m_maxValueLineEdit->setText(strMax);
762 
763  emit applyPushButtonClicked();
764 }
765 
767 {
768  int curCol = m_ui->m_tableWidget->currentColumn();
769 
770  int index = m_ui->m_transformComboBox->currentIndex();
771 
772  int type = m_ui->m_transformComboBox->itemData(index).toInt();
773 
774  if(curCol == 0)
775  {
777  {
778  QColor bgColor = QColor::fromRgb(item->icon().pixmap(24, 24).toImage().pixel(1,1));
779 
780  QColor newBgColor = QColorDialog::getColor(bgColor, m_ui->m_tableWidget);
781 
782  if(newBgColor.isValid())
783  bgColor = newBgColor;
784 
785  QPixmap pix(24, 24);
786  pix.fill(bgColor);
787  QIcon icon(pix);
788 
789  item->setIcon(icon);
790  }
791  else if(type == te::se::INTERPOLATE_TRANSFORMATION)
792  {
793  QMessageBox::information(this, tr("Classification"),
794  tr("Set the colors for the min and max values of this range. Also necessary to change the colors equivalents at another level to maintain consistency."));
795 
796  QColor color1 = QColor::fromRgb(item->icon().pixmap(24, 24).toImage().pixel(1,1));
797 
798  QColor newBgColor = QColorDialog::getColor(color1, m_ui->m_tableWidget);
799 
800  if(newBgColor.isValid())
801  color1 = newBgColor;
802 
803  QColor color2 = QColor::fromRgb(item->icon().pixmap(24, 24).toImage().pixel(22,1));
804 
805  newBgColor = QColorDialog::getColor(color2, m_ui->m_tableWidget);
806 
807  if(newBgColor.isValid())
808  color2 = newBgColor;
809 
810  QPixmap pix(24, 24);
811  QPainter p(&pix);
812 
813  p.fillRect(0,0,12, 24, color1);
814  p.fillRect(12,0,12, 24, color2);
815 
816  QIcon icon(pix);
817 
818  item->setIcon(icon);
819  }
820  }
821 
822  emit applyPushButtonClicked();
823 }
824 
826 {
827  te::se::RasterSymbolizer* symb = 0;
828 
829  if(layer->getType() == "DATASETLAYER")
830  {
831  te::map::DataSetLayer* l = dynamic_cast<te::map::DataSetLayer*>(layer.get());
832 
833  if(l)
834  {
836  }
837  }
838  else if(layer->getType() == "RASTERLAYER")
839  {
840  te::map::RasterLayer* l = dynamic_cast<te::map::RasterLayer*>(layer.get());
841 
842  if(l)
843  {
845  }
846  }
847 
848  if(symb)
849  {
850  if(symb->getColorMap())
851  {
852  return symb->getColorMap();
853  }
854  }
855 
856  return 0;
857 }
858 
860 {
861  if(layer->getType() == "DATASETLAYER")
862  {
863  te::map::DataSetLayer* l = dynamic_cast<te::map::DataSetLayer*>(layer.get());
864 
865  if(l)
866  {
867  std::auto_ptr<te::da::DataSet> ds = layer->getData();
868 
869  if(ds.get())
870  {
871  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
872  return ds->getRaster(rpos).release();
873  }
874  }
875  }
876  else if(layer->getType() == "RASTERLAYER")
877  {
878  te::map::RasterLayer* l = dynamic_cast<te::map::RasterLayer*>(layer.get());
879 
880  if(l)
881  {
882  return l->getRaster();
883  }
884  }
885 
886  return 0;
887 }
888 
889 void te::qt::widgets::ColorMapWidget::setLayers(te::map::AbstractLayerPtr selectedLayer, std::vector<te::map::AbstractLayerPtr> allLayers)
890 {
891  for(std::size_t i = 0; i < allLayers.size(); ++i)
892  {
893  std::auto_ptr<te::da::DataSetType> dt(allLayers[i]->getSchema());
894 
895  if(dt->hasRaster() && getLayerColorMap(allLayers[i]) && allLayers[i]->getId() != selectedLayer->getId())
896  {
897  m_ui->m_layersComboBox->addItem(allLayers[i]->getTitle().c_str(), QVariant::fromValue(allLayers[i]));
898  }
899  }
900 }
901 
903 {
904  if(m_ui->m_layersComboBox->currentText() == "")
905  {
906  QMessageBox::warning(this, tr("Grouping"), tr("There are no other layers with Grouping!"));
907  return;
908  }
909 
910  QVariant varLayer = m_ui->m_layersComboBox->itemData(m_ui->m_layersComboBox->currentIndex(), Qt::UserRole);
911  te::map::AbstractLayerPtr layer = varLayer.value<te::map::AbstractLayerPtr>();
912 
913  te::se::ColorMap* cm = getLayerColorMap(layer);
914 
915  setRaster(getLayerRaster(layer));
916  setColorMap(cm);
917 
918  updateUi(true);
919 
920  emit applyPushButtonClicked();
921 }
ParameterValue * getValue() const
ColorMap * clone() const
Definition: ColorMap.cpp:80
The transformation of continuous values to distinct values (Categorize function). ...
Definition: Categorize.h:90
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr)
void setData(const double &d)
void setMethodType(MethodType t)
Definition: Interpolate.cpp:86
TESEEXPORT RasterSymbolizer * GetRasterSymbolizer(Style *s)
Try to get raster symbolizer from a style.
Definition: Utils.cpp:371
te::rst::Raster * getRaster() const
void addColor(const RGBAColor &color, const double &pos)
It adds a color in the color bar.
Definition: ColorBar.cpp:264
void setLookupValue(ParameterValue *v)
Definition: Categorize.cpp:81
void onTableWidgetItemDoubleClicked(QTableWidgetItem *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.
The transformation of continuous values to a number of values (Interpolate function).
Definition: Interpolate.h:88
The "ParameterValueType" uses WFS-Filter expressions to give values for SE graphic parameters...
A widget used to build.
void setColorBar(te::color::ColorBar *cb)
It sets the color bar.
Definition: ColorBar.cpp:108
void setValue(ParameterValue *v)
std::auto_ptr< te::da::DataSet > getData(te::common::TraverseType travType=te::common::FORWARDONLY, const te::common::AccessPolicy accessPolicy=te::common::RAccess) const
It gets the dataset identified by the layer name.
void setLookupValue(ParameterValue *v)
Definition: Interpolate.cpp:70
A layer with reference to a raster.
Definition: RasterLayer.h:52
ColorMapWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a ShadedReliefWidget dialog which is a child of parent, with widget flags set to f...
void updateUi(bool loadColorBar=false)
Updates the widget form based on internal fill element.
static RasterSummaryManager & getInstance()
It returns a reference to the singleton instance.
void setColorMap(te::se::ColorMap *cm)
void add(InterpolationPoint *i)
Definition: Interpolate.cpp:76
An abstract class for raster data strucutures.
Definition: Raster.h:71
void onBandSelected(QString value)
virtual te::se::Style * getStyle() const
It returns the Style associated to the layer.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
boost::ptr_vector< BandSummary > RasterSummary
RasterSummary is just a typedef of a boost::ptr_vector.
Definition: RasterSummary.h:44
te::se::ColorMap * getLayerColorMap(te::map::AbstractLayerPtr layer)
It QWidget implementation of color bar.
Definition: ColorBar.h:67
void setRaster(te::rst::Raster *r)
The RasterSymbolizer describes how to render raster/matrix-coverage data (e.g., satellite photos...
void initialize()
Internal method to initialize the widget (e.g.: color, combos, icons, etc.)
They are used to define a graph of points.
te::qt::widgets::ColorCatalogWidget * m_colorBar
Widget used to pick a color.
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
te::rst::Raster * getLayerRaster(te::map::AbstractLayerPtr layer)
void setLayers(te::map::AbstractLayerPtr selectedLayer, std::vector< te::map::AbstractLayerPtr > allLayers)
te::se::ColorMap * getColorMap()
It models the concept of color bar.
Definition: ColorBar.h:49
std::auto_ptr< Ui::ColorMapWidgetForm > m_ui
Dialog form.
te::se::ColorMap * getColorMap() const
A layer with reference to a dataset.
Definition: DataSetLayer.h:47
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
Definition: Utils.cpp:481
Calculate the min value.
Definition: Enums.h:40
Calculate the max value.
Definition: Enums.h:41
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void setThresholdsBelongTo(ThresholdsBelongToType t)
Definition: Categorize.cpp:104
void addThreshold(ParameterValue *v)
Definition: Categorize.cpp:94
TESEEXPORT std::string GetString(const te::se::ParameterValue *param)
It gets the parameter value as a string.
Definition: Utils.cpp:453
A ColorMap defines either the colors of a pallette-type raster source or the mapping of numeric pixel...
Definition: ColorMap.h:60
void addValue(ParameterValue *v)
Definition: Categorize.cpp:99
void setFallbackValue(const std::string &v)
Definition: Function.cpp:37