From ad1efe843595e8ad0b2fcb7a90913275183ec6ce 2017-08-24 12:50:36 From: mperrinel Date: 2017-08-24 12:50:36 Subject: [PATCH] Add thread protection for DataSeries Set Y range to varRange instead of graghRange where no data has been computed yet Set cosinus freq to 1htz --- diff --git a/core/src/Variable/VariableModel.cpp b/core/src/Variable/VariableModel.cpp index 0093876..22c4374 100644 --- a/core/src/Variable/VariableModel.cpp +++ b/core/src/Variable/VariableModel.cpp @@ -158,10 +158,13 @@ QVariant VariableModel::data(const QModelIndex &index, int role) const /// that contains the time value to display auto dateTimeVariant = [variable](const auto &getValueFun) { if (auto dataSeries = variable->dataSeries()) { + dataSeries->lockRead(); auto it = getValueFun(*dataSeries); - return (it != dataSeries->cend()) + auto resVariant = (it != dataSeries->cend()) ? DateUtils::dateTime(it->x()).toString(DATETIME_FORMAT) : QVariant{}; + dataSeries->unlock(); + return resVariant; } else { return QVariant{}; diff --git a/gui/src/Visualization/VisualizationGraphHelper.cpp b/gui/src/Visualization/VisualizationGraphHelper.cpp index 64edc65..bdd5a70 100644 --- a/gui/src/Visualization/VisualizationGraphHelper.cpp +++ b/gui/src/Visualization/VisualizationGraphHelper.cpp @@ -38,7 +38,7 @@ QSharedPointer axisTicker(bool isTimeAxis) } } -/// Sets axes properties according to the properties of a data series +/// Sets axes properties according to the properties of a data series. Not thread safe template void setAxesProperties(const DataSeries &dataSeries, QCustomPlot &plot) noexcept { @@ -85,7 +85,9 @@ struct PlottablesCreatorcomponentCount(); + dataSeries.unlock(); auto colors = ColorUtils::colors(Qt::blue, Qt::red, componentCount); @@ -98,7 +100,9 @@ struct PlottablesCreator > dataContainers{}; @@ -145,6 +148,7 @@ struct PlottablesUpdaterdataSeries()) { - auto valuesBounds = dataSeries->valuesBounds(range.m_TStart, range.m_TEnd); + dataSeries->lockRead(); + auto valuesBounds = dataSeries->valuesBounds(variable->range().m_TStart, variable->range().m_TEnd); auto end = dataSeries->cend(); if (valuesBounds.first != end && valuesBounds.second != end) { auto rangeValue = [](const auto &value) { return std::isnan(value) ? 0. : value; }; @@ -202,6 +203,7 @@ VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptrsetYRange(SqpRange{minValue, maxValue}); } + dataSeries->unlock(); } return graphWidget; diff --git a/plugins/mockplugin/src/CosinusProvider.cpp b/plugins/mockplugin/src/CosinusProvider.cpp index cbf2073..4781d41 100644 --- a/plugins/mockplugin/src/CosinusProvider.cpp +++ b/plugins/mockplugin/src/CosinusProvider.cpp @@ -18,7 +18,7 @@ std::shared_ptr CosinusProvider::retrieveData(QUuid acqIdentifier, auto dataIndex = 0; // Gets the timerange from the parameters - double freq = 100.0; + double freq = 1.0; double start = std::ceil(dataRangeRequested.m_TStart * freq); // 100 htz double end = std::floor(dataRangeRequested.m_TEnd * freq); // 100 htz