g2o
Public Slots | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
PropertiesWidget Class Reference

#include <properties_widget.h>

Inheritance diagram for PropertiesWidget:
Inheritance graph
[legend]
Collaboration diagram for PropertiesWidget:
Collaboration graph
[legend]

Public Slots

void on_btnApply_clicked ()
 
void on_btnOK_clicked ()
 

Public Member Functions

 PropertiesWidget (QWidget *parent=0, Qt::WindowFlags f=0)
 
virtual ~PropertiesWidget ()
 
void setProperties (g2o::PropertyMap *properties)
 

Protected Member Functions

virtual void updateDisplayedProperties ()
 
virtual void applyProperties ()
 
virtual std::string humanReadablePropName (const std::string &propertyName) const
 

Protected Attributes

std::vector< std::string > _propNames
 
g2o::PropertyMap_properties
 

Detailed Description

Definition at line 36 of file properties_widget.h.

Constructor & Destructor Documentation

PropertiesWidget::PropertiesWidget ( QWidget *  parent = 0,
Qt::WindowFlags  f = 0 
)

Definition at line 32 of file properties_widget.cpp.

32  :
33  QDialog(parent, f),
34  _properties(0)
35 {
36  setupUi(this);
37 }
g2o::PropertyMap * _properties
PropertiesWidget::~PropertiesWidget ( )
virtual

Definition at line 39 of file properties_widget.cpp.

40 {
41 }

Member Function Documentation

void PropertiesWidget::applyProperties ( )
protectedvirtual

Reimplemented in ViewerPropertiesWidget.

Definition at line 100 of file properties_widget.cpp.

References _properties, _propNames, g2o::BaseProperty::fromString(), g2o::BaseProperty::name(), and g2o::Property< T >::setValue().

Referenced by ViewerPropertiesWidget::applyProperties(), on_btnApply_clicked(), and on_btnOK_clicked().

101 {
102  assert(tableWidget->rowCount() == (int) _propNames.size());
103  PropertyMap* properties = _properties;
104  for (int r = 0; r < tableWidget->rowCount(); ++r) {
105  const std::string& propName = _propNames[r];
106  BaseProperty* baseProp = properties->getProperty<BaseProperty>(propName);
107  if (! baseProp)
108  continue;
109 
110  if (dynamic_cast<Property<bool>*>(baseProp)) {
111  Property<bool>* prop = static_cast<Property<bool>*>(baseProp);
112  QTableWidgetItem* checkItem = tableWidget->item(r, 1);
113  prop->setValue(checkItem->checkState() == Qt::Checked);
114  } else {
115  QLineEdit* editor = dynamic_cast<QLineEdit*>(tableWidget->cellWidget(r, 1));
116  bool status = baseProp->fromString(editor->text().toStdString());
117  if (! status) {
118  cerr << "Warning: unable to set property " << baseProp->name() << endl;
119  }
120  }
121  }
122 }
g2o::PropertyMap * _properties
virtual bool fromString(const std::string &s)=0
std::vector< std::string > _propNames
void setValue(const T &v)
Definition: property.h:56
a collection of properties mapping from name to the property itself
Definition: property.h:76
const std::string & name()
Definition: property.h:43
std::string PropertiesWidget::humanReadablePropName ( const std::string &  propertyName) const
protectedvirtual

Reimplemented in ViewerPropertiesWidget.

Definition at line 135 of file properties_widget.cpp.

Referenced by updateDisplayedProperties().

136 {
137  return propertyName;
138 }
void PropertiesWidget::on_btnApply_clicked ( )
slot

Definition at line 124 of file properties_widget.cpp.

References applyProperties().

125 {
126  applyProperties();
127 }
virtual void applyProperties()
void PropertiesWidget::on_btnOK_clicked ( )
slot

Definition at line 129 of file properties_widget.cpp.

References applyProperties().

130 {
131  applyProperties();
132  close();
133 }
virtual void applyProperties()
void PropertiesWidget::setProperties ( g2o::PropertyMap properties)

Definition at line 140 of file properties_widget.cpp.

References _properties, and updateDisplayedProperties().

Referenced by MainWindow::on_btnOptimizerParamaters_clicked(), and ViewerPropertiesWidget::setViewer().

141 {
142  _properties = properties;
144 }
virtual void updateDisplayedProperties()
g2o::PropertyMap * _properties
void PropertiesWidget::updateDisplayedProperties ( )
protectedvirtual

Definition at line 43 of file properties_widget.cpp.

References _properties, _propNames, humanReadablePropName(), and g2o::Property< T >::value().

Referenced by setProperties().

44 {
45  tableWidget->clear();
46  _propNames.clear();
47 
48  tableWidget->setColumnCount(2);
49 
50  QStringList horizontalHeaders;
51  horizontalHeaders.append("Name");
52  horizontalHeaders.append("Value");
53  tableWidget->setHorizontalHeaderLabels(horizontalHeaders);
54 
55  tableWidget->verticalHeader()->hide();
56 
57  PropertyMap* properties = _properties;
58  if (! properties)
59  return;
60  tableWidget->setRowCount(properties->size());
61 
62  int r = 0;
63  for (PropertyMap::PropertyMapIterator it = properties->begin(); it != properties->end(); ++it, ++r) {
64 
65  QTableWidgetItem* textItem = new QTableWidgetItem;
66  textItem->setText(QString::fromStdString(humanReadablePropName(it->first)));
67  textItem->setFlags(textItem->flags() & ~Qt::ItemIsEditable);
68  tableWidget->setItem(r, 0, textItem);
69  _propNames.push_back(it->first);
70 
71  if (dynamic_cast<Property<bool>*>(it->second)) {
72  Property<bool>* prop = static_cast<Property<bool>*>(it->second);
73  QTableWidgetItem* checkItem = new QTableWidgetItem;
74  checkItem->setText("enabled");
75  checkItem->setFlags(checkItem->flags() | Qt::ItemIsUserCheckable);
76  if (prop->value())
77  checkItem->setCheckState(Qt::Checked);
78  else
79  checkItem->setCheckState(Qt::Unchecked);
80  tableWidget->setItem(r, 1, checkItem);
81  } else {
82  QLineEdit* editor = new QLineEdit(tableWidget);
83  editor->setText(QString::fromStdString(it->second->toString()));
84  if (dynamic_cast<Property<int>*>(it->second)) {
85  editor->setValidator(new QIntValidator(editor));
86  }
87  else if (dynamic_cast<Property<float>*>(it->second)) {
88  editor->setValidator(new QDoubleValidator(editor));
89  }
90  else if (dynamic_cast<Property<double>*>(it->second)) {
91  editor->setValidator(new QDoubleValidator(editor));
92  }
93  tableWidget->setCellWidget(r, 1, editor);
94  }
95 
96  }
97  tableWidget->resizeColumnToContents(0);
98 }
BaseClass::iterator PropertyMapIterator
Definition: property.h:80
g2o::PropertyMap * _properties
virtual std::string humanReadablePropName(const std::string &propertyName) const
std::vector< std::string > _propNames
const T & value() const
Definition: property.h:57
a collection of properties mapping from name to the property itself
Definition: property.h:76

Member Data Documentation

g2o::PropertyMap* PropertiesWidget::_properties
protected

Definition at line 51 of file properties_widget.h.

Referenced by applyProperties(), setProperties(), and updateDisplayedProperties().

std::vector<std::string> PropertiesWidget::_propNames
protected

Definition at line 50 of file properties_widget.h.

Referenced by applyProperties(), and updateDisplayedProperties().


The documentation for this class was generated from the following files: