g2o
Loading...
Searching...
No Matches
properties_widget.cpp
Go to the documentation of this file.
1// g2o - General Graph Optimization
2// Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
3//
4// This file is part of g2o.
5//
6// g2o is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// g2o is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with g2o. If not, see <http://www.gnu.org/licenses/>.
18
19#include "properties_widget.h"
20
21#include <QLineEdit>
22#include <cassert>
23#include <iostream>
24
25#include "g2o/stuff/property.h"
26
27using namespace std;
28
29using namespace g2o;
30
32 : QDialog(parent), _properties(0) {
33 setupUi(this);
34}
35
37
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}
89
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}
112
114
117 close();
118}
119
121 const std::string& propertyName) const {
122 return propertyName;
123}
124
std::vector< std::string > _propNames
void setProperties(g2o::PropertyMap *properties)
virtual std::string humanReadablePropName(const std::string &propertyName) const
virtual void applyProperties()
g2o::PropertyMap * _properties
virtual void updateDisplayedProperties()
PropertiesWidget(QWidget *parent=0)
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
BaseClass::iterator PropertyMapIterator
Definition property.h:81
void setValue(const T &v)
Definition property.h:58
const T & value() const
Definition property.h:59
Definition jet.h:876