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