##// END OF EJS Templates
Add connection logical for the rescale operation
Add connection logical for the rescale operation

File last commit:

r371:40749dfba67d
r403:9fabd78ca3ee
Show More
GenerateVariableMenuOperation.cpp
200 lines | 6.7 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....
r195 #include "Visualization/operations/GenerateVariableMenuOperation.h"
Alexandre Leroux
Moves MenuBuilder in a new class
r207 #include "Visualization/operations/MenuBuilder.h"
Alexandre Leroux
Creates the visitor that generates a hierarchical menu associated with a variable....
r195
#include "Visualization/VisualizationGraphWidget.h"
#include "Visualization/VisualizationTabWidget.h"
#include "Visualization/VisualizationZoneWidget.h"
#include <Variable/Variable.h>
#include <QMenu>
Alexandre Leroux
Defines a menu builder...
r196 #include <QStack>
Q_LOGGING_CATEGORY(LOG_GenerateVariableMenuOperation, "GenerateVariableMenuOperation")
Alexandre Leroux
Creates the visitor that generates a hierarchical menu associated with a variable....
r195 struct GenerateVariableMenuOperation::GenerateVariableMenuOperationPrivate {
explicit GenerateVariableMenuOperationPrivate(QMenu *menu, std::shared_ptr<Variable> variable)
Alexandre Leroux
Unplot menu (2)...
r298 : m_Variable{variable}, m_PlotMenuBuilder{menu}, m_UnplotMenuBuilder{menu}
Alexandre Leroux
Creates the visitor that generates a hierarchical menu associated with a variable....
r195 {
}
Alexandre Leroux
Puts hierarchical menu in a 'Plot' menu
r286 void visitRootEnter()
{
// Creates the root menu
Alexandre Leroux
Disables 'plot' menu when variable data have not been loaded yet
r371 if (auto plotMenu
= m_PlotMenuBuilder.addMenu(QObject::tr("Plot"), QIcon{":/icones/plot.png"})) {
plotMenu->setEnabled(m_Variable && m_Variable->dataSeries() != nullptr);
}
Alexandre Leroux
Unplot menu (2)...
r298 m_UnplotMenuBuilder.addMenu(QObject::tr("Unplot"), QIcon{":/icones/unplot.png"});
Alexandre Leroux
Puts hierarchical menu in a 'Plot' menu
r286 }
void visitRootLeave()
{
// Closes the root menu
Alexandre Leroux
Unplot menu (1)...
r297 m_PlotMenuBuilder.closeMenu();
Alexandre Leroux
Unplot menu (2)...
r298 m_UnplotMenuBuilder.closeMenu();
Alexandre Leroux
Puts hierarchical menu in a 'Plot' menu
r286 }
Alexandre Leroux
Implements visit of tab and zone...
r197 void visitNodeEnter(const IVisualizationWidget &container)
{
// Opens a new menu associated to the node
Alexandre Leroux
Unplot menu (1)...
r297 m_PlotMenuBuilder.addMenu(container.name());
Alexandre Leroux
Unplot menu (3): handles 'Unplot' menu when entering a tab or a zone...
r299 m_UnplotMenuBuilder.addMenu(container.name());
Alexandre Leroux
Implements visit of tab and zone...
r197 }
template <typename ActionFun>
Alexandre Leroux
Unplot menu (4): handles 'Unplot' menu when leaving a tab or a zone...
r300 void visitNodeLeavePlot(const IVisualizationWidget &container, const QString &actionName,
ActionFun actionFunction)
Alexandre Leroux
Implements visit of tab and zone...
r197 {
Alexandre Leroux
Completes visit of tab and zone...
r199 if (m_Variable && container.canDrop(*m_Variable)) {
Alexandre Leroux
Unplot menu (1)...
r297 m_PlotMenuBuilder.addSeparator();
m_PlotMenuBuilder.addAction(actionName, actionFunction);
Alexandre Leroux
Completes visit of tab and zone...
r199 }
Alexandre Leroux
Implements visit of tab and zone...
r197 // Closes the menu associated to the node
Alexandre Leroux
Unplot menu (1)...
r297 m_PlotMenuBuilder.closeMenu();
Alexandre Leroux
Implements visit of tab and zone...
r197 }
Alexandre Leroux
Unplot menu (4): handles 'Unplot' menu when leaving a tab or a zone...
r300 void visitNodeLeaveUnplot()
{
// Closes the menu associated to the node
m_UnplotMenuBuilder.closeMenu();
}
Alexandre Leroux
Implements visit of graph...
r198 template <typename ActionFun>
Alexandre Leroux
Unplot menu (6): handles 'Unplot' menu when visiting a graph...
r302 void visitLeafPlot(const IVisualizationWidget &container, const QString &actionName,
ActionFun actionFunction)
Alexandre Leroux
Implements visit of graph...
r198 {
if (m_Variable && container.canDrop(*m_Variable)) {
Alexandre Leroux
Unplot menu (1)...
r297 m_PlotMenuBuilder.addAction(actionName, actionFunction);
Alexandre Leroux
Implements visit of graph...
r198 }
}
Alexandre Leroux
Unplot menu (6): handles 'Unplot' menu when visiting a graph...
r302 template <typename ActionFun>
void visitLeafUnplot(const IVisualizationWidget &container, const QString &actionName,
ActionFun actionFunction)
{
if (m_Variable && container.contains(*m_Variable)) {
m_UnplotMenuBuilder.addAction(actionName, actionFunction);
}
}
Alexandre Leroux
Creates the visitor that generates a hierarchical menu associated with a variable....
r195 std::shared_ptr<Variable> m_Variable;
Alexandre Leroux
Unplot menu (6): handles 'Unplot' menu when visiting a graph...
r302 MenuBuilder m_PlotMenuBuilder; ///< Builder for the 'Plot' menu
MenuBuilder m_UnplotMenuBuilder; ///< Builder for the 'Unplot' menu
Alexandre Leroux
Creates the visitor that generates a hierarchical menu associated with a variable....
r195 };
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
r286
Alexandre Leroux
Unplot menu (2)...
r298 // 'Plot' and 'Unplot' menus
Alexandre Leroux
Puts hierarchical menu in a 'Plot' menu
r286 impl->visitRootEnter();
Alexandre Leroux
Creates the visitor that generates a hierarchical menu associated with a variable....
r195 }
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
r286
Alexandre Leroux
Unplot menu (2)...
r298 // 'Plot' and 'Unplot' menus
Alexandre Leroux
Puts hierarchical menu in a 'Plot' menu
r286 impl->visitRootLeave();
Alexandre Leroux
Creates the visitor that generates a hierarchical menu associated with a variable....
r195 }
void GenerateVariableMenuOperation::visitEnter(VisualizationTabWidget *tabWidget)
{
Alexandre Leroux
Implements visit of tab and zone...
r197 if (tabWidget) {
Alexandre Leroux
Unplot menu (3): handles 'Unplot' menu when entering a tab or a zone...
r299 // 'Plot' and 'Unplot' menus
Alexandre Leroux
Implements visit of tab and zone...
r197 impl->visitNodeEnter(*tabWidget);
}
Alexandre Leroux
Adds comments
r206 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....
r195 }
void GenerateVariableMenuOperation::visitLeave(VisualizationTabWidget *tabWidget)
{
Alexandre Leroux
Implements visit of tab and zone...
r197 if (tabWidget) {
Alexandre Leroux
Unplot menu (4): handles 'Unplot' menu when leaving a tab or a zone...
r300 // 'Plot' menu
Alexandre Leroux
Uses weak pointers in lambda functions to prevent a shared_ptr from ever being deleted (because a reference would always be kept in the lambda)
r334 impl->visitNodeLeavePlot(*tabWidget, QObject::tr("Open in a new zone"),
[ varW = std::weak_ptr<Variable>{impl->m_Variable}, tabWidget ]() {
if (auto var = varW.lock()) {
tabWidget->createZone(var);
}
});
Alexandre Leroux
Unplot menu (4): handles 'Unplot' menu when leaving a tab or a zone...
r300
// 'Unplot' menu
impl->visitNodeLeaveUnplot();
Alexandre Leroux
Implements visit of tab and zone...
r197 }
Alexandre Leroux
Adds comments
r206 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....
r195 }
void GenerateVariableMenuOperation::visitEnter(VisualizationZoneWidget *zoneWidget)
{
Alexandre Leroux
Implements visit of tab and zone...
r197 if (zoneWidget) {
Alexandre Leroux
Unplot menu (3): handles 'Unplot' menu when entering a tab or a zone...
r299 // 'Plot' and 'Unplot' menus
Alexandre Leroux
Implements visit of tab and zone...
r197 impl->visitNodeEnter(*zoneWidget);
}
Alexandre Leroux
Adds comments
r206 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....
r195 }
void GenerateVariableMenuOperation::visitLeave(VisualizationZoneWidget *zoneWidget)
{
Alexandre Leroux
Implements visit of tab and zone...
r197 if (zoneWidget) {
Alexandre Leroux
Unplot menu (4): handles 'Unplot' menu when leaving a tab or a zone...
r300 // 'Plot' menu
impl->visitNodeLeavePlot(
Alexandre Leroux
Completes visit of tab and zone...
r199 *zoneWidget, QObject::tr("Open in a new graph"),
Alexandre Leroux
Uses weak pointers in lambda functions to prevent a shared_ptr from ever being deleted (because a reference would always be kept in the lambda)
r334 [ varW = std::weak_ptr<Variable>{impl->m_Variable}, zoneWidget ]() {
if (auto var = varW.lock()) {
zoneWidget->createGraph(var);
}
});
Alexandre Leroux
Unplot menu (4): handles 'Unplot' menu when leaving a tab or a zone...
r300
// 'Unplot' menu
impl->visitNodeLeaveUnplot();
Alexandre Leroux
Implements visit of tab and zone...
r197 }
Alexandre Leroux
Adds comments
r206 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....
r195 }
void GenerateVariableMenuOperation::visit(VisualizationGraphWidget *graphWidget)
{
Alexandre Leroux
Implements visit of graph...
r198 if (graphWidget) {
Alexandre Leroux
Unplot menu (6): handles 'Unplot' menu when visiting a graph...
r302 // 'Plot' menu
Alexandre Leroux
Uses weak pointers in lambda functions to prevent a shared_ptr from ever being deleted (because a reference would always be kept in the lambda)
r334 impl->visitLeafPlot(*graphWidget, QObject::tr("Open in %1").arg(graphWidget->name()),
[ varW = std::weak_ptr<Variable>{impl->m_Variable}, graphWidget ]() {
if (auto var = varW.lock()) {
graphWidget->addVariableUsingGraph(var);
}
});
Alexandre Leroux
Unplot menu (6): handles 'Unplot' menu when visiting a graph...
r302
// 'Unplot' menu
Alexandre Leroux
Uses weak pointers in lambda functions to prevent a shared_ptr from ever being deleted (because a reference would always be kept in the lambda)
r334 impl->visitLeafUnplot(*graphWidget, QObject::tr("Remove from %1").arg(graphWidget->name()),
[ varW = std::weak_ptr<Variable>{impl->m_Variable}, graphWidget ]() {
if (auto var = varW.lock()) {
graphWidget->removeVariable(var);
}
});
Alexandre Leroux
Implements visit of graph...
r198 }
Alexandre Leroux
Adds comments
r206 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....
r195 }