##// END OF EJS Templates
Unplot menu (4): handles 'Unplot' menu when leaving a tab or a zone...
Alexandre Leroux -
r300:f83820cc7288
parent child
Show More
@@ -1,154 +1,168
1 1 #include "Visualization/operations/GenerateVariableMenuOperation.h"
2 2 #include "Visualization/operations/MenuBuilder.h"
3 3
4 4 #include "Visualization/VisualizationGraphWidget.h"
5 5 #include "Visualization/VisualizationTabWidget.h"
6 6 #include "Visualization/VisualizationZoneWidget.h"
7 7
8 8 #include <Variable/Variable.h>
9 9
10 10 #include <QMenu>
11 11 #include <QStack>
12 12
13 13 Q_LOGGING_CATEGORY(LOG_GenerateVariableMenuOperation, "GenerateVariableMenuOperation")
14 14
15 15 struct GenerateVariableMenuOperation::GenerateVariableMenuOperationPrivate {
16 16 explicit GenerateVariableMenuOperationPrivate(QMenu *menu, std::shared_ptr<Variable> variable)
17 17 : m_Variable{variable}, m_PlotMenuBuilder{menu}, m_UnplotMenuBuilder{menu}
18 18 {
19 19 }
20 20
21 21 void visitRootEnter()
22 22 {
23 23 // Creates the root menu
24 24 m_PlotMenuBuilder.addMenu(QObject::tr("Plot"), QIcon{":/icones/plot.png"});
25 25 m_UnplotMenuBuilder.addMenu(QObject::tr("Unplot"), QIcon{":/icones/unplot.png"});
26 26 }
27 27
28 28 void visitRootLeave()
29 29 {
30 30 // Closes the root menu
31 31 m_PlotMenuBuilder.closeMenu();
32 32 m_UnplotMenuBuilder.closeMenu();
33 33 }
34 34
35 35 void visitNodeEnter(const IVisualizationWidget &container)
36 36 {
37 37 // Opens a new menu associated to the node
38 38 m_PlotMenuBuilder.addMenu(container.name());
39 39 m_UnplotMenuBuilder.addMenu(container.name());
40 40 }
41 41
42 42 template <typename ActionFun>
43 void visitNodeLeave(const IVisualizationWidget &container, const QString &actionName,
44 ActionFun actionFunction)
43 void visitNodeLeavePlot(const IVisualizationWidget &container, const QString &actionName,
44 ActionFun actionFunction)
45 45 {
46 46 if (m_Variable && container.canDrop(*m_Variable)) {
47 47 m_PlotMenuBuilder.addSeparator();
48 48 m_PlotMenuBuilder.addAction(actionName, actionFunction);
49 49 }
50 50
51 51 // Closes the menu associated to the node
52 52 m_PlotMenuBuilder.closeMenu();
53 53 }
54 54
55 void visitNodeLeaveUnplot()
56 {
57 // Closes the menu associated to the node
58 m_UnplotMenuBuilder.closeMenu();
59 }
60
55 61 template <typename ActionFun>
56 62 void visitLeaf(const IVisualizationWidget &container, const QString &actionName,
57 63 ActionFun actionFunction)
58 64 {
59 65 if (m_Variable && container.canDrop(*m_Variable)) {
60 66 m_PlotMenuBuilder.addAction(actionName, actionFunction);
61 67 }
62 68 }
63 69
64 70 std::shared_ptr<Variable> m_Variable;
65 71 MenuBuilder m_PlotMenuBuilder; ///< Builder for the 'Plot' menu
66 72 MenuBuilder m_UnplotMenuBuilder; ///< Builder for the 'Unplot' menu
67 73 };
68 74
69 75 GenerateVariableMenuOperation::GenerateVariableMenuOperation(QMenu *menu,
70 76 std::shared_ptr<Variable> variable)
71 77 : impl{spimpl::make_unique_impl<GenerateVariableMenuOperationPrivate>(menu, variable)}
72 78 {
73 79 }
74 80
75 81 void GenerateVariableMenuOperation::visitEnter(VisualizationWidget *widget)
76 82 {
77 83 // VisualizationWidget is not intended to accommodate a variable
78 84 Q_UNUSED(widget)
79 85
80 86 // 'Plot' and 'Unplot' menus
81 87 impl->visitRootEnter();
82 88 }
83 89
84 90 void GenerateVariableMenuOperation::visitLeave(VisualizationWidget *widget)
85 91 {
86 92 // VisualizationWidget is not intended to accommodate a variable
87 93 Q_UNUSED(widget)
88 94
89 95 // 'Plot' and 'Unplot' menus
90 96 impl->visitRootLeave();
91 97 }
92 98
93 99 void GenerateVariableMenuOperation::visitEnter(VisualizationTabWidget *tabWidget)
94 100 {
95 101 if (tabWidget) {
96 102 // 'Plot' and 'Unplot' menus
97 103 impl->visitNodeEnter(*tabWidget);
98 104 }
99 105 else {
100 106 qCCritical(LOG_GenerateVariableMenuOperation(),
101 107 "Can't visit enter VisualizationTabWidget : the widget is null");
102 108 }
103 109 }
104 110
105 111 void GenerateVariableMenuOperation::visitLeave(VisualizationTabWidget *tabWidget)
106 112 {
107 113 if (tabWidget) {
108 impl->visitNodeLeave(
114 // 'Plot' menu
115 impl->visitNodeLeavePlot(
109 116 *tabWidget, QObject::tr("Open in a new zone"),
110 117 [ var = impl->m_Variable, tabWidget ]() { tabWidget->createZone(var); });
118
119 // 'Unplot' menu
120 impl->visitNodeLeaveUnplot();
111 121 }
112 122 else {
113 123 qCCritical(LOG_GenerateVariableMenuOperation(),
114 124 "Can't visit leave VisualizationTabWidget : the widget is null");
115 125 }
116 126 }
117 127
118 128 void GenerateVariableMenuOperation::visitEnter(VisualizationZoneWidget *zoneWidget)
119 129 {
120 130 if (zoneWidget) {
121 131 // 'Plot' and 'Unplot' menus
122 132 impl->visitNodeEnter(*zoneWidget);
123 133 }
124 134 else {
125 135 qCCritical(LOG_GenerateVariableMenuOperation(),
126 136 "Can't visit enter VisualizationZoneWidget : the widget is null");
127 137 }
128 138 }
129 139
130 140 void GenerateVariableMenuOperation::visitLeave(VisualizationZoneWidget *zoneWidget)
131 141 {
132 142 if (zoneWidget) {
133 impl->visitNodeLeave(
143 // 'Plot' menu
144 impl->visitNodeLeavePlot(
134 145 *zoneWidget, QObject::tr("Open in a new graph"),
135 146 [ var = impl->m_Variable, zoneWidget ]() { zoneWidget->createGraph(var); });
147
148 // 'Unplot' menu
149 impl->visitNodeLeaveUnplot();
136 150 }
137 151 else {
138 152 qCCritical(LOG_GenerateVariableMenuOperation(),
139 153 "Can't visit leave VisualizationZoneWidget : the widget is null");
140 154 }
141 155 }
142 156
143 157 void GenerateVariableMenuOperation::visit(VisualizationGraphWidget *graphWidget)
144 158 {
145 159 if (graphWidget) {
146 160 impl->visitLeaf(
147 161 *graphWidget, QObject::tr("Open in %1").arg(graphWidget->name()),
148 162 [ var = impl->m_Variable, graphWidget ]() { graphWidget->addVariableUsingGraph(var); });
149 163 }
150 164 else {
151 165 qCCritical(LOG_GenerateVariableMenuOperation(),
152 166 "Can't visit VisualizationGraphWidget : the widget is null");
153 167 }
154 168 }
General Comments 0
You need to be logged in to leave comments. Login now