[apps/shared] Apply changes on confirm with GoTo functions

Change-Id: I6ebec412b4b6612710476274a8665375d21f9ef8
This commit is contained in:
Hugo Saint-Vignes
2020-07-27 15:35:35 +02:00
committed by LeaNumworks
parent 61792058d3
commit 5c75cc55d3
8 changed files with 58 additions and 48 deletions

View File

@@ -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<StackViewController *>(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<StackViewController *>(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;

View File

@@ -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;
};

View File

@@ -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();

View File

@@ -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;

View File

@@ -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> function = myApp->functionStore()->modelForRecord(m_record);

View File

@@ -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();
}
};
}

View File

@@ -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();
}
}
}

View File

@@ -11,16 +11,28 @@ namespace Shared {
class GoToParameterController : public FloatParameterController<double> {
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;
};