##// END OF EJS Templates
Add thread protection for DataSeries...
perrinel -
r594:ad1efe843595
parent child
Show More
@@ -158,10 +158,13 QVariant VariableModel::data(const QModelIndex &index, int role) const
158 /// that contains the time value to display
158 /// that contains the time value to display
159 auto dateTimeVariant = [variable](const auto &getValueFun) {
159 auto dateTimeVariant = [variable](const auto &getValueFun) {
160 if (auto dataSeries = variable->dataSeries()) {
160 if (auto dataSeries = variable->dataSeries()) {
161 dataSeries->lockRead();
161 auto it = getValueFun(*dataSeries);
162 auto it = getValueFun(*dataSeries);
162 return (it != dataSeries->cend())
163 auto resVariant = (it != dataSeries->cend())
163 ? DateUtils::dateTime(it->x()).toString(DATETIME_FORMAT)
164 ? DateUtils::dateTime(it->x()).toString(DATETIME_FORMAT)
164 : QVariant{};
165 : QVariant{};
166 dataSeries->unlock();
167 return resVariant;
165 }
168 }
166 else {
169 else {
167 return QVariant{};
170 return QVariant{};
@@ -38,7 +38,7 QSharedPointer<QCPAxisTicker> axisTicker(bool isTimeAxis)
38 }
38 }
39 }
39 }
40
40
41 /// Sets axes properties according to the properties of a data series
41 /// Sets axes properties according to the properties of a data series. Not thread safe
42 template <int Dim>
42 template <int Dim>
43 void setAxesProperties(const DataSeries<Dim> &dataSeries, QCustomPlot &plot) noexcept
43 void setAxesProperties(const DataSeries<Dim> &dataSeries, QCustomPlot &plot) noexcept
44 {
44 {
@@ -85,7 +85,9 struct PlottablesCreator<T,
85 PlottablesMap result{};
85 PlottablesMap result{};
86
86
87 // Gets the number of components of the data series
87 // Gets the number of components of the data series
88 dataSeries.lockRead();
88 auto componentCount = dataSeries.valuesData()->componentCount();
89 auto componentCount = dataSeries.valuesData()->componentCount();
90 dataSeries.unlock();
89
91
90 auto colors = ColorUtils::colors(Qt::blue, Qt::red, componentCount);
92 auto colors = ColorUtils::colors(Qt::blue, Qt::red, componentCount);
91
93
@@ -98,7 +100,9 struct PlottablesCreator<T,
98 }
100 }
99
101
100 // Axes properties
102 // Axes properties
103 dataSeries.lockRead();
101 setAxesProperties(dataSeries, plot);
104 setAxesProperties(dataSeries, plot);
105 dataSeries.unlock();
102
106
103 plot.replot();
107 plot.replot();
104
108
@@ -133,7 +137,6 struct PlottablesUpdater<T,
133 static void updatePlottables(T &dataSeries, PlottablesMap &plottables, const SqpRange &range,
137 static void updatePlottables(T &dataSeries, PlottablesMap &plottables, const SqpRange &range,
134 bool rescaleAxes)
138 bool rescaleAxes)
135 {
139 {
136 dataSeries.lockRead();
137
140
138 // For each plottable to update, resets its data
141 // For each plottable to update, resets its data
139 std::map<int, QSharedPointer<SqpDataContainer> > dataContainers{};
142 std::map<int, QSharedPointer<SqpDataContainer> > dataContainers{};
@@ -145,6 +148,7 struct PlottablesUpdater<T,
145 dataContainers.insert({plottable.first, dataContainer});
148 dataContainers.insert({plottable.first, dataContainer});
146 }
149 }
147 }
150 }
151 dataSeries.lockRead();
148
152
149 // - Gets the data of the series included in the current range
153 // - Gets the data of the series included in the current range
150 // - Updates each plottable by adding, for each data item, a point that takes x-axis data
154 // - Updates each plottable by adding, for each data item, a point that takes x-axis data
@@ -192,7 +192,8 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V
192
192
193 // get y using variable range
193 // get y using variable range
194 if (auto dataSeries = variable->dataSeries()) {
194 if (auto dataSeries = variable->dataSeries()) {
195 auto valuesBounds = dataSeries->valuesBounds(range.m_TStart, range.m_TEnd);
195 dataSeries->lockRead();
196 auto valuesBounds = dataSeries->valuesBounds(variable->range().m_TStart, variable->range().m_TEnd);
196 auto end = dataSeries->cend();
197 auto end = dataSeries->cend();
197 if (valuesBounds.first != end && valuesBounds.second != end) {
198 if (valuesBounds.first != end && valuesBounds.second != end) {
198 auto rangeValue = [](const auto &value) { return std::isnan(value) ? 0. : value; };
199 auto rangeValue = [](const auto &value) { return std::isnan(value) ? 0. : value; };
@@ -202,6 +203,7 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V
202
203
203 graphWidget->setYRange(SqpRange{minValue, maxValue});
204 graphWidget->setYRange(SqpRange{minValue, maxValue});
204 }
205 }
206 dataSeries->unlock();
205 }
207 }
206
208
207 return graphWidget;
209 return graphWidget;
@@ -18,7 +18,7 std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(QUuid acqIdentifier,
18 auto dataIndex = 0;
18 auto dataIndex = 0;
19
19
20 // Gets the timerange from the parameters
20 // Gets the timerange from the parameters
21 double freq = 100.0;
21 double freq = 1.0;
22 double start = std::ceil(dataRangeRequested.m_TStart * freq); // 100 htz
22 double start = std::ceil(dataRangeRequested.m_TStart * freq); // 100 htz
23 double end = std::floor(dataRangeRequested.m_TEnd * freq); // 100 htz
23 double end = std::floor(dataRangeRequested.m_TEnd * freq); // 100 htz
24
24
General Comments 3
Under Review
author

Auto status change to "Under Review"

Approved
author

Status change > Approved

You need to be logged in to leave comments. Login now