##// END OF EJS Templates
Adds variable controller and properties to test structure...
Adds variable controller and properties to test structure - Properties will be used to define test bounds, like the number of variables to manipulate or the number of random operations to make - Variable controller will be the object manipulated during the random operations

File last commit:

r961:15899f42a907
r1169:49d15be9d590
Show More
GenerateVariableMenuOperation.cpp
216 lines | 7.4 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 {
Alexandre Leroux
Prohibits the plot of a variable in several graphs (2)...
r736 explicit GenerateVariableMenuOperationPrivate(
QMenu *menu, std::shared_ptr<Variable> variable,
std::set<IVisualizationWidget *> variableContainers)
: m_Variable{variable},
Alexandre Leroux
Removes compilation warnings (with Meson)
r961 m_VariableContainers{std::move(variableContainers)},
Alexandre Leroux
Prohibits the plot of a variable in several graphs (2)...
r736 m_PlotMenuBuilder{menu},
Alexandre Leroux
Removes compilation warnings (with Meson)
r961 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
Disables 'plot' menu when variable data have not been loaded yet
r404 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)...
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
Unplot menu (4): handles 'Unplot' menu when leaving a tab or a zone...
r326 void visitNodeLeavePlot(const IVisualizationWidget &container, const QString &actionName,
ActionFun actionFunction)
Alexandre Leroux
Implements visit of tab and zone...
r212 {
Alexandre Leroux
Prohibits the plot of a variable in several graphs (2)...
r736 if (isValidContainer(container)) {
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
Unplot menu (4): handles 'Unplot' menu when leaving a tab or a zone...
r326 void visitNodeLeaveUnplot()
{
// Closes the menu associated to the node
m_UnplotMenuBuilder.closeMenu();
}
Alexandre Leroux
Implements visit of graph...
r213 template <typename ActionFun>
Alexandre Leroux
Unplot menu (6): handles 'Unplot' menu when visiting a graph...
r328 void visitLeafPlot(const IVisualizationWidget &container, const QString &actionName,
ActionFun actionFunction)
Alexandre Leroux
Implements visit of graph...
r213 {
Alexandre Leroux
Prohibits the plot of a variable in several graphs (2)...
r736 if (isValidContainer(container)) {
Alexandre Leroux
Unplot menu (1)...
r323 m_PlotMenuBuilder.addAction(actionName, actionFunction);
Alexandre Leroux
Implements visit of graph...
r213 }
}
Alexandre Leroux
Unplot menu (6): handles 'Unplot' menu when visiting a graph...
r328 template <typename ActionFun>
Alexandre Leroux
Prohibits the plot of a variable in several graphs (2)...
r736 void visitLeafUnplot(IVisualizationWidget *container, const QString &actionName,
Alexandre Leroux
Unplot menu (6): handles 'Unplot' menu when visiting a graph...
r328 ActionFun actionFunction)
{
Alexandre Leroux
Prohibits the plot of a variable in several graphs (2)...
r736 // If the container contains the variable, we generate 'unplot' action
if (m_VariableContainers.count(container) == 1) {
Alexandre Leroux
Unplot menu (6): handles 'Unplot' menu when visiting a graph...
r328 m_UnplotMenuBuilder.addAction(actionName, actionFunction);
}
}
Alexandre Leroux
Prohibits the plot of a variable in several graphs (2)...
r736 bool isValidContainer(const IVisualizationWidget &container) const noexcept
{
// A container is valid if it can contain the variable and if the variable is not already
// contained in another container
return m_Variable && m_VariableContainers.size() == 0 && container.canDrop(*m_Variable);
}
Alexandre Leroux
Creates the visitor that generates a hierarchical menu associated with a variable....
r210 std::shared_ptr<Variable> m_Variable;
Alexandre Leroux
Prohibits the plot of a variable in several graphs (2)...
r736 std::set<IVisualizationWidget *> m_VariableContainers;
Alexandre Leroux
Unplot menu (6): handles 'Unplot' menu when visiting a graph...
r328 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....
r210 };
Alexandre Leroux
Prohibits the plot of a variable in several graphs (2)...
r736 GenerateVariableMenuOperation::GenerateVariableMenuOperation(
QMenu *menu, std::shared_ptr<Variable> variable,
std::set<IVisualizationWidget *> variableContainers)
: impl{spimpl::make_unique_impl<GenerateVariableMenuOperationPrivate>(
menu, variable, std::move(variableContainers))}
Alexandre Leroux
Creates the visitor that generates a hierarchical menu associated with a variable....
r210 {
}
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
Unplot menu (4): handles 'Unplot' menu when leaving a tab or a zone...
r326 // '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)
r361 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...
r326
// 'Unplot' menu
impl->visitNodeLeaveUnplot();
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
Unplot menu (4): handles 'Unplot' menu when leaving a tab or a zone...
r326 // 'Plot' menu
impl->visitNodeLeavePlot(
Alexandre Leroux
Completes visit of tab and zone...
r214 *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)
r361 [ 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...
r326
// 'Unplot' menu
impl->visitNodeLeaveUnplot();
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) {
Alexandre Leroux
Unplot menu (6): handles 'Unplot' menu when visiting a graph...
r328 // '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)
r361 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()) {
Initialisation of the graph range at creation in a new graphe, or inside...
r548 graphWidget->addVariable(var, graphWidget->graphRange());
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)
r361 }
});
Alexandre Leroux
Unplot menu (6): handles 'Unplot' menu when visiting a graph...
r328
// 'Unplot' menu
Alexandre Leroux
Prohibits the plot of a variable in several graphs (2)...
r736 impl->visitLeafUnplot(graphWidget, QObject::tr("Remove from %1").arg(graphWidget->name()),
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)
r361 [ varW = std::weak_ptr<Variable>{impl->m_Variable}, graphWidget ]() {
if (auto var = varW.lock()) {
graphWidget->removeVariable(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 }