From a922e44558425da924e725c22ed82dd463c3f4e6 Mon Sep 17 00:00:00 2001 From: Hugo Saint-Vignes Date: Wed, 21 Oct 2020 15:05:33 +0200 Subject: [PATCH] [apps/statistics] Add temporary parameters for histogram Change-Id: I67c21d59263b7eddd7ee8ee9e61c168e6b013d13 --- .../histogram_parameter_controller.cpp | 40 ++++++++++++++++--- .../histogram_parameter_controller.h | 11 ++++- 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/apps/statistics/histogram_parameter_controller.cpp b/apps/statistics/histogram_parameter_controller.cpp index c9e3a8b45..17e527e8c 100644 --- a/apps/statistics/histogram_parameter_controller.cpp +++ b/apps/statistics/histogram_parameter_controller.cpp @@ -18,6 +18,13 @@ HistogramParameterController::HistogramParameterController(Responder * parentRes } } +void HistogramParameterController::viewWillAppear() { + // Initialize temporary parameters to the extracted value. + setParameterAtIndex(0, extractParameterAtIndex(0)); + setParameterAtIndex(1, extractParameterAtIndex(1)); + FloatParameterController::viewWillAppear(); +} + const char * HistogramParameterController::title() { return I18n::translate(I18n::Message::HistogramSet); } @@ -32,11 +39,27 @@ void HistogramParameterController::willDisplayCellForIndex(HighlightCell * cell, FloatParameterController::willDisplayCellForIndex(cell, index); } -double HistogramParameterController::parameterAtIndex(int index) { +double HistogramParameterController::extractParameterAtIndex(int index) { assert(index >= 0 && index < k_numberOfCells); return index == 0 ? m_store->barWidth() : m_store->firstDrawnBarAbscissa(); } +double HistogramParameterController::parameterAtIndex(int index) { + assert(index >= 0 && index < k_numberOfCells); + return index == 0 ? m_tempBarWidth : m_tempFirstDrawnBarAbscissa; +} + +bool HistogramParameterController::confirmParameterAtIndex(int parameterIndex, double value) { + assert(parameterIndex == 0 || parameterIndex == 1); + if (parameterIndex == 0) { + // Set the bar width + m_store->setBarWidth(value); + } else { + m_store->setFirstDrawnBarAbscissa(value); + } + return true; +} + bool HistogramParameterController::setParameterAtIndex(int parameterIndex, double value) { assert(parameterIndex == 0 || parameterIndex == 1); const bool setBarWidth = parameterIndex == 0; @@ -47,8 +70,8 @@ bool HistogramParameterController::setParameterAtIndex(int parameterIndex, doubl return false; } - const double nextFirstDrawnBarAbscissa = setBarWidth ? m_store->firstDrawnBarAbscissa() : value; - const double nextBarWidth = setBarWidth ? value : m_store->barWidth(); + const double nextFirstDrawnBarAbscissa = setBarWidth ? m_tempFirstDrawnBarAbscissa : value; + const double nextBarWidth = setBarWidth ? value : m_tempBarWidth; // The number of bars cannot be above the max assert(DoublePairStore::k_numberOfSeries > 0); @@ -63,9 +86,9 @@ bool HistogramParameterController::setParameterAtIndex(int parameterIndex, doubl if (setBarWidth) { // Set the bar width - m_store->setBarWidth(value); + m_tempBarWidth = value; } else { - m_store->setFirstDrawnBarAbscissa(value); + m_tempFirstDrawnBarAbscissa = value; } return true; } @@ -75,5 +98,12 @@ HighlightCell * HistogramParameterController::reusableParameterCell(int index, i return &m_cells[index]; } +void HistogramParameterController::buttonAction() { + // Update parameters values and proceed. + if (confirmParameterAtIndex(0, m_tempBarWidth) && confirmParameterAtIndex(1, m_tempFirstDrawnBarAbscissa)) { + FloatParameterController::buttonAction(); + } +} + } diff --git a/apps/statistics/histogram_parameter_controller.h b/apps/statistics/histogram_parameter_controller.h index 7688b7b27..dae05c1ca 100644 --- a/apps/statistics/histogram_parameter_controller.h +++ b/apps/statistics/histogram_parameter_controller.h @@ -10,17 +10,24 @@ namespace Statistics { class HistogramParameterController : public Shared::FloatParameterController { public: HistogramParameterController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegateApp, Store * store); + void viewWillAppear() override; const char * title() override; int numberOfRows() const override { return 1+k_numberOfCells; } void willDisplayCellForIndex(HighlightCell * cell, int index) override; private: constexpr static int k_numberOfCells = 2; + double extractParameterAtIndex(int index); + double parameterAtIndex(int index) override; + bool confirmParameterAtIndex(int parameterIndex, double f); + bool setParameterAtIndex(int parameterIndex, double f) override; HighlightCell * reusableParameterCell(int index, int type) override; int reusableParameterCellCount(int type) override { return k_numberOfCells; } - double parameterAtIndex(int index) override; - bool setParameterAtIndex(int parameterIndex, double f) override; + void buttonAction() override; MessageTableCellWithEditableText m_cells[k_numberOfCells]; Store * m_store; + // Temporary parameters + double m_tempBarWidth; + double m_tempFirstDrawnBarAbscissa; }; }