diff --git a/core/include/Variable/VariableCacheStrategy.h b/core/include/Variable/VariableCacheStrategy.h new file mode 100644 index 0000000..50f417e --- /dev/null +++ b/core/include/Variable/VariableCacheStrategy.h @@ -0,0 +1,40 @@ +#ifndef SCIQLOP_VARIABLECACHESTRATEGY_H +#define SCIQLOP_VARIABLECACHESTRATEGY_H + +#include "CoreGlobal.h" + +#include +#include + +#include + +#include + +#include +#include + + +Q_DECLARE_LOGGING_CATEGORY(LOG_VariableCacheStrategy) + +class Variable; + +/** + * Possible types of zoom operation + */ +enum class CacheStrategy { FixedTolerance, TwoThreashold }; + +/// This class aims to hande the cache strategy. +class SCIQLOP_CORE_EXPORT VariableCacheStrategy : public QObject { + Q_OBJECT +public: + explicit VariableCacheStrategy(QObject *parent = 0); + + std::pair computeCacheRange(const SqpRange &vRange, + const SqpRange &rangeRequested); + +private: + class VariableCacheStrategyPrivate; + spimpl::unique_impl_ptr impl; +}; + +#endif // SCIQLOP_VARIABLECACHESTRATEGY_H diff --git a/core/src/Variable/VariableCacheStrategy.cpp b/core/src/Variable/VariableCacheStrategy.cpp new file mode 100644 index 0000000..8ab1a85 --- /dev/null +++ b/core/src/Variable/VariableCacheStrategy.cpp @@ -0,0 +1,52 @@ +#include "Variable/VariableCacheStrategy.h" + +#include "Settings/SqpSettingsDefs.h" + +#include "Variable/Variable.h" +#include "Variable/VariableController.h" + +Q_LOGGING_CATEGORY(LOG_VariableCacheStrategy, "VariableCacheStrategy") + +struct VariableCacheStrategy::VariableCacheStrategyPrivate { + VariableCacheStrategyPrivate() : m_CacheStrategy{CacheStrategy::FixedTolerance} {} + + CacheStrategy m_CacheStrategy; +}; + + +VariableCacheStrategy::VariableCacheStrategy(QObject *parent) + : QObject{parent}, impl{spimpl::make_unique_impl()} +{ +} + +std::pair +VariableCacheStrategy::computeCacheRange(const SqpRange &vRange, const SqpRange &rangeRequested) +{ + + auto varRanges = std::pair{}; + + auto toleranceFactor = SqpSettings::toleranceValue(GENERAL_TOLERANCE_AT_UPDATE_KEY, + GENERAL_TOLERANCE_AT_UPDATE_DEFAULT_VALUE); + auto tolerance = toleranceFactor * (rangeRequested.m_TEnd - rangeRequested.m_TStart); + + switch (impl->m_CacheStrategy) { + case CacheStrategy::FixedTolerance: { + varRanges.first = rangeRequested; + varRanges.second + = SqpRange{rangeRequested.m_TStart - tolerance, rangeRequested.m_TEnd + tolerance}; + break; + } + + case CacheStrategy::TwoThreashold: { + // TODO Implement + break; + } + default: + qCCritical(LOG_VariableCacheStrategy()) + << tr("Impossible to use compute the cache range with an unknow cache strategy"); + // No action + break; + } + + return varRanges; +}