##// END OF EJS Templates
Unplot menu (3): handles 'Unplot' menu when entering a tab or a zone...
Alexandre Leroux -
r325:257ddf015a9e
parent child
Show More
@@ -1,151 +1,154
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 m_UnplotMenuBuilder.addMenu(container.name());
39 40 }
40 41
41 42 template <typename ActionFun>
42 43 void visitNodeLeave(const IVisualizationWidget &container, const QString &actionName,
43 44 ActionFun actionFunction)
44 45 {
45 46 if (m_Variable && container.canDrop(*m_Variable)) {
46 47 m_PlotMenuBuilder.addSeparator();
47 48 m_PlotMenuBuilder.addAction(actionName, actionFunction);
48 49 }
49 50
50 51 // Closes the menu associated to the node
51 52 m_PlotMenuBuilder.closeMenu();
52 53 }
53 54
54 55 template <typename ActionFun>
55 56 void visitLeaf(const IVisualizationWidget &container, const QString &actionName,
56 57 ActionFun actionFunction)
57 58 {
58 59 if (m_Variable && container.canDrop(*m_Variable)) {
59 60 m_PlotMenuBuilder.addAction(actionName, actionFunction);
60 61 }
61 62 }
62 63
63 64 std::shared_ptr<Variable> m_Variable;
64 65 MenuBuilder m_PlotMenuBuilder; ///< Builder for the 'Plot' menu
65 66 MenuBuilder m_UnplotMenuBuilder; ///< Builder for the 'Unplot' menu
66 67 };
67 68
68 69 GenerateVariableMenuOperation::GenerateVariableMenuOperation(QMenu *menu,
69 70 std::shared_ptr<Variable> variable)
70 71 : impl{spimpl::make_unique_impl<GenerateVariableMenuOperationPrivate>(menu, variable)}
71 72 {
72 73 }
73 74
74 75 void GenerateVariableMenuOperation::visitEnter(VisualizationWidget *widget)
75 76 {
76 77 // VisualizationWidget is not intended to accommodate a variable
77 78 Q_UNUSED(widget)
78 79
79 80 // 'Plot' and 'Unplot' menus
80 81 impl->visitRootEnter();
81 82 }
82 83
83 84 void GenerateVariableMenuOperation::visitLeave(VisualizationWidget *widget)
84 85 {
85 86 // VisualizationWidget is not intended to accommodate a variable
86 87 Q_UNUSED(widget)
87 88
88 89 // 'Plot' and 'Unplot' menus
89 90 impl->visitRootLeave();
90 91 }
91 92
92 93 void GenerateVariableMenuOperation::visitEnter(VisualizationTabWidget *tabWidget)
93 94 {
94 95 if (tabWidget) {
96 // 'Plot' and 'Unplot' menus
95 97 impl->visitNodeEnter(*tabWidget);
96 98 }
97 99 else {
98 100 qCCritical(LOG_GenerateVariableMenuOperation(),
99 101 "Can't visit enter VisualizationTabWidget : the widget is null");
100 102 }
101 103 }
102 104
103 105 void GenerateVariableMenuOperation::visitLeave(VisualizationTabWidget *tabWidget)
104 106 {
105 107 if (tabWidget) {
106 108 impl->visitNodeLeave(
107 109 *tabWidget, QObject::tr("Open in a new zone"),
108 110 [ var = impl->m_Variable, tabWidget ]() { tabWidget->createZone(var); });
109 111 }
110 112 else {
111 113 qCCritical(LOG_GenerateVariableMenuOperation(),
112 114 "Can't visit leave VisualizationTabWidget : the widget is null");
113 115 }
114 116 }
115 117
116 118 void GenerateVariableMenuOperation::visitEnter(VisualizationZoneWidget *zoneWidget)
117 119 {
118 120 if (zoneWidget) {
121 // 'Plot' and 'Unplot' menus
119 122 impl->visitNodeEnter(*zoneWidget);
120 123 }
121 124 else {
122 125 qCCritical(LOG_GenerateVariableMenuOperation(),
123 126 "Can't visit enter VisualizationZoneWidget : the widget is null");
124 127 }
125 128 }
126 129
127 130 void GenerateVariableMenuOperation::visitLeave(VisualizationZoneWidget *zoneWidget)
128 131 {
129 132 if (zoneWidget) {
130 133 impl->visitNodeLeave(
131 134 *zoneWidget, QObject::tr("Open in a new graph"),
132 135 [ var = impl->m_Variable, zoneWidget ]() { zoneWidget->createGraph(var); });
133 136 }
134 137 else {
135 138 qCCritical(LOG_GenerateVariableMenuOperation(),
136 139 "Can't visit leave VisualizationZoneWidget : the widget is null");
137 140 }
138 141 }
139 142
140 143 void GenerateVariableMenuOperation::visit(VisualizationGraphWidget *graphWidget)
141 144 {
142 145 if (graphWidget) {
143 146 impl->visitLeaf(
144 147 *graphWidget, QObject::tr("Open in %1").arg(graphWidget->name()),
145 148 [ var = impl->m_Variable, graphWidget ]() { graphWidget->addVariableUsingGraph(var); });
146 149 }
147 150 else {
148 151 qCCritical(LOG_GenerateVariableMenuOperation(),
149 152 "Can't visit VisualizationGraphWidget : the widget is null");
150 153 }
151 154 }
General Comments 0
You need to be logged in to leave comments. Login now