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