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 
44  : QWidget(parent, f),
45  m_ui(new Ui::NewPropertyWidgetForm),
46  m_spWidget(nullptr),
47  m_simpleProperty(nullptr)
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 
72  m_ui->m_dataTypeComboBox->addItem("");
73 
74  if(ds.get())
75  {
76  //fill combobox type with supported types
77  const te::da::DataSourceCapabilities& capabilities = ds->getCapabilities();
79 
80  //if(dataTypeCapabilities.supportsArray())
81  // m_ui->m_dataTypeComboBox->addItem(tr("Array"), te::dt::ARRAY_TYPE);
82 
83  //if(dataTypeCapabilities.supportsBit())
84  // m_ui->m_dataTypeComboBox->addItem(tr("Bit"), te::dt::BIT_TYPE);
85 
86  if(dataTypeCapabilities.supportsBoolean())
87  m_ui->m_dataTypeComboBox->addItem(tr("Boolean"), te::dt::BOOLEAN_TYPE);
88 
89  //if(dataTypeCapabilities.supportsByteArray())
90  // m_ui->m_dataTypeComboBox->addItem(tr("Byte Array"), te::dt::BYTE_ARRAY_TYPE);
91 
92  if(dataTypeCapabilities.supportsChar())
93  m_ui->m_dataTypeComboBox->addItem(tr("Char"), te::dt::CHAR_TYPE);
94 
95  //if(dataTypeCapabilities.supportsComposite())
96  // m_ui->m_dataTypeComboBox->addItem(tr("Composite"), te::dt::COMPOSITE_TYPE);
97 
98  //if(dataTypeCapabilities.supportsDataset())
99  // m_ui->m_dataTypeComboBox->addItem(tr("Data Set"), te::dt::DATASET_TYPE);
100 
101  if(dataTypeCapabilities.supportsDateTime())
102  m_ui->m_dataTypeComboBox->addItem(tr("Date and Time"), te::dt::DATETIME_TYPE);
103 
104  if(dataTypeCapabilities.supportsDouble())
105  m_ui->m_dataTypeComboBox->addItem(tr("Double"), te::dt::DOUBLE_TYPE);
106 
107  if(dataTypeCapabilities.supportsFloat())
108  m_ui->m_dataTypeComboBox->addItem(tr("Float"), te::dt::FLOAT_TYPE);
109 
110  if(dataTypeCapabilities.supportsGeometry())
111  m_ui->m_dataTypeComboBox->addItem(tr("Geometry"), te::dt::GEOMETRY_TYPE);
112 
113  if(dataTypeCapabilities.supportsInt16())
114  m_ui->m_dataTypeComboBox->addItem(tr("Int 16"), te::dt::INT16_TYPE);
115 
116  if(dataTypeCapabilities.supportsInt32())
117  m_ui->m_dataTypeComboBox->addItem(tr("Int 32"), te::dt::INT32_TYPE);
118 
119  if(dataTypeCapabilities.supportsInt64())
120  m_ui->m_dataTypeComboBox->addItem(tr("Int 64"), te::dt::INT64_TYPE);
121 
122  if(dataTypeCapabilities.supportsNumeric())
123  m_ui->m_dataTypeComboBox->addItem(tr("Numeric"), te::dt::NUMERIC_TYPE);
124 
125  //if(dataTypeCapabilities.supportsRaster())
126  // m_ui->m_dataTypeComboBox->addItem(tr("Raster"), te::dt::RASTER_TYPE);
127 
128  if(dataTypeCapabilities.supportsString())
129  m_ui->m_dataTypeComboBox->addItem(tr("String"), te::dt::STRING_TYPE);
130 
131  if(dataTypeCapabilities.supportsUChar())
132  m_ui->m_dataTypeComboBox->addItem(tr("U Char"), te::dt::UCHAR_TYPE);
133 
134  if(dataTypeCapabilities.supportsUInt16())
135  m_ui->m_dataTypeComboBox->addItem(tr("U Int 16"), te::dt::UINT16_TYPE);
136 
137  if(dataTypeCapabilities.supportsUInt32())
138  m_ui->m_dataTypeComboBox->addItem(tr("U Int 32"), te::dt::UINT32_TYPE);
139 
140  if(dataTypeCapabilities.supportsUInt64())
141  m_ui->m_dataTypeComboBox->addItem(tr("U Int 64"), te::dt::UINT64_TYPE);
142  }
143 
145 }
146 
148 {
149  if(m_simpleProperty)
151 
152  return nullptr;
153 }
154 
156 {
157  //check parameters
158  if(m_ui->m_dataTypeComboBox->currentText().isEmpty())
159  {
160  QMessageBox::warning(this, tr("Warning"), tr("Type not selected."));
161  return false;
162  }
163 
164  if(m_ui->m_nameLineEdit->text().isEmpty())
165  {
166  QMessageBox::warning(this, tr("Warning"), tr("Name not defined."));
167  return false;
168  }
169  std::string name = m_ui->m_nameLineEdit->text().toUtf8().data();
170 
171  std::string defaultValue;
172  if(m_ui->m_defaultValueLineEdit->text().isEmpty() == false)
173  {
174  defaultValue = m_ui->m_defaultValueLineEdit->text().toUtf8().data();
175  }
176 
177  bool isRequired = m_ui->m_requiredCheckBox->isChecked();
178 
179  bool isAutoNumber = m_ui->m_autoNumberCheckBox->isChecked();
180 
181  //build property
182  delete m_simpleProperty;
183 
184  int index = m_ui->m_dataTypeComboBox->currentIndex();
185  int dataType = m_ui->m_dataTypeComboBox->itemData(index).toInt();
186 
187  switch(dataType)
188  {
190  case te::dt::CHAR_TYPE:
191  case te::dt::DOUBLE_TYPE:
192  case te::dt::FLOAT_TYPE:
193  case te::dt::INT16_TYPE:
194  case te::dt::INT32_TYPE:
195  case te::dt::INT64_TYPE:
196  case te::dt::UCHAR_TYPE:
197  case te::dt::UINT16_TYPE:
198  case te::dt::UINT32_TYPE:
199  case te::dt::UINT64_TYPE:
200  {
201  if (defaultValue.empty())
202  m_simpleProperty = new te::dt::SimpleProperty(name, dataType, isRequired);
203  else
204  m_simpleProperty = new te::dt::SimpleProperty(name, dataType, isRequired, new std::string(defaultValue));
205 
206  m_simpleProperty->setAutoNumber(isAutoNumber);
207  break;
208  }
209 
210  case te::dt::STRING_TYPE:
211  {
212  if (defaultValue.empty())
213  m_simpleProperty = new te::dt::StringProperty(name, te::dt::STRING, 0, isRequired);
214  else
215  m_simpleProperty = new te::dt::StringProperty(name, te::dt::STRING, 0, isRequired, new std::string(defaultValue));
216  break;
217  }
218 
220  {
221  if (defaultValue.empty())
222  m_simpleProperty = new te::dt::NumericProperty(name, 0, 0, isRequired);
223  else
224  m_simpleProperty = new te::dt::NumericProperty(name, 0, 0, isRequired, new std::string(defaultValue));
225 
226  m_simpleProperty->setAutoNumber(isAutoNumber);
227  break;
228  }
229 
231  {
232  if (defaultValue.empty())
233  m_simpleProperty = new te::dt::DateTimeProperty(name, te::dt::DATE, 0, isRequired);
234  else
235  m_simpleProperty = new te::dt::DateTimeProperty(name, te::dt::DATE, 0, isRequired, new std::string(defaultValue));
236  break;
237  }
238 
240  {
241  if (defaultValue.empty())
242  m_simpleProperty = new te::gm::GeometryProperty(name, isRequired);
243  else
244  m_simpleProperty = new te::gm::GeometryProperty(name, isRequired, new std::string(defaultValue));
245  break;
246  }
247 
248  default:
249  {
250  m_simpleProperty = nullptr;
251  return false;
252  }
253  }
254 
255  //the custom interface fills the simple property with specific parameters
256  if(m_spWidget)
258 
259  return true;
260 }
261 
263 {
264  //set interface for this new widget
265  m_ui->m_nameLineEdit->clear();
266 
267  m_ui->m_defaultValueLineEdit->clear();
268  m_ui->m_defaultValueLineEdit->setEnabled(true);
269 
270  m_ui->m_autoNumberCheckBox->setChecked(false);
271  m_ui->m_autoNumberCheckBox->setEnabled(true);
272 
273  m_ui->m_requiredCheckBox->setChecked(false);
274  m_ui->m_requiredCheckBox->setEnabled(true);
275 
276  delete m_spWidget;
277  m_spWidget = nullptr;
278 
279  //create the specific widget
280  QVariant var = m_ui->m_dataTypeComboBox->itemData(index);
281 
282  if (!var.isValid())
283  return;
284 
285  int dataType = var.toInt();
286 
288  {
290  m_layout->addWidget(m_spWidget);
291  m_spWidget->show();
292  }
293 }
void setAutoNumber(bool a)
It tells if the property is an autonumber or not.
Geometric property.
virtual void fillProperty(te::dt::SimpleProperty *sp)=0
An atomic property like an integer or double.
te::dt::SimpleProperty * getProperty()
It returns a simple property class object.
boost::shared_ptr< DataSource > DataSourcePtr
const DataTypeCapabilities & getDataTypeCapabilities() const
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
static te::dt::Date ds(2010, 01, 01)
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)
std::unique_ptr< Ui::NewPropertyWidgetForm > m_ui
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
QGridLayout * m_layout
Qt Layout object.
te::da::DataSourceCapabilities capabilities
te::dt::SimpleProperty * m_simpleProperty
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.
te::qt::widgets::SimplePropertyWidget * m_spWidget
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.