##// END OF EJS Templates
Adds icon for 'Plot' menu
Alexandre Leroux -
r322:e195db267c87
parent child
Show More
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
@@ -1,59 +1,60
1 #ifndef SCIQLOP_MENUBUILDER_H
1 #ifndef SCIQLOP_MENUBUILDER_H
2 #define SCIQLOP_MENUBUILDER_H
2 #define SCIQLOP_MENUBUILDER_H
3
3
4 #include <QLoggingCategory>
4 #include <QLoggingCategory>
5 #include <QMenu>
5 #include <QMenu>
6 #include <QStack>
6 #include <QStack>
7
7
8 Q_DECLARE_LOGGING_CATEGORY(LOG_MenuBuilder)
8 Q_DECLARE_LOGGING_CATEGORY(LOG_MenuBuilder)
9
9
10 /// Helper assigned to build a hierarchical menu
10 /// Helper assigned to build a hierarchical menu
11 class MenuBuilder {
11 class MenuBuilder {
12 public:
12 public:
13 /**
13 /**
14 * Ctor
14 * Ctor
15 * @param menu the parent menu
15 * @param menu the parent menu
16 */
16 */
17 explicit MenuBuilder(QMenu *menu);
17 explicit MenuBuilder(QMenu *menu);
18
18
19 /**
19 /**
20 * Adds action to the current menu
20 * Adds action to the current menu
21 * @param actionName the name of the action
21 * @param actionName the name of the action
22 * @param actionFunction the function that will be executed when the action is triggered
22 * @param actionFunction the function that will be executed when the action is triggered
23 */
23 */
24 template <typename ActionFun>
24 template <typename ActionFun>
25 void addAction(const QString &actionName, ActionFun actionFunction);
25 void addAction(const QString &actionName, ActionFun actionFunction);
26
26
27 /**
27 /**
28 * Adds a new menu to the current menu
28 * Adds a new menu to the current menu
29 * @param name the name of the menu
29 * @param name the name of the menu
30 * @param icon the icon of the menu (can be null)
30 */
31 */
31 void addMenu(const QString &name);
32 void addMenu(const QString &name, const QIcon &icon = {});
32
33
33 /// Adds a separator to the current menu. The separator is added only if the menu already
34 /// Adds a separator to the current menu. The separator is added only if the menu already
34 /// contains entries
35 /// contains entries
35 void addSeparator();
36 void addSeparator();
36
37
37 /// Closes the current menu
38 /// Closes the current menu
38 void closeMenu();
39 void closeMenu();
39
40
40 private:
41 private:
41 /// @return the current menu (i.e. the top menu of the stack), nullptr if there is no menu
42 /// @return the current menu (i.e. the top menu of the stack), nullptr if there is no menu
42 QMenu *currentMenu() const;
43 QMenu *currentMenu() const;
43
44
44 /// Stack of all menus currently opened
45 /// Stack of all menus currently opened
45 QStack<QMenu *> m_Menus{};
46 QStack<QMenu *> m_Menus{};
46 };
47 };
47
48
48 template <typename ActionFun>
49 template <typename ActionFun>
49 void MenuBuilder::addAction(const QString &actionName, ActionFun actionFunction)
50 void MenuBuilder::addAction(const QString &actionName, ActionFun actionFunction)
50 {
51 {
51 if (auto currMenu = currentMenu()) {
52 if (auto currMenu = currentMenu()) {
52 currMenu->addAction(actionName, actionFunction);
53 currMenu->addAction(actionName, actionFunction);
53 }
54 }
54 else {
55 else {
55 qCCritical(LOG_MenuBuilder()) << QObject::tr("No current menu to attach the action");
56 qCCritical(LOG_MenuBuilder()) << QObject::tr("No current menu to attach the action");
56 }
57 }
57 }
58 }
58
59
59 #endif // SCIQLOP_MENUBUILDER_H
60 #endif // SCIQLOP_MENUBUILDER_H
@@ -1,8 +1,9
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/previous.png</file>
7 <file>icones/previous.png</file>
7 </qresource>
8 </qresource>
8 </RCC>
9 </RCC>
@@ -1,146 +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()
21 void visitRootEnter()
22 {
22 {
23 // Creates the root menu
23 // Creates the root menu
24 m_MenuBuilder.addMenu(QObject::tr("Plot"));
24 m_MenuBuilder.addMenu(QObject::tr("Plot"), QIcon{":/icones/plot.png"});
25 }
25 }
26
26
27 void visitRootLeave()
27 void visitRootLeave()
28 {
28 {
29 // Closes the root menu
29 // Closes the root menu
30 m_MenuBuilder.closeMenu();
30 m_MenuBuilder.closeMenu();
31 }
31 }
32
32
33 void visitNodeEnter(const IVisualizationWidget &container)
33 void visitNodeEnter(const IVisualizationWidget &container)
34 {
34 {
35 // Opens a new menu associated to the node
35 // Opens a new menu associated to the node
36 m_MenuBuilder.addMenu(container.name());
36 m_MenuBuilder.addMenu(container.name());
37 }
37 }
38
38
39 template <typename ActionFun>
39 template <typename ActionFun>
40 void visitNodeLeave(const IVisualizationWidget &container, const QString &actionName,
40 void visitNodeLeave(const IVisualizationWidget &container, const QString &actionName,
41 ActionFun actionFunction)
41 ActionFun actionFunction)
42 {
42 {
43 if (m_Variable && container.canDrop(*m_Variable)) {
43 if (m_Variable && container.canDrop(*m_Variable)) {
44 m_MenuBuilder.addSeparator();
44 m_MenuBuilder.addSeparator();
45 m_MenuBuilder.addAction(actionName, actionFunction);
45 m_MenuBuilder.addAction(actionName, actionFunction);
46 }
46 }
47
47
48 // Closes the menu associated to the node
48 // Closes the menu associated to the node
49 m_MenuBuilder.closeMenu();
49 m_MenuBuilder.closeMenu();
50 }
50 }
51
51
52 template <typename ActionFun>
52 template <typename ActionFun>
53 void visitLeaf(const IVisualizationWidget &container, const QString &actionName,
53 void visitLeaf(const IVisualizationWidget &container, const QString &actionName,
54 ActionFun actionFunction)
54 ActionFun actionFunction)
55 {
55 {
56 if (m_Variable && container.canDrop(*m_Variable)) {
56 if (m_Variable && container.canDrop(*m_Variable)) {
57 m_MenuBuilder.addAction(actionName, actionFunction);
57 m_MenuBuilder.addAction(actionName, actionFunction);
58 }
58 }
59 }
59 }
60
60
61 std::shared_ptr<Variable> m_Variable;
61 std::shared_ptr<Variable> m_Variable;
62 MenuBuilder m_MenuBuilder;
62 MenuBuilder m_MenuBuilder;
63 };
63 };
64
64
65 GenerateVariableMenuOperation::GenerateVariableMenuOperation(QMenu *menu,
65 GenerateVariableMenuOperation::GenerateVariableMenuOperation(QMenu *menu,
66 std::shared_ptr<Variable> variable)
66 std::shared_ptr<Variable> variable)
67 : impl{spimpl::make_unique_impl<GenerateVariableMenuOperationPrivate>(menu, variable)}
67 : impl{spimpl::make_unique_impl<GenerateVariableMenuOperationPrivate>(menu, variable)}
68 {
68 {
69 }
69 }
70
70
71 void GenerateVariableMenuOperation::visitEnter(VisualizationWidget *widget)
71 void GenerateVariableMenuOperation::visitEnter(VisualizationWidget *widget)
72 {
72 {
73 // VisualizationWidget is not intended to accommodate a variable
73 // VisualizationWidget is not intended to accommodate a variable
74 Q_UNUSED(widget)
74 Q_UNUSED(widget)
75
75
76 impl->visitRootEnter();
76 impl->visitRootEnter();
77 }
77 }
78
78
79 void GenerateVariableMenuOperation::visitLeave(VisualizationWidget *widget)
79 void GenerateVariableMenuOperation::visitLeave(VisualizationWidget *widget)
80 {
80 {
81 // VisualizationWidget is not intended to accommodate a variable
81 // VisualizationWidget is not intended to accommodate a variable
82 Q_UNUSED(widget)
82 Q_UNUSED(widget)
83
83
84 impl->visitRootLeave();
84 impl->visitRootLeave();
85 }
85 }
86
86
87 void GenerateVariableMenuOperation::visitEnter(VisualizationTabWidget *tabWidget)
87 void GenerateVariableMenuOperation::visitEnter(VisualizationTabWidget *tabWidget)
88 {
88 {
89 if (tabWidget) {
89 if (tabWidget) {
90 impl->visitNodeEnter(*tabWidget);
90 impl->visitNodeEnter(*tabWidget);
91 }
91 }
92 else {
92 else {
93 qCCritical(LOG_GenerateVariableMenuOperation(),
93 qCCritical(LOG_GenerateVariableMenuOperation(),
94 "Can't visit enter VisualizationTabWidget : the widget is null");
94 "Can't visit enter VisualizationTabWidget : the widget is null");
95 }
95 }
96 }
96 }
97
97
98 void GenerateVariableMenuOperation::visitLeave(VisualizationTabWidget *tabWidget)
98 void GenerateVariableMenuOperation::visitLeave(VisualizationTabWidget *tabWidget)
99 {
99 {
100 if (tabWidget) {
100 if (tabWidget) {
101 impl->visitNodeLeave(
101 impl->visitNodeLeave(
102 *tabWidget, QObject::tr("Open in a new zone"),
102 *tabWidget, QObject::tr("Open in a new zone"),
103 [ var = impl->m_Variable, tabWidget ]() { tabWidget->createZone(var); });
103 [ var = impl->m_Variable, tabWidget ]() { tabWidget->createZone(var); });
104 }
104 }
105 else {
105 else {
106 qCCritical(LOG_GenerateVariableMenuOperation(),
106 qCCritical(LOG_GenerateVariableMenuOperation(),
107 "Can't visit leave VisualizationTabWidget : the widget is null");
107 "Can't visit leave VisualizationTabWidget : the widget is null");
108 }
108 }
109 }
109 }
110
110
111 void GenerateVariableMenuOperation::visitEnter(VisualizationZoneWidget *zoneWidget)
111 void GenerateVariableMenuOperation::visitEnter(VisualizationZoneWidget *zoneWidget)
112 {
112 {
113 if (zoneWidget) {
113 if (zoneWidget) {
114 impl->visitNodeEnter(*zoneWidget);
114 impl->visitNodeEnter(*zoneWidget);
115 }
115 }
116 else {
116 else {
117 qCCritical(LOG_GenerateVariableMenuOperation(),
117 qCCritical(LOG_GenerateVariableMenuOperation(),
118 "Can't visit enter VisualizationZoneWidget : the widget is null");
118 "Can't visit enter VisualizationZoneWidget : the widget is null");
119 }
119 }
120 }
120 }
121
121
122 void GenerateVariableMenuOperation::visitLeave(VisualizationZoneWidget *zoneWidget)
122 void GenerateVariableMenuOperation::visitLeave(VisualizationZoneWidget *zoneWidget)
123 {
123 {
124 if (zoneWidget) {
124 if (zoneWidget) {
125 impl->visitNodeLeave(
125 impl->visitNodeLeave(
126 *zoneWidget, QObject::tr("Open in a new graph"),
126 *zoneWidget, QObject::tr("Open in a new graph"),
127 [ var = impl->m_Variable, zoneWidget ]() { zoneWidget->createGraph(var); });
127 [ var = impl->m_Variable, zoneWidget ]() { zoneWidget->createGraph(var); });
128 }
128 }
129 else {
129 else {
130 qCCritical(LOG_GenerateVariableMenuOperation(),
130 qCCritical(LOG_GenerateVariableMenuOperation(),
131 "Can't visit leave VisualizationZoneWidget : the widget is null");
131 "Can't visit leave VisualizationZoneWidget : the widget is null");
132 }
132 }
133 }
133 }
134
134
135 void GenerateVariableMenuOperation::visit(VisualizationGraphWidget *graphWidget)
135 void GenerateVariableMenuOperation::visit(VisualizationGraphWidget *graphWidget)
136 {
136 {
137 if (graphWidget) {
137 if (graphWidget) {
138 impl->visitLeaf(
138 impl->visitLeaf(
139 *graphWidget, QObject::tr("Open in %1").arg(graphWidget->name()),
139 *graphWidget, QObject::tr("Open in %1").arg(graphWidget->name()),
140 [ var = impl->m_Variable, graphWidget ]() { graphWidget->addVariableUsingGraph(var); });
140 [ var = impl->m_Variable, graphWidget ]() { graphWidget->addVariableUsingGraph(var); });
141 }
141 }
142 else {
142 else {
143 qCCritical(LOG_GenerateVariableMenuOperation(),
143 qCCritical(LOG_GenerateVariableMenuOperation(),
144 "Can't visit VisualizationGraphWidget : the widget is null");
144 "Can't visit VisualizationGraphWidget : the widget is null");
145 }
145 }
146 }
146 }
@@ -1,55 +1,55
1 #include "Visualization/operations/MenuBuilder.h"
1 #include "Visualization/operations/MenuBuilder.h"
2
2
3 Q_LOGGING_CATEGORY(LOG_MenuBuilder, "MenuBuilder")
3 Q_LOGGING_CATEGORY(LOG_MenuBuilder, "MenuBuilder")
4
4
5 MenuBuilder::MenuBuilder(QMenu *menu)
5 MenuBuilder::MenuBuilder(QMenu *menu)
6 {
6 {
7 if (menu) {
7 if (menu) {
8 m_Menus.push(menu);
8 m_Menus.push(menu);
9 }
9 }
10 else {
10 else {
11 qCCritical(LOG_MenuBuilder()) << QObject::tr("No parent menu has been defined");
11 qCCritical(LOG_MenuBuilder()) << QObject::tr("No parent menu has been defined");
12 }
12 }
13 }
13 }
14
14
15 void MenuBuilder::addMenu(const QString &name)
15 void MenuBuilder::addMenu(const QString &name, const QIcon &icon)
16 {
16 {
17 if (auto currMenu = currentMenu()) {
17 if (auto currMenu = currentMenu()) {
18 m_Menus.push(currMenu->addMenu(name));
18 m_Menus.push(currMenu->addMenu(icon, name));
19 }
19 }
20 else {
20 else {
21 qCCritical(LOG_MenuBuilder()) << QObject::tr("No current menu to attach the new menu");
21 qCCritical(LOG_MenuBuilder()) << QObject::tr("No current menu to attach the new menu");
22 }
22 }
23 }
23 }
24
24
25 void MenuBuilder::addSeparator()
25 void MenuBuilder::addSeparator()
26 {
26 {
27 if (auto currMenu = currentMenu()) {
27 if (auto currMenu = currentMenu()) {
28 if (!currMenu->isEmpty()) {
28 if (!currMenu->isEmpty()) {
29 currMenu->addSeparator();
29 currMenu->addSeparator();
30 }
30 }
31 }
31 }
32 else {
32 else {
33 qCCritical(LOG_MenuBuilder()) << QObject::tr("No current menu to attach the separator");
33 qCCritical(LOG_MenuBuilder()) << QObject::tr("No current menu to attach the separator");
34 }
34 }
35 }
35 }
36
36
37 void MenuBuilder::closeMenu()
37 void MenuBuilder::closeMenu()
38 {
38 {
39 if (!m_Menus.isEmpty()) {
39 if (!m_Menus.isEmpty()) {
40 if (auto closedMenu = m_Menus.pop()) {
40 if (auto closedMenu = m_Menus.pop()) {
41 // Purge menu : if the closed menu has no entries, we remove it from its parent (the
41 // Purge menu : if the closed menu has no entries, we remove it from its parent (the
42 // current menu)
42 // current menu)
43 if (auto currMenu = currentMenu()) {
43 if (auto currMenu = currentMenu()) {
44 if (closedMenu->isEmpty()) {
44 if (closedMenu->isEmpty()) {
45 currMenu->removeAction(closedMenu->menuAction());
45 currMenu->removeAction(closedMenu->menuAction());
46 }
46 }
47 }
47 }
48 }
48 }
49 }
49 }
50 }
50 }
51
51
52 QMenu *MenuBuilder::currentMenu() const
52 QMenu *MenuBuilder::currentMenu() const
53 {
53 {
54 return !m_Menus.isEmpty() ? m_Menus.top() : nullptr;
54 return !m_Menus.isEmpty() ? m_Menus.top() : nullptr;
55 }
55 }
General Comments 0
You need to be logged in to leave comments. Login now