From e702c1f61bda428578584276ca820488c2fbd7f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 18 May 2017 10:34:50 +0200 Subject: [PATCH] [apps/graph][apps/regression][app/sequence] Move model and range versions to the snapshot Change-Id: I6ec56ab59d734c0c43a5df32462173c611cc68b3 --- apps/graph/app.cpp | 10 +++------- apps/graph/app.h | 4 +--- apps/graph/graph/graph_controller.cpp | 4 ++-- apps/graph/graph/graph_controller.h | 2 +- apps/regression/app.cpp | 18 +++++++++++++++++- apps/regression/app.h | 5 +++++ apps/regression/graph_controller.cpp | 4 ++-- apps/regression/graph_controller.h | 2 +- apps/sequence/app.cpp | 10 +++------- apps/sequence/app.h | 4 +--- apps/sequence/graph/graph_controller.cpp | 4 ++-- apps/sequence/graph/graph_controller.h | 2 +- apps/shared/function_app.cpp | 19 +++++++++++++++++++ apps/shared/function_app.h | 16 +++++++++++++++- apps/shared/function_graph_controller.cpp | 4 ++-- apps/shared/function_graph_controller.h | 2 +- .../interactive_curve_view_controller.cpp | 14 +++++++------- .../interactive_curve_view_controller.h | 6 +++--- apps/shared/text_field_delegate_app.h | 3 ++- 19 files changed, 88 insertions(+), 45 deletions(-) diff --git a/apps/graph/app.cpp b/apps/graph/app.cpp index 618441969..0c8dcf9d9 100644 --- a/apps/graph/app.cpp +++ b/apps/graph/app.cpp @@ -21,9 +21,9 @@ const Image * App::Descriptor::icon() { } App::Snapshot::Snapshot() : + Shared::FunctionApp::Snapshot::Snapshot(), m_functionStore(), - m_graphRange(&m_cursor), - m_cursor() + m_graphRange(&m_cursor) { } @@ -48,10 +48,6 @@ InteractiveCurveViewRange * App::Snapshot::graphRange() { return &m_graphRange; } -CurveViewCursor * App::Snapshot::cursor() { - return &m_cursor; -} - void App::Snapshot::tidy() { m_functionStore.tidy(); } @@ -63,7 +59,7 @@ App::App(Container * container, Snapshot * snapshot) : m_listFooter(&m_listHeader, &m_listController, &m_listController, ButtonRowController::Position::Bottom, ButtonRowController::Style::EmbossedGrey), m_listHeader(&m_listStackViewController, &m_listFooter, &m_listController), m_listStackViewController(&m_tabViewController, &m_listHeader), - m_graphController(&m_graphAlternateEmptyViewController, snapshot->functionStore(), snapshot->graphRange(), snapshot->cursor(), &m_graphHeader), + m_graphController(&m_graphAlternateEmptyViewController, snapshot->functionStore(), snapshot->graphRange(), snapshot->cursor(), snapshot->modelVersion(), snapshot->rangeVersion(), &m_graphHeader), m_graphAlternateEmptyViewController(&m_graphHeader, &m_graphController, &m_graphController), m_graphHeader(&m_graphStackViewController, &m_graphAlternateEmptyViewController, &m_graphController), m_graphStackViewController(&m_tabViewController, &m_graphHeader), diff --git a/apps/graph/app.h b/apps/graph/app.h index 335dbd0d8..b0140fd64 100644 --- a/apps/graph/app.h +++ b/apps/graph/app.h @@ -19,7 +19,7 @@ public: I18n::Message upperName() override; const Image * icon() override; }; - class Snapshot : public ::App::Snapshot { + class Snapshot : public Shared::FunctionApp::Snapshot { public: Snapshot(); App * unpack(Container * container) override; @@ -27,12 +27,10 @@ public: Descriptor * descriptor() override; CartesianFunctionStore * functionStore(); Shared::InteractiveCurveViewRange * graphRange(); - Shared::CurveViewCursor * cursor(); private: void tidy() override; CartesianFunctionStore m_functionStore; Shared::InteractiveCurveViewRange m_graphRange; - Shared::CurveViewCursor m_cursor; }; InputViewController * inputViewController() override; /* This local context can parse x. However, it always stores NAN diff --git a/apps/graph/graph/graph_controller.cpp b/apps/graph/graph/graph_controller.cpp index 2a5796961..6477f404a 100644 --- a/apps/graph/graph/graph_controller.cpp +++ b/apps/graph/graph/graph_controller.cpp @@ -5,8 +5,8 @@ using namespace Poincare; namespace Graph { -GraphController::GraphController(Responder * parentResponder, CartesianFunctionStore * functionStore, Shared::InteractiveCurveViewRange * curveViewRange, CurveViewCursor * cursor, ButtonRowController * header) : - FunctionGraphController(parentResponder, header, curveViewRange, &m_view, cursor), +GraphController::GraphController(Responder * parentResponder, CartesianFunctionStore * functionStore, Shared::InteractiveCurveViewRange * curveViewRange, CurveViewCursor * cursor, uint32_t * modelVersion, uint32_t * rangeVersion, ButtonRowController * header) : + FunctionGraphController(parentResponder, header, curveViewRange, &m_view, cursor, modelVersion, rangeVersion), m_bannerView(), m_view(functionStore, curveViewRange, m_cursor, &m_bannerView, &m_cursorView), m_graphRange(curveViewRange), diff --git a/apps/graph/graph/graph_controller.h b/apps/graph/graph/graph_controller.h index f54ddd156..09bdcdc63 100644 --- a/apps/graph/graph/graph_controller.h +++ b/apps/graph/graph/graph_controller.h @@ -13,7 +13,7 @@ namespace Graph { class GraphController : public Shared::FunctionGraphController { public: - GraphController(Responder * parentResponder, CartesianFunctionStore * functionStore, Shared::InteractiveCurveViewRange * curveViewRange, Shared::CurveViewCursor * cursor, ButtonRowController * header); + GraphController(Responder * parentResponder, CartesianFunctionStore * functionStore, Shared::InteractiveCurveViewRange * curveViewRange, Shared::CurveViewCursor * cursor, uint32_t * modelVersion, uint32_t * rangeVersion, ButtonRowController * header); I18n::Message emptyMessage() override; private: BannerView * bannerView() override; diff --git a/apps/regression/app.cpp b/apps/regression/app.cpp index 03220f053..05387bcc6 100644 --- a/apps/regression/app.cpp +++ b/apps/regression/app.cpp @@ -18,6 +18,14 @@ const Image * App::Descriptor::icon() { return ImageStore::RegressionIcon; } +App::Snapshot::Snapshot() : + m_store(), + m_cursor(), + m_modelVersion(0), + m_rangeVersion(0) +{ +} + App * App::Snapshot::unpack(Container * container) { return new App(container, this); } @@ -39,12 +47,20 @@ CurveViewCursor * App::Snapshot::cursor() { return &m_cursor; } +uint32_t * App::Snapshot::modelVersion() { + return &m_modelVersion; +} + +uint32_t * App::Snapshot::rangeVersion() { + return &m_rangeVersion; +} + App::App(Container * container, Snapshot * snapshot) : TextFieldDelegateApp(container, snapshot, &m_tabViewController), m_calculationController(&m_calculationAlternateEmptyViewController, &m_calculationHeader, snapshot->store()), m_calculationAlternateEmptyViewController(&m_calculationHeader, &m_calculationController, &m_calculationController), m_calculationHeader(&m_tabViewController, &m_calculationAlternateEmptyViewController, &m_calculationController), - m_graphController(&m_graphAlternateEmptyViewController, &m_graphHeader, snapshot->store(), snapshot->cursor()), + m_graphController(&m_graphAlternateEmptyViewController, &m_graphHeader, snapshot->store(), snapshot->cursor(), snapshot->modelVersion(), snapshot->rangeVersion()), m_graphAlternateEmptyViewController(&m_graphHeader, &m_graphController, &m_graphController), m_graphHeader(&m_graphStackViewController, &m_graphAlternateEmptyViewController, &m_graphController), m_graphStackViewController(&m_tabViewController, &m_graphHeader), diff --git a/apps/regression/app.h b/apps/regression/app.h index 30b21654d..521a66ae9 100644 --- a/apps/regression/app.h +++ b/apps/regression/app.h @@ -20,14 +20,19 @@ public: }; class Snapshot : public ::App::Snapshot { public: + Snapshot(); App * unpack(Container * container) override; void reset() override; Descriptor * descriptor() override; Store * store(); Shared::CurveViewCursor * cursor(); + uint32_t * modelVersion(); + uint32_t * rangeVersion(); private: Store m_store; Shared::CurveViewCursor m_cursor; + uint32_t m_modelVersion; + uint32_t m_rangeVersion; }; private: App(Container * container, Snapshot * snapshot); diff --git a/apps/regression/graph_controller.cpp b/apps/regression/graph_controller.cpp index a1fe8aca6..3f1c5f0fc 100644 --- a/apps/regression/graph_controller.cpp +++ b/apps/regression/graph_controller.cpp @@ -6,8 +6,8 @@ using namespace Shared; namespace Regression { -GraphController::GraphController(Responder * parentResponder, ButtonRowController * header, Store * store, CurveViewCursor * cursor) : - InteractiveCurveViewController(parentResponder, header, store, &m_view, cursor), +GraphController::GraphController(Responder * parentResponder, ButtonRowController * header, Store * store, CurveViewCursor * cursor, uint32_t * modelVersion, uint32_t * rangeVersion) : + InteractiveCurveViewController(parentResponder, header, store, &m_view, cursor, modelVersion, rangeVersion), m_bannerView(), m_view(store, m_cursor, &m_bannerView, &m_cursorView), m_store(store), diff --git a/apps/regression/graph_controller.h b/apps/regression/graph_controller.h index 095a0001c..d79daedfe 100644 --- a/apps/regression/graph_controller.h +++ b/apps/regression/graph_controller.h @@ -15,7 +15,7 @@ namespace Regression { class GraphController : public Shared::InteractiveCurveViewController { public: - GraphController(Responder * parentResponder, ButtonRowController * header, Store * store, Shared::CurveViewCursor * cursor); + GraphController(Responder * parentResponder, ButtonRowController * header, Store * store, Shared::CurveViewCursor * cursor, uint32_t * modelVersion, uint32_t * rangeVersion); ViewController * initialisationParameterController() override; bool isEmpty() const override; I18n::Message emptyMessage() override; diff --git a/apps/sequence/app.cpp b/apps/sequence/app.cpp index dcc9560ae..732f90d56 100644 --- a/apps/sequence/app.cpp +++ b/apps/sequence/app.cpp @@ -19,9 +19,9 @@ const Image * App::Descriptor::icon() { } App::Snapshot::Snapshot() : + Shared::FunctionApp::Snapshot::Snapshot(), m_sequenceStore(), - m_graphRange(&m_cursor), - m_cursor() + m_graphRange(&m_cursor) { } @@ -46,10 +46,6 @@ CurveViewRange * App::Snapshot::graphRange() { return &m_graphRange; } -Shared::CurveViewCursor * App::Snapshot::cursor() { - return &m_cursor; -} - void App::Snapshot::tidy() { m_sequenceStore.tidy(); } @@ -61,7 +57,7 @@ App::App(Container * container, Snapshot * snapshot) : m_listFooter(&m_listHeader, &m_listController, &m_listController, ButtonRowController::Position::Bottom, ButtonRowController::Style::EmbossedGrey), m_listHeader(nullptr, &m_listFooter, &m_listController), m_listStackViewController(&m_tabViewController, &m_listHeader), - m_graphController(&m_graphAlternateEmptyViewController, snapshot->sequenceStore(), snapshot->graphRange(), snapshot->cursor(), &m_graphHeader), + m_graphController(&m_graphAlternateEmptyViewController, snapshot->sequenceStore(), snapshot->graphRange(), snapshot->cursor(), snapshot->modelVersion(), snapshot->rangeVersion(), &m_graphHeader), m_graphAlternateEmptyViewController(&m_graphHeader, &m_graphController, &m_graphController), m_graphHeader(&m_graphStackViewController, &m_graphAlternateEmptyViewController, &m_graphController), m_graphStackViewController(&m_tabViewController, &m_graphHeader), diff --git a/apps/sequence/app.h b/apps/sequence/app.h index 6614f9b7a..a9d6cb51a 100644 --- a/apps/sequence/app.h +++ b/apps/sequence/app.h @@ -21,7 +21,7 @@ public: I18n::Message upperName() override; const Image * icon() override; }; - class Snapshot : public ::App::Snapshot { + class Snapshot : public Shared::FunctionApp::Snapshot { public: Snapshot(); App * unpack(Container * container) override; @@ -29,12 +29,10 @@ public: Descriptor * descriptor() override; SequenceStore * sequenceStore(); CurveViewRange * graphRange(); - Shared::CurveViewCursor * cursor(); private: void tidy() override; SequenceStore m_sequenceStore; CurveViewRange m_graphRange; - Shared::CurveViewCursor m_cursor; }; InputViewController * inputViewController() override; Poincare::Context * localContext() override; diff --git a/apps/sequence/graph/graph_controller.cpp b/apps/sequence/graph/graph_controller.cpp index 0145bf2ca..f7b59f227 100644 --- a/apps/sequence/graph/graph_controller.cpp +++ b/apps/sequence/graph/graph_controller.cpp @@ -4,8 +4,8 @@ using namespace Shared; namespace Sequence { -GraphController::GraphController(Responder * parentResponder, SequenceStore * sequenceStore, CurveViewRange * graphRange, CurveViewCursor * cursor, ButtonRowController * header) : - FunctionGraphController(parentResponder, header, graphRange, &m_view, cursor), +GraphController::GraphController(Responder * parentResponder, SequenceStore * sequenceStore, CurveViewRange * graphRange, CurveViewCursor * cursor, uint32_t * modelVersion, uint32_t * rangeVersion, ButtonRowController * header) : + FunctionGraphController(parentResponder, header, graphRange, &m_view, cursor, modelVersion, rangeVersion), m_bannerView(), m_view(sequenceStore, graphRange, m_cursor, &m_bannerView, &m_cursorView), m_graphRange(graphRange), diff --git a/apps/sequence/graph/graph_controller.h b/apps/sequence/graph/graph_controller.h index 2fead3141..280bf8ecc 100644 --- a/apps/sequence/graph/graph_controller.h +++ b/apps/sequence/graph/graph_controller.h @@ -13,7 +13,7 @@ namespace Sequence { class GraphController : public Shared::FunctionGraphController { public: - GraphController(Responder * parentResponder, SequenceStore * sequenceStore, CurveViewRange * graphRange, Shared::CurveViewCursor * cursor, ButtonRowController * header); + GraphController(Responder * parentResponder, SequenceStore * sequenceStore, CurveViewRange * graphRange, Shared::CurveViewCursor * cursor, uint32_t * modelVersion, uint32_t * rangeVersion, ButtonRowController * header); void viewWillAppear() override; I18n::Message emptyMessage() override; TermSumController * termSumController(); diff --git a/apps/shared/function_app.cpp b/apps/shared/function_app.cpp index 3804c4110..1741e90e9 100644 --- a/apps/shared/function_app.cpp +++ b/apps/shared/function_app.cpp @@ -5,6 +5,25 @@ using namespace Poincare; namespace Shared { +FunctionApp::Snapshot::Snapshot() : + m_cursor(), + m_modelVersion(0), + m_rangeVersion(0) +{ +} + +CurveViewCursor * FunctionApp::Snapshot::cursor() { + return &m_cursor; +} + +uint32_t * FunctionApp::Snapshot::modelVersion() { + return &m_modelVersion; +} + +uint32_t * FunctionApp::Snapshot::rangeVersion() { + return &m_rangeVersion; +} + FunctionApp::FunctionApp(Container * container, Snapshot * snapshot, ViewController * rootViewController) : TextFieldDelegateApp(container, snapshot, rootViewController) { diff --git a/apps/shared/function_app.h b/apps/shared/function_app.h index 5c592e8bc..a7c3e515a 100644 --- a/apps/shared/function_app.h +++ b/apps/shared/function_app.h @@ -3,6 +3,7 @@ #include #include "text_field_delegate_app.h" +#include "curve_view_cursor.h" class AppsContainer; @@ -10,10 +11,23 @@ namespace Shared { class FunctionApp : public TextFieldDelegateApp { public: - FunctionApp(Container * container, Snapshot * snapshot, ViewController * rootViewController); + class Snapshot : public ::App::Snapshot { + public: + Snapshot(); + CurveViewCursor * cursor(); + uint32_t * modelVersion(); + uint32_t * rangeVersion(); + protected: + CurveViewCursor m_cursor; + private: + uint32_t m_modelVersion; + uint32_t m_rangeVersion; + }; virtual ~FunctionApp() = default; virtual InputViewController * inputViewController() = 0; void willBecomeInactive() override; +protected: + FunctionApp(Container * container, Snapshot * snapshot, ViewController * rootViewController); }; } diff --git a/apps/shared/function_graph_controller.cpp b/apps/shared/function_graph_controller.cpp index edb701605..9a1e15ac0 100644 --- a/apps/shared/function_graph_controller.cpp +++ b/apps/shared/function_graph_controller.cpp @@ -8,8 +8,8 @@ using namespace Poincare; namespace Shared { -FunctionGraphController::FunctionGraphController(Responder * parentResponder, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView, CurveViewCursor * cursor) : - InteractiveCurveViewController(parentResponder, header, interactiveRange, curveView, cursor), +FunctionGraphController::FunctionGraphController(Responder * parentResponder, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView, CurveViewCursor * cursor, uint32_t * modelVersion, uint32_t * rangeVersion) : + InteractiveCurveViewController(parentResponder, header, interactiveRange, curveView, cursor, modelVersion, rangeVersion), m_indexFunctionSelectedByCursor(0), m_initialisationParameterController(InitialisationParameterController(this, interactiveRange)) { diff --git a/apps/shared/function_graph_controller.h b/apps/shared/function_graph_controller.h index 0b53d094d..5e63026fb 100644 --- a/apps/shared/function_graph_controller.h +++ b/apps/shared/function_graph_controller.h @@ -12,7 +12,7 @@ namespace Shared { class FunctionGraphController : public InteractiveCurveViewController, public InteractiveCurveViewRangeDelegate { public: - FunctionGraphController(Responder * parentResponder, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView, CurveViewCursor * cursor); + FunctionGraphController(Responder * parentResponder, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView, CurveViewCursor * cursor, uint32_t * modelVersion, uint32_t * rangeVersion); bool isEmpty() const override; ViewController * initialisationParameterController() override; void viewWillAppear() override; diff --git a/apps/shared/interactive_curve_view_controller.cpp b/apps/shared/interactive_curve_view_controller.cpp index f1d2d67f7..87106a6ac 100644 --- a/apps/shared/interactive_curve_view_controller.cpp +++ b/apps/shared/interactive_curve_view_controller.cpp @@ -7,13 +7,13 @@ using namespace Poincare; namespace Shared { -InteractiveCurveViewController::InteractiveCurveViewController(Responder * parentResponder, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView, CurveViewCursor * cursor) : +InteractiveCurveViewController::InteractiveCurveViewController(Responder * parentResponder, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView, CurveViewCursor * cursor, uint32_t * modelVersion, uint32_t * rangeVersion) : ViewController(parentResponder), ButtonRowDelegate(header, nullptr), m_cursor(cursor), m_cursorView(CursorView()), - m_modelVersion(0), - m_rangeVersion(0), + m_modelVersion(modelVersion), + m_rangeVersion(rangeVersion), m_rangeParameterController(this, interactiveRange), m_zoomParameterController(this, interactiveRange, curveView), m_rangeButton(this, I18n::Message::Axis, Invocation([](void * context, void * sender) { @@ -132,8 +132,8 @@ Responder * InteractiveCurveViewController::defaultController() { void InteractiveCurveViewController::viewWillAppear() { uint32_t newModelVersion = modelVersion(); - if (m_modelVersion != newModelVersion) { - m_modelVersion = newModelVersion; + if (*m_modelVersion != newModelVersion) { + *m_modelVersion = newModelVersion; initRangeParameters(); /* Warning: init cursor parameter before reloading banner view. Indeed, * reloading banner view needs an updated cursor to load the right data. */ @@ -141,8 +141,8 @@ void InteractiveCurveViewController::viewWillAppear() { centerCursorVertically(); } uint32_t newRangeVersion = rangeVersion(); - if (m_rangeVersion != newRangeVersion) { - m_rangeVersion = newRangeVersion; + if (*m_rangeVersion != newRangeVersion) { + *m_rangeVersion = newRangeVersion; if (!interactiveCurveViewRange()->isCursorVisible()) { initCursorParameters(); } diff --git a/apps/shared/interactive_curve_view_controller.h b/apps/shared/interactive_curve_view_controller.h index d35c6db5b..1e66e249c 100644 --- a/apps/shared/interactive_curve_view_controller.h +++ b/apps/shared/interactive_curve_view_controller.h @@ -15,7 +15,7 @@ namespace Shared { class InteractiveCurveViewController : public ViewController, public ButtonRowDelegate, public AlternateEmptyViewDelegate { public: - InteractiveCurveViewController(Responder * parentResponder, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView, CurveViewCursor * cursor); + InteractiveCurveViewController(Responder * parentResponder, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView, CurveViewCursor * cursor, uint32_t * modelVersion, uint32_t * rangeVersion); View * view() override; const char * title() override; bool handleEvent(Ion::Events::Event event) override; @@ -56,8 +56,8 @@ protected: CursorView m_cursorView; OkView m_okView; private: - uint32_t m_modelVersion; - uint32_t m_rangeVersion; + uint32_t * m_modelVersion; + uint32_t * m_rangeVersion; RangeParameterController m_rangeParameterController; ZoomParameterController m_zoomParameterController; Button m_rangeButton; diff --git a/apps/shared/text_field_delegate_app.h b/apps/shared/text_field_delegate_app.h index 9d3d95573..5a0cd218d 100644 --- a/apps/shared/text_field_delegate_app.h +++ b/apps/shared/text_field_delegate_app.h @@ -11,7 +11,6 @@ namespace Shared { class TextFieldDelegateApp : public ::App, public TextFieldDelegate { public: - TextFieldDelegateApp(Container * container, Snapshot * snapshot, ViewController * rootViewController); virtual ~TextFieldDelegateApp() = default; virtual Poincare::Context * localContext(); AppsContainer * container(); @@ -19,6 +18,8 @@ public: bool textFieldShouldFinishEditing(TextField * textField, Ion::Events::Event event) override; bool textFieldDidReceiveEvent(TextField * textField, Ion::Events::Event event) override; Toolbox * toolboxForTextField(TextField * textField) override; +protected: + TextFieldDelegateApp(Container * container, Snapshot * snapshot, ViewController * rootViewController); private: bool cursorInToken(TextField * textField, const char * token); };