From fc4b2122dbde635d901ea238130bda681f3f3632 2017-07-03 13:07:56 From: mperrinel Date: 2017-07-03 13:07:56 Subject: [PATCH] The cache is now updated only if date requested has been successfully acquired --- diff --git a/core/include/Data/SqpDateTime.h b/core/include/Data/SqpDateTime.h index 0a936e2..3ea0484 100644 --- a/core/include/Data/SqpDateTime.h +++ b/core/include/Data/SqpDateTime.h @@ -17,12 +17,12 @@ struct SqpDateTime { /// End time double m_TEnd; - bool contains(const SqpDateTime &dateTime) + bool contains(const SqpDateTime &dateTime) const noexcept { return (m_TStart <= dateTime.m_TStart && m_TEnd >= dateTime.m_TEnd); } - bool intersect(const SqpDateTime &dateTime) + bool intersect(const SqpDateTime &dateTime) const noexcept { return (m_TEnd >= dateTime.m_TStart && m_TStart <= dateTime.m_TEnd); } diff --git a/core/include/Variable/Variable.h b/core/include/Variable/Variable.h index 1bd730c..0232cb1 100644 --- a/core/include/Variable/Variable.h +++ b/core/include/Variable/Variable.h @@ -34,8 +34,9 @@ public: /// @return the data of the variable, nullptr if there is no data IDataSeries *dataSeries() const noexcept; - bool contains(const SqpDateTime &dateTime); - bool intersect(const SqpDateTime &dateTime); + bool contains(const SqpDateTime &dateTime) const noexcept; + bool intersect(const SqpDateTime &dateTime) const noexcept; + bool isInside(const SqpDateTime &dateTime) const noexcept; public slots: void setDataSeries(std::shared_ptr dataSeries) noexcept; diff --git a/core/src/Variable/Variable.cpp b/core/src/Variable/Variable.cpp index 7f98687..17795a3 100644 --- a/core/src/Variable/Variable.cpp +++ b/core/src/Variable/Variable.cpp @@ -78,12 +78,17 @@ IDataSeries *Variable::dataSeries() const noexcept return impl->m_DataSeries.get(); } -bool Variable::contains(const SqpDateTime &dateTime) +bool Variable::contains(const SqpDateTime &dateTime) const noexcept { return impl->m_DateTime.contains(dateTime); } -bool Variable::intersect(const SqpDateTime &dateTime) +bool Variable::intersect(const SqpDateTime &dateTime) const noexcept { return impl->m_DateTime.intersect(dateTime); } + +bool Variable::isInside(const SqpDateTime &dateTime) const noexcept +{ + return dateTime.contains(SqpDateTime{impl->m_DateTime.m_TStart, impl->m_DateTime.m_TEnd}); +} diff --git a/core/src/Variable/VariableController.cpp b/core/src/Variable/VariableController.cpp index 41021cb..88a5567 100644 --- a/core/src/Variable/VariableController.cpp +++ b/core/src/Variable/VariableController.cpp @@ -104,8 +104,16 @@ void VariableController::createVariable(const QString &name, // store the provider impl->m_VariableToProviderMap[newVariable] = provider; - connect(provider.get(), &IDataProvider::dataProvided, newVariable.get(), - &Variable::setDataSeries); + + auto addDateTimeAcquired + = [this, newVariable](auto dataSeriesAcquired, auto dateTimeToPutInCache) { + + impl->m_VariableCacheController->addDateTime(newVariable, dateTimeToPutInCache); + newVariable->setDataSeries(dataSeriesAcquired); + + }; + + connect(provider.get(), &IDataProvider::dataProvided, addDateTimeAcquired); // store in cache @@ -144,8 +152,6 @@ void VariableController::onRequestDataLoading(std::shared_ptr variable // Ask the provider for each data on the dateTimeListNotInCache impl->m_VariableToProviderMap.at(variable)->requestDataLoading( std::move(dateTimeListNotInCache)); - // store in cache - impl->m_VariableCacheController->addDateTime(variable, dateTime); } else { emit variable->updated(); diff --git a/gui/src/Visualization/VisualizationGraphHelper.cpp b/gui/src/Visualization/VisualizationGraphHelper.cpp index 0d094f7..b80cb8f 100644 --- a/gui/src/Visualization/VisualizationGraphHelper.cpp +++ b/gui/src/Visualization/VisualizationGraphHelper.cpp @@ -42,7 +42,6 @@ void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSerie const auto &valuesData = scalarSeries.valuesData()->data(); const auto count = xData.count(); qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points in cache" << xData.count(); - auto xValue = QVector(count); auto vValue = QVector(count); @@ -65,7 +64,6 @@ void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSerie qcpGraph->setData(xValue, vValue); // Display all data - // component->parentPlot()->xAxis->setRange(dateTime.m_TStart, dateTime.m_TEnd); component->rescaleAxes(); component->parentPlot()->replot(); } diff --git a/gui/src/Visualization/VisualizationGraphWidget.cpp b/gui/src/Visualization/VisualizationGraphWidget.cpp index c8f4ce9..2c37585 100644 --- a/gui/src/Visualization/VisualizationGraphWidget.cpp +++ b/gui/src/Visualization/VisualizationGraphWidget.cpp @@ -177,9 +177,10 @@ void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1) if (!variable->contains(dateTime)) { auto variableDateTimeWithTolerance = dateTime; - if (variable->intersect(dateTime)) { + if (!variable->isInside(dateTime)) { auto variableDateTime = variable->dateTime(); if (variableDateTime.m_TStart < dateTime.m_TStart) { + qCDebug(LOG_VisualizationGraphWidget()) << tr("TDetection pan to right:"); auto diffEndToKeepDelta = dateTime.m_TEnd - variableDateTime.m_TEnd; dateTime.m_TStart = variableDateTime.m_TStart + diffEndToKeepDelta; @@ -188,7 +189,8 @@ void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1) auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart); variableDateTimeWithTolerance.m_TEnd += tolerance; } - if (variableDateTime.m_TEnd > dateTime.m_TEnd) { + else if (variableDateTime.m_TEnd > dateTime.m_TEnd) { + qCDebug(LOG_VisualizationGraphWidget()) << tr("Detection pan to left: "); auto diffStartToKeepDelta = variableDateTime.m_TStart - dateTime.m_TStart; dateTime.m_TEnd = variableDateTime.m_TEnd - diffStartToKeepDelta; // Tolerance have to be added to the left @@ -196,8 +198,13 @@ void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1) auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart); variableDateTimeWithTolerance.m_TStart -= tolerance; } + else { + qCWarning(LOG_VisualizationGraphWidget()) + << tr("Detection anormal zoom detection: "); + } } else { + qCDebug(LOG_VisualizationGraphWidget()) << tr("Detection zoom out: "); // add 10% tolerance for each side auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart); variableDateTimeWithTolerance.m_TStart -= tolerance; @@ -208,6 +215,9 @@ void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1) // CHangement detected, we need to ask controller to request data loading emit requestDataLoading(variable, variableDateTimeWithTolerance); } + else { + qCDebug(LOG_VisualizationGraphWidget()) << tr("Detection zoom in: "); + } } }