ActionsMenuBuilder.cpp
Go to the documentation of this file.
1 #include "ActionsMenuBuilder.h"
2 
4 
5 
7 {
10  QWidget* parent,
11  std::function<void(const MemoryID&, const actions::ActionPath&)> func) :
12  memoryID(std::move(memoryID)), parent(parent), func(std::move(func))
13  {
14  }
15 
16  QMenu*
17  ActionsMenuBuilder::buildActionsMenu(actions::data::GetActionsOutput& actionsOutput)
18  {
19  auto* menu = new QMenu("Actions", parent);
20 
21  for (const auto& entry : actions::Menu::fromIce(actionsOutput.menu).entries)
22  {
23  addMenuEntry(menu, {}, entry);
24  }
25 
26  return menu;
27  }
28 
29  void
30  ActionsMenuBuilder::addMenuEntry( // NOLINT (clangd complains about the recursion here)
31  QMenu* menu,
32  actions::ActionPath path,
33  const actions::MenuEntry& entry)
34  {
35  path.push_back(entry.id);
36  if (entry.entries.empty())
37  {
38  menu->addAction(QString::fromStdString(entry.text),
39  parent,
40  [this, path]() { func(memoryID, path); });
41  }
42  else
43  {
44  QMenu* qSubmenu = menu->addMenu(QString::fromStdString(entry.text));
45  for (const auto& subEntry : entry.entries)
46  {
47  addMenuEntry(qSubmenu, path, subEntry);
48  }
49  }
50  }
51 
52 } // namespace armarx::armem::gui
ActionsMenuBuilder.h
armarx::armem::actions::MenuEntry::text
std::string text
Definition: actions.h:29
armarx::armem::actions::MenuEntry
Definition: actions.h:13
armarx::armem::actions::Menu::entries
std::vector< MenuEntry > entries
Definition: actions.h:68
armarx::armem::gui::ActionsMenuBuilder::buildActionsMenu
QMenu * buildActionsMenu(actions::data::GetActionsOutput &actionsOutput)
Definition: ActionsMenuBuilder.cpp:17
armarx::armem::actions::MenuEntry::entries
std::vector< MenuEntry > entries
Definition: actions.h:30
armarx::armem::MemoryID
A memory ID.
Definition: MemoryID.h:47
armarx::armem::actions::Menu::fromIce
static Menu fromIce(const data::MenuPtr &ice)
Definition: actions.cpp:103
std
Definition: Application.h:66
armarx::armem::gui
Definition: ActionsMenuBuilder.cpp:6
armarx::armem::index::memoryID
const MemoryID memoryID
Definition: memory_ids.cpp:29
armarx::armem::gui::ActionsMenuBuilder::ActionsMenuBuilder
ActionsMenuBuilder(MemoryID memoryID, QWidget *parent, std::function< void(const MemoryID &, const actions::ActionPath &)> func)
Definition: ActionsMenuBuilder.cpp:8
armarx::armem::actions::MenuEntry::id
std::string id
Definition: actions.h:28
ice_conversions.h