##// END OF EJS Templates
Unplot menu (3): handles 'Unplot' menu when entering a tab or a zone...
Unplot menu (3): handles 'Unplot' menu when entering a tab or a zone The behavior is the same as for the menu 'Plot'

File last commit:

r325:257ddf015a9e
r325:257ddf015a9e
Show More
GenerateVariableMenuOperation.cpp
154 lines | 5.0 KiB | text/x-c | CppLexer
/ gui / src / Visualization / operations / GenerateVariableMenuOperation.cpp
Alexandre Leroux
Creates the visitor that generates a hierarchical menu associated with a variable....
r210 #include "Visualization/operations/GenerateVariableMenuOperation.h"
Alexandre Leroux
Moves MenuBuilder in a new class
r222 #include "Visualization/operations/MenuBuilder.h"
Alexandre Leroux
Creates the visitor that generates a hierarchical menu associated with a variable....
r210
#include "Visualization/VisualizationGraphWidget.h"
#include "Visualization/VisualizationTabWidget.h"
#include "Visualization/VisualizationZoneWidget.h"
#include <Variable/Variable.h>
#include <QMenu>
Alexandre Leroux
Defines a menu builder...
r211 #include <QStack>
Q_LOGGING_CATEGORY(LOG_GenerateVariableMenuOperation, "GenerateVariableMenuOperation")
Alexandre Leroux
Creates the visitor that generates a hierarchical menu associated with a variable....
r210 struct GenerateVariableMenuOperation::GenerateVariableMenuOperationPrivate {
explicit GenerateVariableMenuOperationPrivate(QMenu *menu, std::shared_ptr<Variable> variable)
Alexandre Leroux
Unplot menu (2)...
r324 : m_Variable{variable}, m_PlotMenuBuilder{menu}, m_UnplotMenuBuilder{menu}
Alexandre Leroux
Creates the visitor that generates a hierarchical menu associated with a variable....
r210 {
}
Alexandre Leroux
Puts hierarchical menu in a 'Plot' menu
r309 void visitRootEnter()
{
// Creates the root menu
Alexandre Leroux
Unplot menu (1)...
r323 m_PlotMenuBuilder.addMenu(QObject::tr("Plot"), QIcon{":/icones/plot.png"});
Alexandre Leroux
Unplot menu (2)...
r324 m_UnplotMenuBuilder.addMenu(QObject::tr("Unplot"), QIcon{":/icones/unplot.png"});
Alexandre Leroux
Puts hierarchical menu in a 'Plot' menu
r309 }
void visitRootLeave()
{
// Closes the root menu
Alexandre Leroux
Unplot menu (1)...
r323 m_PlotMenuBuilder.closeMenu();
Alexandre Leroux
Unplot menu (2)...
r324 m_UnplotMenuBuilder.closeMenu();
Alexandre Leroux
Puts hierarchical menu in a 'Plot' menu
r309 }
Alexandre Leroux
Implements visit of tab and zone...
r212 void visitNodeEnter(const IVisualizationWidget &container)
{
// Opens a new menu associated to the node
Alexandre Leroux
Unplot menu (1)...
r323 m_PlotMenuBuilder.addMenu(container.name());
Alexandre Leroux
Unplot menu (3): handles 'Unplot' menu when entering a tab or a zone...
r325 m_UnplotMenuBuilder.addMenu(container.name());
Alexandre Leroux
Implements visit of tab and zone...
r212 }
template <typename ActionFun>
Alexandre Leroux
Completes visit of tab and zone...
r214 void visitNodeLeave(const IVisualizationWidget &container, const QString &actionName,
ActionFun actionFunction)
Alexandre Leroux
Implements visit of tab and zone...
r212 {
Alexandre Leroux
Completes visit of tab and zone...
r214 if (m_Variable && container.canDrop(*m_Variable)) {
Alexandre Leroux
Unplot menu (1)...
r323 m_PlotMenuBuilder.addSeparator();
m_PlotMenuBuilder.addAction(actionName, actionFunction);
Alexandre Leroux
Completes visit of tab and zone...
r214 }
Alexandre Leroux
Implements visit of tab and zone...
r212 // Closes the menu associated to the node
Alexandre Leroux
Unplot menu (1)...
r323 m_PlotMenuBuilder.closeMenu();
Alexandre Leroux
Implements visit of tab and zone...
r212 }
Alexandre Leroux
Implements visit of graph...
r213 template <typename ActionFun>
void visitLeaf(const IVisualizationWidget &container, const QString &actionName,
ActionFun actionFunction)
{
if (m_Variable && container.canDrop(*m_Variable)) {
Alexandre Leroux
Unplot menu (1)...
r323 m_PlotMenuBuilder.addAction(actionName, actionFunction);
Alexandre Leroux
Implements visit of graph...
r213 }
}
Alexandre Leroux
Creates the visitor that generates a hierarchical menu associated with a variable....
r210 std::shared_ptr<Variable> m_Variable;
Alexandre Leroux
Unplot menu (1)...
r323 MenuBuilder m_PlotMenuBuilder; ///< Builder for the 'Plot' menu
Alexandre Leroux
Unplot menu (2)...
r324 MenuBuilder m_UnplotMenuBuilder; ///< Builder for the 'Unplot' menu
Alexandre Leroux
Creates the visitor that generates a hierarchical menu associated with a variable....
r210 };
GenerateVariableMenuOperation::GenerateVariableMenuOperation(QMenu *menu,
std::shared_ptr<Variable> variable)
: impl{spimpl::make_unique_impl<GenerateVariableMenuOperationPrivate>(menu, variable)}
{
}
void GenerateVariableMenuOperation::visitEnter(VisualizationWidget *widget)
{
// VisualizationWidget is not intended to accommodate a variable
Q_UNUSED(widget)
Alexandre Leroux
Puts hierarchical menu in a 'Plot' menu
r309
Alexandre Leroux
Unplot menu (2)...
r324 // 'Plot' and 'Unplot' menus
Alexandre Leroux
Puts hierarchical menu in a 'Plot' menu
r309 impl->visitRootEnter();
Alexandre Leroux
Creates the visitor that generates a hierarchical menu associated with a variable....
r210 }
void GenerateVariableMenuOperation::visitLeave(VisualizationWidget *widget)
{
// VisualizationWidget is not intended to accommodate a variable
Q_UNUSED(widget)
Alexandre Leroux
Puts hierarchical menu in a 'Plot' menu
r309
Alexandre Leroux
Unplot menu (2)...
r324 // 'Plot' and 'Unplot' menus
Alexandre Leroux
Puts hierarchical menu in a 'Plot' menu
r309 impl->visitRootLeave();
Alexandre Leroux
Creates the visitor that generates a hierarchical menu associated with a variable....
r210 }
void GenerateVariableMenuOperation::visitEnter(VisualizationTabWidget *tabWidget)
{
Alexandre Leroux
Implements visit of tab and zone...
r212 if (tabWidget) {
Alexandre Leroux
Unplot menu (3): handles 'Unplot' menu when entering a tab or a zone...
r325 // 'Plot' and 'Unplot' menus
Alexandre Leroux
Implements visit of tab and zone...
r212 impl->visitNodeEnter(*tabWidget);
}
Alexandre Leroux
Adds comments
r221 else {
qCCritical(LOG_GenerateVariableMenuOperation(),
"Can't visit enter VisualizationTabWidget : the widget is null");
}
Alexandre Leroux
Creates the visitor that generates a hierarchical menu associated with a variable....
r210 }
void GenerateVariableMenuOperation::visitLeave(VisualizationTabWidget *tabWidget)
{
Alexandre Leroux
Implements visit of tab and zone...
r212 if (tabWidget) {
Alexandre Leroux
Completes visit of tab and zone...
r214 impl->visitNodeLeave(
*tabWidget, QObject::tr("Open in a new zone"),
[ var = impl->m_Variable, tabWidget ]() { tabWidget->createZone(var); });
Alexandre Leroux
Implements visit of tab and zone...
r212 }
Alexandre Leroux
Adds comments
r221 else {
qCCritical(LOG_GenerateVariableMenuOperation(),
"Can't visit leave VisualizationTabWidget : the widget is null");
}
Alexandre Leroux
Creates the visitor that generates a hierarchical menu associated with a variable....
r210 }
void GenerateVariableMenuOperation::visitEnter(VisualizationZoneWidget *zoneWidget)
{
Alexandre Leroux
Implements visit of tab and zone...
r212 if (zoneWidget) {
Alexandre Leroux
Unplot menu (3): handles 'Unplot' menu when entering a tab or a zone...
r325 // 'Plot' and 'Unplot' menus
Alexandre Leroux
Implements visit of tab and zone...
r212 impl->visitNodeEnter(*zoneWidget);
}
Alexandre Leroux
Adds comments
r221 else {
qCCritical(LOG_GenerateVariableMenuOperation(),
"Can't visit enter VisualizationZoneWidget : the widget is null");
}
Alexandre Leroux
Creates the visitor that generates a hierarchical menu associated with a variable....
r210 }
void GenerateVariableMenuOperation::visitLeave(VisualizationZoneWidget *zoneWidget)
{
Alexandre Leroux
Implements visit of tab and zone...
r212 if (zoneWidget) {
Alexandre Leroux
Completes visit of tab and zone...
r214 impl->visitNodeLeave(
*zoneWidget, QObject::tr("Open in a new graph"),
[ var = impl->m_Variable, zoneWidget ]() { zoneWidget->createGraph(var); });
Alexandre Leroux
Implements visit of tab and zone...
r212 }
Alexandre Leroux
Adds comments
r221 else {
qCCritical(LOG_GenerateVariableMenuOperation(),
"Can't visit leave VisualizationZoneWidget : the widget is null");
}
Alexandre Leroux
Creates the visitor that generates a hierarchical menu associated with a variable....
r210 }
void GenerateVariableMenuOperation::visit(VisualizationGraphWidget *graphWidget)
{
Alexandre Leroux
Implements visit of graph...
r213 if (graphWidget) {
impl->visitLeaf(
*graphWidget, QObject::tr("Open in %1").arg(graphWidget->name()),
variable time is now set to range graphe displayed when it is displayed...
r314 [ var = impl->m_Variable, graphWidget ]() { graphWidget->addVariableUsingGraph(var); });
Alexandre Leroux
Implements visit of graph...
r213 }
Alexandre Leroux
Adds comments
r221 else {
qCCritical(LOG_GenerateVariableMenuOperation(),
"Can't visit VisualizationGraphWidget : the widget is null");
}
Alexandre Leroux
Creates the visitor that generates a hierarchical menu associated with a variable....
r210 }