YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
partItemTree.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: LGPL-2.1-or-later
5 */
6
7#include "partItemTree.h"
8
9PartItemTree::PartItemTree(int index, QWidget *parent) : QWidget(parent), m_index(index)
10{
11 const int flowLayoutSpacing = 5;
12 m_layout = new FlowLayout(flowLayoutSpacing, flowLayoutSpacing, flowLayoutSpacing);
13 setLayout(m_layout);
14 setFocusPolicy(Qt::FocusPolicy::NoFocus);
15 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
16}
17
19{
20 return m_layout->count();
21}
22
24{
25 JointItemTree* added = new JointItemTree(m_layout->count(), this);
26 connect(added, SIGNAL(sig_jointClicked(int)), this, SLOT(onJointClicked(int)));
27 connect(added, SIGNAL(sig_homeClicked(int)), this, SLOT(onHomeClicked(int)));
28 connect(added, SIGNAL(sig_runClicked(int)), this, SLOT(onRunClicked(int)));
29 connect(added, SIGNAL(sig_idleClicked(int)), this, SLOT(onIdleClicked(int)));
30 connect(added, SIGNAL(sig_PIDClicked(int)), this, SLOT(onPIDClicked(int)));
31
32 m_layout->addWidget(added);
33 return added;
34}
35
37{
38 if (index < 0 || index >= numberOfJoints())
39 {
40 return nullptr;
41 }
42
43 return static_cast<JointItemTree*>(m_layout->itemAt(index)->widget());
44}
45
47{
48 if (m_layout->count() == 0)
49 {
50 return;
51 }
52
53 QSize desiredSize = m_desiredElementSize.expandedTo(getMaxElementSize());
54
55 for (int i = 0; i < m_layout->count(); ++i)
56 {
57 JointItemTree* item = getJoint(i);
58 item->setDesiredSize(desiredSize.width(), desiredSize.height());
59 }
60
61 m_layout->activate(); //Update the layout
62}
63
64void PartItemTree::resizeEvent(QResizeEvent *event)
65{
67 QWidget::resizeEvent(event);
68}
69
71{
72 QSize output;
73 m_layout->activate(); //To make sure that the widgets have already the appropriate size
74
75 for (int i = 0; i < m_layout->count(); ++i)
76 {
77 output = output.expandedTo(m_layout->itemAt(i)->widget()->size());
78 }
79 return output;
80}
81
82void PartItemTree::setDesiredElementSize(const QSize& maxSize)
83{
84 m_desiredElementSize = maxSize;
85}
86
88{
89 emit sig_jointClicked(m_index, index);
90}
91
93{
94 emit sig_homeClicked(m_index, index);
95}
96
98{
99 emit sig_runClicked(m_index, index);
100}
101
103{
104 emit sig_idleClicked(m_index, index);
105}
106
108{
109 emit sig_PIDClicked(m_index, index);
110}
int SIGNAL(int pid, int signum)
Original license follows:
Definition flowlayout.h:59
QLayoutItem * itemAt(int index) const override
int count() const override
void setDesiredSize(int w, int h)
void resizeEvent(QResizeEvent *event) override
void onRunClicked(int index)
void onHomeClicked(int index)
void sig_jointClicked(int partIndex, int jointIndex)
void setDesiredElementSize(const QSize &maxSize)
void sig_homeClicked(int partIndex, int jointIndex)
JointItemTree * getJoint(int index)
void onPIDClicked(int index)
QSize getMaxElementSize()
PartItemTree(int index, QWidget *parent=nullptr)
int numberOfJoints() const
void sig_idleClicked(int partIndex, int jointIndex)
void onJointClicked(int index)
void sig_runClicked(int partIndex, int jointIndex)
void sig_PIDClicked(int partIndex, int jointIndex)
void onIdleClicked(int index)
JointItemTree * addJoint()
void uniformLayout()