##// END OF EJS Templates
Prohibits the plot of a variable in several graphs (2)...
Alexandre Leroux -
r736:bca343a0ae6b
parent child
Show More
@@ -7,7 +7,10
7
7
8 #include <QLoggingCategory>
8 #include <QLoggingCategory>
9
9
10 #include <set>
11
10 class QMenu;
12 class QMenu;
13 class IVisualizationWidget;
11 class Variable;
14 class Variable;
12
15
13 Q_DECLARE_LOGGING_CATEGORY(LOG_GenerateVariableMenuOperation)
16 Q_DECLARE_LOGGING_CATEGORY(LOG_GenerateVariableMenuOperation)
@@ -23,8 +26,11 public:
23 * Ctor
26 * Ctor
24 * @param menu the menu to which to attach the generated menu
27 * @param menu the menu to which to attach the generated menu
25 * @param variable the variable for which to generate the menu
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 void visitEnter(VisualizationWidget *widget) override final;
35 void visitEnter(VisualizationWidget *widget) override final;
30 void visitLeave(VisualizationWidget *widget) override final;
36 void visitLeave(VisualizationWidget *widget) override final;
@@ -3,6 +3,7
3 #include "Visualization/VisualizationGraphWidget.h"
3 #include "Visualization/VisualizationGraphWidget.h"
4 #include "Visualization/VisualizationTabWidget.h"
4 #include "Visualization/VisualizationTabWidget.h"
5 #include "Visualization/VisualizationZoneWidget.h"
5 #include "Visualization/VisualizationZoneWidget.h"
6 #include "Visualization/operations/FindVariableOperation.h"
6 #include "Visualization/operations/GenerateVariableMenuOperation.h"
7 #include "Visualization/operations/GenerateVariableMenuOperation.h"
7 #include "Visualization/operations/RemoveVariableOperation.h"
8 #include "Visualization/operations/RemoveVariableOperation.h"
8 #include "Visualization/operations/RescaleAxeOperation.h"
9 #include "Visualization/operations/RescaleAxeOperation.h"
@@ -120,8 +121,14 void VisualizationWidget::attachVariableMenu(
120 // Menu is generated only if there is a single variable
121 // Menu is generated only if there is a single variable
121 if (variables.size() == 1) {
122 if (variables.size() == 1) {
122 if (auto variable = variables.first()) {
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 // Generates the actions that make it possible to visualize the variable
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 accept(&generateVariableMenuOperation);
132 accept(&generateVariableMenuOperation);
126 }
133 }
127 else {
134 else {
@@ -13,8 +13,13
13 Q_LOGGING_CATEGORY(LOG_GenerateVariableMenuOperation, "GenerateVariableMenuOperation")
13 Q_LOGGING_CATEGORY(LOG_GenerateVariableMenuOperation, "GenerateVariableMenuOperation")
14
14
15 struct GenerateVariableMenuOperation::GenerateVariableMenuOperationPrivate {
15 struct GenerateVariableMenuOperation::GenerateVariableMenuOperationPrivate {
16 explicit GenerateVariableMenuOperationPrivate(QMenu *menu, std::shared_ptr<Variable> variable)
16 explicit GenerateVariableMenuOperationPrivate(
17 : m_Variable{variable}, m_PlotMenuBuilder{menu}, m_UnplotMenuBuilder{menu}
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 void visitNodeLeavePlot(const IVisualizationWidget &container, const QString &actionName,
52 void visitNodeLeavePlot(const IVisualizationWidget &container, const QString &actionName,
48 ActionFun actionFunction)
53 ActionFun actionFunction)
49 {
54 {
50 if (m_Variable && container.canDrop(*m_Variable)) {
55 if (isValidContainer(container)) {
51 m_PlotMenuBuilder.addSeparator();
56 m_PlotMenuBuilder.addSeparator();
52 m_PlotMenuBuilder.addAction(actionName, actionFunction);
57 m_PlotMenuBuilder.addAction(actionName, actionFunction);
53 }
58 }
@@ -66,28 +71,39 struct GenerateVariableMenuOperation::GenerateVariableMenuOperationPrivate {
66 void visitLeafPlot(const IVisualizationWidget &container, const QString &actionName,
71 void visitLeafPlot(const IVisualizationWidget &container, const QString &actionName,
67 ActionFun actionFunction)
72 ActionFun actionFunction)
68 {
73 {
69 if (m_Variable && container.canDrop(*m_Variable)) {
74 if (isValidContainer(container)) {
70 m_PlotMenuBuilder.addAction(actionName, actionFunction);
75 m_PlotMenuBuilder.addAction(actionName, actionFunction);
71 }
76 }
72 }
77 }
73
78
74 template <typename ActionFun>
79 template <typename ActionFun>
75 void visitLeafUnplot(const IVisualizationWidget &container, const QString &actionName,
80 void visitLeafUnplot(IVisualizationWidget *container, const QString &actionName,
76 ActionFun actionFunction)
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 m_UnplotMenuBuilder.addAction(actionName, actionFunction);
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 std::shared_ptr<Variable> m_Variable;
96 std::shared_ptr<Variable> m_Variable;
97 std::set<IVisualizationWidget *> m_VariableContainers;
84 MenuBuilder m_PlotMenuBuilder; ///< Builder for the 'Plot' menu
98 MenuBuilder m_PlotMenuBuilder; ///< Builder for the 'Plot' menu
85 MenuBuilder m_UnplotMenuBuilder; ///< Builder for the 'Unplot' menu
99 MenuBuilder m_UnplotMenuBuilder; ///< Builder for the 'Unplot' menu
86 };
100 };
87
101
88 GenerateVariableMenuOperation::GenerateVariableMenuOperation(QMenu *menu,
102 GenerateVariableMenuOperation::GenerateVariableMenuOperation(
89 std::shared_ptr<Variable> variable)
103 QMenu *menu, std::shared_ptr<Variable> variable,
90 : impl{spimpl::make_unique_impl<GenerateVariableMenuOperationPrivate>(menu, 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 void GenerateVariableMenuOperation::visitLeave(VisualizationZoneWidget *zoneWidget)
172 void GenerateVariableMenuOperation::visitLeave(VisualizationZoneWidget *zoneWidget)
157 {
173 {
158 qCCritical(LOG_GenerateVariableMenuOperation(), "Open in a new graph DETECTED !!");
159 if (zoneWidget) {
174 if (zoneWidget) {
160 // 'Plot' menu
175 // 'Plot' menu
161 impl->visitNodeLeavePlot(
176 impl->visitNodeLeavePlot(
@@ -187,7 +202,7 void GenerateVariableMenuOperation::visit(VisualizationGraphWidget *graphWidget)
187 });
202 });
188
203
189 // 'Unplot' menu
204 // 'Unplot' menu
190 impl->visitLeafUnplot(*graphWidget, QObject::tr("Remove from %1").arg(graphWidget->name()),
205 impl->visitLeafUnplot(graphWidget, QObject::tr("Remove from %1").arg(graphWidget->name()),
191 [ varW = std::weak_ptr<Variable>{impl->m_Variable}, graphWidget ]() {
206 [ varW = std::weak_ptr<Variable>{impl->m_Variable}, graphWidget ]() {
192 if (auto var = varW.lock()) {
207 if (auto var = varW.lock()) {
193 graphWidget->removeVariable(var);
208 graphWidget->removeVariable(var);
General Comments 0
You need to be logged in to leave comments. Login now