@@ -1,298 +1,302 | |||||
1 | #include "Visualization/VisualizationZoneWidget.h" |
|
1 | #include "Visualization/VisualizationZoneWidget.h" | |
2 |
|
2 | |||
3 | #include "Visualization/IVisualizationWidgetVisitor.h" |
|
3 | #include "Visualization/IVisualizationWidgetVisitor.h" | |
4 | #include "Visualization/QCustomPlotSynchronizer.h" |
|
4 | #include "Visualization/QCustomPlotSynchronizer.h" | |
5 | #include "Visualization/VisualizationGraphWidget.h" |
|
5 | #include "Visualization/VisualizationGraphWidget.h" | |
6 | #include "ui_VisualizationZoneWidget.h" |
|
6 | #include "ui_VisualizationZoneWidget.h" | |
7 |
|
7 | |||
8 | #include <Data/SqpRange.h> |
|
8 | #include <Data/SqpRange.h> | |
9 | #include <Variable/Variable.h> |
|
9 | #include <Variable/Variable.h> | |
10 | #include <Variable/VariableController.h> |
|
10 | #include <Variable/VariableController.h> | |
11 |
|
11 | |||
12 | #include <QUuid> |
|
12 | #include <QUuid> | |
13 | #include <SqpApplication.h> |
|
13 | #include <SqpApplication.h> | |
14 | #include <cmath> |
|
14 | #include <cmath> | |
15 |
|
15 | |||
16 | Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget") |
|
16 | Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget") | |
17 |
|
17 | |||
18 | namespace { |
|
18 | namespace { | |
19 |
|
19 | |||
20 | /// Minimum height for graph added in zones (in pixels) |
|
20 | /// Minimum height for graph added in zones (in pixels) | |
21 | const auto GRAPH_MINIMUM_HEIGHT = 300; |
|
21 | const auto GRAPH_MINIMUM_HEIGHT = 300; | |
22 |
|
22 | |||
23 | /// Generates a default name for a new graph, according to the number of graphs already displayed in |
|
23 | /// Generates a default name for a new graph, according to the number of graphs already displayed in | |
24 | /// the zone |
|
24 | /// the zone | |
25 | QString defaultGraphName(const QLayout &layout) |
|
25 | QString defaultGraphName(const QLayout &layout) | |
26 | { |
|
26 | { | |
27 | auto count = 0; |
|
27 | auto count = 0; | |
28 | for (auto i = 0; i < layout.count(); ++i) { |
|
28 | for (auto i = 0; i < layout.count(); ++i) { | |
29 | if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) { |
|
29 | if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) { | |
30 | count++; |
|
30 | count++; | |
31 | } |
|
31 | } | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | return QObject::tr("Graph %1").arg(count + 1); |
|
34 | return QObject::tr("Graph %1").arg(count + 1); | |
35 | } |
|
35 | } | |
36 |
|
36 | |||
37 | /** |
|
37 | /** | |
38 | * Applies a function to all graphs of the zone represented by its layout |
|
38 | * Applies a function to all graphs of the zone represented by its layout | |
39 | * @param layout the layout that contains graphs |
|
39 | * @param layout the layout that contains graphs | |
40 | * @param fun the function to apply to each graph |
|
40 | * @param fun the function to apply to each graph | |
41 | */ |
|
41 | */ | |
42 | template <typename Fun> |
|
42 | template <typename Fun> | |
43 | void processGraphs(QLayout &layout, Fun fun) |
|
43 | void processGraphs(QLayout &layout, Fun fun) | |
44 | { |
|
44 | { | |
45 | for (auto i = 0; i < layout.count(); ++i) { |
|
45 | for (auto i = 0; i < layout.count(); ++i) { | |
46 | if (auto item = layout.itemAt(i)) { |
|
46 | if (auto item = layout.itemAt(i)) { | |
47 | if (auto visualizationGraphWidget |
|
47 | if (auto visualizationGraphWidget | |
48 | = dynamic_cast<VisualizationGraphWidget *>(item->widget())) { |
|
48 | = dynamic_cast<VisualizationGraphWidget *>(item->widget())) { | |
49 | fun(*visualizationGraphWidget); |
|
49 | fun(*visualizationGraphWidget); | |
50 | } |
|
50 | } | |
51 | } |
|
51 | } | |
52 | } |
|
52 | } | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | } // namespace |
|
55 | } // namespace | |
56 |
|
56 | |||
57 | struct VisualizationZoneWidget::VisualizationZoneWidgetPrivate { |
|
57 | struct VisualizationZoneWidget::VisualizationZoneWidgetPrivate { | |
58 |
|
58 | |||
59 | explicit VisualizationZoneWidgetPrivate() |
|
59 | explicit VisualizationZoneWidgetPrivate() | |
60 | : m_SynchronisationGroupId{QUuid::createUuid()}, |
|
60 | : m_SynchronisationGroupId{QUuid::createUuid()}, | |
61 | m_Synchronizer{std::make_unique<QCustomPlotSynchronizer>()} |
|
61 | m_Synchronizer{std::make_unique<QCustomPlotSynchronizer>()} | |
62 | { |
|
62 | { | |
63 | } |
|
63 | } | |
64 | QUuid m_SynchronisationGroupId; |
|
64 | QUuid m_SynchronisationGroupId; | |
65 | std::unique_ptr<IGraphSynchronizer> m_Synchronizer; |
|
65 | std::unique_ptr<IGraphSynchronizer> m_Synchronizer; | |
66 | }; |
|
66 | }; | |
67 |
|
67 | |||
68 | VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent) |
|
68 | VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent) | |
69 | : QWidget{parent}, |
|
69 | : QWidget{parent}, | |
70 | ui{new Ui::VisualizationZoneWidget}, |
|
70 | ui{new Ui::VisualizationZoneWidget}, | |
71 | impl{spimpl::make_unique_impl<VisualizationZoneWidgetPrivate>()} |
|
71 | impl{spimpl::make_unique_impl<VisualizationZoneWidgetPrivate>()} | |
72 | { |
|
72 | { | |
73 | ui->setupUi(this); |
|
73 | ui->setupUi(this); | |
74 |
|
74 | |||
75 | ui->zoneNameLabel->setText(name); |
|
75 | ui->zoneNameLabel->setText(name); | |
76 |
|
76 | |||
77 | // 'Close' options : widget is deleted when closed |
|
77 | // 'Close' options : widget is deleted when closed | |
78 | setAttribute(Qt::WA_DeleteOnClose); |
|
78 | setAttribute(Qt::WA_DeleteOnClose); | |
79 | connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationZoneWidget::close); |
|
79 | connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationZoneWidget::close); | |
80 | ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton)); |
|
80 | ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton)); | |
81 |
|
81 | |||
82 | // Synchronisation id |
|
82 | // Synchronisation id | |
83 | QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronizationGroupId", |
|
83 | QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronizationGroupId", | |
84 | Qt::QueuedConnection, Q_ARG(QUuid, impl->m_SynchronisationGroupId)); |
|
84 | Qt::QueuedConnection, Q_ARG(QUuid, impl->m_SynchronisationGroupId)); | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 | VisualizationZoneWidget::~VisualizationZoneWidget() |
|
87 | VisualizationZoneWidget::~VisualizationZoneWidget() | |
88 | { |
|
88 | { | |
89 | delete ui; |
|
89 | delete ui; | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 | void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget) |
|
92 | void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget) | |
93 | { |
|
93 | { | |
94 | // Synchronize new graph with others in the zone |
|
94 | // Synchronize new graph with others in the zone | |
95 | impl->m_Synchronizer->addGraph(*graphWidget); |
|
95 | impl->m_Synchronizer->addGraph(*graphWidget); | |
96 |
|
96 | |||
97 | ui->visualizationZoneFrame->layout()->addWidget(graphWidget); |
|
97 | ui->visualizationZoneFrame->layout()->addWidget(graphWidget); | |
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 | VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable) |
|
100 | VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable) | |
101 | { |
|
101 | { | |
102 | auto graphWidget = new VisualizationGraphWidget{ |
|
102 | auto graphWidget = new VisualizationGraphWidget{ | |
103 | defaultGraphName(*ui->visualizationZoneFrame->layout()), this}; |
|
103 | defaultGraphName(*ui->visualizationZoneFrame->layout()), this}; | |
104 |
|
104 | |||
105 |
|
105 | |||
106 | // Set graph properties |
|
106 | // Set graph properties | |
107 | graphWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); |
|
107 | graphWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); | |
108 | graphWidget->setMinimumHeight(GRAPH_MINIMUM_HEIGHT); |
|
108 | graphWidget->setMinimumHeight(GRAPH_MINIMUM_HEIGHT); | |
109 |
|
109 | |||
110 |
|
110 | |||
111 | // Lambda to synchronize zone widget |
|
111 | // Lambda to synchronize zone widget | |
112 | auto synchronizeZoneWidget = [this, graphWidget](const SqpRange &graphRange, |
|
112 | auto synchronizeZoneWidget = [this, graphWidget](const SqpRange &graphRange, | |
113 | const SqpRange &oldGraphRange) { |
|
113 | const SqpRange &oldGraphRange) { | |
114 |
|
114 | |||
115 | auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange); |
|
115 | auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange); | |
116 | auto frameLayout = ui->visualizationZoneFrame->layout(); |
|
116 | auto frameLayout = ui->visualizationZoneFrame->layout(); | |
117 | for (auto i = 0; i < frameLayout->count(); ++i) { |
|
117 | for (auto i = 0; i < frameLayout->count(); ++i) { | |
118 | auto graphChild |
|
118 | auto graphChild | |
119 | = dynamic_cast<VisualizationGraphWidget *>(frameLayout->itemAt(i)->widget()); |
|
119 | = dynamic_cast<VisualizationGraphWidget *>(frameLayout->itemAt(i)->widget()); | |
120 | if (graphChild && (graphChild != graphWidget)) { |
|
120 | if (graphChild && (graphChild != graphWidget)) { | |
121 |
|
121 | |||
122 | auto graphChildRange = graphChild->graphRange(); |
|
122 | auto graphChildRange = graphChild->graphRange(); | |
123 | switch (zoomType) { |
|
123 | switch (zoomType) { | |
124 | case AcquisitionZoomType::ZoomIn: { |
|
124 | case AcquisitionZoomType::ZoomIn: { | |
125 | auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart; |
|
125 | auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart; | |
126 | auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd; |
|
126 | auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd; | |
127 | graphChildRange.m_TStart += deltaLeft; |
|
127 | graphChildRange.m_TStart += deltaLeft; | |
128 | graphChildRange.m_TEnd -= deltaRight; |
|
128 | graphChildRange.m_TEnd -= deltaRight; | |
129 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomIn"); |
|
129 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomIn"); | |
130 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft") |
|
130 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft") | |
131 | << deltaLeft; |
|
131 | << deltaLeft; | |
132 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight") |
|
132 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight") | |
133 | << deltaRight; |
|
133 | << deltaRight; | |
134 | qCDebug(LOG_VisualizationZoneWidget()) |
|
134 | qCDebug(LOG_VisualizationZoneWidget()) | |
135 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; |
|
135 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; | |
136 |
|
136 | |||
137 | break; |
|
137 | break; | |
138 | } |
|
138 | } | |
139 |
|
139 | |||
140 | case AcquisitionZoomType::ZoomOut: { |
|
140 | case AcquisitionZoomType::ZoomOut: { | |
141 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomOut"); |
|
141 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomOut"); | |
142 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; |
|
142 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; | |
143 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; |
|
143 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; | |
144 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft") |
|
144 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft") | |
145 | << deltaLeft; |
|
145 | << deltaLeft; | |
146 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight") |
|
146 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight") | |
147 | << deltaRight; |
|
147 | << deltaRight; | |
148 | qCDebug(LOG_VisualizationZoneWidget()) |
|
148 | qCDebug(LOG_VisualizationZoneWidget()) | |
149 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; |
|
149 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; | |
150 | graphChildRange.m_TStart -= deltaLeft; |
|
150 | graphChildRange.m_TStart -= deltaLeft; | |
151 | graphChildRange.m_TEnd += deltaRight; |
|
151 | graphChildRange.m_TEnd += deltaRight; | |
152 | break; |
|
152 | break; | |
153 | } |
|
153 | } | |
154 | case AcquisitionZoomType::PanRight: { |
|
154 | case AcquisitionZoomType::PanRight: { | |
155 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: PanRight"); |
|
155 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: PanRight"); | |
156 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; |
|
156 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; | |
157 | graphChildRange.m_TStart += deltaRight; |
|
157 | graphChildRange.m_TStart += deltaRight; | |
158 | graphChildRange.m_TEnd += deltaRight; |
|
158 | graphChildRange.m_TEnd += deltaRight; | |
159 | qCDebug(LOG_VisualizationZoneWidget()) |
|
159 | qCDebug(LOG_VisualizationZoneWidget()) | |
160 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; |
|
160 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; | |
161 | break; |
|
161 | break; | |
162 | } |
|
162 | } | |
163 | case AcquisitionZoomType::PanLeft: { |
|
163 | case AcquisitionZoomType::PanLeft: { | |
164 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: PanLeft"); |
|
164 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: PanLeft"); | |
165 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; |
|
165 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; | |
166 | graphChildRange.m_TStart -= deltaLeft; |
|
166 | graphChildRange.m_TStart -= deltaLeft; | |
167 | graphChildRange.m_TEnd -= deltaLeft; |
|
167 | graphChildRange.m_TEnd -= deltaLeft; | |
168 | break; |
|
168 | break; | |
169 | } |
|
169 | } | |
170 | case AcquisitionZoomType::Unknown: { |
|
170 | case AcquisitionZoomType::Unknown: { | |
171 | qCDebug(LOG_VisualizationZoneWidget()) |
|
171 | qCDebug(LOG_VisualizationZoneWidget()) | |
172 | << tr("Impossible to synchronize: zoom type unknown"); |
|
172 | << tr("Impossible to synchronize: zoom type unknown"); | |
173 | break; |
|
173 | break; | |
174 | } |
|
174 | } | |
175 | default: |
|
175 | default: | |
176 | qCCritical(LOG_VisualizationZoneWidget()) |
|
176 | qCCritical(LOG_VisualizationZoneWidget()) | |
177 | << tr("Impossible to synchronize: zoom type not take into account"); |
|
177 | << tr("Impossible to synchronize: zoom type not take into account"); | |
178 | // No action |
|
178 | // No action | |
179 | break; |
|
179 | break; | |
180 | } |
|
180 | } | |
181 | graphChild->enableAcquisition(false); |
|
181 | graphChild->enableAcquisition(false); | |
182 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: Range before: ") |
|
182 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: Range before: ") | |
183 | << graphChild->graphRange(); |
|
183 | << graphChild->graphRange(); | |
184 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: Range after : ") |
|
184 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: Range after : ") | |
185 | << graphChildRange; |
|
185 | << graphChildRange; | |
186 | qCDebug(LOG_VisualizationZoneWidget()) |
|
186 | qCDebug(LOG_VisualizationZoneWidget()) | |
187 | << tr("TORM: child dt") << graphChildRange.m_TEnd - graphChildRange.m_TStart; |
|
187 | << tr("TORM: child dt") << graphChildRange.m_TEnd - graphChildRange.m_TStart; | |
188 | graphChild->setGraphRange(graphChildRange); |
|
188 | graphChild->setGraphRange(graphChildRange); | |
189 | graphChild->enableAcquisition(true); |
|
189 | graphChild->enableAcquisition(true); | |
190 | } |
|
190 | } | |
191 | } |
|
191 | } | |
192 | }; |
|
192 | }; | |
193 |
|
193 | |||
194 | // connection for synchronization |
|
194 | // connection for synchronization | |
195 | connect(graphWidget, &VisualizationGraphWidget::synchronize, synchronizeZoneWidget); |
|
195 | connect(graphWidget, &VisualizationGraphWidget::synchronize, synchronizeZoneWidget); | |
196 | connect(graphWidget, &VisualizationGraphWidget::variableAdded, this, |
|
196 | connect(graphWidget, &VisualizationGraphWidget::variableAdded, this, | |
197 | &VisualizationZoneWidget::onVariableAdded); |
|
197 | &VisualizationZoneWidget::onVariableAdded); | |
198 | connect(graphWidget, &VisualizationGraphWidget::variableAboutToBeRemoved, this, |
|
198 | connect(graphWidget, &VisualizationGraphWidget::variableAboutToBeRemoved, this, | |
199 | &VisualizationZoneWidget::onVariableAboutToBeRemoved); |
|
199 | &VisualizationZoneWidget::onVariableAboutToBeRemoved); | |
200 |
|
200 | |||
201 | auto range = SqpRange{}; |
|
201 | auto range = SqpRange{}; | |
202 |
|
202 | |||
203 | // Apply visitor to graph children |
|
203 | // Apply visitor to graph children | |
204 | auto layout = ui->visualizationZoneFrame->layout(); |
|
204 | auto layout = ui->visualizationZoneFrame->layout(); | |
205 | if (layout->count() > 0) { |
|
205 | if (layout->count() > 0) { | |
206 | // Case of a new graph in a existant zone |
|
206 | // Case of a new graph in a existant zone | |
207 | if (auto visualizationGraphWidget |
|
207 | if (auto visualizationGraphWidget | |
208 | = dynamic_cast<VisualizationGraphWidget *>(layout->itemAt(0)->widget())) { |
|
208 | = dynamic_cast<VisualizationGraphWidget *>(layout->itemAt(0)->widget())) { | |
209 | range = visualizationGraphWidget->graphRange(); |
|
209 | range = visualizationGraphWidget->graphRange(); | |
210 | } |
|
210 | } | |
211 | } |
|
211 | } | |
212 | else { |
|
212 | else { | |
213 | // Case of a new graph as the first of the zone |
|
213 | // Case of a new graph as the first of the zone | |
214 | range = variable->range(); |
|
214 | range = variable->range(); | |
215 | } |
|
215 | } | |
216 |
|
216 | |||
217 | this->addGraph(graphWidget); |
|
217 | this->addGraph(graphWidget); | |
218 |
|
218 | |||
219 | graphWidget->addVariable(variable, range); |
|
219 | graphWidget->addVariable(variable, range); | |
220 |
|
220 | |||
221 | // get y using variable range |
|
221 | // get y using variable range | |
222 | if (auto dataSeries = variable->dataSeries()) { |
|
222 | if (auto dataSeries = variable->dataSeries()) { | |
223 | dataSeries->lockRead(); |
|
223 | dataSeries->lockRead(); | |
224 | auto valuesBounds |
|
224 | auto valuesBounds | |
225 | = dataSeries->valuesBounds(variable->range().m_TStart, variable->range().m_TEnd); |
|
225 | = dataSeries->valuesBounds(variable->range().m_TStart, variable->range().m_TEnd); | |
226 | auto end = dataSeries->cend(); |
|
226 | auto end = dataSeries->cend(); | |
227 | if (valuesBounds.first != end && valuesBounds.second != end) { |
|
227 | if (valuesBounds.first != end && valuesBounds.second != end) { | |
228 | auto rangeValue = [](const auto &value) { return std::isnan(value) ? 0. : value; }; |
|
228 | auto rangeValue = [](const auto &value) { return std::isnan(value) ? 0. : value; }; | |
229 |
|
229 | |||
230 | auto minValue = rangeValue(valuesBounds.first->minValue()); |
|
230 | auto minValue = rangeValue(valuesBounds.first->minValue()); | |
231 | auto maxValue = rangeValue(valuesBounds.second->maxValue()); |
|
231 | auto maxValue = rangeValue(valuesBounds.second->maxValue()); | |
232 |
|
232 | |||
233 | graphWidget->setYRange(SqpRange{minValue, maxValue}); |
|
233 | graphWidget->setYRange(SqpRange{minValue, maxValue}); | |
234 | } |
|
234 | } | |
235 | dataSeries->unlock(); |
|
235 | dataSeries->unlock(); | |
236 | } |
|
236 | } | |
237 |
|
237 | |||
238 | return graphWidget; |
|
238 | return graphWidget; | |
239 | } |
|
239 | } | |
240 |
|
240 | |||
241 | void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
241 | void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor) | |
242 | { |
|
242 | { | |
243 | if (visitor) { |
|
243 | if (visitor) { | |
244 | visitor->visitEnter(this); |
|
244 | visitor->visitEnter(this); | |
245 |
|
245 | |||
246 | // Apply visitor to graph children: widgets different from graphs are not visited (no |
|
246 | // Apply visitor to graph children: widgets different from graphs are not visited (no | |
247 | // action) |
|
247 | // action) | |
248 | processGraphs( |
|
248 | processGraphs( | |
249 | *ui->visualizationZoneFrame->layout(), |
|
249 | *ui->visualizationZoneFrame->layout(), | |
250 | [visitor](VisualizationGraphWidget &graphWidget) { graphWidget.accept(visitor); }); |
|
250 | [visitor](VisualizationGraphWidget &graphWidget) { graphWidget.accept(visitor); }); | |
251 |
|
251 | |||
252 | visitor->visitLeave(this); |
|
252 | visitor->visitLeave(this); | |
253 | } |
|
253 | } | |
254 | else { |
|
254 | else { | |
255 | qCCritical(LOG_VisualizationZoneWidget()) << tr("Can't visit widget : the visitor is null"); |
|
255 | qCCritical(LOG_VisualizationZoneWidget()) << tr("Can't visit widget : the visitor is null"); | |
256 | } |
|
256 | } | |
257 | } |
|
257 | } | |
258 |
|
258 | |||
259 | bool VisualizationZoneWidget::canDrop(const Variable &variable) const |
|
259 | bool VisualizationZoneWidget::canDrop(const Variable &variable) const | |
260 | { |
|
260 | { | |
261 | // A tab can always accomodate a variable |
|
261 | // A tab can always accomodate a variable | |
262 | Q_UNUSED(variable); |
|
262 | Q_UNUSED(variable); | |
263 | return true; |
|
263 | return true; | |
264 | } |
|
264 | } | |
265 |
|
265 | |||
266 | bool VisualizationZoneWidget::contains(const Variable &variable) const |
|
266 | bool VisualizationZoneWidget::contains(const Variable &variable) const | |
267 | { |
|
267 | { | |
268 | Q_UNUSED(variable); |
|
268 | Q_UNUSED(variable); | |
269 | return false; |
|
269 | return false; | |
270 | } |
|
270 | } | |
271 |
|
271 | |||
272 | QString VisualizationZoneWidget::name() const |
|
272 | QString VisualizationZoneWidget::name() const | |
273 | { |
|
273 | { | |
274 | return ui->zoneNameLabel->text(); |
|
274 | return ui->zoneNameLabel->text(); | |
275 | } |
|
275 | } | |
276 |
|
276 | |||
277 | void VisualizationZoneWidget::closeEvent(QCloseEvent *event) |
|
277 | void VisualizationZoneWidget::closeEvent(QCloseEvent *event) | |
278 | { |
|
278 | { | |
279 | // Closes graphs in the zone |
|
279 | // Closes graphs in the zone | |
280 | processGraphs(*ui->visualizationZoneFrame->layout(), |
|
280 | processGraphs(*ui->visualizationZoneFrame->layout(), | |
281 | [](VisualizationGraphWidget &graphWidget) { graphWidget.close(); }); |
|
281 | [](VisualizationGraphWidget &graphWidget) { graphWidget.close(); }); | |
282 |
|
282 | |||
|
283 | // Delete synchronization group from variable controller | |||
|
284 | QMetaObject::invokeMethod(&sqpApp->variableController(), "onRemoveSynchronizationGroupId", | |||
|
285 | Qt::QueuedConnection, Q_ARG(QUuid, impl->m_SynchronisationGroupId)); | |||
|
286 | ||||
283 | QWidget::closeEvent(event); |
|
287 | QWidget::closeEvent(event); | |
284 | } |
|
288 | } | |
285 |
|
289 | |||
286 | void VisualizationZoneWidget::onVariableAdded(std::shared_ptr<Variable> variable) |
|
290 | void VisualizationZoneWidget::onVariableAdded(std::shared_ptr<Variable> variable) | |
287 | { |
|
291 | { | |
288 | QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronized", |
|
292 | QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronized", | |
289 | Qt::QueuedConnection, Q_ARG(std::shared_ptr<Variable>, variable), |
|
293 | Qt::QueuedConnection, Q_ARG(std::shared_ptr<Variable>, variable), | |
290 | Q_ARG(QUuid, impl->m_SynchronisationGroupId)); |
|
294 | Q_ARG(QUuid, impl->m_SynchronisationGroupId)); | |
291 | } |
|
295 | } | |
292 |
|
296 | |||
293 | void VisualizationZoneWidget::onVariableAboutToBeRemoved(std::shared_ptr<Variable> variable) |
|
297 | void VisualizationZoneWidget::onVariableAboutToBeRemoved(std::shared_ptr<Variable> variable) | |
294 | { |
|
298 | { | |
295 | QMetaObject::invokeMethod(&sqpApp->variableController(), "desynchronize", Qt::QueuedConnection, |
|
299 | QMetaObject::invokeMethod(&sqpApp->variableController(), "desynchronize", Qt::QueuedConnection, | |
296 | Q_ARG(std::shared_ptr<Variable>, variable), |
|
300 | Q_ARG(std::shared_ptr<Variable>, variable), | |
297 | Q_ARG(QUuid, impl->m_SynchronisationGroupId)); |
|
301 | Q_ARG(QUuid, impl->m_SynchronisationGroupId)); | |
298 | } |
|
302 | } |
General Comments 0
You need to be logged in to leave comments.
Login now