6 #include <QTreeWidgetItem>
8 #include "../AronTreeWidgetItem.h"
9 #include "../ListDictHelper.h"
17 QTreeWidget* contextMenuParent,
19 parentItem(i), contextMenuParent(contextMenuParent), pos(pos),
index(x)
24 AronTreeWidgetContextMenuVisitor::addDeleteAction()
32 auto aronType = castedParent->aronType->getDescriptor();
35 QMenu contextMenu(
"Context menu", contextMenuParent);
36 actions.emplace_back(
"remove element", contextMenuParent);
37 action_callbacks.push_back([
this]()
mutable { this->executeDelete(); });
42 AronTreeWidgetContextMenuVisitor::executeDelete()
44 auto* containerPtr = parentItem->QTreeWidgetItem::parent();
45 containerPtr->removeChild(parentItem);
49 if (castedContainer &&
53 for (
int i = index; i < castedContainer->childCount(); ++i)
56 castedContainer->child(i)->setText(0, numberString.c_str());
60 containerPtr->setText(1, numElemsText);
62 auto currFont = castedContainer->font(1);
63 currFont.setItalic(
true);
64 castedContainer->setFont(1, currFont);
77 armarx::AronTreeWidgetContextMenuVisitor::addAddAction()
79 actions.emplace_back(
"Add element", contextMenuParent);
80 action_callbacks.push_back([
this]()
mutable { this->executeAddElement(); });
84 AronTreeWidgetContextMenuVisitor::executeAddElement()
86 AronTreeWidgetCreatorVisitor creator(parentItem);
89 if (!creator.createdQWidgetItem)
91 throw std::runtime_error(
"Creation of TreeElementChild failed unexpectedly");
97 if (castedContainer &&
102 castedContainer->setText(1, numElemsText);
104 auto currFont = castedContainer->font(1);
105 currFont.setItalic(
true);
106 castedContainer->setFont(1, currFont);
211 ARMARX_WARNING <<
"Tried to open Context menu on unknown aron type";
217 QMenu menu(
"Context Menu", contextMenuParent);
218 for (
auto& el : actions)
222 auto* chosenAction = menu.exec(contextMenuParent->mapToGlobal(pos));
230 auto it = actions.begin();
232 while (it != actions.end())
234 if (chosenAction == &*it)
236 action_callbacks[count]();