##// END OF EJS Templates
Defines a menu builder...
Alexandre Leroux -
r196:244c7de3b522
parent child
Show More
@@ -1,38 +1,42
1 1 #ifndef SCIQLOP_GENERATEVARIABLEMENUOPERATION_H
2 2 #define SCIQLOP_GENERATEVARIABLEMENUOPERATION_H
3 3
4 4 #include "Visualization/IVisualizationWidgetVisitor.h"
5 5
6 6 #include <Common/spimpl.h>
7 7
8 #include <QLoggingCategory>
9
8 10 class QMenu;
9 11 class Variable;
10 12
13 Q_DECLARE_LOGGING_CATEGORY(LOG_GenerateVariableMenuOperation)
14
11 15 /**
12 16 * @brief The GenerateVariableMenuOperation class defines an operation that traverses all of
13 17 * visualization widgets to determine which can accommodate a variable. The result of the operation
14 18 * is a menu that contains actions to add the variable into the containers.
15 19 */
16 20 class GenerateVariableMenuOperation : public IVisualizationWidgetVisitor {
17 21 public:
18 22 /**
19 23 * Ctor
20 24 * @param menu the menu to which to attach the generated menu
21 25 * @param variable the variable for which to generate the menu
22 26 */
23 27 explicit GenerateVariableMenuOperation(QMenu *menu, std::shared_ptr<Variable> variable);
24 28
25 29 void visitEnter(VisualizationWidget *widget) override final;
26 30 void visitLeave(VisualizationWidget *widget) override final;
27 31 void visitEnter(VisualizationTabWidget *tabWidget) override final;
28 32 void visitLeave(VisualizationTabWidget *tabWidget) override final;
29 33 void visitEnter(VisualizationZoneWidget *zoneWidget) override final;
30 34 void visitLeave(VisualizationZoneWidget *zoneWidget) override final;
31 35 void visit(VisualizationGraphWidget *graphWidget) override final;
32 36
33 37 private:
34 38 class GenerateVariableMenuOperationPrivate;
35 39 spimpl::unique_impl_ptr<GenerateVariableMenuOperationPrivate> impl;
36 40 };
37 41
38 42 #endif // SCIQLOP_GENERATEVARIABLEMENUOPERATION_H
@@ -1,61 +1,116
1 1 #include "Visualization/operations/GenerateVariableMenuOperation.h"
2 2
3 3 #include "Visualization/VisualizationGraphWidget.h"
4 4 #include "Visualization/VisualizationTabWidget.h"
5 5 #include "Visualization/VisualizationZoneWidget.h"
6 6
7 7 #include <Variable/Variable.h>
8 8
9 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 {
note

Transorm in MenuBuilder class with .h and .cpp

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; }
note

Add in the doc that nullptr can be a normal result that is different from m_Menus.top() = nullptr

58
59 /// Stack of all menus currently opened
60 QStack<QMenu *> m_Menus{};
61 };
62
63 } // namespace
10 64
11 65 struct GenerateVariableMenuOperation::GenerateVariableMenuOperationPrivate {
12 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 71 std::shared_ptr<Variable> m_Variable;
72 MenuBuilder m_MenuBuilder;
18 73 };
19 74
20 75 GenerateVariableMenuOperation::GenerateVariableMenuOperation(QMenu *menu,
21 76 std::shared_ptr<Variable> variable)
22 77 : impl{spimpl::make_unique_impl<GenerateVariableMenuOperationPrivate>(menu, variable)}
23 78 {
24 79 }
25 80
26 81 void GenerateVariableMenuOperation::visitEnter(VisualizationWidget *widget)
27 82 {
28 83 // VisualizationWidget is not intended to accommodate a variable
29 84 Q_UNUSED(widget)
30 85 }
31 86
32 87 void GenerateVariableMenuOperation::visitLeave(VisualizationWidget *widget)
33 88 {
34 89 // VisualizationWidget is not intended to accommodate a variable
35 90 Q_UNUSED(widget)
36 91 }
37 92
38 93 void GenerateVariableMenuOperation::visitEnter(VisualizationTabWidget *tabWidget)
39 94 {
40 95 /// @todo ALX
41 96 }
42 97
43 98 void GenerateVariableMenuOperation::visitLeave(VisualizationTabWidget *tabWidget)
44 99 {
45 100 /// @todo ALX
46 101 }
47 102
48 103 void GenerateVariableMenuOperation::visitEnter(VisualizationZoneWidget *zoneWidget)
49 104 {
50 105 /// @todo ALX
51 106 }
52 107
53 108 void GenerateVariableMenuOperation::visitLeave(VisualizationZoneWidget *zoneWidget)
54 109 {
55 110 /// @todo ALX
56 111 }
57 112
58 113 void GenerateVariableMenuOperation::visit(VisualizationGraphWidget *graphWidget)
59 114 {
60 115 /// @todo ALX
61 116 }
General Comments 0
You need to be logged in to leave comments. Login now