@@ -207,7 +207,7 class SCIQLOP_CORE_EXPORT DataSeries : public IDataSeries { | |||
|
207 | 207 | public: |
|
208 | 208 | /// @sa IDataSeries::xAxisData() |
|
209 | 209 | std::shared_ptr<ArrayData<1> > xAxisData() override { return m_XAxisData; } |
|
210 | const std::shared_ptr<ArrayData<1> > xAxisData() const { return m_XAxisData; } | |
|
210 | const std::shared_ptr<ArrayData<1> > xAxisData() const override { return m_XAxisData; } | |
|
211 | 211 | |
|
212 | 212 | /// @sa IDataSeries::xAxisUnit() |
|
213 | 213 | Unit xAxisUnit() const override { return m_XAxisUnit; } |
@@ -415,9 +415,12 public: | |||
|
415 | 415 | // Mutexes // |
|
416 | 416 | // /////// // |
|
417 | 417 | |
|
418 | virtual void lockRead() { m_Lock.lockForRead(); } | |
|
419 | virtual void lockWrite() { m_Lock.lockForWrite(); } | |
|
420 | virtual void unlock() { m_Lock.unlock(); } | |
|
418 | virtual QReadLocker getReadLock() override { return QReadLocker{&m_Lock}; } | |
|
419 | virtual QWriteLocker getWriteLock() override { return QWriteLocker{&m_Lock}; } | |
|
420 | ||
|
421 | virtual void lockRead() override { m_Lock.lockForRead(); } | |
|
422 | virtual void lockWrite() override { m_Lock.lockForWrite(); } | |
|
423 | virtual void unlock() override { m_Lock.unlock(); } | |
|
421 | 424 | |
|
422 | 425 | protected: |
|
423 | 426 | /// Protected ctor (DataSeries is abstract). |
@@ -1,14 +1,17 | |||
|
1 | 1 | #ifndef SCIQLOP_IDATASERIES_H |
|
2 | 2 | #define SCIQLOP_IDATASERIES_H |
|
3 | 3 | |
|
4 | #include <memory> | |
|
5 | ||
|
6 | #include <QReadWriteLock> | |
|
7 | #include <QString> | |
|
8 | ||
|
4 | 9 | #include <Common/MetaTypes.h> |
|
5 | 10 | #include <Data/DataSeriesIterator.h> |
|
6 | 11 | #include <Data/DateTimeRange.h> |
|
7 | 12 | #include <Data/Unit.h> |
|
13 | #include <Common/deprecate.h> | |
|
8 | 14 | |
|
9 | #include <memory> | |
|
10 | ||
|
11 | #include <QString> | |
|
12 | 15 | |
|
13 | 16 | template <int Dim> |
|
14 | 17 | class ArrayData; |
@@ -90,10 +93,13 public: | |||
|
90 | 93 | // /////// // |
|
91 | 94 | // Mutexes // |
|
92 | 95 | // /////// // |
|
93 | ||
|
96 | virtual QReadLocker getReadLock() = 0; | |
|
97 | virtual QWriteLocker getWriteLock() = 0; | |
|
98 | DEPRECATE( | |
|
94 | 99 | virtual void lockRead() = 0; |
|
95 | 100 | virtual void lockWrite() = 0; |
|
96 | 101 | virtual void unlock() = 0; |
|
102 | ) | |
|
97 | 103 | }; |
|
98 | 104 | |
|
99 | 105 | // Required for using shared_ptr in signals/slots |
@@ -26,7 +26,7 public: | |||
|
26 | 26 | explicit VectorSeries(std::vector<double> xAxisData, std::vector<double> valuesData, |
|
27 | 27 | const Unit &xAxisUnit, const Unit &valuesUnit); |
|
28 | 28 | |
|
29 | std::unique_ptr<IDataSeries> clone() const; | |
|
29 | std::unique_ptr<IDataSeries> clone() const override; | |
|
30 | 30 | |
|
31 | 31 | std::shared_ptr<IDataSeries> subDataSeries(const DateTimeRange &range) override; |
|
32 | 32 | }; |
@@ -1,15 +1,16 | |||
|
1 | 1 | #ifndef SCIQLOP_VARIABLE_H |
|
2 | 2 | #define SCIQLOP_VARIABLE_H |
|
3 | 3 | |
|
4 | #include "CoreGlobal.h" | |
|
4 | #include <QLoggingCategory> | |
|
5 | #include <QObject> | |
|
6 | #include <QUuid> | |
|
7 | #include <QReadWriteLock> | |
|
5 | 8 | |
|
9 | #include "CoreGlobal.h" | |
|
6 | 10 | #include <Data/DataSeriesIterator.h> |
|
7 | 11 | #include <Data/DataSeriesType.h> |
|
8 | 12 | #include <Data/DateTimeRange.h> |
|
9 | 13 | |
|
10 | #include <QLoggingCategory> | |
|
11 | #include <QObject> | |
|
12 | #include <QUuid> | |
|
13 | 14 | |
|
14 | 15 | #include <Common/deprecate.h> |
|
15 | 16 | #include <Common/MetaTypes.h> |
@@ -77,7 +78,10 DEPRECATE( | |||
|
77 | 78 | DEPRECATE( |
|
78 | 79 | void mergeDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept; |
|
79 | 80 | ) |
|
80 | void mergeDataSeries(IDataSeries* dataSeries, bool notify=false) noexcept; | |
|
81 | ||
|
82 | void updateData(const std::vector<IDataSeries*>& dataSeries, | |
|
83 | const DateTimeRange& newRange, const DateTimeRange& newCacheRange, | |
|
84 | bool notify=true); | |
|
81 | 85 | |
|
82 | 86 | DEPRECATE( |
|
83 | 87 | static QVector<DateTimeRange> provideNotInCacheRangeList(const DateTimeRange &oldRange, |
@@ -98,6 +102,7 private: | |||
|
98 | 102 | class VariablePrivate; |
|
99 | 103 | spimpl::unique_impl_ptr<VariablePrivate> impl; |
|
100 | 104 | QUuid _uuid; |
|
105 | QReadWriteLock m_lock; | |
|
101 | 106 | }; |
|
102 | 107 | |
|
103 | 108 | // Required for using shared_ptr in signals/slots |
@@ -12,7 +12,6 | |||
|
12 | 12 | |
|
13 | 13 | Q_LOGGING_CATEGORY(LOG_Variable, "Variable") |
|
14 | 14 | |
|
15 | namespace { | |
|
16 | 15 | |
|
17 | 16 | /** |
|
18 | 17 | * Searches in metadata for a value that can be converted to DataSeriesType |
@@ -20,7 +19,7 namespace { | |||
|
20 | 19 | * @return the value converted to a DataSeriesType if it was found, UNKNOWN type otherwise |
|
21 | 20 | * @sa DataSeriesType |
|
22 | 21 | */ |
|
23 | DataSeriesType findDataSeriesType(const QVariantHash &metadata) | |
|
22 | static DataSeriesType findDataSeriesType(const QVariantHash &metadata) | |
|
24 | 23 | { |
|
25 | 24 | auto dataSeriesType = DataSeriesType::UNKNOWN; |
|
26 | 25 | |
@@ -33,7 +32,6 DataSeriesType findDataSeriesType(const QVariantHash &metadata) | |||
|
33 | 32 | return dataSeriesType; |
|
34 | 33 | } |
|
35 | 34 | |
|
36 | } // namespace | |
|
37 | 35 | |
|
38 | 36 | #define VP_PROPERTY(property,getter,setter,type) \ |
|
39 | 37 | type getter() noexcept\ |
@@ -95,23 +93,31 struct Variable::VariablePrivate { | |||
|
95 | 93 | updateRealRange(); |
|
96 | 94 | updateNbPoints(); |
|
97 | 95 | } |
|
98 | ||
|
96 | void mergeDataSeries(const std::vector<IDataSeries*>& dataseries) | |
|
97 | { | |
|
98 | QWriteLocker lock{&m_Lock}; | |
|
99 | for(auto ds:dataseries) | |
|
100 | { | |
|
101 | if(m_DataSeries) | |
|
102 | m_DataSeries->merge(ds); | |
|
103 | else | |
|
104 | m_DataSeries = ds->clone(); | |
|
105 | } | |
|
106 | } | |
|
99 | 107 | void updateNbPoints() { m_NbPoints = m_DataSeries ? m_DataSeries->nbPoints() : 0; } |
|
100 | 108 | |
|
101 | 109 | /// Updates real range according to current variable range and data series |
|
102 | 110 | void updateRealRange() |
|
103 | 111 | { |
|
104 | 112 | if (m_DataSeries) { |
|
105 |
m_DataSeries-> |
|
|
113 | auto lock = m_DataSeries->getReadLock(); | |
|
106 | 114 | auto end = m_DataSeries->cend(); |
|
107 | 115 | auto minXAxisIt = m_DataSeries->minXAxisData(m_Range.m_TStart); |
|
108 | 116 | auto maxXAxisIt = m_DataSeries->maxXAxisData(m_Range.m_TEnd); |
|
109 | ||
|
110 | m_RealRange | |
|
111 | = (minXAxisIt != end && maxXAxisIt != end && minXAxisIt->x() <= maxXAxisIt->x()) | |
|
112 | ? DateTimeRange{minXAxisIt->x(), maxXAxisIt->x()} | |
|
113 | : INVALID_RANGE; | |
|
114 | m_DataSeries->unlock(); | |
|
117 | if(minXAxisIt != end && maxXAxisIt != end && minXAxisIt->x() <= maxXAxisIt->x()) | |
|
118 | m_RealRange = DateTimeRange{minXAxisIt->x(), maxXAxisIt->x()}; | |
|
119 | else | |
|
120 | m_RealRange = std::nullopt; | |
|
115 | 121 | } |
|
116 | 122 | else { |
|
117 | 123 | m_RealRange = std::nullopt; |
@@ -201,34 +207,17 void Variable::mergeDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept | |||
|
201 | 207 | } |
|
202 | 208 | } |
|
203 | 209 | |
|
204 | void Variable::mergeDataSeries(IDataSeries *dataSeries, bool notify) noexcept | |
|
210 | void Variable::updateData(const std::vector<IDataSeries *> &dataSeries, const DateTimeRange &newRange, const DateTimeRange &newCacheRange, bool notify) | |
|
205 | 211 | { |
|
206 | if (dataSeries==nullptr) { | |
|
207 | SCIQLOP_ERROR(Variable,"Given IDataSeries is nullptr"); | |
|
208 | return; | |
|
209 | } | |
|
210 | ||
|
211 | auto dataInit = false; | |
|
212 | // @TODO move impl to Pimpl this is what it stands for... | |
|
213 | // Add or merge the data | |
|
214 | impl->lockWrite(); | |
|
215 | if (!impl->m_DataSeries) { | |
|
216 | //@TODO find a better way | |
|
217 | impl->m_DataSeries = dataSeries->clone(); | |
|
218 | dataInit = true; | |
|
219 | delete dataSeries; | |
|
220 | } | |
|
221 | else { | |
|
222 | impl->m_DataSeries->merge(dataSeries); | |
|
223 | } | |
|
224 | impl->purgeDataSeries(); | |
|
225 | impl->unlock(); | |
|
226 | ||
|
227 | if (dataInit) { | |
|
228 | emit dataInitialized(); | |
|
212 | { | |
|
213 | QWriteLocker lock{&m_lock}; | |
|
214 | impl->mergeDataSeries(dataSeries); | |
|
215 | impl->setRange(newRange); | |
|
216 | impl->setCacheRange(newCacheRange); | |
|
217 | impl->purgeDataSeries(); | |
|
229 | 218 | } |
|
230 | 219 | if(notify) |
|
231 |
emit |
|
|
220 | emit updated(); | |
|
232 | 221 | } |
|
233 | 222 | |
|
234 | 223 |
@@ -40,13 +40,12 class VariableController2::VariableController2Private | |||
|
40 | 40 | newCacheRange = _cacheStrategy->computeRange(var->cacheRange(),r); |
|
41 | 41 | missingRanges = newCacheRange - var->cacheRange(); |
|
42 | 42 | } |
|
43 | std::vector<IDataSeries*> data; | |
|
43 | 44 | for(auto range:missingRanges) |
|
44 | 45 | { |
|
45 |
|
|
|
46 | var->mergeDataSeries(data); | |
|
46 | data.push_back(provider->getData(DataProviderParameters{{range},var->metadata()})); | |
|
47 | 47 | } |
|
48 |
var-> |
|
|
49 | var->setRange(r); | |
|
48 | var->updateData(data,r,newCacheRange,true); | |
|
50 | 49 | } |
|
51 | 50 | public: |
|
52 | 51 | VariableController2Private(QObject* parent=Q_NULLPTR) |
@@ -12,7 +12,7 namespace { | |||
|
12 | 12 | |
|
13 | 13 | /// Provider used for the tests |
|
14 | 14 | class TestProvider : public IDataProvider { |
|
15 | std::shared_ptr<IDataProvider> clone() const { return std::make_shared<TestProvider>(); } | |
|
15 | std::shared_ptr<IDataProvider> clone() const override { return std::make_shared<TestProvider>(); } | |
|
16 | 16 | |
|
17 | 17 | void requestDataLoading(QUuid acqIdentifier, const DataProviderParameters ¶meters) override |
|
18 | 18 | { |
@@ -69,7 +69,7 void validateRanges(VariableController &variableController, | |||
|
69 | 69 | |
|
70 | 70 | /// Provider used for the tests |
|
71 | 71 | class TestProvider : public IDataProvider { |
|
72 | std::shared_ptr<IDataProvider> clone() const { return std::make_shared<TestProvider>(); } | |
|
72 | std::shared_ptr<IDataProvider> clone() const override { return std::make_shared<TestProvider>(); } | |
|
73 | 73 | |
|
74 | 74 | void requestDataLoading(QUuid acqIdentifier, const DataProviderParameters ¶meters) override |
|
75 | 75 | { |
General Comments 0
You need to be logged in to leave comments.
Login now