From 946a2291304e34e9a5c9ec983e1353509d269bdb 2017-06-22 12:29:16 From: Alexandre Leroux Date: 2017-06-22 12:29:16 Subject: [PATCH] Implements visit of graph When a graph is visited, we check if it can contains the variable, and if it's the case, we add an action to the current menu to open the variable in this graph. --- diff --git a/gui/src/Visualization/operations/GenerateVariableMenuOperation.cpp b/gui/src/Visualization/operations/GenerateVariableMenuOperation.cpp index fa5bb1b..8ae2c92 100644 --- a/gui/src/Visualization/operations/GenerateVariableMenuOperation.cpp +++ b/gui/src/Visualization/operations/GenerateVariableMenuOperation.cpp @@ -31,6 +31,23 @@ struct MenuBuilder { } /** + * Adds action to the current menu + * @param actionName the name of the action + * @param actionFunction the function that will be executed when the action is triggered + */ + template + void addAction(const QString &actionName, ActionFun actionFunction) + { + if (auto currMenu = currentMenu()) { + currMenu->addAction(actionName, actionFunction); + } + else { + qCCritical(LOG_GenerateVariableMenuOperation()) + << QObject::tr("No current menu to attach the action"); + } + } + + /** * Adds a new menu to the current menu * @param name the name of the menu */ @@ -81,6 +98,15 @@ struct GenerateVariableMenuOperation::GenerateVariableMenuOperationPrivate { m_MenuBuilder.closeMenu(); } + template + void visitLeaf(const IVisualizationWidget &container, const QString &actionName, + ActionFun actionFunction) + { + if (m_Variable && container.canDrop(*m_Variable)) { + m_MenuBuilder.addAction(actionName, actionFunction); + } + } + std::shared_ptr m_Variable; MenuBuilder m_MenuBuilder; }; @@ -133,5 +159,9 @@ void GenerateVariableMenuOperation::visitLeave(VisualizationZoneWidget *zoneWidg void GenerateVariableMenuOperation::visit(VisualizationGraphWidget *graphWidget) { - /// @todo ALX + if (graphWidget) { + impl->visitLeaf( + *graphWidget, QObject::tr("Open in %1").arg(graphWidget->name()), + [ var = impl->m_Variable, graphWidget ]() { graphWidget->addVariable(var); }); + } }