##// END OF EJS Templates
Merge branch 'feature/VariableDeletion' into develop
Alexandre Leroux -
r311:c155354de1ae merge
parent child
Show More
@@ -0,0 +1,41
1 #ifndef SCIQLOP_REMOVEVARIABLEOPERATION_H
2 #define SCIQLOP_REMOVEVARIABLEOPERATION_H
3
4 #include "Visualization/IVisualizationWidgetVisitor.h"
5
6 #include <Common/spimpl.h>
7
8 #include <QLoggingCategory>
9
10 #include <memory>
11
12 class Variable;
13
14 Q_DECLARE_LOGGING_CATEGORY(LOG_RemoveVariableOperation)
15
16 /**
17 * @brief The RemoveVariableOperation class defines an operation that traverses all of visualization
18 * widgets to remove a variable if they contain it
19 */
20 class RemoveVariableOperation : public IVisualizationWidgetVisitor {
21 public:
22 /**
23 * Ctor
24 * @param variable the variable to remove from widgets
25 */
26 explicit RemoveVariableOperation(std::shared_ptr<Variable> variable);
27
28 void visitEnter(VisualizationWidget *widget) override final;
29 void visitLeave(VisualizationWidget *widget) override final;
30 void visitEnter(VisualizationTabWidget *tabWidget) override final;
31 void visitLeave(VisualizationTabWidget *tabWidget) override final;
32 void visitEnter(VisualizationZoneWidget *zoneWidget) override final;
33 void visitLeave(VisualizationZoneWidget *zoneWidget) override final;
34 void visit(VisualizationGraphWidget *graphWidget) override final;
35
36 private:
37 class RemoveVariableOperationPrivate;
38 spimpl::unique_impl_ptr<RemoveVariableOperationPrivate> impl;
39 };
40
41 #endif // SCIQLOP_REMOVEVARIABLEOPERATION_H
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
@@ -0,0 +1,70
1 #include "Visualization/operations/RemoveVariableOperation.h"
2 #include "Visualization/VisualizationGraphWidget.h"
3
4 #include <Variable/Variable.h>
5
6 Q_LOGGING_CATEGORY(LOG_RemoveVariableOperation, "RemoveVariableOperation")
7
8 struct RemoveVariableOperation::RemoveVariableOperationPrivate {
9 explicit RemoveVariableOperationPrivate(std::shared_ptr<Variable> variable)
10 : m_Variable(variable)
11 {
12 }
13
14 std::shared_ptr<Variable> m_Variable;
15 };
16
17 RemoveVariableOperation::RemoveVariableOperation(std::shared_ptr<Variable> variable)
18 : impl{spimpl::make_unique_impl<RemoveVariableOperationPrivate>(variable)}
19 {
20 }
21
22 void RemoveVariableOperation::visitEnter(VisualizationWidget *widget)
23 {
24 // VisualizationWidget is not intended to contain a variable
25 Q_UNUSED(widget)
26 }
27
28 void RemoveVariableOperation::visitLeave(VisualizationWidget *widget)
29 {
30 // VisualizationWidget is not intended to contain a variable
31 Q_UNUSED(widget)
32 }
33
34 void RemoveVariableOperation::visitEnter(VisualizationTabWidget *tabWidget)
35 {
36 // VisualizationTabWidget is not intended to contain a variable
37 Q_UNUSED(tabWidget)
38 }
39
40 void RemoveVariableOperation::visitLeave(VisualizationTabWidget *tabWidget)
41 {
42 // VisualizationTabWidget is not intended to contain a variable
43 Q_UNUSED(tabWidget)
44 }
45
46 void RemoveVariableOperation::visitEnter(VisualizationZoneWidget *zoneWidget)
47 {
48 // VisualizationZoneWidget is not intended to contain a variable
49 Q_UNUSED(zoneWidget)
50 }
51
52 void RemoveVariableOperation::visitLeave(VisualizationZoneWidget *zoneWidget)
53 {
54 // VisualizationZoneWidget is not intended to contain a variable
55 Q_UNUSED(zoneWidget)
56 }
57
58 void RemoveVariableOperation::visit(VisualizationGraphWidget *graphWidget)
59 {
60 if (graphWidget) {
61 // If the widget contains the variable, removes it
62 if (impl->m_Variable && graphWidget->contains(*impl->m_Variable)) {
63 graphWidget->removeVariable(impl->m_Variable);
64 }
65 }
66 else {
67 qCCritical(LOG_RemoveVariableOperation(),
68 "Can't visit VisualizationGraphWidget : the widget is null");
69 }
70 }
@@ -173,6 +173,10 MainWindow::MainWindow(QWidget *parent)
173 auto timeWidget = new TimeWidget{};
173 auto timeWidget = new TimeWidget{};
174 mainToolBar->addWidget(timeWidget);
174 mainToolBar->addWidget(timeWidget);
175
175
176 // Controllers / controllers connections
177 connect(&sqpApp->timeController(), SIGNAL(timeUpdated(SqpDateTime)),
178 &sqpApp->variableController(), SLOT(onDateTimeOnSelection(SqpDateTime)));
179
176 // Widgets / controllers connections
180 // Widgets / controllers connections
177
181
178 // DataSource
182 // DataSource
@@ -183,8 +187,10 MainWindow::MainWindow(QWidget *parent)
183 connect(timeWidget, SIGNAL(timeUpdated(SqpDateTime)), &sqpApp->timeController(),
187 connect(timeWidget, SIGNAL(timeUpdated(SqpDateTime)), &sqpApp->timeController(),
184 SLOT(onTimeToUpdate(SqpDateTime)));
188 SLOT(onTimeToUpdate(SqpDateTime)));
185
189
186 connect(&sqpApp->timeController(), SIGNAL(timeUpdated(SqpDateTime)),
190 // Visualization
187 &sqpApp->variableController(), SLOT(onDateTimeOnSelection(SqpDateTime)));
191 connect(&sqpApp->visualizationController(),
192 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), m_Ui->view,
193 SLOT(onVariableAboutToBeDeleted(std::shared_ptr<Variable>)));
188
194
189 // Widgets / widgets connections
195 // Widgets / widgets connections
190
196
@@ -1,6 +1,7
1 #ifndef SCIQLOP_VARIABLECACHECONTROLLER_H
1 #ifndef SCIQLOP_VARIABLECACHECONTROLLER_H
2 #define SCIQLOP_VARIABLECACHECONTROLLER_H
2 #define SCIQLOP_VARIABLECACHECONTROLLER_H
3
3
4 #include <QLoggingCategory>
4 #include <QObject>
5 #include <QObject>
5
6
6 #include <Data/SqpDateTime.h>
7 #include <Data/SqpDateTime.h>
@@ -9,6 +10,8
9
10
10 #include <Common/spimpl.h>
11 #include <Common/spimpl.h>
11
12
13 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableCacheController)
14
12 class Variable;
15 class Variable;
13
16
14 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableCacheController)
17 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableCacheController)
@@ -23,6 +26,9 public:
23
26
24 void addDateTime(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime);
27 void addDateTime(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime);
25
28
29 /// Clears cache concerning a variable
30 void clear(std::shared_ptr<Variable> variable) noexcept;
31
26 /// Return all of the SqpDataTime part of the dateTime whose are not in the cache
32 /// Return all of the SqpDataTime part of the dateTime whose are not in the cache
27 QVector<SqpDateTime> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable,
33 QVector<SqpDateTime> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable,
28 const SqpDateTime &dateTime);
34 const SqpDateTime &dateTime);
@@ -30,8 +30,29 public:
30
30
31 void setTimeController(TimeController *timeController) noexcept;
31 void setTimeController(TimeController *timeController) noexcept;
32
32
33 /**
34 * Deletes from the controller the variable passed in parameter.
35 *
36 * Delete a variable includes:
37 * - the deletion of the various references to the variable in SciQlop
38 * - the deletion of the model variable
39 * - the deletion of the provider associated with the variable
40 * - removing the cache associated with the variable
41 *
42 * @param variable the variable to delete from the controller.
43 */
44 void deleteVariable(std::shared_ptr<Variable> variable) noexcept;
45
46 /**
47 * Deletes from the controller the variables passed in parameter.
48 * @param variables the variables to delete from the controller.
49 * @sa deleteVariable()
50 */
51 void deleteVariables(const QVector<std::shared_ptr<Variable> > &variables) noexcept;
33
52
34 signals:
53 signals:
54 /// Signal emitted when a variable is about to be deleted from the controller
55 void variableAboutToBeDeleted(std::shared_ptr<Variable> variable);
35 /// Signal emitted when a variable has been created
56 /// Signal emitted when a variable has been created
36 void variableCreated(std::shared_ptr<Variable> variable);
57 void variableCreated(std::shared_ptr<Variable> variable);
37
58
@@ -30,6 +30,12 public:
30 std::shared_ptr<Variable> createVariable(const QString &name,
30 std::shared_ptr<Variable> createVariable(const QString &name,
31 const SqpDateTime &dateTime) noexcept;
31 const SqpDateTime &dateTime) noexcept;
32
32
33 /**
34 * Deletes a variable from the model, if it exists
35 * @param variable the variable to delete
36 */
37 void deleteVariable(std::shared_ptr<Variable> variable) noexcept;
38
33 std::shared_ptr<Variable> variable(int index) const;
39 std::shared_ptr<Variable> variable(int index) const;
34
40
35 // /////////////////////////// //
41 // /////////////////////////// //
@@ -26,6 +26,8 public:
26 virtual ~VisualizationController();
26 virtual ~VisualizationController();
27
27
28 signals:
28 signals:
29 /// Signal emitted when a variable is about to be deleted from SciQlop
30 void variableAboutToBeDeleted(std::shared_ptr<Variable> variable);
29 /// Signal emitted when a variable has been created in SciQlop
31 /// Signal emitted when a variable has been created in SciQlop
30 void variableCreated(std::shared_ptr<Variable> variable);
32 void variableCreated(std::shared_ptr<Variable> variable);
31
33
@@ -61,6 +61,22 void VariableCacheController::addDateTime(std::shared_ptr<Variable> variable,
61 }
61 }
62 }
62 }
63
63
64 void VariableCacheController::clear(std::shared_ptr<Variable> variable) noexcept
65 {
66 if (!variable) {
67 qCCritical(LOG_VariableCacheController()) << "Can't clear variable cache: variable is null";
68 return;
69 }
70
71 auto nbEntries = impl->m_VariableToSqpDateTimeListMap.erase(variable);
72
73 auto clearCacheMessage
74 = (nbEntries != 0)
75 ? tr("Variable cache cleared for variable %1").arg(variable->name())
76 : tr("No deletion of variable cache: no cache was associated with the variable");
77 qCDebug(LOG_VariableCacheController()) << clearCacheMessage;
78 }
79
64 QVector<SqpDateTime>
80 QVector<SqpDateTime>
65 VariableCacheController::provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable,
81 VariableCacheController::provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable,
66 const SqpDateTime &dateTime)
82 const SqpDateTime &dateTime)
@@ -82,6 +82,38 void VariableController::setTimeController(TimeController *timeController) noexc
82 impl->m_TimeController = timeController;
82 impl->m_TimeController = timeController;
83 }
83 }
84
84
85 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept
86 {
87 if (!variable) {
88 qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null";
89 return;
90 }
91
92 // Spreads in SciQlop that the variable will be deleted, so that potential receivers can
93 // make some treatments before the deletion
94 emit variableAboutToBeDeleted(variable);
95
96 // Deletes provider
97 auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
98 qCDebug(LOG_VariableController())
99 << tr("Number of providers deleted for variable %1: %2")
100 .arg(variable->name(), QString::number(nbProvidersDeleted));
101
102 // Clears cache
103 impl->m_VariableCacheController->clear(variable);
104
105 // Deletes from model
106 impl->m_VariableModel->deleteVariable(variable);
107 }
108
109 void VariableController::deleteVariables(
110 const QVector<std::shared_ptr<Variable> > &variables) noexcept
111 {
112 for (auto variable : qAsConst(variables)) {
113 deleteVariable(variable);
114 }
115 }
116
85 void VariableController::createVariable(const QString &name,
117 void VariableController::createVariable(const QString &name,
86 std::shared_ptr<IDataProvider> provider) noexcept
118 std::shared_ptr<IDataProvider> provider) noexcept
87 {
119 {
@@ -69,6 +69,32 std::shared_ptr<Variable> VariableModel::createVariable(const QString &name,
69 return variable;
69 return variable;
70 }
70 }
71
71
72 void VariableModel::deleteVariable(std::shared_ptr<Variable> variable) noexcept
73 {
74 if (!variable) {
75 qCCritical(LOG_Variable()) << "Can't delete a null variable from the model";
76 return;
77 }
78
79 // Finds variable in the model
80 auto begin = impl->m_Variables.cbegin();
81 auto end = impl->m_Variables.cend();
82 auto it = std::find(begin, end, variable);
83 if (it != end) {
84 auto removeIndex = std::distance(begin, it);
85
86 // Deletes variable
87 beginRemoveRows({}, removeIndex, removeIndex);
88 impl->m_Variables.erase(it);
89 endRemoveRows();
90 }
91 else {
92 qCritical(LOG_VariableModel())
93 << tr("Can't delete variable %1 from the model: the variable is not in the model")
94 .arg(variable->name());
95 }
96 }
97
72 std::shared_ptr<Variable> VariableModel::variable(int index) const
98 std::shared_ptr<Variable> VariableModel::variable(int index) const
73 {
99 {
74 return (index >= 0 && index < impl->m_Variables.size()) ? impl->m_Variables[index] : nullptr;
100 return (index >= 0 && index < impl->m_Variables.size()) ? impl->m_Variables[index] : nullptr;
@@ -13,6 +13,9 public:
13
13
14 /// Checks if the container can handle the variable passed in parameter
14 /// Checks if the container can handle the variable passed in parameter
15 virtual bool canDrop(const Variable &variable) const = 0;
15 virtual bool canDrop(const Variable &variable) const = 0;
16
17 /// Checks if the container contains the variable passed in parameter
18 virtual bool contains(const Variable &variable) const = 0;
16 };
19 };
17
20
18
21
@@ -35,6 +35,7 public:
35 // IVisualizationWidget interface
35 // IVisualizationWidget interface
36 void accept(IVisualizationWidgetVisitor *visitor) override;
36 void accept(IVisualizationWidgetVisitor *visitor) override;
37 bool canDrop(const Variable &variable) const override;
37 bool canDrop(const Variable &variable) const override;
38 bool contains(const Variable &variable) const override;
38 QString name() const override;
39 QString name() const override;
39
40
40 void updateDisplay(std::shared_ptr<Variable> variable);
41 void updateDisplay(std::shared_ptr<Variable> variable);
@@ -38,6 +38,7 public:
38 // IVisualizationWidget interface
38 // IVisualizationWidget interface
39 void accept(IVisualizationWidgetVisitor *visitor) override;
39 void accept(IVisualizationWidgetVisitor *visitor) override;
40 bool canDrop(const Variable &variable) const override;
40 bool canDrop(const Variable &variable) const override;
41 bool contains(const Variable &variable) const override;
41 QString name() const override;
42 QString name() const override;
42
43
43 private:
44 private:
@@ -26,6 +26,7 public:
26 // IVisualizationWidget interface
26 // IVisualizationWidget interface
27 void accept(IVisualizationWidgetVisitor *visitor) override;
27 void accept(IVisualizationWidgetVisitor *visitor) override;
28 bool canDrop(const Variable &variable) const override;
28 bool canDrop(const Variable &variable) const override;
29 bool contains(const Variable &variable) const override;
29 QString name() const override;
30 QString name() const override;
30
31
31 public slots:
32 public slots:
@@ -37,6 +38,9 public slots:
37 void attachVariableMenu(QMenu *menu,
38 void attachVariableMenu(QMenu *menu,
38 const QVector<std::shared_ptr<Variable> > &variables) noexcept;
39 const QVector<std::shared_ptr<Variable> > &variables) noexcept;
39
40
41 /// Slot called when a variable is about to be deleted from SciQlop
42 void onVariableAboutToBeDeleted(std::shared_ptr<Variable> variable) noexcept;
43
40 private:
44 private:
41 Ui::VisualizationWidget *ui;
45 Ui::VisualizationWidget *ui;
42 };
46 };
@@ -35,6 +35,7 public:
35 // IVisualizationWidget interface
35 // IVisualizationWidget interface
36 void accept(IVisualizationWidgetVisitor *visitor) override;
36 void accept(IVisualizationWidgetVisitor *visitor) override;
37 bool canDrop(const Variable &variable) const override;
37 bool canDrop(const Variable &variable) const override;
38 bool contains(const Variable &variable) const override;
38 QString name() const override;
39 QString name() const override;
39
40
40 private:
41 private:
@@ -27,8 +27,9 public:
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
@@ -3,6 +3,8
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>
8 <file>icones/unplot.png</file>
7 </qresource>
9 </qresource>
8 </RCC>
10 </RCC>
@@ -32,6 +32,10 public:
32 connect(m_VariableController.get(), SIGNAL(variableCreated(std::shared_ptr<Variable>)),
32 connect(m_VariableController.get(), SIGNAL(variableCreated(std::shared_ptr<Variable>)),
33 m_VisualizationController.get(),
33 m_VisualizationController.get(),
34 SIGNAL(variableCreated(std::shared_ptr<Variable>)));
34 SIGNAL(variableCreated(std::shared_ptr<Variable>)));
35 connect(m_VariableController.get(),
36 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)),
37 m_VisualizationController.get(),
38 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), Qt::DirectConnection);
35
39
36 m_DataSourceController->moveToThread(&m_DataSourceControllerThread);
40 m_DataSourceController->moveToThread(&m_DataSourceControllerThread);
37 m_VariableController->moveToThread(&m_VariableControllerThread);
41 m_VariableController->moveToThread(&m_VariableControllerThread);
@@ -68,8 +68,8 void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept
68 // Adds menu-specific actions
68 // Adds menu-specific actions
69 if (!selectedVariables.isEmpty()) {
69 if (!selectedVariables.isEmpty()) {
70 // 'Delete' action
70 // 'Delete' action
71 auto deleteFun = []() {
71 auto deleteFun = [&selectedVariables]() {
72 /// @todo ALX : call variable deletion
72 sqpApp->variableController().deleteVariables(selectedVariables);
73 };
73 };
74
74
75 tableMenu.addSeparator();
75 tableMenu.addSeparator();
@@ -141,6 +141,18 bool VisualizationGraphWidget::canDrop(const Variable &variable) const
141 return true;
141 return true;
142 }
142 }
143
143
144 bool VisualizationGraphWidget::contains(const Variable &variable) const
145 {
146 // Finds the variable among the keys of the map
147 auto variablePtr = &variable;
148 auto findVariable
149 = [variablePtr](const auto &entry) { return variablePtr == entry.first.get(); };
150
151 auto end = impl->m_VariableToPlotMultiMap.cend();
152 auto it = std::find_if(impl->m_VariableToPlotMultiMap.cbegin(), end, findVariable);
153 return it != end;
154 }
155
144 QString VisualizationGraphWidget::name() const
156 QString VisualizationGraphWidget::name() const
145 {
157 {
146 return ui->graphNameLabel->text();
158 return ui->graphNameLabel->text();
@@ -93,6 +93,12 bool VisualizationTabWidget::canDrop(const Variable &variable) const
93 return true;
93 return true;
94 }
94 }
95
95
96 bool VisualizationTabWidget::contains(const Variable &variable) const
97 {
98 Q_UNUSED(variable);
99 return false;
100 }
101
96 QString VisualizationTabWidget::name() const
102 QString VisualizationTabWidget::name() const
97 {
103 {
98 return impl->m_Name;
104 return impl->m_Name;
@@ -4,6 +4,7
4 #include "Visualization/VisualizationTabWidget.h"
4 #include "Visualization/VisualizationTabWidget.h"
5 #include "Visualization/VisualizationZoneWidget.h"
5 #include "Visualization/VisualizationZoneWidget.h"
6 #include "Visualization/operations/GenerateVariableMenuOperation.h"
6 #include "Visualization/operations/GenerateVariableMenuOperation.h"
7 #include "Visualization/operations/RemoveVariableOperation.h"
7 #include "Visualization/qcustomplot.h"
8 #include "Visualization/qcustomplot.h"
8
9
9 #include "ui_VisualizationWidget.h"
10 #include "ui_VisualizationWidget.h"
@@ -101,6 +102,12 bool VisualizationWidget::canDrop(const Variable &variable) const
101 return false;
102 return false;
102 }
103 }
103
104
105 bool VisualizationWidget::contains(const Variable &variable) const
106 {
107 Q_UNUSED(variable);
108 return false;
109 }
110
104 QString VisualizationWidget::name() const
111 QString VisualizationWidget::name() const
105 {
112 {
106 return QStringLiteral("MainView");
113 return QStringLiteral("MainView");
@@ -127,3 +134,10 void VisualizationWidget::attachVariableMenu(
127 "selected");
134 "selected");
128 }
135 }
129 }
136 }
137
138 void VisualizationWidget::onVariableAboutToBeDeleted(std::shared_ptr<Variable> variable) noexcept
139 {
140 // Calls the operation of removing all references to the variable in the visualization
141 auto removeVariableOperation = RemoveVariableOperation{variable};
142 accept(&removeVariableOperation);
143 }
@@ -99,6 +99,12 bool VisualizationZoneWidget::canDrop(const Variable &variable) const
99 return true;
99 return true;
100 }
100 }
101
101
102 bool VisualizationZoneWidget::contains(const Variable &variable) const
103 {
104 Q_UNUSED(variable);
105 return false;
106 }
107
102 QString VisualizationZoneWidget::name() const
108 QString VisualizationZoneWidget::name() const
103 {
109 {
104 return ui->zoneNameLabel->text();
110 return ui->zoneNameLabel->text();
@@ -14,52 +14,71 Q_LOGGING_CATEGORY(LOG_GenerateVariableMenuOperation, "GenerateVariableMenuOpera
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_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_MenuBuilder.addMenu(QObject::tr("Plot"));
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_MenuBuilder.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_MenuBuilder.addMenu(container.name());
38 m_PlotMenuBuilder.addMenu(container.name());
39 m_UnplotMenuBuilder.addMenu(container.name());
37 }
40 }
38
41
39 template <typename ActionFun>
42 template <typename ActionFun>
40 void visitNodeLeave(const IVisualizationWidget &container, const QString &actionName,
43 void visitNodeLeavePlot(const IVisualizationWidget &container, const QString &actionName,
41 ActionFun actionFunction)
44 ActionFun actionFunction)
42 {
45 {
43 if (m_Variable && container.canDrop(*m_Variable)) {
46 if (m_Variable && container.canDrop(*m_Variable)) {
44 m_MenuBuilder.addSeparator();
47 m_PlotMenuBuilder.addSeparator();
45 m_MenuBuilder.addAction(actionName, actionFunction);
48 m_PlotMenuBuilder.addAction(actionName, actionFunction);
46 }
49 }
47
50
48 // Closes the menu associated to the node
51 // Closes the menu associated to the node
49 m_MenuBuilder.closeMenu();
52 m_PlotMenuBuilder.closeMenu();
53 }
54
55 void visitNodeLeaveUnplot()
56 {
57 // Closes the menu associated to the node
58 m_UnplotMenuBuilder.closeMenu();
50 }
59 }
51
60
52 template <typename ActionFun>
61 template <typename ActionFun>
53 void visitLeaf(const IVisualizationWidget &container, const QString &actionName,
62 void visitLeafPlot(const IVisualizationWidget &container, const QString &actionName,
54 ActionFun actionFunction)
63 ActionFun actionFunction)
55 {
64 {
56 if (m_Variable && container.canDrop(*m_Variable)) {
65 if (m_Variable && container.canDrop(*m_Variable)) {
57 m_MenuBuilder.addAction(actionName, actionFunction);
66 m_PlotMenuBuilder.addAction(actionName, actionFunction);
67 }
68 }
69
70 template <typename ActionFun>
71 void visitLeafUnplot(const IVisualizationWidget &container, const QString &actionName,
72 ActionFun actionFunction)
73 {
74 if (m_Variable && container.contains(*m_Variable)) {
75 m_UnplotMenuBuilder.addAction(actionName, actionFunction);
58 }
76 }
59 }
77 }
60
78
61 std::shared_ptr<Variable> m_Variable;
79 std::shared_ptr<Variable> m_Variable;
62 MenuBuilder m_MenuBuilder;
80 MenuBuilder m_PlotMenuBuilder; ///< Builder for the 'Plot' menu
81 MenuBuilder m_UnplotMenuBuilder; ///< Builder for the 'Unplot' menu
63 };
82 };
64
83
65 GenerateVariableMenuOperation::GenerateVariableMenuOperation(QMenu *menu,
84 GenerateVariableMenuOperation::GenerateVariableMenuOperation(QMenu *menu,
@@ -73,6 +92,7 void GenerateVariableMenuOperation::visitEnter(VisualizationWidget *widget)
73 // VisualizationWidget is not intended to accommodate a variable
92 // VisualizationWidget is not intended to accommodate a variable
74 Q_UNUSED(widget)
93 Q_UNUSED(widget)
75
94
95 // 'Plot' and 'Unplot' menus
76 impl->visitRootEnter();
96 impl->visitRootEnter();
77 }
97 }
78
98
@@ -81,12 +101,14 void GenerateVariableMenuOperation::visitLeave(VisualizationWidget *widget)
81 // VisualizationWidget is not intended to accommodate a variable
101 // VisualizationWidget is not intended to accommodate a variable
82 Q_UNUSED(widget)
102 Q_UNUSED(widget)
83
103
104 // 'Plot' and 'Unplot' menus
84 impl->visitRootLeave();
105 impl->visitRootLeave();
85 }
106 }
86
107
87 void GenerateVariableMenuOperation::visitEnter(VisualizationTabWidget *tabWidget)
108 void GenerateVariableMenuOperation::visitEnter(VisualizationTabWidget *tabWidget)
88 {
109 {
89 if (tabWidget) {
110 if (tabWidget) {
111 // 'Plot' and 'Unplot' menus
90 impl->visitNodeEnter(*tabWidget);
112 impl->visitNodeEnter(*tabWidget);
91 }
113 }
92 else {
114 else {
@@ -98,9 +120,13 void GenerateVariableMenuOperation::visitEnter(VisualizationTabWidget *tabWidget
98 void GenerateVariableMenuOperation::visitLeave(VisualizationTabWidget *tabWidget)
120 void GenerateVariableMenuOperation::visitLeave(VisualizationTabWidget *tabWidget)
99 {
121 {
100 if (tabWidget) {
122 if (tabWidget) {
101 impl->visitNodeLeave(
123 // 'Plot' menu
124 impl->visitNodeLeavePlot(
102 *tabWidget, QObject::tr("Open in a new zone"),
125 *tabWidget, QObject::tr("Open in a new zone"),
103 [ var = impl->m_Variable, tabWidget ]() { tabWidget->createZone(var); });
126 [ var = impl->m_Variable, tabWidget ]() { tabWidget->createZone(var); });
127
128 // 'Unplot' menu
129 impl->visitNodeLeaveUnplot();
104 }
130 }
105 else {
131 else {
106 qCCritical(LOG_GenerateVariableMenuOperation(),
132 qCCritical(LOG_GenerateVariableMenuOperation(),
@@ -111,6 +137,7 void GenerateVariableMenuOperation::visitLeave(VisualizationTabWidget *tabWidget
111 void GenerateVariableMenuOperation::visitEnter(VisualizationZoneWidget *zoneWidget)
137 void GenerateVariableMenuOperation::visitEnter(VisualizationZoneWidget *zoneWidget)
112 {
138 {
113 if (zoneWidget) {
139 if (zoneWidget) {
140 // 'Plot' and 'Unplot' menus
114 impl->visitNodeEnter(*zoneWidget);
141 impl->visitNodeEnter(*zoneWidget);
115 }
142 }
116 else {
143 else {
@@ -122,9 +149,13 void GenerateVariableMenuOperation::visitEnter(VisualizationZoneWidget *zoneWidg
122 void GenerateVariableMenuOperation::visitLeave(VisualizationZoneWidget *zoneWidget)
149 void GenerateVariableMenuOperation::visitLeave(VisualizationZoneWidget *zoneWidget)
123 {
150 {
124 if (zoneWidget) {
151 if (zoneWidget) {
125 impl->visitNodeLeave(
152 // 'Plot' menu
153 impl->visitNodeLeavePlot(
126 *zoneWidget, QObject::tr("Open in a new graph"),
154 *zoneWidget, QObject::tr("Open in a new graph"),
127 [ var = impl->m_Variable, zoneWidget ]() { zoneWidget->createGraph(var); });
155 [ var = impl->m_Variable, zoneWidget ]() { zoneWidget->createGraph(var); });
156
157 // 'Unplot' menu
158 impl->visitNodeLeaveUnplot();
128 }
159 }
129 else {
160 else {
130 qCCritical(LOG_GenerateVariableMenuOperation(),
161 qCCritical(LOG_GenerateVariableMenuOperation(),
@@ -135,9 +166,15 void GenerateVariableMenuOperation::visitLeave(VisualizationZoneWidget *zoneWidg
135 void GenerateVariableMenuOperation::visit(VisualizationGraphWidget *graphWidget)
166 void GenerateVariableMenuOperation::visit(VisualizationGraphWidget *graphWidget)
136 {
167 {
137 if (graphWidget) {
168 if (graphWidget) {
138 impl->visitLeaf(
169 // 'Plot' menu
170 impl->visitLeafPlot(
139 *graphWidget, QObject::tr("Open in %1").arg(graphWidget->name()),
171 *graphWidget, QObject::tr("Open in %1").arg(graphWidget->name()),
140 [ var = impl->m_Variable, graphWidget ]() { graphWidget->addVariableUsingGraph(var); });
172 [ var = impl->m_Variable, graphWidget ]() { graphWidget->addVariableUsingGraph(var); });
173
174 // 'Unplot' menu
175 impl->visitLeafUnplot(
176 *graphWidget, QObject::tr("Remove from %1").arg(graphWidget->name()),
177 [ var = impl->m_Variable, graphWidget ]() { graphWidget->removeVariable(var); });
141 }
178 }
142 else {
179 else {
143 qCCritical(LOG_GenerateVariableMenuOperation(),
180 qCCritical(LOG_GenerateVariableMenuOperation(),
@@ -12,10 +12,10 MenuBuilder::MenuBuilder(QMenu *menu)
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");
General Comments 0
You need to be logged in to leave comments. Login now