diff --git a/core/include/Variable/Variable.h b/core/include/Variable/Variable.h index bf30f18..88c5682 100644 --- a/core/include/Variable/Variable.h +++ b/core/include/Variable/Variable.h @@ -68,6 +68,12 @@ public: QVector provideInCacheRangeList(const SqpRange &range) const noexcept; void mergeDataSeries(std::shared_ptr dataSeries) noexcept; + static QVector provideNotInCacheRangeList(const SqpRange &oldRange, + const SqpRange &nextRange); + + static QVector provideInCacheRangeList(const SqpRange &oldRange, + const SqpRange &nextRange); + signals: void updated(); diff --git a/core/src/Variable/Variable.cpp b/core/src/Variable/Variable.cpp index 988f06a..8d68fa0 100644 --- a/core/src/Variable/Variable.cpp +++ b/core/src/Variable/Variable.cpp @@ -138,7 +138,6 @@ void Variable::setCacheRange(const SqpRange &cacheRange) noexcept impl->lockWrite(); if (cacheRange != impl->m_CacheRange) { impl->m_CacheRange = cacheRange; - impl->purgeDataSeries(); } impl->unlock(); } @@ -174,6 +173,7 @@ void Variable::mergeDataSeries(std::shared_ptr dataSeries) noexcept impl->unlock(); } + std::shared_ptr Variable::dataSeries() const noexcept { impl->lockRead(); @@ -285,7 +285,7 @@ QVector Variable::provideInCacheRangeList(const SqpRange &range) const if (impl->m_CacheRange != INVALID_RANGE) { - if (this->intersect(range)) { + if (this->cacheIntersect(range)) { if (range.m_TStart <= impl->m_CacheRange.m_TStart && range.m_TEnd >= impl->m_CacheRange.m_TStart && range.m_TEnd < impl->m_CacheRange.m_TEnd) { @@ -313,3 +313,76 @@ QVector Variable::provideInCacheRangeList(const SqpRange &range) const return inCache; } + + +QVector Variable::provideNotInCacheRangeList(const SqpRange &oldRange, + const SqpRange &nextRange) +{ + + // This code assume that cach in contigue. Can return 0, 1 or 2 SqpRange + auto notInCache = QVector{}; + if (oldRange != INVALID_RANGE) { + + if (!oldRange.contains(nextRange)) { + if (nextRange.m_TEnd <= oldRange.m_TStart || nextRange.m_TStart >= oldRange.m_TEnd) { + notInCache << nextRange; + } + else if (nextRange.m_TStart < oldRange.m_TStart + && nextRange.m_TEnd <= oldRange.m_TEnd) { + notInCache << SqpRange{nextRange.m_TStart, oldRange.m_TStart}; + } + else if (nextRange.m_TStart < oldRange.m_TStart && nextRange.m_TEnd > oldRange.m_TEnd) { + notInCache << SqpRange{nextRange.m_TStart, oldRange.m_TStart} + << SqpRange{oldRange.m_TEnd, nextRange.m_TEnd}; + } + else if (nextRange.m_TStart < oldRange.m_TEnd) { + notInCache << SqpRange{oldRange.m_TEnd, nextRange.m_TEnd}; + } + else { + qCCritical(LOG_Variable()) << tr("Detection of unknown case.") + << QThread::currentThread(); + } + } + } + else { + notInCache << nextRange; + } + + return notInCache; +} + +QVector Variable::provideInCacheRangeList(const SqpRange &oldRange, + const SqpRange &nextRange) +{ + // This code assume that cach is contigue. Can return 0 or 1 SqpRange + + auto inCache = QVector{}; + + if (oldRange != INVALID_RANGE) { + + if (oldRange.intersect(nextRange)) { + if (nextRange.m_TStart <= oldRange.m_TStart && nextRange.m_TEnd >= oldRange.m_TStart + && nextRange.m_TEnd < oldRange.m_TEnd) { + inCache << SqpRange{oldRange.m_TStart, nextRange.m_TEnd}; + } + + else if (nextRange.m_TStart >= oldRange.m_TStart + && nextRange.m_TEnd <= oldRange.m_TEnd) { + inCache << nextRange; + } + else if (nextRange.m_TStart > oldRange.m_TStart && nextRange.m_TEnd > oldRange.m_TEnd) { + inCache << SqpRange{nextRange.m_TStart, oldRange.m_TEnd}; + } + else if (nextRange.m_TStart <= oldRange.m_TStart + && nextRange.m_TEnd >= oldRange.m_TEnd) { + inCache << oldRange; + } + else { + qCCritical(LOG_Variable()) << tr("Detection of unknown case.") + << QThread::currentThread(); + } + } + } + + return inCache; +}