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