All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
NewPropertyWidget.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/property/NewPropertyWidget.cpp
22 
23  \brief A class used to define the NewPropertyWidget class.
24 */
25 
26 // TerraLib
27 #include "../../../dataaccess/datasource/DataSourceManager.h"
28 #include "../../../dataaccess/datasource/DataSourceCapabilities.h"
29 #include "../../../datatype/DateTimeProperty.h"
30 #include "../../../datatype/NumericProperty.h"
31 #include "../../../datatype/SimpleProperty.h"
32 #include "../../../datatype/StringProperty.h"
33 #include "../../../geometry/GeometryProperty.h"
34 #include "NewPropertyWidget.h"
35 #include "SimplePropertyWidget.h"
37 #include "ui_NewPropertyWidgetForm.h"
38 
39 // Qt
40 #include <QMessageBox>
41 
42 
43 te::qt::widgets::NewPropertyWidget::NewPropertyWidget(QWidget* parent, Qt::WindowFlags f)
44  : QWidget(parent, f),
45  m_ui(new Ui::NewPropertyWidgetForm),
46  m_spWidget(0),
47  m_simpleProperty(0)
48 {
49  m_ui->setupUi(this);
50 
51  //adjust interface
52  m_layout = new QGridLayout(m_ui->m_scrollArea);
53  m_layout->setAlignment(Qt::AlignTop);
54 
55  //connects
56  connect(m_ui->m_dataTypeComboBox, SIGNAL(activated(int)), this, SLOT(onDataTypeComboBoxActivated(int)));
57 }
58 
60 {
61  delete m_spWidget;
62  delete m_simpleProperty;
63 }
64 
66 {
68 
69  //clear combobox
70  m_ui->m_dataTypeComboBox->clear();
71  m_ui->m_dataTypeComboBox->addItem("");
72 
73  if(ds.get())
74  {
75  //fill combobox type with supported types
76  const te::da::DataSourceCapabilities& capabilities = ds->getCapabilities();
78 
79  //if(dataTypeCapabilities.supportsArray())
80  // m_ui->m_dataTypeComboBox->addItem(tr("Array"), te::dt::ARRAY_TYPE);
81 
82  //if(dataTypeCapabilities.supportsBit())
83  // m_ui->m_dataTypeComboBox->addItem(tr("Bit"), te::dt::BIT_TYPE);
84 
85  if(dataTypeCapabilities.supportsBoolean())
86  m_ui->m_dataTypeComboBox->addItem(tr("Boolean"), te::dt::BOOLEAN_TYPE);
87 
88  //if(dataTypeCapabilities.supportsByteArray())
89  // m_ui->m_dataTypeComboBox->addItem(tr("Byte Array"), te::dt::BYTE_ARRAY_TYPE);
90 
91  if(dataTypeCapabilities.supportsChar())
92  m_ui->m_dataTypeComboBox->addItem(tr("Char"), te::dt::CHAR_TYPE);
93 
94  //if(dataTypeCapabilities.supportsComposite())
95  // m_ui->m_dataTypeComboBox->addItem(tr("Composite"), te::dt::COMPOSITE_TYPE);
96 
97  //if(dataTypeCapabilities.supportsDataset())
98  // m_ui->m_dataTypeComboBox->addItem(tr("Data Set"), te::dt::DATASET_TYPE);
99 
100  if(dataTypeCapabilities.supportsDateTime())
101  m_ui->m_dataTypeComboBox->addItem(tr("Date and Time"), te::dt::DATETIME_TYPE);
102 
103  if(dataTypeCapabilities.supportsDouble())
104  m_ui->m_dataTypeComboBox->addItem(tr("Double"), te::dt::DOUBLE_TYPE);
105 
106  if(dataTypeCapabilities.supportsFloat())
107  m_ui->m_dataTypeComboBox->addItem(tr("Float"), te::dt::FLOAT_TYPE);
108 
109  if(dataTypeCapabilities.supportsGeometry())
110  m_ui->m_dataTypeComboBox->addItem(tr("Geometry"), te::dt::GEOMETRY_TYPE);
111 
112  if(dataTypeCapabilities.supportsInt16())
113  m_ui->m_dataTypeComboBox->addItem(tr("Int 16"), te::dt::INT16_TYPE);
114 
115  if(dataTypeCapabilities.supportsInt32())
116  m_ui->m_dataTypeComboBox->addItem(tr("Int 32"), te::dt::INT32_TYPE);
117 
118  if(dataTypeCapabilities.supportsInt64())
119  m_ui->m_dataTypeComboBox->addItem(tr("Int 64"), te::dt::INT64_TYPE);
120 
121  if(dataTypeCapabilities.supportsNumeric())
122  m_ui->m_dataTypeComboBox->addItem(tr("Numeric"), te::dt::NUMERIC_TYPE);
123 
124  //if(dataTypeCapabilities.supportsRaster())
125  // m_ui->m_dataTypeComboBox->addItem(tr("Raster"), te::dt::RASTER_TYPE);
126 
127  if(dataTypeCapabilities.supportsString())
128  m_ui->m_dataTypeComboBox->addItem(tr("String"), te::dt::STRING_TYPE);
129 
130  if(dataTypeCapabilities.supportsUChar())
131  m_ui->m_dataTypeComboBox->addItem(tr("U Char"), te::dt::UCHAR_TYPE);
132 
133  if(dataTypeCapabilities.supportsUInt16())
134  m_ui->m_dataTypeComboBox->addItem(tr("U Int 16"), te::dt::UINT16_TYPE);
135 
136  if(dataTypeCapabilities.supportsUInt32())
137  m_ui->m_dataTypeComboBox->addItem(tr("U Int 32"), te::dt::UINT32_TYPE);
138 
139  if(dataTypeCapabilities.supportsUInt64())
140  m_ui->m_dataTypeComboBox->addItem(tr("U Int 64"), te::dt::UINT64_TYPE);
141  }
142 }
143 
145 {
146  if(m_simpleProperty)
147  return (te::dt::SimpleProperty*)m_simpleProperty->clone();
148 
149  return 0;
150 }
151 
153 {
154  //check parameters
155  if(m_ui->m_dataTypeComboBox->currentText().isEmpty())
156  {
157  QMessageBox::warning(this, tr("Warning"), tr("Type not selected."));
158  return false;
159  }
160 
161  if(m_ui->m_nameLineEdit->text().isEmpty())
162  {
163  QMessageBox::warning(this, tr("Warning"), tr("Name not defined."));
164  return false;
165  }
166  std::string name = m_ui->m_nameLineEdit->text().toStdString();
167 
168  std::string defaultValue = "";
169  if(m_ui->m_defaultValueLineEdit->text().isEmpty() == false)
170  {
171  defaultValue = m_ui->m_defaultValueLineEdit->text().toStdString();
172  }
173 
174  bool isRequired = false;
175  if(m_ui->m_requiredCheckBox->isEnabled())
176  {
177  isRequired = m_ui->m_requiredCheckBox->isChecked();
178  }
179 
180  bool isAutoNumber = false;
181  if(m_ui->m_autoNumberCheckBox->isEnabled())
182  {
183  isAutoNumber = m_ui->m_autoNumberCheckBox->isChecked();
184  }
185 
186  //build property
187  delete m_simpleProperty;
188 
189  int index = m_ui->m_dataTypeComboBox->currentIndex();
190  int dataType = m_ui->m_dataTypeComboBox->itemData(index).toInt();
191 
192  switch(dataType)
193  {
195  case te::dt::CHAR_TYPE:
196  case te::dt::DOUBLE_TYPE:
197  case te::dt::FLOAT_TYPE:
198  case te::dt::INT16_TYPE:
199  case te::dt::INT32_TYPE:
200  case te::dt::INT64_TYPE:
201  case te::dt::UCHAR_TYPE:
202  case te::dt::UINT16_TYPE:
203  case te::dt::UINT32_TYPE:
204  case te::dt::UINT64_TYPE:
205  {
206  m_simpleProperty = new te::dt::SimpleProperty(name, dataType, isRequired, new std::string(defaultValue));
207  m_simpleProperty->setAutoNumber(isAutoNumber);
208  break;
209  }
210 
211  case te::dt::STRING_TYPE:
212  {
213  m_simpleProperty = new te::dt::StringProperty(name, te::dt::STRING, isRequired, new std::string(defaultValue));
214  break;
215  }
216 
218  {
219  m_simpleProperty = new te::dt::NumericProperty(name, 0, 0, isRequired, new std::string(defaultValue));
220  m_simpleProperty->setAutoNumber(isAutoNumber);
221  break;
222  }
223 
225  {
226  m_simpleProperty = new te::dt::DateTimeProperty(name, te::dt::DATE, isRequired, new std::string(defaultValue));
227  break;
228  }
229 
231  {
232  m_simpleProperty = new te::gm::GeometryProperty(name, isRequired, new std::string(defaultValue));
233  break;
234  }
235 
236  default:
237  {
238  m_simpleProperty = 0;
239  return false;
240  }
241  }
242 
243  //the custom interface fills the simple property with specific parameters
244  if(m_spWidget)
245  m_spWidget->fillProperty(m_simpleProperty);
246 
247  return true;
248 }
249 
251 {
252  //create the specific widget
253  int dataType = m_ui->m_dataTypeComboBox->itemData(index).toInt();
254 
255  delete m_spWidget;
256 
258  {
259  m_spWidget = te::qt::widgets::SimplePropertyWidgetFactory::make(dataType, m_ui->m_scrollArea);
260  m_layout->addWidget(m_spWidget);
261  m_spWidget->show();
262  }
263  else
264  {
265  m_spWidget = 0;
266  }
267 
268  //set interface for this new widget
269  m_ui->m_nameLineEdit->clear();
270 
271  m_ui->m_defaultValueLineEdit->clear();
272  m_ui->m_defaultValueLineEdit->setEnabled(false);
273 
274  m_ui->m_autoNumberCheckBox->setChecked(false);
275  m_ui->m_autoNumberCheckBox->setEnabled(false);
276 
277  m_ui->m_requiredCheckBox->setChecked(false);
278  m_ui->m_requiredCheckBox->setEnabled(false);
279 
280  if(m_spWidget)
281  {
282  m_ui->m_defaultValueLineEdit->setEnabled(m_spWidget->hasAttributeDefaultValue());
283  m_ui->m_autoNumberCheckBox->setEnabled(m_spWidget->hasAttributeAutoNumber());
284  m_ui->m_requiredCheckBox->setEnabled(m_spWidget->hasAttributeRequired());
285  }
286 }
std::auto_ptr< Ui::NewPropertyWidgetForm > m_ui
Geometric property.
An atomic property like an integer or double.
te::dt::SimpleProperty * getProperty()
It returns a simple property class object.
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1435
const DataTypeCapabilities & getDataTypeCapabilities() const
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
static te::qt::widgets::SimplePropertyWidget * make(const int &type)
A class used to define the NewPropertyWidget class.
A class that represents the supported data types of a specific data source.
The type for arbitrary precison numbers, like numeric(p, q).
te::da::DataTypeCapabilities dataTypeCapabilities
NewPropertyWidget(QWidget *parent=0, Qt::WindowFlags f=0)
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
QGridLayout * m_layout
Qt Layout object.
te::da::DataSourceCapabilities capabilities
The type for string types: FIXED_STRING, VAR_STRING or STRING.
virtual Property * clone() const
It returns a clone of the object.
void setDataSourceId(std::string id)
Used to get all data types supported by this data source.
static const factory_type * find(const int &factoryKey)
A base widget for simple properties.
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.