29 namespace ProjectActions {
31 ViewerActions::ViewerActions(
const shared_ptr<Viewer::IViewerNode>& root_node)
33 function<QMenu*(const shared_ptr<Viewer::IViewerNode>&, QAction*)> init_recursive;
34 init_recursive = [&](
const shared_ptr<Viewer::IViewerNode>& root_node, QAction* parent_action)
38 for (
auto& node : *root_node) {
39 result->addSeparator();
41 QAction* enable_action = result->addAction(QString::fromStdString(node.first));
42 enable_action->setCheckable(
true);
43 if (node.second->IsEnabled())
44 enable_action->setChecked(
true);
45 enable_action->setEnabled(node.second->IsParentEnabled());
46 m_node_map.insert({enable_action, node.second});
47 m_children_map[parent_action].push_back(enable_action);
48 connect(enable_action, SIGNAL(toggled(
bool)),
this, SLOT(SLOT_Toggle(
bool)));
49 auto children_menu = init_recursive(node.second, enable_action);
50 if (children_menu->actions().size())
51 result->addMenu(children_menu);
55 m_menu = init_recursive(root_node,
nullptr);
58 ViewerActions::~ViewerActions()
62 shared_ptr<ViewerActions> ViewerActions::Create(
const shared_ptr<Viewer::IViewerNode>& root_node)
64 auto result = shared_ptr<ViewerActions>(
new ViewerActions(root_node));
66 for (
auto& val : result->m_node_map) {
68 auto type = e.GetType();
69 bool checked = type == Viewer::Event::ViewerEvent::Enabled;
70 static_cast<QAction*>(val.first)->setChecked(checked);
77 QMenu* ViewerActions::GetMenu()
const
82 void ViewerActions::SLOT_Toggle(
bool checked)
84 auto& node = m_node_map[sender()];
92 function<void(vector<QAction*>& children)> work_on_children;
93 work_on_children = [&](vector<QAction*>& children) {
94 for (
auto a : children) {
95 a->setEnabled(m_node_map[a]->IsParentEnabled());
96 work_on_children(m_children_map[a]);
99 work_on_children(m_children_map[sender()]);
Given a so-called 'root' viewer instance, constructs a menu representing the hierarchical structure o...
An event transmitted by viewers to notify whether they are enabled or disabled.
see the online Qt documentation
Namespace for generic graphical shell for simulators.