@@ -7,7 +7,10 | |||
|
7 | 7 | |
|
8 | 8 | #include <QLoggingCategory> |
|
9 | 9 | |
|
10 | #include <set> | |
|
11 | ||
|
10 | 12 | class QMenu; |
|
13 | class IVisualizationWidget; | |
|
11 | 14 | class Variable; |
|
12 | 15 | |
|
13 | 16 | Q_DECLARE_LOGGING_CATEGORY(LOG_GenerateVariableMenuOperation) |
@@ -23,8 +26,11 public: | |||
|
23 | 26 | * Ctor |
|
24 | 27 | * @param menu the menu to which to attach the generated menu |
|
25 | 28 | * @param variable the variable for which to generate the menu |
|
29 | * @param variableContainers the containers that already contain the variable for which to | |
|
30 | * generate the menu | |
|
26 | 31 | */ |
|
27 |
explicit GenerateVariableMenuOperation(QMenu *menu, std::shared_ptr<Variable> variable |
|
|
32 | explicit GenerateVariableMenuOperation(QMenu *menu, std::shared_ptr<Variable> variable, | |
|
33 | std::set<IVisualizationWidget *> variableContainers); | |
|
28 | 34 | |
|
29 | 35 | void visitEnter(VisualizationWidget *widget) override final; |
|
30 | 36 | void visitLeave(VisualizationWidget *widget) override final; |
@@ -3,6 +3,7 | |||
|
3 | 3 | #include "Visualization/VisualizationGraphWidget.h" |
|
4 | 4 | #include "Visualization/VisualizationTabWidget.h" |
|
5 | 5 | #include "Visualization/VisualizationZoneWidget.h" |
|
6 | #include "Visualization/operations/FindVariableOperation.h" | |
|
6 | 7 | #include "Visualization/operations/GenerateVariableMenuOperation.h" |
|
7 | 8 | #include "Visualization/operations/RemoveVariableOperation.h" |
|
8 | 9 | #include "Visualization/operations/RescaleAxeOperation.h" |
@@ -120,8 +121,14 void VisualizationWidget::attachVariableMenu( | |||
|
120 | 121 | // Menu is generated only if there is a single variable |
|
121 | 122 | if (variables.size() == 1) { |
|
122 | 123 | if (auto variable = variables.first()) { |
|
124 | // Gets the containers of the variable | |
|
125 | FindVariableOperation findVariableOperation{variable}; | |
|
126 | accept(&findVariableOperation); | |
|
127 | auto variableContainers = findVariableOperation.result(); | |
|
128 | ||
|
123 | 129 | // Generates the actions that make it possible to visualize the variable |
|
124 | auto generateVariableMenuOperation = GenerateVariableMenuOperation{menu, variable}; | |
|
130 | GenerateVariableMenuOperation generateVariableMenuOperation{ | |
|
131 | menu, variable, std::move(variableContainers)}; | |
|
125 | 132 | accept(&generateVariableMenuOperation); |
|
126 | 133 | } |
|
127 | 134 | else { |
@@ -13,8 +13,13 | |||
|
13 | 13 | Q_LOGGING_CATEGORY(LOG_GenerateVariableMenuOperation, "GenerateVariableMenuOperation") |
|
14 | 14 | |
|
15 | 15 | struct GenerateVariableMenuOperation::GenerateVariableMenuOperationPrivate { |
|
16 |
explicit GenerateVariableMenuOperationPrivate( |
|
|
17 | : m_Variable{variable}, m_PlotMenuBuilder{menu}, m_UnplotMenuBuilder{menu} | |
|
16 | explicit GenerateVariableMenuOperationPrivate( | |
|
17 | QMenu *menu, std::shared_ptr<Variable> variable, | |
|
18 | std::set<IVisualizationWidget *> variableContainers) | |
|
19 | : m_Variable{variable}, | |
|
20 | m_PlotMenuBuilder{menu}, | |
|
21 | m_UnplotMenuBuilder{menu}, | |
|
22 | m_VariableContainers{std::move(variableContainers)} | |
|
18 | 23 | { |
|
19 | 24 | } |
|
20 | 25 | |
@@ -47,7 +52,7 struct GenerateVariableMenuOperation::GenerateVariableMenuOperationPrivate { | |||
|
47 | 52 | void visitNodeLeavePlot(const IVisualizationWidget &container, const QString &actionName, |
|
48 | 53 | ActionFun actionFunction) |
|
49 | 54 | { |
|
50 | if (m_Variable && container.canDrop(*m_Variable)) { | |
|
55 | if (isValidContainer(container)) { | |
|
51 | 56 | m_PlotMenuBuilder.addSeparator(); |
|
52 | 57 | m_PlotMenuBuilder.addAction(actionName, actionFunction); |
|
53 | 58 | } |
@@ -66,28 +71,39 struct GenerateVariableMenuOperation::GenerateVariableMenuOperationPrivate { | |||
|
66 | 71 | void visitLeafPlot(const IVisualizationWidget &container, const QString &actionName, |
|
67 | 72 | ActionFun actionFunction) |
|
68 | 73 | { |
|
69 | if (m_Variable && container.canDrop(*m_Variable)) { | |
|
74 | if (isValidContainer(container)) { | |
|
70 | 75 | m_PlotMenuBuilder.addAction(actionName, actionFunction); |
|
71 | 76 | } |
|
72 | 77 | } |
|
73 | 78 | |
|
74 | 79 | template <typename ActionFun> |
|
75 |
void visitLeafUnplot( |
|
|
80 | void visitLeafUnplot(IVisualizationWidget *container, const QString &actionName, | |
|
76 | 81 | ActionFun actionFunction) |
|
77 | 82 | { |
|
78 | if (m_Variable && container.contains(*m_Variable)) { | |
|
83 | // If the container contains the variable, we generate 'unplot' action | |
|
84 | if (m_VariableContainers.count(container) == 1) { | |
|
79 | 85 | m_UnplotMenuBuilder.addAction(actionName, actionFunction); |
|
80 | 86 | } |
|
81 | 87 | } |
|
82 | 88 | |
|
89 | bool isValidContainer(const IVisualizationWidget &container) const noexcept | |
|
90 | { | |
|
91 | // A container is valid if it can contain the variable and if the variable is not already | |
|
92 | // contained in another container | |
|
93 | return m_Variable && m_VariableContainers.size() == 0 && container.canDrop(*m_Variable); | |
|
94 | } | |
|
95 | ||
|
83 | 96 | std::shared_ptr<Variable> m_Variable; |
|
97 | std::set<IVisualizationWidget *> m_VariableContainers; | |
|
84 | 98 | MenuBuilder m_PlotMenuBuilder; ///< Builder for the 'Plot' menu |
|
85 | 99 | MenuBuilder m_UnplotMenuBuilder; ///< Builder for the 'Unplot' menu |
|
86 | 100 | }; |
|
87 | 101 | |
|
88 |
GenerateVariableMenuOperation::GenerateVariableMenuOperation( |
|
|
89 | std::shared_ptr<Variable> variable) | |
|
90 | : impl{spimpl::make_unique_impl<GenerateVariableMenuOperationPrivate>(menu, variable)} | |
|
102 | GenerateVariableMenuOperation::GenerateVariableMenuOperation( | |
|
103 | QMenu *menu, std::shared_ptr<Variable> variable, | |
|
104 | std::set<IVisualizationWidget *> variableContainers) | |
|
105 | : impl{spimpl::make_unique_impl<GenerateVariableMenuOperationPrivate>( | |
|
106 | menu, variable, std::move(variableContainers))} | |
|
91 | 107 | { |
|
92 | 108 | } |
|
93 | 109 | |
@@ -155,7 +171,6 void GenerateVariableMenuOperation::visitEnter(VisualizationZoneWidget *zoneWidg | |||
|
155 | 171 | |
|
156 | 172 | void GenerateVariableMenuOperation::visitLeave(VisualizationZoneWidget *zoneWidget) |
|
157 | 173 | { |
|
158 | qCCritical(LOG_GenerateVariableMenuOperation(), "Open in a new graph DETECTED !!"); | |
|
159 | 174 | if (zoneWidget) { |
|
160 | 175 | // 'Plot' menu |
|
161 | 176 | impl->visitNodeLeavePlot( |
@@ -187,7 +202,7 void GenerateVariableMenuOperation::visit(VisualizationGraphWidget *graphWidget) | |||
|
187 | 202 | }); |
|
188 | 203 | |
|
189 | 204 | // 'Unplot' menu |
|
190 |
impl->visitLeafUnplot( |
|
|
205 | impl->visitLeafUnplot(graphWidget, QObject::tr("Remove from %1").arg(graphWidget->name()), | |
|
191 | 206 | [ varW = std::weak_ptr<Variable>{impl->m_Variable}, graphWidget ]() { |
|
192 | 207 | if (auto var = varW.lock()) { |
|
193 | 208 | graphWidget->removeVariable(var); |
General Comments 0
You need to be logged in to leave comments.
Login now