How to find QMenu by Path?
I have QMenuBar with menu: File, New, Addons, Help. What I want to do: Menu with the name Addons is configurable. The user writes in console, for example, create_menu("Hello/world"), I need to create QMenu in Addons with the name "Hello" and Action in that menu with name world. If the user writes create_menu("Hello/world2") I need to add an action with the name "world2" in the menu Hello. Also i want to implement command to delete menus by that path. Now I have such a solution to create menus, but I what to find the simpler solution:
auto fspath = std::filesystem::path(path);
std::function<std::pair<QMenu*, fs::path::iterator>(QMenu*, fs::path::iterator,
fs::path::iterator)> enumerateMenu = [&enumerateMenu](auto menu, auto it, auto end)
{
foreach (QAction *action, menu->actions()) {
if(it != end && (*it) == action->text().toStdString() && action->menu())
return enumerateMenu(action->menu(), ++it, end);
}
return std::make_pair(menu, it);
};
auto menuPos = enumerateMenu(customMenu, fspath.begin(), fspath.end());
auto submenu = menuPos.first;
for(auto it = menuPos.second;; ++it)
{
if(std::next(it) != fspath.end())
submenu = submenu->addMenu(QString::fromUtf8((it->c_str())));
else
{
auto actionsList = submenu->actions();
auto pa = new QAction(QString::fromUtf8(it->c_str()), this);
//connect(pa, &QAction::triggered, /*Not implemented*/);
submenu->addAction(pa);
break;
}
}
How many English words
do you know?
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
how many words do you know
Powered by Examplum