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