5 #include <QApplication>
8 #include <QResizeEvent>
11 #include <qcheckbox.h>
12 #include <qmessagebox.h>
13 #include <qpushbutton.h>
14 #include <qtreewidget.h>
32 std::optional<SkillID>
35 if (shownSkill.has_value())
37 return shownSkill.value().skillId;
56 if (shownSkill.has_value())
58 auto remDesc = shownSkill.value().descr;
74 QTreeWidgetItem* aronTreeWidgetItem =
new QTreeWidgetItem(
this);
75 aronTreeWidgetItem->setText(0, QString::fromStdString(
"Parameters"));
77 aronTreeWidgetController = std::make_shared<AronTreeWidgetController>(
78 this, aronTreeWidgetItem, aron_args, default_args_of_profile);
87 shownSkill = {skillId, descr, aronTreeWidgetController->convertToAron()};
93 this->aronTreeWidgetController =
nullptr;
99 if (not shownSkill.has_value())
110 auto skillsMap =
update.skills;
111 if (skillsMap.count(sid.
providerId.value()) == 0 ||
112 skillsMap.at(sid.
providerId.value()).count(sid) == 0)
123 if (descr.skillId != shownSkill->descr.skillId || descr.timeout != shownSkill->descr.timeout || descr.description != shownSkill->descr.description)
125 ARMARX_WARNING <<
"The skill description of the currently shown skill has changed. Resetting the widget...";
131 SkillDetailsTreeWidget::setupUi()
133 this->setColumnCount(3);
135 this->setContextMenuPolicy(Qt::CustomContextMenu);
136 this->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed);
138 QTreeWidgetItem* qtreewidgetitem2 = this->headerItem();
139 qtreewidgetitem2->setText(3,
"defaultValue (hidden in GUI)");
140 qtreewidgetitem2->setText(2,
"Type");
141 qtreewidgetitem2->setText(1,
"Value");
142 qtreewidgetitem2->setText(0,
"Key");
144 setColumnHidden(3,
true);
148 SkillDetailsTreeWidget::askUserToConfirmWidgetReset()
150 std::string msg =
"The skill details widget will be reset. All changes will be lost, unless saved.";
152 msgBox.setText(QString::fromStdString(msg));
153 QCheckBox* ignoreCheckbox =
new QCheckBox(
"Do not ask again in this session.");
154 msgBox.setCheckBox(ignoreCheckbox);
155 QPushButton* copyParamsButton = msgBox.addButton(tr(
"Copy Parameters && Close"), QMessageBox::ActionRole);
156 QPushButton* copySkillIdButton = msgBox.addButton(tr(
"Copy SkillID && Close"), QMessageBox::ActionRole);
157 QPushButton* closeWithoutSavingButton = msgBox.addButton(tr(
"Close"), QMessageBox::ActionRole);
159 msgBox.setDefaultButton(closeWithoutSavingButton);
160 QObject::connect(ignoreCheckbox, &QCheckBox::stateChanged, [
this](
int state){
161 if (
static_cast<Qt::CheckState
>(state) == Qt::CheckState::Checked) {
162 this->showWidgetResetConfirmation_ =
false;
173 SkillDetailsTreeWidget::checkIfParametersAreModified()
175 if (not shownSkill.has_value())
180 auto defaults = shownSkill->originalParameters;
182 if (this->aronTreeWidgetController.get() ==
nullptr)
187 auto params = this->aronTreeWidgetController->convertToAron();
189 if (defaults.get() ==
nullptr and params.get() ==
nullptr)
194 bool modified = not(*defaults == *params);
211 const int widthRemainder = this->width() - typeWidth;
214 const int dynamicColumnSize = widthRemainder / 2;
218 this->setColumnWidth(0, dynamicColumnSize);
220 this->setColumnWidth(1, dynamicColumnSize);
225 if (not shownSkill.has_value())
230 auto params =
memory->getLatestParametersForSkill(shownSkill->skillId);
232 if (not params.has_value())
237 ARMARX_INFO <<
"Reloaded parameters from the last execution";
238 aronTreeWidgetController->setFromAron(params.value());
243 auto executions =
memory->getExecutions();
244 if (executions.empty() || not shownSkill.has_value())
252 std::optional<armarx::skills::SkillStatusUpdate> found = std::nullopt;
253 for (
auto& execution : executions)
255 if (execution.first.skillId == shownSkill->skillId)
257 if (not found.has_value())
259 found = execution.second;
263 if (found->executionId.executionStartedTime < execution.first.executionStartedTime)
266 found = execution.second;
272 if (not found.has_value())
275 ARMARX_INFO<<
"No execution for the skill " << shownSkill->skillId.toString() <<
" has been found in the memory. The parametrization cannot be reloaded.";
278 auto params = found->parameters;
280 ARMARX_INFO <<
"Reloading parameters of skill " << found->executionId.skillId;
281 this->aronTreeWidgetController->setFromAron(params);
288 if (aronTreeWidgetController)
290 return aronTreeWidgetController->convertToAron();
305 QClipboard* clipboard = QApplication::clipboard();
306 clipboard->setText(QString::fromStdString(json.dump(2)));
311 if (not shownSkill.has_value())
316 QClipboard* clipboard = QApplication::clipboard();
317 clipboard->setText(QString::fromStdString(shownSkill->skillId.toString()));
323 QClipboard* clipboard = QApplication::clipboard();
324 std::string
s = clipboard->text().toStdString();
325 nlohmann::json json = nlohmann::json::parse(
s);
329 if (!aronTreeWidgetController)
334 aronTreeWidgetController->setFromAron(
data);
344 if (!shownSkill.has_value())
364 if (checkIfParametersAreModified())
366 if (shownSkill.has_value())
368 ARMARX_IMPORTANT <<
"A skill parametrization has been lost in the GUI. It can now be reloaded.";
369 memory->addParametersToHistory(shownSkill->skillId, aronTreeWidgetController->convertToAron());
370 emit
updated(shownSkill->skillId);
374 this->shownSkill = std::nullopt;
375 aronTreeWidgetController =
nullptr;