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