g2o
Loading...
Searching...
No Matches
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)
 
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 34 of file properties_widget.h.

Constructor & Destructor Documentation

◆ PropertiesWidget()

PropertiesWidget::PropertiesWidget ( QWidget *  parent = 0)

Definition at line 31 of file properties_widget.cpp.

32 : QDialog(parent), _properties(0) {
33 setupUi(this);
34}
g2o::PropertyMap * _properties

◆ ~PropertiesWidget()

PropertiesWidget::~PropertiesWidget ( )
virtual

Definition at line 36 of file properties_widget.cpp.

36{}

Member Function Documentation

◆ applyProperties()

void PropertiesWidget::applyProperties ( )
protectedvirtual

Reimplemented in ViewerPropertiesWidget.

Definition at line 90 of file properties_widget.cpp.

90 {
91 assert(tableWidget->rowCount() == (int)_propNames.size());
92 PropertyMap* properties = _properties;
93 for (int r = 0; r < tableWidget->rowCount(); ++r) {
94 const std::string& propName = _propNames[r];
95 BaseProperty* baseProp = properties->getProperty<BaseProperty>(propName);
96 if (!baseProp) continue;
97
98 if (dynamic_cast<Property<bool>*>(baseProp)) {
99 Property<bool>* prop = static_cast<Property<bool>*>(baseProp);
100 QTableWidgetItem* checkItem = tableWidget->item(r, 1);
101 prop->setValue(checkItem->checkState() == Qt::Checked);
102 } else {
103 QLineEdit* editor =
104 dynamic_cast<QLineEdit*>(tableWidget->cellWidget(r, 1));
105 bool status = baseProp->fromString(editor->text().toStdString());
106 if (!status) {
107 cerr << "Warning: unable to set property " << baseProp->name() << endl;
108 }
109 }
110 }
111}
std::vector< std::string > _propNames
const std::string & name()
Definition property.h:43
virtual bool fromString(const std::string &s)=0
a collection of properties mapping from name to the property itself
Definition property.h:78
P * getProperty(const std::string &name_)
Definition property.h:100
void setValue(const T &v)
Definition property.h:58

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

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

◆ humanReadablePropName()

std::string PropertiesWidget::humanReadablePropName ( const std::string &  propertyName) const
protectedvirtual

Reimplemented in ViewerPropertiesWidget.

Definition at line 120 of file properties_widget.cpp.

121 {
122 return propertyName;
123}

Referenced by updateDisplayedProperties().

◆ on_btnApply_clicked

void PropertiesWidget::on_btnApply_clicked ( )
slot

Definition at line 113 of file properties_widget.cpp.

113{ applyProperties(); }
virtual void applyProperties()

References applyProperties().

◆ on_btnOK_clicked

void PropertiesWidget::on_btnOK_clicked ( )
slot

Definition at line 115 of file properties_widget.cpp.

115 {
117 close();
118}

References applyProperties().

◆ setProperties()

void PropertiesWidget::setProperties ( g2o::PropertyMap properties)

◆ updateDisplayedProperties()

void PropertiesWidget::updateDisplayedProperties ( )
protectedvirtual

Definition at line 38 of file properties_widget.cpp.

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

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

Referenced by setProperties().

Member Data Documentation

◆ _properties

g2o::PropertyMap* PropertiesWidget::_properties
protected

Definition at line 49 of file properties_widget.h.

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

◆ _propNames

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

Definition at line 48 of file properties_widget.h.

Referenced by applyProperties(), and updateDisplayedProperties().


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