@@ -80,6 +80,8 public: | |||
|
80 | 80 | |
|
81 | 81 | signals: |
|
82 | 82 | void updated(); |
|
83 | /// Signal emitted when when the data series of the variable is loaded for the first time | |
|
84 | void dataInitialized(); | |
|
83 | 85 | |
|
84 | 86 | private: |
|
85 | 87 | class VariablePrivate; |
@@ -187,16 +187,23 void Variable::mergeDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept | |||
|
187 | 187 | return; |
|
188 | 188 | } |
|
189 | 189 | |
|
190 | auto dataInit = false; | |
|
191 | ||
|
190 | 192 | // Add or merge the data |
|
191 | 193 | impl->lockWrite(); |
|
192 | 194 | if (!impl->m_DataSeries) { |
|
193 | 195 | impl->m_DataSeries = dataSeries->clone(); |
|
196 | dataInit = true; | |
|
194 | 197 | } |
|
195 | 198 | else { |
|
196 | 199 | impl->m_DataSeries->merge(dataSeries.get()); |
|
197 | 200 | } |
|
198 | 201 | impl->purgeDataSeries(); |
|
199 | 202 | impl->unlock(); |
|
203 | ||
|
204 | if (dataInit) { | |
|
205 | emit dataInitialized(); | |
|
206 | } | |
|
200 | 207 | } |
|
201 | 208 | |
|
202 | 209 |
@@ -294,28 +294,44 void VisualizationGraphWidget::enableAcquisition(bool enable) | |||
|
294 | 294 | |
|
295 | 295 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable, SqpRange range) |
|
296 | 296 | { |
|
297 | // Uses delegate to create the qcpplot components according to the variable | |
|
298 | auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget); | |
|
297 | /// Lambda used to set graph's units and range according to the variable passed in parameter | |
|
298 | auto loadRange = [this](std::shared_ptr<Variable> variable, const SqpRange &range) { | |
|
299 | impl->m_RenderingDelegate->setAxesUnits(*variable); | |
|
299 | 300 | |
|
300 | if (auto dataSeries = variable->dataSeries()) { | |
|
301 | // Set axes properties according to the units of the data series | |
|
302 | impl->m_RenderingDelegate->setAxesProperties(dataSeries); | |
|
303 | ||
|
304 | // Sets rendering properties for the new plottables | |
|
305 | // Warning: this method must be called after setAxesProperties(), as it can access to some | |
|
306 | // axes properties that have to be initialized | |
|
307 | impl->m_RenderingDelegate->setPlottablesProperties(dataSeries, createdPlottables); | |
|
308 | } | |
|
301 | enableAcquisition(false); | |
|
302 | setGraphRange(range); | |
|
303 | enableAcquisition(true); | |
|
309 | 304 | |
|
310 | impl->m_VariableToPlotMultiMap.insert({variable, std::move(createdPlottables)}); | |
|
305 | emit requestDataLoading({variable}, range, false); | |
|
306 | }; | |
|
311 | 307 | |
|
312 | 308 | connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated())); |
|
313 | 309 | |
|
314 | this->enableAcquisition(false); | |
|
315 | this->setGraphRange(range); | |
|
316 | this->enableAcquisition(true); | |
|
310 | // Calls update of graph's range and units when the data of the variable have been initialized. | |
|
311 | // Note: we use QueuedConnection here as the update event must be called in the UI thread | |
|
312 | connect(variable.get(), &Variable::dataInitialized, this, | |
|
313 | [ varW = std::weak_ptr<Variable>{variable}, range, loadRange ]() { | |
|
314 | if (auto var = varW.lock()) { | |
|
315 | // If the variable is the first added in the graph, we load its range | |
|
316 | auto firstVariableInGraph = range == INVALID_RANGE; | |
|
317 | auto loadedRange = firstVariableInGraph ? var->range() : range; | |
|
318 | loadRange(var, loadedRange); | |
|
319 | } | |
|
320 | }, | |
|
321 | Qt::QueuedConnection); | |
|
322 | ||
|
323 | // Uses delegate to create the qcpplot components according to the variable | |
|
324 | auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget); | |
|
325 | ||
|
326 | // Sets graph properties | |
|
327 | impl->m_RenderingDelegate->setGraphProperties(*variable, createdPlottables); | |
|
317 | 328 | |
|
318 | emit requestDataLoading(QVector<std::shared_ptr<Variable> >() << variable, range, false); | |
|
329 | impl->m_VariableToPlotMultiMap.insert({variable, std::move(createdPlottables)}); | |
|
330 | ||
|
331 | // If the variable already has its data loaded, load its units and its range in the graph | |
|
332 | if (variable->dataSeries() != nullptr) { | |
|
333 | loadRange(variable, range); | |
|
334 | } | |
|
319 | 335 | |
|
320 | 336 | emit variableAdded(variable); |
|
321 | 337 | } |
General Comments 0
You need to be logged in to leave comments.
Login now