All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MaskDialog.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/MaskDialog.cpp
22 
23  \brief This file defines a class for a MaskDialog.
24 */
25 
26 // TerraLib
27 #include "MaskDialog.h"
28 #include "ui_MaskDialogForm.h"
29 
30 // Qt
31 #include <QGridLayout>
32 #include <QLineEdit>
33 #include <QMessageBox>
34 
35 te::qt::widgets::MaskDialog::MaskDialog(QWidget* parent, Qt::WindowFlags f)
36  : QDialog(parent, f),
37  m_ui(new Ui::MaskDialogForm)
38 {
39 //build form
40  m_ui->setupUi(this);
41 
42 //connects
43  connect(m_ui->m_okPushButton, SIGNAL(clicked()), SLOT(onOkPushButtonClicked()));
44 }
45 
47 {
48  m_matrix.clear();
49  m_window.clear();
50 }
51 
52 void te::qt::widgets::MaskDialog::setMaskSize(int height, int width, double defaultValue)
53 {
54  QGridLayout* layout = new QGridLayout(m_ui->m_widget);
55 
56  QString defaultValueStr;
57  defaultValueStr.setNum(defaultValue);
58 
59  for(int i = 0; i < height; ++i)
60  {
61  std::vector<QLineEdit*> line;
62 
63  for(int j = 0; j < width; ++j)
64  {
65  QLineEdit* lineEdit = new QLineEdit(m_ui->m_widget);
66 
67  lineEdit->setValidator(new QDoubleValidator(this));
68  lineEdit->setMaximumWidth(50);
69  lineEdit->setAlignment(Qt::AlignHCenter);
70  lineEdit->setText(defaultValueStr);
71 
72  layout->addWidget(lineEdit, i, j);
73 
74  line.push_back(lineEdit);
75  }
76 
77  m_matrix.push_back(line);
78  }
79 }
80 
81 void te::qt::widgets::MaskDialog::setMaskSize(boost::numeric::ublas::matrix<double> matrix)
82 {
83  QGridLayout* layout = new QGridLayout(m_ui->m_widget);
84 
85  for(std::size_t i = 0; i < matrix.size1(); ++i)
86  {
87  std::vector<QLineEdit*> line;
88 
89  for(std::size_t j = 0; j < matrix.size2(); ++j)
90  {
91  QLineEdit* lineEdit = new QLineEdit(m_ui->m_widget);
92 
93  lineEdit->setValidator(new QDoubleValidator(this));
94  lineEdit->setMaximumWidth(50);
95  lineEdit->setAlignment(Qt::AlignHCenter);
96 
97  QString value;
98  value.setNum(matrix(i,j));
99  lineEdit->setText(value);
100 
101  layout->addWidget(lineEdit, i, j);
102 
103  line.push_back(lineEdit);
104  }
105 
106  m_matrix.push_back(line);
107  }
108 }
109 
110 boost::numeric::ublas::matrix<double> te::qt::widgets::MaskDialog::getMatrix()
111 {
112  return m_window;
113 }
114 
116 {
117  if(m_matrix.empty())
118  {
119  QMessageBox::warning(this, tr("Warning"), tr("Matrix empty."));
120  return;
121  }
122 
123  m_window.resize(m_matrix.size(), m_matrix[0].size());
124 
125  for(std::size_t i = 0; i < m_matrix.size(); ++i)
126  {
127  for(std::size_t j = 0; j < m_matrix[i].size(); ++j)
128  {
129  QLineEdit* lineEdit = m_matrix[i][j];
130 
131  if(lineEdit->text().isEmpty())
132  {
133  QMessageBox::warning(this, tr("Warning"), tr("Matrix with empty values."));
134  return;
135  }
136 
137  m_window(i,j) = lineEdit->text().toDouble();
138  }
139  }
140 
141  accept();
142 }
std::auto_ptr< Ui::MaskDialogForm > m_ui
Definition: MaskDialog.h:79
This file defines a class for a MaskDialog.
void setMaskSize(int height, int width, double defaultValue)
Definition: MaskDialog.cpp:52
boost::numeric::ublas::matrix< double > getMatrix()
Definition: MaskDialog.cpp:110
MaskDialog(QWidget *parent=0, Qt::WindowFlags f=0)
Definition: MaskDialog.cpp:35