##// END OF EJS Templates
Uses weak pointers in lambda functions to prevent a shared_ptr from ever being deleted (because a reference would always be kept in the lambda)
Alexandre Leroux -
r361:ca227f940fcb
parent child
Show More
@@ -1,206 +1,207
1 #include <Variable/Variable.h>
1 #include <Variable/Variable.h>
2 #include <Variable/VariableCacheController.h>
2 #include <Variable/VariableCacheController.h>
3 #include <Variable/VariableController.h>
3 #include <Variable/VariableController.h>
4 #include <Variable/VariableModel.h>
4 #include <Variable/VariableModel.h>
5
5
6 #include <Data/DataProviderParameters.h>
6 #include <Data/DataProviderParameters.h>
7 #include <Data/IDataProvider.h>
7 #include <Data/IDataProvider.h>
8 #include <Data/IDataSeries.h>
8 #include <Data/IDataSeries.h>
9 #include <Time/TimeController.h>
9 #include <Time/TimeController.h>
10
10
11 #include <QDateTime>
11 #include <QDateTime>
12 #include <QMutex>
12 #include <QMutex>
13 #include <QThread>
13 #include <QThread>
14 #include <QtCore/QItemSelectionModel>
14 #include <QtCore/QItemSelectionModel>
15
15
16 #include <unordered_map>
16 #include <unordered_map>
17
17
18 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
18 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
19
19
20 namespace {
20 namespace {
21
21
22 /// @todo Generates default dataseries, according to the provider passed in parameter. This method
22 /// @todo Generates default dataseries, according to the provider passed in parameter. This method
23 /// will be deleted when the timerange is recovered from SciQlop
23 /// will be deleted when the timerange is recovered from SciQlop
24 std::shared_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider,
24 std::shared_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider,
25 const SqpDateTime &dateTime) noexcept
25 const SqpDateTime &dateTime) noexcept
26 {
26 {
27 auto parameters = DataProviderParameters{dateTime};
27 auto parameters = DataProviderParameters{dateTime};
28
28
29 return provider.retrieveData(parameters);
29 return provider.retrieveData(parameters);
30 }
30 }
31
31
32 } // namespace
32 } // namespace
33
33
34 struct VariableController::VariableControllerPrivate {
34 struct VariableController::VariableControllerPrivate {
35 explicit VariableControllerPrivate(VariableController *parent)
35 explicit VariableControllerPrivate(VariableController *parent)
36 : m_WorkingMutex{},
36 : m_WorkingMutex{},
37 m_VariableModel{new VariableModel{parent}},
37 m_VariableModel{new VariableModel{parent}},
38 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
38 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
39 m_VariableCacheController{std::make_unique<VariableCacheController>()}
39 m_VariableCacheController{std::make_unique<VariableCacheController>()}
40 {
40 {
41 }
41 }
42
42
43 QMutex m_WorkingMutex;
43 QMutex m_WorkingMutex;
44 /// Variable model. The VariableController has the ownership
44 /// Variable model. The VariableController has the ownership
45 VariableModel *m_VariableModel;
45 VariableModel *m_VariableModel;
46 QItemSelectionModel *m_VariableSelectionModel;
46 QItemSelectionModel *m_VariableSelectionModel;
47
47
48
48
49 TimeController *m_TimeController{nullptr};
49 TimeController *m_TimeController{nullptr};
50 std::unique_ptr<VariableCacheController> m_VariableCacheController;
50 std::unique_ptr<VariableCacheController> m_VariableCacheController;
51
51
52 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
52 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
53 m_VariableToProviderMap;
53 m_VariableToProviderMap;
54 };
54 };
55
55
56 VariableController::VariableController(QObject *parent)
56 VariableController::VariableController(QObject *parent)
57 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
57 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
58 {
58 {
59 qCDebug(LOG_VariableController()) << tr("VariableController construction")
59 qCDebug(LOG_VariableController()) << tr("VariableController construction")
60 << QThread::currentThread();
60 << QThread::currentThread();
61 }
61 }
62
62
63 VariableController::~VariableController()
63 VariableController::~VariableController()
64 {
64 {
65 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
65 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
66 << QThread::currentThread();
66 << QThread::currentThread();
67 this->waitForFinish();
67 this->waitForFinish();
68 }
68 }
69
69
70 VariableModel *VariableController::variableModel() noexcept
70 VariableModel *VariableController::variableModel() noexcept
71 {
71 {
72 return impl->m_VariableModel;
72 return impl->m_VariableModel;
73 }
73 }
74
74
75 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
75 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
76 {
76 {
77 return impl->m_VariableSelectionModel;
77 return impl->m_VariableSelectionModel;
78 }
78 }
79
79
80 void VariableController::setTimeController(TimeController *timeController) noexcept
80 void VariableController::setTimeController(TimeController *timeController) noexcept
81 {
81 {
82 impl->m_TimeController = timeController;
82 impl->m_TimeController = timeController;
83 }
83 }
84
84
85 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept
85 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept
86 {
86 {
87 if (!variable) {
87 if (!variable) {
88 qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null";
88 qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null";
89 return;
89 return;
90 }
90 }
91
91
92 // Spreads in SciQlop that the variable will be deleted, so that potential receivers can
92 // Spreads in SciQlop that the variable will be deleted, so that potential receivers can
93 // make some treatments before the deletion
93 // make some treatments before the deletion
94 emit variableAboutToBeDeleted(variable);
94 emit variableAboutToBeDeleted(variable);
95
95
96 // Deletes provider
96 // Deletes provider
97 auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
97 auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
98 qCDebug(LOG_VariableController())
98 qCDebug(LOG_VariableController())
99 << tr("Number of providers deleted for variable %1: %2")
99 << tr("Number of providers deleted for variable %1: %2")
100 .arg(variable->name(), QString::number(nbProvidersDeleted));
100 .arg(variable->name(), QString::number(nbProvidersDeleted));
101
101
102 // Clears cache
102 // Clears cache
103 impl->m_VariableCacheController->clear(variable);
103 impl->m_VariableCacheController->clear(variable);
104
104
105 // Deletes from model
105 // Deletes from model
106 impl->m_VariableModel->deleteVariable(variable);
106 impl->m_VariableModel->deleteVariable(variable);
107 }
107 }
108
108
109 void VariableController::deleteVariables(
109 void VariableController::deleteVariables(
110 const QVector<std::shared_ptr<Variable> > &variables) noexcept
110 const QVector<std::shared_ptr<Variable> > &variables) noexcept
111 {
111 {
112 for (auto variable : qAsConst(variables)) {
112 for (auto variable : qAsConst(variables)) {
113 deleteVariable(variable);
113 deleteVariable(variable);
114 }
114 }
115 }
115 }
116
116
117 void VariableController::createVariable(const QString &name,
117 void VariableController::createVariable(const QString &name,
118 std::shared_ptr<IDataProvider> provider) noexcept
118 std::shared_ptr<IDataProvider> provider) noexcept
119 {
119 {
120
120
121 if (!impl->m_TimeController) {
121 if (!impl->m_TimeController) {
122 qCCritical(LOG_VariableController())
122 qCCritical(LOG_VariableController())
123 << tr("Impossible to create variable: The time controller is null");
123 << tr("Impossible to create variable: The time controller is null");
124 return;
124 return;
125 }
125 }
126
126
127
127
128 /// @todo : for the moment :
128 /// @todo : for the moment :
129 /// - the provider is only used to retrieve data from the variable for its initialization, but
129 /// - the provider is only used to retrieve data from the variable for its initialization, but
130 /// it will be retained later
130 /// it will be retained later
131 /// - default data are generated for the variable, without taking into account the timerange set
131 /// - default data are generated for the variable, without taking into account the timerange set
132 /// in sciqlop
132 /// in sciqlop
133 auto dateTime = impl->m_TimeController->dateTime();
133 auto dateTime = impl->m_TimeController->dateTime();
134 if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime)) {
134 if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime)) {
135
135
136 // store the provider
136 // store the provider
137 impl->m_VariableToProviderMap[newVariable] = provider;
137 impl->m_VariableToProviderMap[newVariable] = provider;
138
138
139 auto addDateTimeAcquired
139 auto addDateTimeAcquired = [ this, varW = std::weak_ptr<Variable>{newVariable} ](
140 = [this, newVariable](auto dataSeriesAcquired, auto dateTimeToPutInCache) {
140 auto dataSeriesAcquired, auto dateTimeToPutInCache)
141
141 {
142 impl->m_VariableCacheController->addDateTime(newVariable, dateTimeToPutInCache);
142 if (auto variable = varW.lock()) {
143 newVariable->setDataSeries(dataSeriesAcquired);
143 impl->m_VariableCacheController->addDateTime(variable, dateTimeToPutInCache);
144
144 variable->setDataSeries(dataSeriesAcquired);
145 }
145 };
146 };
146
147
147 connect(provider.get(), &IDataProvider::dataProvided, addDateTimeAcquired);
148 connect(provider.get(), &IDataProvider::dataProvided, addDateTimeAcquired);
148 this->onRequestDataLoading(newVariable, dateTime);
149 this->onRequestDataLoading(newVariable, dateTime);
149 }
150 }
150 }
151 }
151
152
152 void VariableController::onDateTimeOnSelection(const SqpDateTime &dateTime)
153 void VariableController::onDateTimeOnSelection(const SqpDateTime &dateTime)
153 {
154 {
154 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
155 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
155
156
156 for (const auto &selectedRow : qAsConst(selectedRows)) {
157 for (const auto &selectedRow : qAsConst(selectedRows)) {
157 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
158 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
158 selectedVariable->setDateTime(dateTime);
159 selectedVariable->setDateTime(dateTime);
159 this->onRequestDataLoading(selectedVariable, dateTime);
160 this->onRequestDataLoading(selectedVariable, dateTime);
160 }
161 }
161 }
162 }
162 }
163 }
163
164
164
165
165 void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable,
166 void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable,
166 const SqpDateTime &dateTime)
167 const SqpDateTime &dateTime)
167 {
168 {
168 // we want to load data of the variable for the dateTime.
169 // we want to load data of the variable for the dateTime.
169 // First we check if the cache contains some of them.
170 // First we check if the cache contains some of them.
170 // For the other, we ask the provider to give them.
171 // For the other, we ask the provider to give them.
171 if (variable) {
172 if (variable) {
172
173
173 auto dateTimeListNotInCache
174 auto dateTimeListNotInCache
174 = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime);
175 = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime);
175
176
176 if (!dateTimeListNotInCache.empty()) {
177 if (!dateTimeListNotInCache.empty()) {
177 // Ask the provider for each data on the dateTimeListNotInCache
178 // Ask the provider for each data on the dateTimeListNotInCache
178 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(
179 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(
179 std::move(dateTimeListNotInCache));
180 std::move(dateTimeListNotInCache));
180 }
181 }
181 else {
182 else {
182 emit variable->updated();
183 emit variable->updated();
183 }
184 }
184 }
185 }
185 else {
186 else {
186 qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null");
187 qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null");
187 }
188 }
188 }
189 }
189
190
190
191
191 void VariableController::initialize()
192 void VariableController::initialize()
192 {
193 {
193 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
194 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
194 impl->m_WorkingMutex.lock();
195 impl->m_WorkingMutex.lock();
195 qCDebug(LOG_VariableController()) << tr("VariableController init END");
196 qCDebug(LOG_VariableController()) << tr("VariableController init END");
196 }
197 }
197
198
198 void VariableController::finalize()
199 void VariableController::finalize()
199 {
200 {
200 impl->m_WorkingMutex.unlock();
201 impl->m_WorkingMutex.unlock();
201 }
202 }
202
203
203 void VariableController::waitForFinish()
204 void VariableController::waitForFinish()
204 {
205 {
205 QMutexLocker locker{&impl->m_WorkingMutex};
206 QMutexLocker locker{&impl->m_WorkingMutex};
206 }
207 }
@@ -1,183 +1,196
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}, m_UnplotMenuBuilder{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 m_UnplotMenuBuilder.addMenu(QObject::tr("Unplot"), QIcon{":/icones/unplot.png"});
26 }
26 }
27
27
28 void visitRootLeave()
28 void visitRootLeave()
29 {
29 {
30 // Closes the root menu
30 // Closes the root menu
31 m_PlotMenuBuilder.closeMenu();
31 m_PlotMenuBuilder.closeMenu();
32 m_UnplotMenuBuilder.closeMenu();
32 m_UnplotMenuBuilder.closeMenu();
33 }
33 }
34
34
35 void visitNodeEnter(const IVisualizationWidget &container)
35 void visitNodeEnter(const IVisualizationWidget &container)
36 {
36 {
37 // Opens a new menu associated to the node
37 // Opens a new menu associated to the node
38 m_PlotMenuBuilder.addMenu(container.name());
38 m_PlotMenuBuilder.addMenu(container.name());
39 m_UnplotMenuBuilder.addMenu(container.name());
39 m_UnplotMenuBuilder.addMenu(container.name());
40 }
40 }
41
41
42 template <typename ActionFun>
42 template <typename ActionFun>
43 void visitNodeLeavePlot(const IVisualizationWidget &container, const QString &actionName,
43 void visitNodeLeavePlot(const IVisualizationWidget &container, const QString &actionName,
44 ActionFun actionFunction)
44 ActionFun actionFunction)
45 {
45 {
46 if (m_Variable && container.canDrop(*m_Variable)) {
46 if (m_Variable && container.canDrop(*m_Variable)) {
47 m_PlotMenuBuilder.addSeparator();
47 m_PlotMenuBuilder.addSeparator();
48 m_PlotMenuBuilder.addAction(actionName, actionFunction);
48 m_PlotMenuBuilder.addAction(actionName, actionFunction);
49 }
49 }
50
50
51 // Closes the menu associated to the node
51 // Closes the menu associated to the node
52 m_PlotMenuBuilder.closeMenu();
52 m_PlotMenuBuilder.closeMenu();
53 }
53 }
54
54
55 void visitNodeLeaveUnplot()
55 void visitNodeLeaveUnplot()
56 {
56 {
57 // Closes the menu associated to the node
57 // Closes the menu associated to the node
58 m_UnplotMenuBuilder.closeMenu();
58 m_UnplotMenuBuilder.closeMenu();
59 }
59 }
60
60
61 template <typename ActionFun>
61 template <typename ActionFun>
62 void visitLeafPlot(const IVisualizationWidget &container, const QString &actionName,
62 void visitLeafPlot(const IVisualizationWidget &container, const QString &actionName,
63 ActionFun actionFunction)
63 ActionFun actionFunction)
64 {
64 {
65 if (m_Variable && container.canDrop(*m_Variable)) {
65 if (m_Variable && container.canDrop(*m_Variable)) {
66 m_PlotMenuBuilder.addAction(actionName, actionFunction);
66 m_PlotMenuBuilder.addAction(actionName, actionFunction);
67 }
67 }
68 }
68 }
69
69
70 template <typename ActionFun>
70 template <typename ActionFun>
71 void visitLeafUnplot(const IVisualizationWidget &container, const QString &actionName,
71 void visitLeafUnplot(const IVisualizationWidget &container, const QString &actionName,
72 ActionFun actionFunction)
72 ActionFun actionFunction)
73 {
73 {
74 if (m_Variable && container.contains(*m_Variable)) {
74 if (m_Variable && container.contains(*m_Variable)) {
75 m_UnplotMenuBuilder.addAction(actionName, actionFunction);
75 m_UnplotMenuBuilder.addAction(actionName, actionFunction);
76 }
76 }
77 }
77 }
78
78
79 std::shared_ptr<Variable> m_Variable;
79 std::shared_ptr<Variable> m_Variable;
80 MenuBuilder m_PlotMenuBuilder; ///< Builder for the 'Plot' menu
80 MenuBuilder m_PlotMenuBuilder; ///< Builder for the 'Plot' menu
81 MenuBuilder m_UnplotMenuBuilder; ///< Builder for the 'Unplot' menu
81 MenuBuilder m_UnplotMenuBuilder; ///< Builder for the 'Unplot' menu
82 };
82 };
83
83
84 GenerateVariableMenuOperation::GenerateVariableMenuOperation(QMenu *menu,
84 GenerateVariableMenuOperation::GenerateVariableMenuOperation(QMenu *menu,
85 std::shared_ptr<Variable> variable)
85 std::shared_ptr<Variable> variable)
86 : impl{spimpl::make_unique_impl<GenerateVariableMenuOperationPrivate>(menu, variable)}
86 : impl{spimpl::make_unique_impl<GenerateVariableMenuOperationPrivate>(menu, variable)}
87 {
87 {
88 }
88 }
89
89
90 void GenerateVariableMenuOperation::visitEnter(VisualizationWidget *widget)
90 void GenerateVariableMenuOperation::visitEnter(VisualizationWidget *widget)
91 {
91 {
92 // VisualizationWidget is not intended to accommodate a variable
92 // VisualizationWidget is not intended to accommodate a variable
93 Q_UNUSED(widget)
93 Q_UNUSED(widget)
94
94
95 // 'Plot' and 'Unplot' menus
95 // 'Plot' and 'Unplot' menus
96 impl->visitRootEnter();
96 impl->visitRootEnter();
97 }
97 }
98
98
99 void GenerateVariableMenuOperation::visitLeave(VisualizationWidget *widget)
99 void GenerateVariableMenuOperation::visitLeave(VisualizationWidget *widget)
100 {
100 {
101 // VisualizationWidget is not intended to accommodate a variable
101 // VisualizationWidget is not intended to accommodate a variable
102 Q_UNUSED(widget)
102 Q_UNUSED(widget)
103
103
104 // 'Plot' and 'Unplot' menus
104 // 'Plot' and 'Unplot' menus
105 impl->visitRootLeave();
105 impl->visitRootLeave();
106 }
106 }
107
107
108 void GenerateVariableMenuOperation::visitEnter(VisualizationTabWidget *tabWidget)
108 void GenerateVariableMenuOperation::visitEnter(VisualizationTabWidget *tabWidget)
109 {
109 {
110 if (tabWidget) {
110 if (tabWidget) {
111 // 'Plot' and 'Unplot' menus
111 // 'Plot' and 'Unplot' menus
112 impl->visitNodeEnter(*tabWidget);
112 impl->visitNodeEnter(*tabWidget);
113 }
113 }
114 else {
114 else {
115 qCCritical(LOG_GenerateVariableMenuOperation(),
115 qCCritical(LOG_GenerateVariableMenuOperation(),
116 "Can't visit enter VisualizationTabWidget : the widget is null");
116 "Can't visit enter VisualizationTabWidget : the widget is null");
117 }
117 }
118 }
118 }
119
119
120 void GenerateVariableMenuOperation::visitLeave(VisualizationTabWidget *tabWidget)
120 void GenerateVariableMenuOperation::visitLeave(VisualizationTabWidget *tabWidget)
121 {
121 {
122 if (tabWidget) {
122 if (tabWidget) {
123 // 'Plot' menu
123 // 'Plot' menu
124 impl->visitNodeLeavePlot(
124 impl->visitNodeLeavePlot(*tabWidget, QObject::tr("Open in a new zone"),
125 *tabWidget, QObject::tr("Open in a new zone"),
125 [ varW = std::weak_ptr<Variable>{impl->m_Variable}, tabWidget ]() {
126 [ var = impl->m_Variable, tabWidget ]() { tabWidget->createZone(var); });
126 if (auto var = varW.lock()) {
127 tabWidget->createZone(var);
128 }
129 });
127
130
128 // 'Unplot' menu
131 // 'Unplot' menu
129 impl->visitNodeLeaveUnplot();
132 impl->visitNodeLeaveUnplot();
130 }
133 }
131 else {
134 else {
132 qCCritical(LOG_GenerateVariableMenuOperation(),
135 qCCritical(LOG_GenerateVariableMenuOperation(),
133 "Can't visit leave VisualizationTabWidget : the widget is null");
136 "Can't visit leave VisualizationTabWidget : the widget is null");
134 }
137 }
135 }
138 }
136
139
137 void GenerateVariableMenuOperation::visitEnter(VisualizationZoneWidget *zoneWidget)
140 void GenerateVariableMenuOperation::visitEnter(VisualizationZoneWidget *zoneWidget)
138 {
141 {
139 if (zoneWidget) {
142 if (zoneWidget) {
140 // 'Plot' and 'Unplot' menus
143 // 'Plot' and 'Unplot' menus
141 impl->visitNodeEnter(*zoneWidget);
144 impl->visitNodeEnter(*zoneWidget);
142 }
145 }
143 else {
146 else {
144 qCCritical(LOG_GenerateVariableMenuOperation(),
147 qCCritical(LOG_GenerateVariableMenuOperation(),
145 "Can't visit enter VisualizationZoneWidget : the widget is null");
148 "Can't visit enter VisualizationZoneWidget : the widget is null");
146 }
149 }
147 }
150 }
148
151
149 void GenerateVariableMenuOperation::visitLeave(VisualizationZoneWidget *zoneWidget)
152 void GenerateVariableMenuOperation::visitLeave(VisualizationZoneWidget *zoneWidget)
150 {
153 {
151 if (zoneWidget) {
154 if (zoneWidget) {
152 // 'Plot' menu
155 // 'Plot' menu
153 impl->visitNodeLeavePlot(
156 impl->visitNodeLeavePlot(
154 *zoneWidget, QObject::tr("Open in a new graph"),
157 *zoneWidget, QObject::tr("Open in a new graph"),
155 [ var = impl->m_Variable, zoneWidget ]() { zoneWidget->createGraph(var); });
158 [ varW = std::weak_ptr<Variable>{impl->m_Variable}, zoneWidget ]() {
159 if (auto var = varW.lock()) {
160 zoneWidget->createGraph(var);
161 }
162 });
156
163
157 // 'Unplot' menu
164 // 'Unplot' menu
158 impl->visitNodeLeaveUnplot();
165 impl->visitNodeLeaveUnplot();
159 }
166 }
160 else {
167 else {
161 qCCritical(LOG_GenerateVariableMenuOperation(),
168 qCCritical(LOG_GenerateVariableMenuOperation(),
162 "Can't visit leave VisualizationZoneWidget : the widget is null");
169 "Can't visit leave VisualizationZoneWidget : the widget is null");
163 }
170 }
164 }
171 }
165
172
166 void GenerateVariableMenuOperation::visit(VisualizationGraphWidget *graphWidget)
173 void GenerateVariableMenuOperation::visit(VisualizationGraphWidget *graphWidget)
167 {
174 {
168 if (graphWidget) {
175 if (graphWidget) {
169 // 'Plot' menu
176 // 'Plot' menu
170 impl->visitLeafPlot(
177 impl->visitLeafPlot(*graphWidget, QObject::tr("Open in %1").arg(graphWidget->name()),
171 *graphWidget, QObject::tr("Open in %1").arg(graphWidget->name()),
178 [ varW = std::weak_ptr<Variable>{impl->m_Variable}, graphWidget ]() {
172 [ var = impl->m_Variable, graphWidget ]() { graphWidget->addVariableUsingGraph(var); });
179 if (auto var = varW.lock()) {
180 graphWidget->addVariableUsingGraph(var);
181 }
182 });
173
183
174 // 'Unplot' menu
184 // 'Unplot' menu
175 impl->visitLeafUnplot(
185 impl->visitLeafUnplot(*graphWidget, QObject::tr("Remove from %1").arg(graphWidget->name()),
176 *graphWidget, QObject::tr("Remove from %1").arg(graphWidget->name()),
186 [ varW = std::weak_ptr<Variable>{impl->m_Variable}, graphWidget ]() {
177 [ var = impl->m_Variable, graphWidget ]() { graphWidget->removeVariable(var); });
187 if (auto var = varW.lock()) {
188 graphWidget->removeVariable(var);
189 }
190 });
178 }
191 }
179 else {
192 else {
180 qCCritical(LOG_GenerateVariableMenuOperation(),
193 qCCritical(LOG_GenerateVariableMenuOperation(),
181 "Can't visit VisualizationGraphWidget : the widget is null");
194 "Can't visit VisualizationGraphWidget : the widget is null");
182 }
195 }
183 }
196 }
General Comments 0
You need to be logged in to leave comments. Login now