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