g2o
Toggle main menu visibility
Loading...
Searching...
No Matches
g2o
apps
g2o_viewer
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
27
using namespace
std
;
28
29
using namespace
g2o
;
30
31
PropertiesWidget::PropertiesWidget
(QWidget* parent)
32
: QDialog(parent),
_properties
(0) {
33
setupUi(
this
);
34
}
35
36
PropertiesWidget::~PropertiesWidget
() {}
37
38
void
PropertiesWidget::updateDisplayedProperties
() {
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
90
void
PropertiesWidget::applyProperties
() {
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
113
void
PropertiesWidget::on_btnApply_clicked
() {
applyProperties
(); }
114
115
void
PropertiesWidget::on_btnOK_clicked
() {
116
applyProperties
();
117
close();
118
}
119
120
std::string
PropertiesWidget::humanReadablePropName
(
121
const
std::string& propertyName)
const
{
122
return
propertyName;
123
}
124
125
void
PropertiesWidget::setProperties
(
PropertyMap
* properties) {
126
_properties
= properties;
127
updateDisplayedProperties
();
128
}
PropertiesWidget::on_btnApply_clicked
void on_btnApply_clicked()
Definition
properties_widget.cpp:113
PropertiesWidget::_propNames
std::vector< std::string > _propNames
Definition
properties_widget.h:48
PropertiesWidget::on_btnOK_clicked
void on_btnOK_clicked()
Definition
properties_widget.cpp:115
PropertiesWidget::setProperties
void setProperties(g2o::PropertyMap *properties)
Definition
properties_widget.cpp:125
PropertiesWidget::~PropertiesWidget
virtual ~PropertiesWidget()
Definition
properties_widget.cpp:36
PropertiesWidget::humanReadablePropName
virtual std::string humanReadablePropName(const std::string &propertyName) const
Definition
properties_widget.cpp:120
PropertiesWidget::applyProperties
virtual void applyProperties()
Definition
properties_widget.cpp:90
PropertiesWidget::_properties
g2o::PropertyMap * _properties
Definition
properties_widget.h:49
PropertiesWidget::updateDisplayedProperties
virtual void updateDisplayedProperties()
Definition
properties_widget.cpp:38
PropertiesWidget::PropertiesWidget
PropertiesWidget(QWidget *parent=0)
Definition
properties_widget.cpp:31
g2o::BaseProperty
Definition
property.h:39
g2o::BaseProperty::name
const std::string & name()
Definition
property.h:43
g2o::BaseProperty::fromString
virtual bool fromString(const std::string &s)=0
g2o::PropertyMap
a collection of properties mapping from name to the property itself
Definition
property.h:78
g2o::PropertyMap::getProperty
P * getProperty(const std::string &name_)
Definition
property.h:100
g2o::PropertyMap::PropertyMapIterator
BaseClass::iterator PropertyMapIterator
Definition
property.h:81
g2o::Property
Definition
property.h:52
g2o::Property::setValue
void setValue(const T &v)
Definition
property.h:58
g2o::Property::value
const T & value() const
Definition
property.h:59
g2o
Definition
dl_wrapper.cpp:55
std
Definition
jet.h:876
properties_widget.h
property.h
Generated on
for g2o by
1.17.0