##// END OF EJS Templates
Defines a menu builder...
Alexandre Leroux -
r211:244c7de3b522
parent child
Show More
@@ -1,38 +1,42
1 #ifndef SCIQLOP_GENERATEVARIABLEMENUOPERATION_H
1 #ifndef SCIQLOP_GENERATEVARIABLEMENUOPERATION_H
2 #define SCIQLOP_GENERATEVARIABLEMENUOPERATION_H
2 #define SCIQLOP_GENERATEVARIABLEMENUOPERATION_H
3
3
4 #include "Visualization/IVisualizationWidgetVisitor.h"
4 #include "Visualization/IVisualizationWidgetVisitor.h"
5
5
6 #include <Common/spimpl.h>
6 #include <Common/spimpl.h>
7
7
8 #include <QLoggingCategory>
9
8 class QMenu;
10 class QMenu;
9 class Variable;
11 class Variable;
10
12
13 Q_DECLARE_LOGGING_CATEGORY(LOG_GenerateVariableMenuOperation)
14
11 /**
15 /**
12 * @brief The GenerateVariableMenuOperation class defines an operation that traverses all of
16 * @brief The GenerateVariableMenuOperation class defines an operation that traverses all of
13 * visualization widgets to determine which can accommodate a variable. The result of the operation
17 * visualization widgets to determine which can accommodate a variable. The result of the operation
14 * is a menu that contains actions to add the variable into the containers.
18 * is a menu that contains actions to add the variable into the containers.
15 */
19 */
16 class GenerateVariableMenuOperation : public IVisualizationWidgetVisitor {
20 class GenerateVariableMenuOperation : public IVisualizationWidgetVisitor {
17 public:
21 public:
18 /**
22 /**
19 * Ctor
23 * Ctor
20 * @param menu the menu to which to attach the generated menu
24 * @param menu the menu to which to attach the generated menu
21 * @param variable the variable for which to generate the menu
25 * @param variable the variable for which to generate the menu
22 */
26 */
23 explicit GenerateVariableMenuOperation(QMenu *menu, std::shared_ptr<Variable> variable);
27 explicit GenerateVariableMenuOperation(QMenu *menu, std::shared_ptr<Variable> variable);
24
28
25 void visitEnter(VisualizationWidget *widget) override final;
29 void visitEnter(VisualizationWidget *widget) override final;
26 void visitLeave(VisualizationWidget *widget) override final;
30 void visitLeave(VisualizationWidget *widget) override final;
27 void visitEnter(VisualizationTabWidget *tabWidget) override final;
31 void visitEnter(VisualizationTabWidget *tabWidget) override final;
28 void visitLeave(VisualizationTabWidget *tabWidget) override final;
32 void visitLeave(VisualizationTabWidget *tabWidget) override final;
29 void visitEnter(VisualizationZoneWidget *zoneWidget) override final;
33 void visitEnter(VisualizationZoneWidget *zoneWidget) override final;
30 void visitLeave(VisualizationZoneWidget *zoneWidget) override final;
34 void visitLeave(VisualizationZoneWidget *zoneWidget) override final;
31 void visit(VisualizationGraphWidget *graphWidget) override final;
35 void visit(VisualizationGraphWidget *graphWidget) override final;
32
36
33 private:
37 private:
34 class GenerateVariableMenuOperationPrivate;
38 class GenerateVariableMenuOperationPrivate;
35 spimpl::unique_impl_ptr<GenerateVariableMenuOperationPrivate> impl;
39 spimpl::unique_impl_ptr<GenerateVariableMenuOperationPrivate> impl;
36 };
40 };
37
41
38 #endif // SCIQLOP_GENERATEVARIABLEMENUOPERATION_H
42 #endif // SCIQLOP_GENERATEVARIABLEMENUOPERATION_H
@@ -1,61 +1,116
1 #include "Visualization/operations/GenerateVariableMenuOperation.h"
1 #include "Visualization/operations/GenerateVariableMenuOperation.h"
2
2
3 #include "Visualization/VisualizationGraphWidget.h"
3 #include "Visualization/VisualizationGraphWidget.h"
4 #include "Visualization/VisualizationTabWidget.h"
4 #include "Visualization/VisualizationTabWidget.h"
5 #include "Visualization/VisualizationZoneWidget.h"
5 #include "Visualization/VisualizationZoneWidget.h"
6
6
7 #include <Variable/Variable.h>
7 #include <Variable/Variable.h>
8
8
9 #include <QMenu>
9 #include <QMenu>
10 #include <QStack>
11
12 Q_LOGGING_CATEGORY(LOG_GenerateVariableMenuOperation, "GenerateVariableMenuOperation")
13
14 namespace {
15
16 /// Helper assigned to build the hierarchical menu associated with a variable
17 struct MenuBuilder {
18 /**
19 * Ctor
20 * @param menu the parent menu
21 */
22 explicit MenuBuilder(QMenu *menu)
23 {
24 if (menu) {
25 m_Menus.push(menu);
26 }
27 else {
28 qCCritical(LOG_GenerateVariableMenuOperation())
29 << QObject::tr("No parent menu has been defined");
30 }
31 }
32
33 /**
34 * Adds a new menu to the current menu
35 * @param name the name of the menu
36 */
37 void addMenu(const QString &name)
38 {
39 if (auto currMenu = currentMenu()) {
40 m_Menus.push(currMenu->addMenu(name));
41 }
42 else {
43 qCCritical(LOG_GenerateVariableMenuOperation())
44 << QObject::tr("No current menu to attach the new menu");
45 }
46 }
47
48 /// Closes the current menu
49 void closeMenu()
50 {
51 if (!m_Menus.isEmpty()) {
52 m_Menus.pop();
53 }
54 }
55
56 /// Gets the current menu (i.e. the top menu of the stack)
57 QMenu *currentMenu() const { return !m_Menus.isEmpty() ? m_Menus.top() : nullptr; }
58
59 /// Stack of all menus currently opened
60 QStack<QMenu *> m_Menus{};
61 };
62
63 } // namespace
10
64
11 struct GenerateVariableMenuOperation::GenerateVariableMenuOperationPrivate {
65 struct GenerateVariableMenuOperation::GenerateVariableMenuOperationPrivate {
12 explicit GenerateVariableMenuOperationPrivate(QMenu *menu, std::shared_ptr<Variable> variable)
66 explicit GenerateVariableMenuOperationPrivate(QMenu *menu, std::shared_ptr<Variable> variable)
13 : m_Variable{variable}
67 : m_Variable{variable}, m_MenuBuilder{menu}
14 {
68 {
15 }
69 }
16
70
17 std::shared_ptr<Variable> m_Variable;
71 std::shared_ptr<Variable> m_Variable;
72 MenuBuilder m_MenuBuilder;
18 };
73 };
19
74
20 GenerateVariableMenuOperation::GenerateVariableMenuOperation(QMenu *menu,
75 GenerateVariableMenuOperation::GenerateVariableMenuOperation(QMenu *menu,
21 std::shared_ptr<Variable> variable)
76 std::shared_ptr<Variable> variable)
22 : impl{spimpl::make_unique_impl<GenerateVariableMenuOperationPrivate>(menu, variable)}
77 : impl{spimpl::make_unique_impl<GenerateVariableMenuOperationPrivate>(menu, variable)}
23 {
78 {
24 }
79 }
25
80
26 void GenerateVariableMenuOperation::visitEnter(VisualizationWidget *widget)
81 void GenerateVariableMenuOperation::visitEnter(VisualizationWidget *widget)
27 {
82 {
28 // VisualizationWidget is not intended to accommodate a variable
83 // VisualizationWidget is not intended to accommodate a variable
29 Q_UNUSED(widget)
84 Q_UNUSED(widget)
30 }
85 }
31
86
32 void GenerateVariableMenuOperation::visitLeave(VisualizationWidget *widget)
87 void GenerateVariableMenuOperation::visitLeave(VisualizationWidget *widget)
33 {
88 {
34 // VisualizationWidget is not intended to accommodate a variable
89 // VisualizationWidget is not intended to accommodate a variable
35 Q_UNUSED(widget)
90 Q_UNUSED(widget)
36 }
91 }
37
92
38 void GenerateVariableMenuOperation::visitEnter(VisualizationTabWidget *tabWidget)
93 void GenerateVariableMenuOperation::visitEnter(VisualizationTabWidget *tabWidget)
39 {
94 {
40 /// @todo ALX
95 /// @todo ALX
41 }
96 }
42
97
43 void GenerateVariableMenuOperation::visitLeave(VisualizationTabWidget *tabWidget)
98 void GenerateVariableMenuOperation::visitLeave(VisualizationTabWidget *tabWidget)
44 {
99 {
45 /// @todo ALX
100 /// @todo ALX
46 }
101 }
47
102
48 void GenerateVariableMenuOperation::visitEnter(VisualizationZoneWidget *zoneWidget)
103 void GenerateVariableMenuOperation::visitEnter(VisualizationZoneWidget *zoneWidget)
49 {
104 {
50 /// @todo ALX
105 /// @todo ALX
51 }
106 }
52
107
53 void GenerateVariableMenuOperation::visitLeave(VisualizationZoneWidget *zoneWidget)
108 void GenerateVariableMenuOperation::visitLeave(VisualizationZoneWidget *zoneWidget)
54 {
109 {
55 /// @todo ALX
110 /// @todo ALX
56 }
111 }
57
112
58 void GenerateVariableMenuOperation::visit(VisualizationGraphWidget *graphWidget)
113 void GenerateVariableMenuOperation::visit(VisualizationGraphWidget *graphWidget)
59 {
114 {
60 /// @todo ALX
115 /// @todo ALX
61 }
116 }
General Comments 0
You need to be logged in to leave comments. Login now