VariantWidget.cpp
Go to the documentation of this file.
1/*
2* This file is part of ArmarX.
3*
4* ArmarX is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License version 2 as
6* published by the Free Software Foundation.
7*
8* ArmarX is distributed in the hope that it will be useful, but
9* WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details.
12*
13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15*
16* @package ArmarX::Gui
17* @author Kai Welke (welke@kit.edu)
18* @copyright 2012 Humanoids Group, IAIM, IFA
19* @license http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21*/
22
23#include "VariantWidget.h"
24
25#include <QLabel>
26#include <QLineEdit>
27#include <QTextEdit>
28#include <QVBoxLayout>
29
30namespace armarx
31{
32 VariantWidget::VariantWidget(VariantPtr variant, QWidget* parent, Qt::WindowFlags f) :
33 QWidget(parent, f)
34 {
35 this->variant = variant;
36 enableEdit = true;
37 showType = false;
38 layout = new QVBoxLayout(this);
39 variantEdit = new QTextEdit(this);
40 setLayout(layout);
41 setupLayout();
42 }
43
44 void
46 {
47 VariantTypeId type = variant->getType();
48 QString valueString;
49 if (variant->getInitialized())
50 {
51 if (type == VariantType::Bool)
52 {
53 QString value("%1");
54 value = value.arg((variant->getBool() == 1));
55 valueString = value;
56 }
57
58 else if (type == VariantType::Float)
59 {
60 QString value("%1");
61 value = value.arg(variant->getFloat(), 0, 'f', 2);
62 valueString = value;
63 }
64
65 else if (type == VariantType::Double)
66 {
67 QString value("%1");
68 value = value.arg(variant->getDouble(), 0, 'f', 2);
69 valueString = value;
70 }
71
72 else if (type == VariantType::Int)
73 {
74 QString value("%1");
75 value = value.arg(variant->getInt());
76 valueString = value;
77 }
78
79 else if (type == VariantType::Long)
80 {
81 QString value("%1");
82 value = value.arg(variant->getLong());
83 valueString = value;
84 }
85
86 else if (type == VariantType::String)
87 {
88 QString value(variant->getString().c_str());
89 valueString = value;
90 }
91 else
92 {
93 VariantDataClassPtr var = variant->getClass<VariantDataClass>();
94 QString value(var->output().c_str());
95 valueString = value;
96 }
97 }
98 else
99 {
100 valueString = "<i>not initalized</i>";
101 }
102 variantEdit->setEnabled(variant->getInitialized());
103 variantEdit->setText(valueString);
104 }
105
106 void
108 {
109 this->enableEdit = enableEdit;
110 setupLayout();
111 }
112
113 void
115 {
116 this->showType = showType;
117 setupLayout();
118 }
119
120 bool
122 {
123 return enableEdit;
124 }
125
126 bool
128 {
129 return showType;
130 }
131
132 QString
134 {
135 return variantEdit->toPlainText();
136 }
137
138 void
139 VariantWidget::setupLayout()
140 {
141 int valueEditWidth = 120;
142
143
144 // clean old lineedits
145 std::vector<QWidget*>::iterator iter = widgets.begin();
146
147 while (iter != widgets.end())
148 {
149 delete *iter;
150 iter++;
151 }
152 widgets.clear();
153 int x_start = 0;
154 int y_start = 0;
155 int x_gap = 10;
156
157
158 layout->addWidget(variantEdit);
159 variantEdit->setGeometry(
160 x_start + 0 * (valueEditWidth + x_gap), y_start, valueEditWidth, 20);
161 variantEdit->setReadOnly(!enableEdit);
162
163 setValue(variant);
164
165
166 if (showType)
167 {
168 int x = x_start + 1 * (valueEditWidth + x_gap);
169 QLabel* label = new QLabel(this);
170 label->setTextInteractionFlags(Qt::TextSelectableByMouse);
171 label->setGeometry(x, y_start, 120, 21);
172 label->setText(variant->getTypeName().c_str());
173 layout->addWidget(label);
174
175 widgets.push_back(label);
176 }
177 }
178
179 void
181 {
182 // NYI
183 }
184} // namespace armarx
VariantWidget(VariantPtr variant, QWidget *parent=0, Qt::WindowFlags f=0)
void setEnableEdit(bool enableEdit)
void setShowType(bool showType)
void setValue(const VariantPtr &variant)
const VariantTypeId String
Definition Variant.h:921
const VariantTypeId Int
Definition Variant.h:917
const VariantTypeId Long
Definition Variant.h:918
const VariantTypeId Bool
Definition Variant.h:916
const VariantTypeId Double
Definition Variant.h:920
const VariantTypeId Float
Definition Variant.h:919
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< Variant > VariantPtr
Definition Variant.h:41
Ice::Int VariantTypeId
Definition Variant.h:43