ElementaryCheckPropertiesWidget.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
24
25#include <QHeaderView>
26#include <QLabel>
27#include <QScrollBar>
28
29#include <ArmarXCore/interface/observers/TermImplBase.h>
30#include <ArmarXCore/interface/observers/VariantBase.h>
33
34#include "../VariantWidget.h"
35
36namespace armarx
37{
39 const ConditionCheckBasePtr check,
40 std::string checkName,
41 bool showSupportedTypes,
42 bool showParameters,
43 bool showResult,
44 QWidget* parent,
45 Qt::WindowFlags f) :
46 PropertiesWidget(parent, f)
47 {
48 this->showSupportedTypes = showSupportedTypes;
49 this->showParameters = showParameters;
50 this->showResult = showResult;
51 this->checkName = checkName;
52
53 createUi(check);
54 }
55
56 void
57 ElementaryCheckPropertiesWidget::createUi(const ConditionCheckBasePtr check)
58 {
59 // create property entries
60 setPropertiesTitle("Check");
61 addProperty("Name", checkName.c_str());
62
63 // supported types
64 if (showSupportedTypes)
65 {
66 addHeading("Supported types");
67
68 QTableWidget* typesTable = new QTableWidget(this);
69 typesTable->horizontalHeader()->setStretchLastSection(true);
70 typesTable->setColumnCount(check->numberParameters + 1);
71 QStringList headers;
72 headers.append("Datafield");
73
74 for (int i = 0; i < check->numberParameters; i++)
75 {
76 headers.append(QString("Param %1").arg(i + 1));
77 }
78
79 typesTable->setHorizontalHeaderLabels(headers);
80 typesTable->verticalHeader()->setVisible(false);
81 typesTable->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
82 typesTable->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
83
84 int r = 0;
85
86 SupportedTypeList::const_iterator iter = check->supportedTypes.begin();
87
88 while (iter != check->supportedTypes.end())
89 {
90 typesTable->setRowCount(r + 1);
91 Variant tmp;
92 tmp.setType(iter->dataFieldType);
93 std::string typeStr = tmp.getTypeName();
94
95 if (iter->dataFieldType == 0)
96 {
97 typeStr = "Any type";
98 }
99
100 typesTable->setItem(r, 0, new QTableWidgetItem(typeStr.c_str()));
101
102 ParameterTypeList::const_iterator iterList = iter->parameterTypes.begin();
103 int c = 1;
104
105 while (iterList != iter->parameterTypes.end())
106 {
107 Variant tmp2;
108 tmp2.setType(*iterList);
109 std::string typeStr = tmp2.getTypeName();
110
111 if (*iterList == 0)
112 {
113 typeStr = "Any type";
114 }
115
116 typesTable->setItem(r, c, new QTableWidgetItem(typeStr.c_str()));
117
118 iterList++;
119 c++;
120 }
121
122 iter++;
123 r++;
124 }
125
126 addWidget(typesTable);
127 }
128
129 // check parameters
130 if (showParameters)
131 {
132 DataFieldIdentifierPtr dataField =
133 DataFieldIdentifierPtr::dynamicCast(check->configuration.dataFieldIdentifier);
134 addProperty("Datafield identifier", dataField->getIdentifierStr().c_str());
135
136 ParameterList::iterator iter = check->configuration.checkParameters.begin();
137 int p = 1;
138
139 while (iter != check->configuration.checkParameters.end())
140 {
141 VariantPtr parameter = VariantPtr::dynamicCast(*iter);
142
143 addProperty(QString("Param %1 type").arg(p), parameter->getTypeName().c_str());
144 addProperty(QString("Param %1 value").arg(p), new VariantWidget(parameter));
145
146 p++;
147 iter++;
148 }
149 }
150
151 // check result
152 if (showResult)
153 {
154 std::string text;
155
156 if (check->fulFilled)
157 {
158 text = "True";
159 }
160 else
161 {
162 text = "False";
163 }
164
165 addProperty("Fulfilled", text.c_str());
166 }
167 }
168} // namespace armarx
constexpr T c
ElementaryCheckPropertiesWidget(const ConditionCheckBasePtr check, std::string checkName, bool showSupportedTypes=true, bool showParameters=true, bool showResult=true, QWidget *parent=0, Qt::WindowFlags f=0)
void addWidget(QWidget *widget)
void addHeading(const QString &heading)
void addProperty(const QString &label, QWidget *propertyWidget)
void setPropertiesTitle(const QString &title)
PropertiesWidget(QWidget *parent=0, Qt::WindowFlags f=0)
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< Variant > VariantPtr
Definition Variant.h:41
IceInternal::Handle< DataFieldIdentifier > DataFieldIdentifierPtr
Typedef of DataFieldIdentifierPtr as IceInternal::Handle<DataFieldIdentifier> for convenience.