##// END OF EJS Templates
Fix bug when creating two variables crash the app. ...
perrinel -
r756:a7f60f6512e6
parent child
Show More
@@ -25,8 +25,7 class SCIQLOP_CORE_EXPORT Variable : public QObject {
25 Q_OBJECT
25 Q_OBJECT
26
26
27 public:
27 public:
28 explicit Variable(const QString &name, const SqpRange &dateTime,
28 explicit Variable(const QString &name, const QVariantHash &metadata = {});
29 const QVariantHash &metadata = {});
30
29
31 /// Copy ctor
30 /// Copy ctor
32 explicit Variable(const Variable &other);
31 explicit Variable(const Variable &other);
@@ -45,11 +45,10 public:
45 /**
45 /**
46 * Creates a new variable in the model
46 * Creates a new variable in the model
47 * @param name the name of the new variable
47 * @param name the name of the new variable
48 * @param dateTime the dateTime of the new variable
49 * @param metadata the metadata associated to the new variable
48 * @param metadata the metadata associated to the new variable
50 * @return the pointer to the new variable
49 * @return the pointer to the new variable
51 */
50 */
52 std::shared_ptr<Variable> createVariable(const QString &name, const SqpRange &dateTime,
51 std::shared_ptr<Variable> createVariable(const QString &name,
53 const QVariantHash &metadata) noexcept;
52 const QVariantHash &metadata) noexcept;
54
53
55 /**
54 /**
@@ -10,10 +10,10
10 Q_LOGGING_CATEGORY(LOG_Variable, "Variable")
10 Q_LOGGING_CATEGORY(LOG_Variable, "Variable")
11
11
12 struct Variable::VariablePrivate {
12 struct Variable::VariablePrivate {
13 explicit VariablePrivate(const QString &name, const SqpRange &dateTime,
13 explicit VariablePrivate(const QString &name, const QVariantHash &metadata)
14 const QVariantHash &metadata)
15 : m_Name{name},
14 : m_Name{name},
16 m_Range{dateTime},
15 m_Range{INVALID_RANGE},
16 m_CacheRange{INVALID_RANGE},
17 m_Metadata{metadata},
17 m_Metadata{metadata},
18 m_DataSeries{nullptr},
18 m_DataSeries{nullptr},
19 m_RealRange{INVALID_RANGE},
19 m_RealRange{INVALID_RANGE},
@@ -24,6 +24,7 struct Variable::VariablePrivate {
24 VariablePrivate(const VariablePrivate &other)
24 VariablePrivate(const VariablePrivate &other)
25 : m_Name{other.m_Name},
25 : m_Name{other.m_Name},
26 m_Range{other.m_Range},
26 m_Range{other.m_Range},
27 m_CacheRange{other.m_CacheRange},
27 m_Metadata{other.m_Metadata},
28 m_Metadata{other.m_Metadata},
28 m_DataSeries{other.m_DataSeries != nullptr ? other.m_DataSeries->clone() : nullptr},
29 m_DataSeries{other.m_DataSeries != nullptr ? other.m_DataSeries->clone() : nullptr},
29 m_RealRange{other.m_RealRange},
30 m_RealRange{other.m_RealRange},
@@ -55,9 +56,10 struct Variable::VariablePrivate {
55 auto minXAxisIt = m_DataSeries->minXAxisData(m_Range.m_TStart);
56 auto minXAxisIt = m_DataSeries->minXAxisData(m_Range.m_TStart);
56 auto maxXAxisIt = m_DataSeries->maxXAxisData(m_Range.m_TEnd);
57 auto maxXAxisIt = m_DataSeries->maxXAxisData(m_Range.m_TEnd);
57
58
58 m_RealRange = (minXAxisIt != end && maxXAxisIt != end)
59 m_RealRange
59 ? SqpRange{minXAxisIt->x(), maxXAxisIt->x()}
60 = (minXAxisIt != end && maxXAxisIt != end && minXAxisIt->x() <= maxXAxisIt->x())
60 : INVALID_RANGE;
61 ? SqpRange{minXAxisIt->x(), maxXAxisIt->x()}
62 : INVALID_RANGE;
61 m_DataSeries->unlock();
63 m_DataSeries->unlock();
62 }
64 }
63 else {
65 else {
@@ -77,8 +79,8 struct Variable::VariablePrivate {
77 QReadWriteLock m_Lock;
79 QReadWriteLock m_Lock;
78 };
80 };
79
81
80 Variable::Variable(const QString &name, const SqpRange &dateTime, const QVariantHash &metadata)
82 Variable::Variable(const QString &name, const QVariantHash &metadata)
81 : impl{spimpl::make_unique_impl<VariablePrivate>(name, dateTime, metadata)}
83 : impl{spimpl::make_unique_impl<VariablePrivate>(name, metadata)}
82 {
84 {
83 }
85 }
84
86
@@ -242,31 +244,35 bool Variable::cacheIsInside(const SqpRange &range) const noexcept
242 QVector<SqpRange> Variable::provideNotInCacheRangeList(const SqpRange &range) const noexcept
244 QVector<SqpRange> Variable::provideNotInCacheRangeList(const SqpRange &range) const noexcept
243 {
245 {
244 // This code assume that cach in contigue. Can return 0, 1 or 2 SqpRange
246 // This code assume that cach in contigue. Can return 0, 1 or 2 SqpRange
245
246 auto notInCache = QVector<SqpRange>{};
247 auto notInCache = QVector<SqpRange>{};
247
248 if (impl->m_CacheRange != INVALID_RANGE) {
248 if (!this->cacheContains(range)) {
249
249 if (range.m_TEnd <= impl->m_CacheRange.m_TStart
250 if (!this->cacheContains(range)) {
250 || range.m_TStart >= impl->m_CacheRange.m_TEnd) {
251 if (range.m_TEnd <= impl->m_CacheRange.m_TStart
251 notInCache << range;
252 || range.m_TStart >= impl->m_CacheRange.m_TEnd) {
252 }
253 notInCache << range;
253 else if (range.m_TStart < impl->m_CacheRange.m_TStart
254 }
254 && range.m_TEnd <= impl->m_CacheRange.m_TEnd) {
255 else if (range.m_TStart < impl->m_CacheRange.m_TStart
255 notInCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TStart};
256 && range.m_TEnd <= impl->m_CacheRange.m_TEnd) {
256 }
257 notInCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TStart};
257 else if (range.m_TStart < impl->m_CacheRange.m_TStart
258 }
258 && range.m_TEnd > impl->m_CacheRange.m_TEnd) {
259 else if (range.m_TStart < impl->m_CacheRange.m_TStart
259 notInCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TStart}
260 && range.m_TEnd > impl->m_CacheRange.m_TEnd) {
260 << SqpRange{impl->m_CacheRange.m_TEnd, range.m_TEnd};
261 notInCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TStart}
261 }
262 << SqpRange{impl->m_CacheRange.m_TEnd, range.m_TEnd};
262 else if (range.m_TStart < impl->m_CacheRange.m_TEnd) {
263 }
263 notInCache << SqpRange{impl->m_CacheRange.m_TEnd, range.m_TEnd};
264 else if (range.m_TStart < impl->m_CacheRange.m_TEnd) {
264 }
265 notInCache << SqpRange{impl->m_CacheRange.m_TEnd, range.m_TEnd};
265 else {
266 }
266 qCCritical(LOG_Variable()) << tr("Detection of unknown case.")
267 else {
267 << QThread::currentThread();
268 qCCritical(LOG_Variable()) << tr("Detection of unknown case.")
269 << QThread::currentThread();
270 }
268 }
271 }
269 }
272 }
273 else {
274 notInCache << range;
275 }
270
276
271 return notInCache;
277 return notInCache;
272 }
278 }
@@ -277,29 +283,31 QVector<SqpRange> Variable::provideInCacheRangeList(const SqpRange &range) const
277
283
278 auto inCache = QVector<SqpRange>{};
284 auto inCache = QVector<SqpRange>{};
279
285
280
286 if (impl->m_CacheRange != INVALID_RANGE) {
281 if (this->intersect(range)) {
287
282 if (range.m_TStart <= impl->m_CacheRange.m_TStart
288 if (this->intersect(range)) {
283 && range.m_TEnd >= impl->m_CacheRange.m_TStart
289 if (range.m_TStart <= impl->m_CacheRange.m_TStart
284 && range.m_TEnd < impl->m_CacheRange.m_TEnd) {
290 && range.m_TEnd >= impl->m_CacheRange.m_TStart
285 inCache << SqpRange{impl->m_CacheRange.m_TStart, range.m_TEnd};
291 && range.m_TEnd < impl->m_CacheRange.m_TEnd) {
286 }
292 inCache << SqpRange{impl->m_CacheRange.m_TStart, range.m_TEnd};
287
293 }
288 else if (range.m_TStart >= impl->m_CacheRange.m_TStart
294
289 && range.m_TEnd <= impl->m_CacheRange.m_TEnd) {
295 else if (range.m_TStart >= impl->m_CacheRange.m_TStart
290 inCache << range;
296 && range.m_TEnd <= impl->m_CacheRange.m_TEnd) {
291 }
297 inCache << range;
292 else if (range.m_TStart > impl->m_CacheRange.m_TStart
298 }
293 && range.m_TEnd > impl->m_CacheRange.m_TEnd) {
299 else if (range.m_TStart > impl->m_CacheRange.m_TStart
294 inCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TEnd};
300 && range.m_TEnd > impl->m_CacheRange.m_TEnd) {
295 }
301 inCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TEnd};
296 else if (range.m_TStart <= impl->m_CacheRange.m_TStart
302 }
297 && range.m_TEnd >= impl->m_CacheRange.m_TEnd) {
303 else if (range.m_TStart <= impl->m_CacheRange.m_TStart
298 inCache << impl->m_CacheRange;
304 && range.m_TEnd >= impl->m_CacheRange.m_TEnd) {
299 }
305 inCache << impl->m_CacheRange;
300 else {
306 }
301 qCCritical(LOG_Variable()) << tr("Detection of unknown case.")
307 else {
302 << QThread::currentThread();
308 qCCritical(LOG_Variable()) << tr("Detection of unknown case.")
309 << QThread::currentThread();
310 }
303 }
311 }
304 }
312 }
305
313
@@ -265,7 +265,7 VariableController::createVariable(const QString &name, const QVariantHash &meta
265
265
266 auto range = impl->m_TimeController->dateTime();
266 auto range = impl->m_TimeController->dateTime();
267
267
268 if (auto newVariable = impl->m_VariableModel->createVariable(name, range, metadata)) {
268 if (auto newVariable = impl->m_VariableModel->createVariable(name, metadata)) {
269 auto identifier = QUuid::createUuid();
269 auto identifier = QUuid::createUuid();
270
270
271 // store the provider
271 // store the provider
@@ -573,7 +573,7 void VariableController::VariableControllerPrivate::processRequest(std::shared_p
573 varProvider);
573 varProvider);
574
574
575 if (!varRequestIdCanceled.isNull()) {
575 if (!varRequestIdCanceled.isNull()) {
576 qCDebug(LOG_VariableAcquisitionWorker()) << tr("varRequestIdCanceled: ")
576 qCDebug(LOG_VariableAcquisitionWorker()) << tr("vsarRequestIdCanceled: ")
577 << varRequestIdCanceled;
577 << varRequestIdCanceled;
578 cancelVariableRequest(varRequestIdCanceled);
578 cancelVariableRequest(varRequestIdCanceled);
579 }
579 }
@@ -588,7 +588,6 void VariableController::VariableControllerPrivate::processRequest(std::shared_p
588 }
588 }
589 }
589 }
590 else {
590 else {
591
592 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
591 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
593 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
592 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
594 // store VarRequest
593 // store VarRequest
@@ -97,10 +97,9 bool VariableModel::containsVariable(std::shared_ptr<Variable> variable) const n
97 }
97 }
98
98
99 std::shared_ptr<Variable> VariableModel::createVariable(const QString &name,
99 std::shared_ptr<Variable> VariableModel::createVariable(const QString &name,
100 const SqpRange &dateTime,
101 const QVariantHash &metadata) noexcept
100 const QVariantHash &metadata) noexcept
102 {
101 {
103 auto variable = std::make_shared<Variable>(name, dateTime, metadata);
102 auto variable = std::make_shared<Variable>(name, metadata);
104 addVariable(variable);
103 addVariable(variable);
105
104
106 return variable;
105 return variable;
@@ -24,10 +24,12 void TestVariable::testNotInCacheRangeList()
24
24
25 auto varCRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}};
25 auto varCRS = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}};
26 auto varCRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}};
26 auto varCRE = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}};
27
27 auto sqpCR
28 auto sqpCR
28 = SqpRange{DateUtils::secondsSinceEpoch(varCRS), DateUtils::secondsSinceEpoch(varCRE)};
29 = SqpRange{DateUtils::secondsSinceEpoch(varCRS), DateUtils::secondsSinceEpoch(varCRE)};
29
30
30 Variable var{"Var test", sqpR};
31 Variable var{"Var test"};
32 var.setRange(sqpR);
31 var.setCacheRange(sqpCR);
33 var.setCacheRange(sqpCR);
32
34
33 // 1: [ts,te] < varTS
35 // 1: [ts,te] < varTS
@@ -109,7 +111,8 void TestVariable::testInCacheRangeList()
109 auto sqpCR
111 auto sqpCR
110 = SqpRange{DateUtils::secondsSinceEpoch(varCRS), DateUtils::secondsSinceEpoch(varCRE)};
112 = SqpRange{DateUtils::secondsSinceEpoch(varCRS), DateUtils::secondsSinceEpoch(varCRE)};
111
113
112 Variable var{"Var test", sqpR};
114 Variable var{"Var test"};
115 var.setRange(sqpR);
113 var.setCacheRange(sqpCR);
116 var.setCacheRange(sqpCR);
114
117
115 // 1: [ts,te] < varTS
118 // 1: [ts,te] < varTS
@@ -32,7 +32,8 void TestVariableCacheController::testProvideNotInCacheDateTimeList()
32 auto te2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 20, 0, 0}};
32 auto te2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 20, 0, 0}};
33 auto sqp2 = SqpRange{DateUtils::secondsSinceEpoch(ts2), DateUtils::secondsSinceEpoch(te2)};
33 auto sqp2 = SqpRange{DateUtils::secondsSinceEpoch(ts2), DateUtils::secondsSinceEpoch(te2)};
34
34
35 auto var0 = std::make_shared<Variable>("", sqp0);
35 auto var0 = std::make_shared<Variable>("");
36 var0->setRange(sqp0);
36
37
37 variableCacheController.addDateTime(var0, sqp0);
38 variableCacheController.addDateTime(var0, sqp0);
38 variableCacheController.addDateTime(var0, sqp1);
39 variableCacheController.addDateTime(var0, sqp1);
@@ -267,7 +268,8 void TestVariableCacheController::testAddDateTime()
267 auto sqp03 = SqpRange{DateUtils::secondsSinceEpoch(ts03), DateUtils::secondsSinceEpoch(te03)};
268 auto sqp03 = SqpRange{DateUtils::secondsSinceEpoch(ts03), DateUtils::secondsSinceEpoch(te03)};
268
269
269
270
270 auto var0 = std::make_shared<Variable>("", sqp0);
271 auto var0 = std::make_shared<Variable>("");
272 var0->setRange(sqp0);
271
273
272
274
273 // First case: add the first interval to the variable :sqp0
275 // First case: add the first interval to the variable :sqp0
@@ -107,7 +107,6 void AmdaProvider::onReplyDownloadProgress(QUuid acqIdentifier,
107 auto acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier);
107 auto acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier);
108 if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) {
108 if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) {
109
109
110 qCDebug(LOG_AmdaProvider()) << tr("1 onReplyDownloadProgress found") << progress;
111 auto requestPtr = networkRequest;
110 auto requestPtr = networkRequest;
112 auto findRequest = [requestPtr](const auto &entry) { return requestPtr == entry.first; };
111 auto findRequest = [requestPtr](const auto &entry) { return requestPtr == entry.first; };
113
112
@@ -159,7 +158,6 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa
159 qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve data: unknown product id");
158 qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve data: unknown product id");
160 return;
159 return;
161 }
160 }
162 qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData") << dateTime;
163
161
164 // Retrieves the data type that determines whether the expected format for the result file is
162 // Retrieves the data type that determines whether the expected format for the result file is
165 // scalar, vector...
163 // scalar, vector...
@@ -210,7 +208,7 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa
210 if (reply->error() != QNetworkReply::OperationCanceledError) {
208 if (reply->error() != QNetworkReply::OperationCanceledError) {
211 auto downloadFileUrl = QUrl{QString{reply->readAll()}};
209 auto downloadFileUrl = QUrl{QString{reply->readAll()}};
212
210
213 qCInfo(LOG_AmdaProvider())
211 qCDebug(LOG_AmdaProvider())
214 << tr("TORM AmdaProvider::retrieveData downloadFileUrl:") << downloadFileUrl;
212 << tr("TORM AmdaProvider::retrieveData downloadFileUrl:") << downloadFileUrl;
215 // Executes request for downloading file //
213 // Executes request for downloading file //
216
214
@@ -100,8 +100,6 void TestAmdaAcquisition::testAcquisition()
100 auto var = vc.createVariable("bx_gse", metaData, provider);
100 auto var = vc.createVariable("bx_gse", metaData, provider);
101
101
102 // 1 : Variable creation
102 // 1 : Variable creation
103 QCOMPARE(var->range().m_TStart, sqpR.m_TStart);
104 QCOMPARE(var->range().m_TEnd, sqpR.m_TEnd);
105
103
106 qDebug() << " 1: TIMECONTROLLER" << timeController->dateTime();
104 qDebug() << " 1: TIMECONTROLLER" << timeController->dateTime();
107 qDebug() << " 1: RANGE " << var->range();
105 qDebug() << " 1: RANGE " << var->range();
General Comments 0
You need to be logged in to leave comments. Login now