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