ParameterTableItem.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package
19  * @author
20  * @date
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 #include "ParameterTableItem.h"
25 
26 #include <QGraphicsGridLayout>
27 #include <QGraphicsProxyWidget>
28 #include <QGraphicsWidget>
29 #include <QLabel>
30 #include <QPushButton> //TODO: remove after testing
31 
32 #include "../StateScene.h"
33 #include "../model/StateParameter.h"
34 #include "StateItem.h"
35 
38  QGraphicsItem* parent) :
39  QGraphicsWidget(parent), paramMap(parameterMap), parentScene(parentItem()->scene())
40 {
41  QGraphicsGridLayout* layout = new QGraphicsGridLayout();
42 
43  setHeadRow(layout);
44 
45  int row = 1;
46 
47  for (statechartmodel::StateParameterPtr param : paramMap)
48  {
49  addStateParameterToLayout(param, layout, row);
50  row++;
51  }
52 
53  setLayout(layout);
54 }
55 
57 {
58  //delete stateScene? rather not, as it is not owned by this class
59 }
60 
61 void
62 armarx::ParameterTableItem::addStateParameterToLayout(
64  QGraphicsGridLayout* layout,
65  int row)
66 {
67  QGraphicsWidget* typeLabel = parentScene->addWidget(new QLabel(param->type));
68  QGraphicsWidget* defaultValueLabel =
69  parentScene->addWidget(new QLabel(param->getDefaultValueJson())); //TODO: proper translation
70 
71  QString optionalText;
72 
73  if (param->optional)
74  {
75  optionalText = "yes";
76  }
77  else
78  {
79  optionalText = "no";
80  }
81 
82  QGraphicsWidget* optionalLabel = parentScene->addWidget(new QLabel(optionalText));
83 
84  QGraphicsWidget* descriptionLabel = parentScene->addWidget(new QLabel(param->description));
85 
86  layout->addItem(typeLabel, row, 0);
87  layout->addItem(defaultValueLabel, row, 1);
88  layout->addItem(optionalLabel, row, 2);
89  layout->addItem(descriptionLabel, row, 3);
90 }
91 
92 void
93 armarx::ParameterTableItem::setHeadRow(QGraphicsGridLayout* layout)
94 {
95  QGraphicsWidget* typeItem = parentScene->addWidget(new QLabel("Type"));
96  QGraphicsWidget* defaultValueItem = parentScene->addWidget(new QLabel("Default Value"));
97  QGraphicsWidget* optionalItem = parentScene->addWidget(new QLabel("Is optional"));
98  QGraphicsWidget* descriptionItem = parentScene->addWidget(new QLabel("Description"));
99 
100  layout->addItem(typeItem, 0, 0);
101  layout->addItem(defaultValueItem, 0, 1);
102  layout->addItem(optionalItem, 0, 2);
103  layout->addItem(descriptionItem, 0, 3);
104 }
armarx::ParameterTableItem::ParameterTableItem
ParameterTableItem(statechartmodel::StateParameterMap parameterMap, QGraphicsItem *parent=0)
Definition: ParameterTableItem.cpp:36
StateItem.h
armarx::statechartmodel::StateParameterMap
QMap< QString, StateParameterPtr > StateParameterMap
Definition: StateParameter.h:46
armarx::statechartmodel::StateParameterPtr
std::shared_ptr< StateParameter > StateParameterPtr
Definition: StateParameter.h:45
armarx::ParameterTableItem::~ParameterTableItem
~ParameterTableItem() override
Definition: ParameterTableItem.cpp:56
ParameterTableItem.h