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);
76 AronTreeWidgetContextMenuVisitor::addAddAction()
78 actions.emplace_back(
"Add element", contextMenuParent);
79 action_callbacks.push_back([
this]()
mutable { this->executeAddElement(); });
83 AronTreeWidgetContextMenuVisitor::executeAddElement()
88 if (!creator.createdQWidgetItem)
90 throw std::runtime_error(
"Creation of TreeElementChild failed unexpectedly");
96 if (castedContainer &&
101 castedContainer->setText(1, numElemsText);
103 auto currFont = castedContainer->font(1);
104 currFont.setItalic(
true);
105 castedContainer->setFont(1, currFont);
210 ARMARX_WARNING <<
"Tried to open Context menu on unknown aron type";
216 QMenu menu(
"Context Menu", contextMenuParent);
217 for (
auto& el : actions)
221 auto* chosenAction = menu.exec(contextMenuParent->mapToGlobal(pos));
229 auto it = actions.begin();
231 while (it != actions.end())
233 if (chosenAction == &*it)
235 action_callbacks[count]();