SkillDetailsGroupBox.cpp
Go to the documentation of this file.
2
3#include <qpushbutton.h>
4
7
9{
10 void
12 {
13 if (_skillId.skillName == SkillID::UNKNOWN)
14 return;
15
16 auto const& skills = memory->getSkills();
17
18 std::optional<skills::ProviderID> provider_opt;
19 // check skillId
20 if (_skillId.isProviderSpecified())
21 {
22 provider_opt = _skillId.providerId;
23 }
24 else
25 {
26 // find first provider to provide the skill
27 provider_opt = SkillManagerWrapper::findFirstProvider(skills, _skillId);
28 }
29
30 if (provider_opt == std::nullopt)
31 {
32 // skill was not found in snapshot. Abort...
33 return;
34 }
35
36 // construct skill id (with guaranteed valid provider)
37 skills::SkillID skillId = {provider_opt, _skillId.skillName};
38
39
40 // Maybe the search doesn't include the shown skill?
41 if (skills.count(skillId.providerId.value()) == 0 ||
42 skills.at(skillId.providerId.value()).count(skillId) == 0)
43 {
44 // reset details widget
45 skillDetailsTreeWidget->resetWidget();
46 return;
47 }
48
49
50 // get skill description
51 skills::SkillDescription descr = skills.at(skillId.providerId.value()).at(skillId);
52
53 // ------------ update widgets ------------
54
55 setDisabled(true);
56
57 // setup groupBox
58 titleLabel->setText(QString::fromStdString(skillId.toString()));
59 setDisabled(false);
60
61 // setup table view
62 skillDetailsTreeWidget->updateContents(skillId, descr);
63
64 // description widget
65 skillDescriptionWidget->setSkillDescription(descr);
66
67
68 // add new profiles for this skill
69 // TODO: Where stored?
70 }
71
72 void
73 SkillDetailGroupBox::connectGui(std::string observerName)
74 {
75 skillDetailsTreeWidget->setEditTriggers(QAbstractItemView::EditTrigger::NoEditTriggers);
76 }
77
78 void
79 SkillDetailGroupBox::handleExecutionRequest()
80 {
81 auto data = skillDetailsTreeWidget->getConfigAsAron();
82 auto skillId = skillDetailsTreeWidget->getShownId();
83 if (skillId.has_value())
84 {
85 memory->startExecutionWithParams(skillId.value(), data);
86 }
87 }
88
89 void
90 SkillDetailGroupBox::resizeEvent(QResizeEvent* event)
91 {
92 QGroupBox::resizeEvent(event);
93 skillDetailsTreeWidget->resizeContents();
94 }
95
96 void
97 SkillDetailGroupBox::setupUi()
98 {
99 this->setTitle(QString::fromStdString(GROUP_BOX_TITLE));
100 titleLabel = new QLabel(QString::fromStdString("Skill ID"));
101 titleLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
102
103 this->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
104
105 // construct all sub widgets
106 this->executeSkillButton = new QPushButton();
107 this->profileMenuWidget = new ProfileMenuWidget(this->memory, this);
108 this->skillDetailsTreeWidget = new SkillDetailsTreeWidget(this->memory, this);
109 this->skillDescriptionWidget = new SkillDescriptionWidget(this);
110 this->layout = new QVBoxLayout();
111 this->splitter = new QSplitter();
112 splitter->setOrientation(Qt::Orientation::Vertical);
113
114 // Layouting
115 this->setLayout(layout);
116 layout->addWidget(titleLabel);
117 layout->addWidget(this->profileMenuWidget);
118 layout->addWidget(splitter);
119 splitter->addWidget(this->skillDescriptionWidget);
120 splitter->addWidget(this->skillDetailsTreeWidget);
121 layout->addWidget(this->executeSkillButton);
122
123 // Text
124 this->executeSkillButton->setText(
125 QString::fromStdString(SkillDetailGroupBox::EXECUTE_SKILL_BUTTON_TEXT));
126 {
127 QPixmap pix(QString::fromStdString(":icons/run.svg"));
128 QIcon icon(pix);
129 this->executeSkillButton->setIcon(icon);
130 }
131
132
133 connectSignals();
134 }
135
136 void
137 SkillDetailGroupBox::connectSignals()
138 {
139 connect(executeSkillButton,
140 &QPushButton::clicked,
141 this,
142 &SkillDetailGroupBox::handleExecutionRequest);
143 connect(this,
145 skillDetailsTreeWidget,
147 connect(this,
149 skillDetailsTreeWidget,
151
152 // profile buttons
153 connect(profileMenuWidget->copyArgsToClipboard,
154 &QPushButton::clicked,
155 skillDetailsTreeWidget,
157 connect(profileMenuWidget->copyShortcutToClipboard,
158 &QPushButton::clicked,
159 skillDetailsTreeWidget,
161 connect(profileMenuWidget->setArgsFromClipboard,
162 &QPushButton::clicked,
163 skillDetailsTreeWidget,
165 connect(profileMenuWidget->resetArgsToProfile,
166 &QPushButton::clicked,
167 skillDetailsTreeWidget,
169 connect(profileMenuWidget->changesSelector,
170 &QPushButton::pressed,
171 skillDetailsTreeWidget,
173 connect(skillDetailsTreeWidget,
175 profileMenuWidget,
177 connect(profileMenuWidget->historySelector,
178 &QPushButton::pressed,
179 skillDetailsTreeWidget,
181 }
182
183
184} // namespace armarx::skills::gui
Brief description of class memory.
Definition memory.h:39
bool isProviderSpecified() const
Definition SkillID.cpp:90
std::string toString() const
Definition SkillID.cpp:68
std::optional< ProviderID > providerId
Definition SkillID.h:40
static const constexpr char * UNKNOWN
Definition SkillID.h:18
std::string skillName
Definition SkillID.h:41
std::shared_ptr< SkillManagerWrapper > memory
void updateChangesSelector(const skills::SkillID shownSkill)
static const constexpr char * GROUP_BOX_TITLE
void updateSkillDetails(skills::SkillID &skillId)
Notify subwidgets of an updated skill selection.
void updateGui(SkillManagerWrapper::Snapshot update)
static const constexpr char * EXECUTE_SKILL_BUTTON_TEXT
void resizeContents()
Problem: columns 0 and 1 have arbitrary size; so we want to limit their size, to make sure everything...
void updated(const skills::SkillID shownSkill)
void updateGui(SkillManagerWrapper::Snapshot update)
std::optional< skills::SkillID > getShownId()
static const std::optional< skills::ProviderID > findFirstProvider(SkillMap const &map, SkillID const &skillId)
This file is part of ArmarX.