RetypeColumnDialog.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 #include "RetypeColumnDialog.h"
21 
22 #include <ui_RetypeColumnDialogForm.h>
23 
24 // TerraLib
31 
32 
33 int GetType(const int& te_type)
34 {
35  switch (te_type)
36  {
37  case te::dt::CHAR_TYPE:
38  case te::dt::UCHAR_TYPE:
40 
41  return 2;
42  break;
43 
44  case te::dt::INT16_TYPE:
46  case te::dt::INT32_TYPE:
48  case te::dt::INT64_TYPE:
50  return 0;
51  break;
52 
53  case te::dt::FLOAT_TYPE:
56  return 1;
57  break;
58 
60  return 3;
61  break;
62 
63  default:
64  return 4;
65  };
66 
67 }
68 
69 QString GetSType(const int& te_type)
70 {
71  int type = GetType(te_type);
72 
73  switch(type)
74  {
75  case 0:
76  return "INT";
77  break;
78 
79  case 1:
80  return "REAL";
81  break;
82 
83  case 2:
84  return "STRING";
85  break;
86 
87  case 3:
88  return "DATETIME";
89  break;
90 
91  default:
92  return "UNKNOWN TYPE";
93  break;
94  };
95 }
96 
97 int GetIType (const int& type)
98 {
99  switch (type)
100  {
101  case 0:
102  return te::dt::INT32_TYPE;
103  break;
104 
105  case 1:
106  return te::dt::DOUBLE_TYPE;
107  break;
108 
109  case 2:
110  return te::dt::STRING_TYPE;
111  break;
112 
113  case 3:
114  return te::dt::DATETIME_TYPE;
115  break;
116  };
117 
118  return -1;
119 }
120 
122 QDialog(parent)
123 {
124  m_ui.reset(new Ui::RetypeColumnDialogForm);
125  m_ui->setupUi(this);
126 
127  connect (m_ui->m_okPushButton, SIGNAL(pressed()), SLOT(accept()));
128  connect (m_ui->m_cancelPushButton, SIGNAL(pressed()), SLOT(reject()));
129 }
130 
132 
134 {
135  m_ui->m_tableNameLineEdit->setText(name);
136 }
137 
139 {
140  m_ui->m_typeLineEdit->setText(GetSType(type));
141 }
142 
144 {
145  m_ui->m_columnNameLineEdit->setText(name);
146 }
147 
149 {
150  m_ui->m_sizeLineEdit->setText(QString::number(size));
151 }
152 
154 {
155  return GetIType(m_ui->m_typeComboBox->currentIndex());
156 }
157 
159 {
160  return m_ui->m_sizeComboBox->currentText().toInt();
161 }
162 
163 std::unique_ptr<te::dt::Property> te::qt::widgets::RetypeColumnDialog::getProperty()
164 {
165  std::unique_ptr<te::dt::Property> res;
166  std::string name = m_ui->m_columnNameLineEdit->text().toUtf8().data();
167 
168  int cType = getColumnType();
169 
170  switch (cType)
171  {
172  case te::dt::INT32_TYPE:
173  case te::dt::DOUBLE_TYPE:
174  res.reset(new te::dt::SimpleProperty(name, cType));
175  break;
176 
177  case te::dt::STRING_TYPE:
178  res.reset(new te::dt::StringProperty(name, te::dt::STRING));
179  break;
180 
182  res.reset(new te::dt::DateTimeProperty(name, te::dt::DATE_PERIOD));
183  break;
184  };
185 
186  return res;
187 }
An atomic property like an integer or double.
It models a property definition.
General enumerations for the data type module.
void setTableName(const QString &name)
The type for arbitrary precision numbers, like numeric(p, q).
void setColumnName(const QString &name)
The type for string types: FIXED_STRING, VAR_STRING or STRING.
The type for string types: FIXED_STRING, VAR_STRING or STRING.
QString GetSType(const int &te_type)
int GetType(const int &te_type)
The type for date and time types: date, date period, date duration, time duration, time instant, time period, time instant with time zone or time period with time zone.
The type for date and time types.
An atomic property like an integer or double.
std::unique_ptr< te::dt::Property > getProperty()
int GetIType(const int &type)
std::unique_ptr< Ui::RetypeColumnDialogForm > m_ui