All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ColorTransformWizardPage.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/rp/ColorTransformWizardPage.cpp
22 
23  \brief This file defines a class for a ColorTransform Wizard page.
24 */
25 
26 // TerraLib
27 #include "../../../dataaccess/dataset/DataSet.h"
28 #include "../../../dataaccess/utils/Utils.h"
29 #include "../../../raster/Utils.h"
31 #include "ui_ColorTransformWizardPageForm.h"
32 
33 // Qt
34 #include <QApplication>
35 #include <QGridLayout>
36 #include <QMessageBox>
37 
38 // stl
39 #include <memory>
40 
42 
44  : QWizardPage(parent),
45  m_ui(new Ui::ColorTransformWizardPageForm)
46 {
47 // setup controls
48  m_ui->setupUi(this);
49 
51 
52 //configure page
53  this->setTitle(tr("Color Transform"));
54  this->setSubTitle(tr("Select the type of color transformation and set their specific parameters."));
55 
56  m_ui->m_rgbMinLineEdit->setValidator(new QDoubleValidator(this));
57  m_ui->m_rgbMaxLineEdit->setValidator(new QDoubleValidator(this));
58  m_ui->m_ihsMinLineEdit->setValidator(new QDoubleValidator(this));
59  m_ui->m_ihsMaxLineEdit->setValidator(new QDoubleValidator(this));
60 
61  //connects
62  connect(m_ui->m_rgbRComboBox, SIGNAL(activated(int)), this, SLOT(rgbRComboBoxActivated(int)));
63  connect(m_ui->m_rgbGComboBox, SIGNAL(activated(int)), this, SLOT(rgbGComboBoxActivated(int)));
64  connect(m_ui->m_rgbBComboBox, SIGNAL(activated(int)), this, SLOT(rgbBComboBoxActivated(int)));
65 
66  connect(m_ui->m_ihsIComboBox, SIGNAL(activated(int)), this, SLOT(ihsIComboBoxActivated(int)));
67  connect(m_ui->m_ihsHComboBox, SIGNAL(activated(int)), this, SLOT(ihsHComboBoxActivated(int)));
68  connect(m_ui->m_ihsSComboBox, SIGNAL(activated(int)), this, SLOT(ihsSComboBoxActivated(int)));
69 }
70 
72 {
73 
74 }
75 
77 {
78  return true;
79 }
80 
82 {
83  int idx = m_ui->m_colorTransformTypeComboBox->currentIndex();
84 
85  int type = m_ui->m_colorTransformTypeComboBox->itemData(idx).toInt();
86 
87  return (type == COLORTRANSFORM_RGB2IHS);
88 }
89 
91 {
92  int idx = m_ui->m_colorTransformTypeComboBox->currentIndex();
93 
94  int type = m_ui->m_colorTransformTypeComboBox->itemData(idx).toInt();
95 
96  return (type == COLORTRANSFORM_IHS2RGB);
97 }
98 
100 {
101  //TEMPORARY USE ONLY ONE LAYER
102 
103  QVariant varLayer = m_ui->m_rgbRComboBox->itemData(0, Qt::UserRole);
105  std::auto_ptr<te::da::DataSet> ds = l->getData();
106  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
107 
108  return ds->getRaster(rpos).release();
109 }
110 
112 {
113  return m_ui->m_rgbRBandComboBox->currentText().toUInt();
114 }
115 
117 {
118  return m_ui->m_rgbGBandComboBox->currentText().toUInt();
119 }
120 
122 {
123  return m_ui->m_rgbBBandComboBox->currentText().toUInt();
124 }
125 
127 {
128  return m_ui->m_rgbMinLineEdit->text().isEmpty() ? 0 : m_ui->m_rgbMinLineEdit->text().toDouble();
129 }
130 
132 {
133  return m_ui->m_rgbMaxLineEdit->text().isEmpty() ? 255 : m_ui->m_rgbMaxLineEdit->text().toDouble();
134 }
135 
137 {
138  //TEMPORARY USE ONLY ONE LAYER
139 
140  QVariant varLayer = m_ui->m_ihsIComboBox->itemData(0, Qt::UserRole);
142  std::auto_ptr<te::da::DataSet> ds = l->getData();
143  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
144 
145  return ds->getRaster(rpos).release();
146 }
147 
149 {
150  return m_ui->m_ihsIBandComboBox->currentText().toUInt();
151 }
152 
154 {
155  return m_ui->m_ihsHBandComboBox->currentText().toUInt();
156 }
157 
159 {
160  return m_ui->m_ihsSBandComboBox->currentText().toUInt();
161 }
162 
164 {
165  return m_ui->m_ihsMinLineEdit->text().isEmpty() ? 0 : m_ui->m_ihsMinLineEdit->text().toDouble();
166 }
167 
169 {
170  return m_ui->m_ihsMaxLineEdit->text().isEmpty() ? 255 : m_ui->m_ihsMaxLineEdit->text().toDouble();
171 }
172 
173 void te::qt::widgets::ColorTransformWizardPage::setList(std::list<te::map::AbstractLayerPtr>& layerList)
174 {
175  m_layerList = layerList;
176 
177  //fill layer combos
178  m_ui->m_rgbRComboBox->clear();
179  m_ui->m_rgbGComboBox->clear();
180  m_ui->m_rgbBComboBox->clear();
181 
182  m_ui->m_ihsIComboBox->clear();
183  m_ui->m_ihsHComboBox->clear();
184  m_ui->m_ihsSComboBox->clear();
185 
186  std::list<te::map::AbstractLayerPtr>::iterator it = m_layerList.begin();
187  std::vector<std::size_t> bands;
188 
189  while(it != m_layerList.end())
190  {
192 
193  std::auto_ptr<te::da::DataSetType> dst = l->getSchema();
194 
195  if(dst.get() && dst->hasRaster())
196  {
197  m_ui->m_rgbRComboBox->addItem(l->getTitle().c_str(), QVariant::fromValue(l));
198  m_ui->m_rgbGComboBox->addItem(l->getTitle().c_str(), QVariant::fromValue(l));
199  m_ui->m_rgbBComboBox->addItem(l->getTitle().c_str(), QVariant::fromValue(l));
200 
201  m_ui->m_ihsIComboBox->addItem(l->getTitle().c_str(), QVariant::fromValue(l));
202  m_ui->m_ihsHComboBox->addItem(l->getTitle().c_str(), QVariant::fromValue(l));
203  m_ui->m_ihsSComboBox->addItem(l->getTitle().c_str(), QVariant::fromValue(l));
204  }
205 
206  ++it;
207  }
208 
209  rgbRComboBoxActivated(0);
210  rgbGComboBoxActivated(0);
211  rgbBComboBoxActivated(0);
212 
213  ihsIComboBoxActivated(0);
214  ihsHComboBoxActivated(0);
215  ihsSComboBoxActivated(0);
216 }
217 
219 {
220  getRasterBands(m_ui->m_rgbRComboBox, index, m_ui->m_rgbRBandComboBox);
221 }
222 
224 {
225  getRasterBands(m_ui->m_rgbGComboBox, index, m_ui->m_rgbGBandComboBox);
226 }
227 
229 {
230  getRasterBands(m_ui->m_rgbBComboBox, index, m_ui->m_rgbBBandComboBox);
231 }
232 
234 {
235  getRasterBands(m_ui->m_ihsIComboBox, index, m_ui->m_ihsIBandComboBox);
236 }
237 
239 {
240  getRasterBands(m_ui->m_ihsHComboBox, index, m_ui->m_ihsHBandComboBox);
241 }
242 
244 {
245  getRasterBands(m_ui->m_ihsSComboBox, index, m_ui->m_ihsSBandComboBox);
246 }
247 
249 {
250  //colorTransform types
251  m_ui->m_colorTransformTypeComboBox->clear();
252 
253  m_ui->m_colorTransformTypeComboBox->addItem(tr("RGB - IHS"), COLORTRANSFORM_RGB2IHS);
254  m_ui->m_colorTransformTypeComboBox->addItem(tr("IHS - RGB"), COLORTRANSFORM_IHS2RGB);
255 }
256 
257 void te::qt::widgets::ColorTransformWizardPage::getRasterBands(QComboBox* layer, int index, QComboBox* band)
258 {
259  //get layer
260  QVariant varLayer = layer->itemData(index, Qt::UserRole);
262 
263  //get raster
264  std::auto_ptr<te::da::DataSet> ds = l->getData();
265  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
266  std::auto_ptr<te::rst::Raster> rst = ds->getRaster(rpos);
267 
268  //fill band info
269  if(rst.get())
270  {
271  band->clear();
272 
273  for(std::size_t t = 0; t < rst->getNumberOfBands(); ++t)
274  band->addItem(QString::number(t));
275  }
276 
277  //check data type range
278  double min, max;
279 
280  te::rst::GetDataTypeRanges(rst->getBandDataType(0), min, max);
281 
282  m_ui->m_rgbMinLineEdit->setText(QString::number(min));
283  m_ui->m_ihsMinLineEdit->setText(QString::number(min));
284 
285  m_ui->m_rgbMaxLineEdit->setText(QString::number(max));
286  m_ui->m_ihsMaxLineEdit->setText(QString::number(max));
287 }
288 
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr)
void getRasterBands(QComboBox *layer, int index, QComboBox *band)
TERASTEREXPORT void GetDataTypeRanges(const int &dataType, double &min, double &max)
Return the values range of a given data type.
Definition: Utils.cpp:334
This file defines a class for a ColorTransform Wizard page.
An abstract class for raster data strucutures.
Definition: Raster.h:71
std::auto_ptr< Ui::ColorTransformWizardPageForm > m_ui
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
Definition: Utils.cpp:481
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void setList(std::list< te::map::AbstractLayerPtr > &layerList)