All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
FeatureAttributesDialog.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/edit/qt/FeatureAttributesDialog.cpp
22 
23  \brief A widget used to show and setup feature attributes.
24 */
25 
26 // TerraLib
27 #include "../../dataaccess/dataset/DataSetType.h"
29 #include "ui_FeatureAttributesDialogForm.h"
30 
31 // Qt
32 #include <QTreeWidgetItem>
33 
34 // STL
35 #include <cassert>
36 
38  : QDialog(parent, f),
39  m_ui(new Ui::FeatureAttributesDialogForm),
40  m_type(0),
41  m_feature(0)
42 {
43  m_ui->setupUi(this);
44 
45  // Setup the widget that will be used to show the attributes
46  m_ui->m_attributesTreeWidget->setAlternatingRowColors(true);
47  m_ui->m_attributesTreeWidget->setColumnCount(2);
48 
49  QStringList labels;
50  labels << tr("Property") << tr("Value");
51  m_ui->m_attributesTreeWidget->setHeaderLabels(labels);
52 
53  // Signals & slots
54  connect(m_ui->m_okPushButton, SIGNAL(pressed()), this, SLOT(onOkPushButtonPressed()));
55  connect(m_ui->m_attributesTreeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(onAttributesTreeWidgetItemDoubleClicked(QTreeWidgetItem*, int)));
56 }
57 
59 {
60 }
61 
63 {
64  m_type = type;
65  m_feature = f;
66 
67  initialize();
68 }
69 
71 {
72  const std::vector<te::dt::Property*>& properties = m_type->getProperties();
73 
74  for(std::size_t i = 0; i < properties.size(); ++i) // for each property
75  {
76  te::dt::Property* p = properties[i];
77 
78  QTreeWidgetItem* propertyItem = new QTreeWidgetItem;
79  propertyItem->setText(0, p->getName().c_str());
80  propertyItem->setText(1, tr("Value"));
81 
82  m_ui->m_attributesTreeWidget->addTopLevelItem(propertyItem);
83  }
84 }
85 
87 {
88  close();
89 }
90 
91 // Hack from http://stackoverflow.com/a/13374558 to making only one column of a QTreeWidgetItem editable
93 {
94  Qt::ItemFlags tmp = item->flags();
95  if(column == 1)
96  item->setFlags(tmp | Qt::ItemIsEditable);
97  else if(tmp & Qt::ItemIsEditable)
98  item->setFlags(tmp ^ Qt::ItemIsEditable);
99 }
void onAttributesTreeWidgetItemDoubleClicked(QTreeWidgetItem *item, int column)
A class that models the description of a dataset.
Definition: DataSetType.h:72
void initialize()
Internal method to initialize the dialog.
FeatureAttributesDialog(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs the feature attributes dialog which is a child of parent, with widget flags set to f...
A widget used to show and setup feature attributes.
It models a property definition.
Definition: Property.h:59
void set(te::da::DataSetType *type, Feature *f)
std::auto_ptr< Ui::FeatureAttributesDialogForm > m_ui
Dialog form.
const std::string & getName() const
It returns the property name.
Definition: Property.h:127