diff --git a/apps/graph/graph/preimage_parameter_controller.cpp b/apps/graph/graph/preimage_parameter_controller.cpp index 1c1e519da..cc96183b2 100644 --- a/apps/graph/graph/preimage_parameter_controller.cpp +++ b/apps/graph/graph/preimage_parameter_controller.cpp @@ -21,10 +21,6 @@ PreimageParameterController::PreimageParameterController( { } -const char * PreimageParameterController::title() { - return I18n::translate(I18n::Message::Preimage); -} - void PreimageParameterController::viewWillAppear() { setParameterName(I18n::Message::Y); m_preimageGraphController->setImage(m_cursor->y()); @@ -32,19 +28,17 @@ void PreimageParameterController::viewWillAppear() { } void PreimageParameterController::buttonAction() { - m_preimageGraphController->setRecord(m_record); - StackViewController * stack = static_cast(parentResponder()); - stack->pop(); - stack->pop(); - stack->pop(); - stack->push(m_preimageGraphController); + if (confirmParameterAtIndex(0, m_tempParameter)) { + m_preimageGraphController->setRecord(m_record); + StackViewController * stack = static_cast(parentResponder()); + stack->pop(); + stack->pop(); + stack->pop(); + stack->push(m_preimageGraphController); + } } -double PreimageParameterController::parameterAtIndex(int index) { - assert(index == 0); - return m_preimageGraphController->image(); -} -bool PreimageParameterController::setParameterAtIndex(int parameterIndex, double f) { +bool PreimageParameterController::confirmParameterAtIndex(int parameterIndex, double f) { assert(parameterIndex == 0); m_preimageGraphController->setImage(f); return true; diff --git a/apps/graph/graph/preimage_parameter_controller.h b/apps/graph/graph/preimage_parameter_controller.h index dbe683004..1b8d1a963 100644 --- a/apps/graph/graph/preimage_parameter_controller.h +++ b/apps/graph/graph/preimage_parameter_controller.h @@ -15,13 +15,16 @@ public: Shared::CurveViewCursor * cursor, PreimageGraphController * preimageGraphController ); - const char * title() override; + const char * title() override { return I18n::translate(I18n::Message::Preimage); } void setRecord(Ion::Storage::Record record) { m_record = record; } void viewWillAppear() override; private: void buttonAction() override; - double parameterAtIndex(int index) override; - bool setParameterAtIndex(int parameterIndex, double f) override; + double extractParameterAtIndex(int index) override { + assert(index == 0); + return m_preimageGraphController->image(); + } + bool confirmParameterAtIndex(int parameterIndex, double f) override; Ion::Storage::Record m_record; PreimageGraphController * m_preimageGraphController; }; diff --git a/apps/regression/go_to_parameter_controller.cpp b/apps/regression/go_to_parameter_controller.cpp index d313f8e63..461f98bfa 100644 --- a/apps/regression/go_to_parameter_controller.cpp +++ b/apps/regression/go_to_parameter_controller.cpp @@ -30,7 +30,7 @@ const char * GoToParameterController::title() { return I18n::translate(I18n::Message::YPrediction); } -double GoToParameterController::parameterAtIndex(int index) { +double GoToParameterController::extractParameterAtIndex(int index) { assert(index == 0); if (m_xPrediction) { return m_cursor->x(); @@ -38,7 +38,7 @@ double GoToParameterController::parameterAtIndex(int index) { return m_cursor->y(); } -bool GoToParameterController::setParameterAtIndex(int parameterIndex, double f) { +bool GoToParameterController::confirmParameterAtIndex(int parameterIndex, double f) { assert(parameterIndex == 0); int series = m_graphController->selectedSeriesIndex(); Poincare::Context * globContext = AppsContainer::sharedAppsContainer()->globalContext(); diff --git a/apps/regression/go_to_parameter_controller.h b/apps/regression/go_to_parameter_controller.h index c5d27f6c7..3fa6d6aab 100644 --- a/apps/regression/go_to_parameter_controller.h +++ b/apps/regression/go_to_parameter_controller.h @@ -15,8 +15,8 @@ public: void setXPrediction(bool xPrediction); const char * title() override; private: - double parameterAtIndex(int index) override; - bool setParameterAtIndex(int parameterIndex, double f) override; + double extractParameterAtIndex(int index) override; + bool confirmParameterAtIndex(int parameterIndex, double f) override; Store * m_store; bool m_xPrediction; GraphController * m_graphController; diff --git a/apps/shared/function_go_to_parameter_controller.cpp b/apps/shared/function_go_to_parameter_controller.cpp index 3382815b1..c5b21cb43 100644 --- a/apps/shared/function_go_to_parameter_controller.cpp +++ b/apps/shared/function_go_to_parameter_controller.cpp @@ -11,16 +11,7 @@ FunctionGoToParameterController::FunctionGoToParameterController(Responder * par { } -const char * FunctionGoToParameterController::title() { - return I18n::translate(I18n::Message::Goto); -} - -double FunctionGoToParameterController::parameterAtIndex(int index) { - assert(index == 0); - return m_cursor->t(); -} - -bool FunctionGoToParameterController::setParameterAtIndex(int parameterIndex, double f) { +bool FunctionGoToParameterController::confirmParameterAtIndex(int parameterIndex, double f) { assert(parameterIndex == 0); FunctionApp * myApp = FunctionApp::app(); ExpiringPointer function = myApp->functionStore()->modelForRecord(m_record); diff --git a/apps/shared/function_go_to_parameter_controller.h b/apps/shared/function_go_to_parameter_controller.h index 5af912a31..a5680105f 100644 --- a/apps/shared/function_go_to_parameter_controller.h +++ b/apps/shared/function_go_to_parameter_controller.h @@ -9,13 +9,16 @@ namespace Shared { class FunctionGoToParameterController : public GoToParameterController { public: FunctionGoToParameterController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, InteractiveCurveViewRange * graphRange, CurveViewCursor * cursor); - const char * title() override; + const char * title() override { return I18n::translate(I18n::Message::Goto); } void setRecord(Ion::Storage::Record record); protected: - bool setParameterAtIndex(int parameterIndex, double f) override; + bool confirmParameterAtIndex(int parameterIndex, double f) override; Ion::Storage::Record m_record; private: - double parameterAtIndex(int index) override; + double extractParameterAtIndex(int index) override { + assert(index == 0); + return m_cursor->t(); + } }; } diff --git a/apps/shared/go_to_parameter_controller.cpp b/apps/shared/go_to_parameter_controller.cpp index d72ab64d9..5151af985 100644 --- a/apps/shared/go_to_parameter_controller.cpp +++ b/apps/shared/go_to_parameter_controller.cpp @@ -11,19 +11,11 @@ GoToParameterController::GoToParameterController(Responder * parentResponder, In { } -int GoToParameterController::numberOfRows() const { - return 2; -} - HighlightCell * GoToParameterController::reusableParameterCell(int index, int type) { assert(index == 0); return &m_parameterCell; } -int GoToParameterController::reusableParameterCellCount(int type) { - return 1; -} - bool GoToParameterController::handleEvent(Ion::Events::Event event) { if (event == Ion::Events::Left) { stackController()->pop(); @@ -32,10 +24,25 @@ bool GoToParameterController::handleEvent(Ion::Events::Event event) { return false; } +void GoToParameterController::viewWillAppear() { + // Initialize m_tempParameter to the extracted value. + setParameterAtIndex(0, extractParameterAtIndex(0)); + FloatParameterController::viewWillAppear(); +} + +bool GoToParameterController::setParameterAtIndex(int parameterIndex, double f) { + assert(parameterIndex == 0); + m_tempParameter = f; + return true; +} + void GoToParameterController::buttonAction() { - StackViewController * stack = (StackViewController *)parentResponder(); - stack->pop(); - stack->pop(); + // Update parameter value to m_tempParameter, and proceed if value is valid + if (confirmParameterAtIndex(0, m_tempParameter)) { + StackViewController * stack = (StackViewController *)parentResponder(); + stack->pop(); + stack->pop(); + } } } diff --git a/apps/shared/go_to_parameter_controller.h b/apps/shared/go_to_parameter_controller.h index 31516b923..24b39c5ea 100644 --- a/apps/shared/go_to_parameter_controller.h +++ b/apps/shared/go_to_parameter_controller.h @@ -11,16 +11,28 @@ namespace Shared { class GoToParameterController : public FloatParameterController { public: GoToParameterController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, InteractiveCurveViewRange * graphRange, CurveViewCursor * cursor); - int numberOfRows() const override; + int numberOfRows() const override { return 2; } bool handleEvent(Ion::Events::Event event) override; protected: void setParameterName(I18n::Message message) { m_parameterCell.setMessage(message); } + void viewWillAppear() override; + // extractParameterAtIndex extracts the current value of the parameter + virtual double extractParameterAtIndex(int index) = 0; + // confirmParameterAtIndex updates the current value of the parameter + virtual bool confirmParameterAtIndex(int parameterIndex, double f) = 0; + // parameterAtIndex and setParameterAtIndex manipulate m_tempParameter only + double parameterAtIndex(int index) override { + assert(index == 0); + return m_tempParameter; + } + bool setParameterAtIndex(int parameterIndex, double f) override; CurveViewCursor * m_cursor; InteractiveCurveViewRange * m_graphRange; + double m_tempParameter; private: void buttonAction() override; HighlightCell * reusableParameterCell(int index, int type) override; - int reusableParameterCellCount(int type) override; + int reusableParameterCellCount(int type) override { return 1; } MessageTableCellWithEditableText m_parameterCell; };