##// END OF EJS Templates
Calls the update of the graph's units and range data of a variable have been loaded
Alexandre Leroux -
r1255:91b47d337d40
parent child
Show More
@@ -80,6 +80,8 public:
80
80
81 signals:
81 signals:
82 void updated();
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 private:
86 private:
85 class VariablePrivate;
87 class VariablePrivate;
@@ -187,16 +187,23 void Variable::mergeDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
187 return;
187 return;
188 }
188 }
189
189
190 auto dataInit = false;
191
190 // Add or merge the data
192 // Add or merge the data
191 impl->lockWrite();
193 impl->lockWrite();
192 if (!impl->m_DataSeries) {
194 if (!impl->m_DataSeries) {
193 impl->m_DataSeries = dataSeries->clone();
195 impl->m_DataSeries = dataSeries->clone();
196 dataInit = true;
194 }
197 }
195 else {
198 else {
196 impl->m_DataSeries->merge(dataSeries.get());
199 impl->m_DataSeries->merge(dataSeries.get());
197 }
200 }
198 impl->purgeDataSeries();
201 impl->purgeDataSeries();
199 impl->unlock();
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 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable, SqpRange range)
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
297 /// Lambda used to set graph's units and range according to the variable passed in parameter
298 auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
298 auto loadRange = [this](std::shared_ptr<Variable> variable, const SqpRange &range) {
299 impl->m_RenderingDelegate->setAxesUnits(*variable);
300
301 enableAcquisition(false);
302 setGraphRange(range);
303 enableAcquisition(true);
299
304
300 if (auto dataSeries = variable->dataSeries()) {
305 emit requestDataLoading({variable}, range, false);
301 // Set axes properties according to the units of the data series
306 };
302 impl->m_RenderingDelegate->setAxesProperties(dataSeries);
307
308 connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
303
309
304 // Sets rendering properties for the new plottables
310 // Calls update of graph's range and units when the data of the variable have been initialized.
305 // Warning: this method must be called after setAxesProperties(), as it can access to some
311 // Note: we use QueuedConnection here as the update event must be called in the UI thread
306 // axes properties that have to be initialized
312 connect(variable.get(), &Variable::dataInitialized, this,
307 impl->m_RenderingDelegate->setPlottablesProperties(dataSeries, createdPlottables);
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);
308 }
319 }
320 },
321 Qt::QueuedConnection);
309
322
310 impl->m_VariableToPlotMultiMap.insert({variable, std::move(createdPlottables)});
323 // Uses delegate to create the qcpplot components according to the variable
324 auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
311
325
312 connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
326 // Sets graph properties
327 impl->m_RenderingDelegate->setGraphProperties(*variable, createdPlottables);
313
328
314 this->enableAcquisition(false);
329 impl->m_VariableToPlotMultiMap.insert({variable, std::move(createdPlottables)});
315 this->setGraphRange(range);
316 this->enableAcquisition(true);
317
330
318 emit requestDataLoading(QVector<std::shared_ptr<Variable> >() << variable, range, false);
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 emit variableAdded(variable);
336 emit variableAdded(variable);
321 }
337 }
General Comments 0
You need to be logged in to leave comments. Login now