All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ArithmeticOpWizardPage.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/ArithmeticOpWizardPage.cpp
22 
23  \brief This file defines a class for a ArithmeticOp Wizard page.
24 */
25 
26 // TerraLib
27 #include "../../../dataaccess/dataset/DataSet.h"
28 #include "../../../dataaccess/utils/Utils.h"
29 #include "ArithmeticOpWizard.h"
30 #include "ArithmeticOpWizardPage.h"
31 #include "ui_ArithmeticOpWizardPageForm.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::ArithmeticOpWizardPageForm)
46 {
47 // setup controls
48  m_ui->setupUi(this);
49 
50 //configure page
51  this->setTitle(tr("Arithmetic Operations"));
52  this->setSubTitle(tr("Select the type of arithmetic operation and set their specific parameters."));
53 
54  m_ui->m_valueLineEdit->setValidator(new QDoubleValidator(this));
55  m_ui->m_gainLineEdit->setValidator(new QDoubleValidator(this));
56  m_ui->m_offsetLineEdit->setValidator(new QDoubleValidator(this));
57 
58  m_ui->m_addValueOpToolButton->setIcon(QIcon::fromTheme("list-add"));
59  m_ui->m_addRasterOpToolButton->setIcon(QIcon::fromTheme("list-add"));
60  m_ui->m_undoToolButton->setIcon(QIcon::fromTheme("edit-undo"));
61  m_ui->m_redoToolButton->setIcon(QIcon::fromTheme("edit-redo"));
62  m_ui->m_clearToolButton->setIcon(QIcon::fromTheme("edit-clear"));
63  m_ui->m_validateToolButton->setIcon(QIcon::fromTheme("check"));
64 
66 
67  m_ui->m_undoToolButton->setEnabled(false);
68  m_ui->m_redoToolButton->setEnabled(false);
69 
70  m_ui->m_tabWidget->removeTab(1);
71 
72  //connects
73  connect(m_ui->m_layerComboBox, SIGNAL(activated(int)), this, SLOT(layerComboBoxActivated(int)));
74  connect(m_ui->m_layerAComboBox, SIGNAL(activated(int)), this, SLOT(layerAComboBoxActivated(int)));
75  connect(m_ui->m_layerBComboBox, SIGNAL(activated(int)), this, SLOT(layerBComboBoxActivated(int)));
76 
77  connect(m_ui->m_leftBracketToolButton, SIGNAL(clicked()), this, SLOT(leftBracketToolButtonClicked()));
78  connect(m_ui->m_rightBracketToolButton, SIGNAL(clicked()), this, SLOT(rightBracketToolButtonClicked()));
79  connect(m_ui->m_plusToolButton, SIGNAL(clicked()), this, SLOT(plusToolButtonClicked()));
80  connect(m_ui->m_minusToolButton, SIGNAL(clicked()), this, SLOT(minusToolButtonClicked()));
81  connect(m_ui->m_multiToolButton, SIGNAL(clicked()), this, SLOT(multiToolButtonClicked()));
82  connect(m_ui->m_divToolButton, SIGNAL(clicked()), this, SLOT(divToolButtonClicked()));
83 
84  connect(m_ui->m_addValueOpToolButton, SIGNAL(clicked()), this, SLOT(addValueOpToolButtonClicked()));
85  connect(m_ui->m_addRasterOpToolButton, SIGNAL(clicked()), this, SLOT(addRasterOpToolButtonClicked()));
86 
87  connect(m_ui->m_undoToolButton, SIGNAL(clicked()), this, SLOT(undoToolButtonClicked()));
88  connect(m_ui->m_redoToolButton, SIGNAL(clicked()), this, SLOT(redoToolButtonClicked()));
89  connect(m_ui->m_clearToolButton, SIGNAL(clicked()), this, SLOT(clearToolButtonClicked()));
90  connect(m_ui->m_validateToolButton, SIGNAL(clicked()), this, SLOT(validateToolButtonClicked()));
91 
92 }
93 
95 {
96  m_expressionHistory.clear();
97 }
98 
100 {
101  return true;
102 }
103 
104 
105 void te::qt::widgets::ArithmeticOpWizardPage::setList(std::list<te::map::AbstractLayerPtr>& layerList)
106 {
107  m_layerList = layerList;
108 
109  //fill layer combo
110  m_ui->m_layerComboBox->clear();
111  m_ui->m_layerAComboBox->clear();
112  m_ui->m_layerBComboBox->clear();
113  m_ui->m_rasterIdComboBox->clear();
114 
115  std::list<te::map::AbstractLayerPtr>::iterator it = m_layerList.begin();
116  std::vector<std::size_t> bands;
117 
118  int count = 0;
119 
120  while(it != m_layerList.end())
121  {
123 
124  std::auto_ptr<te::da::DataSetType> dst = l->getSchema();
125 
126  if(dst.get() && dst->hasRaster())
127  {
128  m_ui->m_layerComboBox->addItem(l->getTitle().c_str(), QVariant::fromValue(l));
129  m_ui->m_layerAComboBox->addItem(l->getTitle().c_str(), QVariant::fromValue(l));
130  m_ui->m_layerBComboBox->addItem(l->getTitle().c_str(), QVariant::fromValue(l));
131 
132  m_ui->m_rasterIdComboBox->addItem("R" + QString::number(count));
133 
134  ++count;
135  }
136 
137  ++it;
138  }
139 
140  layerComboBoxActivated(0);
141  layerAComboBoxActivated(0);
142  layerBComboBoxActivated(0);
143 }
144 
146 {
147  int type = -1;
148 
149  if(m_ui->m_tabWidget->currentIndex() == 1)
150  {
152  }
153  else if(m_ui->m_op1RadioButton->isChecked())
155  else if(m_ui->m_op2RadioButton->isChecked())
157  else if(m_ui->m_op3RadioButton->isChecked())
159  else if(m_ui->m_op4RadioButton->isChecked())
161  else if(m_ui->m_op5RadioButton->isChecked())
163  else if(m_ui->m_op6RadioButton->isChecked())
165 
166 
167  return type;
168 }
169 
171 {
172  int curIdx = m_ui->m_layerAComboBox->currentIndex();
173  QVariant varLayer = m_ui->m_layerAComboBox->itemData(curIdx, Qt::UserRole);
175 
176  return l;
177 }
178 
180 {
181  return m_ui->m_bandAComboBox->currentText().toInt();
182 }
183 
185 {
186  int curIdx = m_ui->m_layerBComboBox->currentIndex();
187  QVariant varLayer = m_ui->m_layerBComboBox->itemData(curIdx, Qt::UserRole);
189 
190  return l;
191 }
192 
194 {
195  return m_ui->m_bandBComboBox->currentText().toInt();
196 }
197 
199 {
200  double val = 1.;
201 
202  if(!m_ui->m_gainLineEdit->text().isEmpty())
203  val = m_ui->m_gainLineEdit->text().toDouble();
204 
205  return val;
206 }
207 
209 {
210  double val = 0.;
211 
212  if(!m_ui->m_offsetLineEdit->text().isEmpty())
213  val = m_ui->m_offsetLineEdit->text().toDouble();
214 
215  return val;
216 }
217 
219 {
220  return m_ui->m_normalizeCheckBox->isChecked();
221 }
222 
224 {
225  return m_ui->m_expressionLineEdit->text().toLatin1().data();
226 }
227 
229 {
230  getRasterBands(m_ui->m_layerComboBox, index, m_ui->m_bandComboBox);
231 
232  m_ui->m_rasterIdComboBox->setCurrentIndex(index);
233 }
234 
236 {
237  getRasterBands(m_ui->m_layerAComboBox, index, m_ui->m_bandAComboBox);
238 }
239 
241 {
242  getRasterBands(m_ui->m_layerBComboBox, index, m_ui->m_bandBComboBox);
243 }
244 
246 {
247  m_ui->m_expressionLineEdit->insert("( ");
248 
249  updateExpressionHistory();
250 }
251 
253 {
254  m_ui->m_expressionLineEdit->insert(") ");
255 
256  updateExpressionHistory();
257 }
258 
260 {
261  m_ui->m_expressionLineEdit->insert("+ ");
262 
263  updateExpressionHistory();
264 }
265 
267 {
268  m_ui->m_expressionLineEdit->insert("- ");
269 
270  updateExpressionHistory();
271 }
272 
274 {
275  m_ui->m_expressionLineEdit->insert("* ");
276 
277  updateExpressionHistory();
278 }
279 
281 {
282  m_ui->m_expressionLineEdit->insert("/ ");
283 
284  updateExpressionHistory();
285 }
286 
288 {
289  m_ui->m_expressionLineEdit->insert(m_ui->m_valueLineEdit->text() + " ");
290 
291  updateExpressionHistory();
292 }
293 
295 {
296  m_ui->m_expressionLineEdit->insert(m_ui->m_rasterIdComboBox->currentText() + ":" + m_ui->m_bandComboBox->currentText() + " ");
297 
298  updateExpressionHistory();
299 }
300 
302 {
303  --m_expressionHistoryCounter;
304 
305  if(m_expressionHistoryCounter >= (int)m_expressionHistory.size() || m_expressionHistoryCounter < 0)
306  {
307  m_expressionHistoryCounter = 0;
308 
309  m_expressionHistory.clear();
310 
311  m_ui->m_expressionLineEdit->clear();
312 
313  m_ui->m_undoToolButton->setEnabled(false);
314  m_ui->m_redoToolButton->setEnabled(false);
315 
316  return;
317  }
318 
319  std::string expression = m_expressionHistory[m_expressionHistoryCounter];
320 
321  m_ui->m_expressionLineEdit->setText(expression.c_str());
322 
323  if(m_expressionHistoryCounter < 0)
324  m_ui->m_undoToolButton->setEnabled(false);
325 
326  m_ui->m_redoToolButton->setEnabled(true);
327 }
328 
330 {
331  ++m_expressionHistoryCounter;
332 
333  if(m_expressionHistoryCounter >= (int)m_expressionHistory.size() || m_expressionHistoryCounter < 0)
334  {
335  m_expressionHistoryCounter = (int)m_expressionHistory.size() - 1;
336 
337  m_ui->m_redoToolButton->setEnabled(false);
338 
339  return;
340  }
341 
342  std::string expression = m_expressionHistory[m_expressionHistoryCounter];
343 
344  m_ui->m_expressionLineEdit->setText(expression.c_str());
345 
346  if(m_expressionHistoryCounter >= (int)m_expressionHistory.size() - 1)
347  m_ui->m_redoToolButton->setEnabled(false);
348 
349  m_ui->m_undoToolButton->setEnabled(true);
350 }
351 
353 {
354  m_expressionHistoryCounter = 0;
355 
356  m_expressionHistory.clear();
357 
358  m_ui->m_expressionLineEdit->clear();
359 
360  m_ui->m_undoToolButton->setEnabled(false);
361  m_ui->m_redoToolButton->setEnabled(false);
362 }
363 
365 {
366 }
367 
368 void te::qt::widgets::ArithmeticOpWizardPage::getRasterBands(QComboBox* layer, int index, QComboBox* band)
369 {
370  //get layer
371  QVariant varLayer = layer->itemData(index, Qt::UserRole);
373 
374  //get raster
375  std::auto_ptr<te::da::DataSet> ds = l->getData();
376  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
377  std::auto_ptr<te::rst::Raster> rst = ds->getRaster(rpos);
378 
379  //fill band info
380  if(rst.get())
381  {
382  band->clear();
383 
384  for(std::size_t t = 0; t < rst->getNumberOfBands(); ++t)
385  band->addItem(QString::number(t));
386  }
387 }
388 
390 {
391  m_expressionHistory.push_back(m_ui->m_expressionLineEdit->text().toLatin1().data());
392 
393  m_ui->m_undoToolButton->setEnabled(true);
394  m_ui->m_redoToolButton->setEnabled(false);
395 
396  m_expressionHistoryCounter = (int)m_expressionHistory.size() - 1;
397 }
void setList(std::list< te::map::AbstractLayerPtr > &layerList)
This file defines a class for a ArithmeticOp Wizard page.
A Qt dialog that allows users to run a arithmeticOp operation defined by RP module.
std::auto_ptr< Ui::ArithmeticOpWizardPageForm > m_ui
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr)
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
Definition: Utils.cpp:481
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void getRasterBands(QComboBox *layer, int index, QComboBox *band)