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 <QGraphicsGridLayout>
25 #include <QGraphicsWidget>
26 #include <QGraphicsProxyWidget>
27 #include <QLabel>
28 #include <QPushButton> //TODO: remove after testing
29 
30 #include "../model/StateParameter.h"
31 #include "../StateScene.h"
32 #include "ParameterTableItem.h"
33 #include "StateItem.h"
34 
36  QGraphicsWidget(parent),
37  paramMap(parameterMap),
38  parentScene(parentItem()->scene())
39 {
40  QGraphicsGridLayout* layout = new QGraphicsGridLayout();
41 
42  setHeadRow(layout);
43 
44  int row = 1;
45 
46  for (statechartmodel::StateParameterPtr param : paramMap)
47  {
48  addStateParameterToLayout(param, layout, row);
49  row++;
50  }
51 
52  setLayout(layout);
53 }
54 
56 {
57  //delete stateScene? rather not, as it is not owned by this class
58 }
59 
60 void armarx::ParameterTableItem::addStateParameterToLayout(armarx::statechartmodel::StateParameterPtr param, QGraphicsGridLayout* layout, int row)
61 {
62  QGraphicsWidget* typeLabel = parentScene->addWidget(new QLabel(param->type));
63  QGraphicsWidget* defaultValueLabel = parentScene->addWidget(new QLabel(param->getDefaultValueJson())); //TODO: proper translation
64 
65  QString optionalText;
66 
67  if (param->optional)
68  {
69  optionalText = "yes";
70  }
71  else
72  {
73  optionalText = "no";
74  }
75 
76  QGraphicsWidget* optionalLabel = parentScene->addWidget(new QLabel(optionalText));
77 
78  QGraphicsWidget* descriptionLabel = parentScene->addWidget(new QLabel(param->description));
79 
80  layout->addItem(typeLabel, row, 0);
81  layout->addItem(defaultValueLabel, row, 1);
82  layout->addItem(optionalLabel, row, 2);
83  layout->addItem(descriptionLabel, row, 3);
84 }
85 
86 void armarx::ParameterTableItem::setHeadRow(QGraphicsGridLayout* layout)
87 {
88  QGraphicsWidget* typeItem = parentScene->addWidget(new QLabel("Type"));
89  QGraphicsWidget* defaultValueItem = parentScene->addWidget(new QLabel("Default Value"));
90  QGraphicsWidget* optionalItem = parentScene->addWidget(new QLabel("Is optional"));
91  QGraphicsWidget* descriptionItem = parentScene->addWidget(new QLabel("Description"));
92 
93  layout->addItem(typeItem, 0, 0);
94  layout->addItem(defaultValueItem, 0, 1);
95  layout->addItem(optionalItem, 0, 2);
96  layout->addItem(descriptionItem, 0, 3);
97 }
armarx::ParameterTableItem::ParameterTableItem
ParameterTableItem(statechartmodel::StateParameterMap parameterMap, QGraphicsItem *parent=0)
Definition: ParameterTableItem.cpp:35
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:55
ParameterTableItem.h