diff --git a/apps/apps_container.cpp b/apps/apps_container.cpp index 5e189b92d..8a6f9b619 100644 --- a/apps/apps_container.cpp +++ b/apps/apps_container.cpp @@ -8,9 +8,9 @@ AppsContainer::AppsContainer() : Container(), m_window(AppsWindow()), m_homeApp(this), - m_graphApp(this, &m_globalContext, &m_preferences), + m_graphApp(this, &m_globalContext), m_probabilityApp(this), - m_calculationApp(this, &m_globalContext, &m_preferences), + m_calculationApp(this, &m_globalContext), m_regressionApp(this), m_settingsApp(this, &m_preferences), m_statisticsApp(this), @@ -46,6 +46,10 @@ Context * AppsContainer::globalContext() { return &m_globalContext; } +Preferences * AppsContainer::preferences() { + return &m_preferences; +} + ToolboxController * AppsContainer::toolboxController() { return &m_toolboxController; } diff --git a/apps/apps_container.h b/apps/apps_container.h index fa1c8185c..c9c8801b1 100644 --- a/apps/apps_container.h +++ b/apps/apps_container.h @@ -25,6 +25,7 @@ public: int numberOfApps(); App * appAtIndex(int index); Context * globalContext(); + Preferences * preferences(); ToolboxController * toolboxController(); VariableBoxController * variableBoxController(); bool handleEvent(Ion::Events::Event event) override; diff --git a/apps/calculation/app.cpp b/apps/calculation/app.cpp index 737c56172..aa703240b 100644 --- a/apps/calculation/app.cpp +++ b/apps/calculation/app.cpp @@ -3,10 +3,9 @@ namespace Calculation { -App::App(Container * container, Context * context, Preferences * preferences) : +App::App(Container * container, Context * context) : TextFieldDelegateApp(container, &m_editExpressionController, "Calculs", "CALCULS", ImageStore::CalculationIcon), m_localContext(LocalContext((GlobalContext *)context, &m_calculationStore)), - m_preferences(preferences), m_calculationStore(CalculationStore()), m_historyController(HistoryController(&m_editExpressionController, &m_calculationStore)), m_editExpressionController(EditExpressionController(&m_modalViewController, &m_historyController, &m_calculationStore)) @@ -17,8 +16,4 @@ Context * App::localContext() { return &m_localContext; } -Preferences * App::preferences() { - return m_preferences; -} - } diff --git a/apps/calculation/app.h b/apps/calculation/app.h index 5ed227e23..d16b11d57 100644 --- a/apps/calculation/app.h +++ b/apps/calculation/app.h @@ -5,19 +5,16 @@ #include "local_context.h" #include "history_controller.h" #include "../text_field_delegate_app.h" -#include "../preferences.h" #include namespace Calculation { class App : public TextFieldDelegateApp { public: - App(Container * container, Context * context, Preferences * preferences); + App(Container * container, Context * context); Context * localContext() override; - Preferences * preferences(); private: LocalContext m_localContext; - Preferences * m_preferences; CalculationStore m_calculationStore; HistoryController m_historyController; EditExpressionController m_editExpressionController; diff --git a/apps/calculation/edit_expression_controller.cpp b/apps/calculation/edit_expression_controller.cpp index bc5653310..9f09c8b2d 100644 --- a/apps/calculation/edit_expression_controller.cpp +++ b/apps/calculation/edit_expression_controller.cpp @@ -1,5 +1,6 @@ #include "edit_expression_controller.h" #include "app.h" +#include "../apps_container.h" #include namespace Calculation { @@ -81,7 +82,8 @@ bool EditExpressionController::textFieldDidReceiveEvent(::TextField * textField, bool EditExpressionController::textFieldDidFinishEditing(::TextField * textField, const char * text) { App * calculationApp = (App *)app(); - m_calculationStore->push(textBody(), calculationApp->localContext(), calculationApp->preferences()); + AppsContainer * appsContainer = (AppsContainer *)calculationApp->container(); + m_calculationStore->push(textBody(), calculationApp->localContext(), appsContainer->preferences()); m_historyController->reload(); m_contentView.mainView()->scrollToCell(0, m_historyController->numberOfRows()-1); m_contentView.textField()->setText(""); diff --git a/apps/calculation/history_controller.cpp b/apps/calculation/history_controller.cpp index 9561c2be1..fd986e0ce 100644 --- a/apps/calculation/history_controller.cpp +++ b/apps/calculation/history_controller.cpp @@ -1,5 +1,6 @@ #include "history_controller.h" #include "app.h" +#include "../apps_container.h" #include namespace Calculation { @@ -70,7 +71,8 @@ bool HistoryController::handleEvent(Ion::Events::Event event) { } m_selectableTableView.deselectTable(); App * calculationApp = (App *)app(); - m_calculationStore->push(text, calculationApp->localContext(), calculationApp->preferences()); + AppsContainer * appsContainer = (AppsContainer *)calculationApp->container(); + m_calculationStore->push(text, calculationApp->localContext(), appsContainer->preferences()); reload(); m_selectableTableView.scrollToCell(0, numberOfRows()-1); app()->setFirstResponder(editController); diff --git a/apps/graph/app.cpp b/apps/graph/app.cpp index a4cc1f27f..be898f627 100644 --- a/apps/graph/app.cpp +++ b/apps/graph/app.cpp @@ -3,11 +3,10 @@ namespace Graph { -App::App(Container * container, Context * context, Preferences * preferences) : +App::App(Container * container, Context * context) : TextFieldDelegateApp(container, &m_inputViewController, "Fonctions", "FONCTIONS", ImageStore::GraphIcon), m_functionStore(FunctionStore()), m_xContext(VariableContext('x', context)), - m_preferences(preferences), m_listController(ListController(&m_listHeader, &m_functionStore, &m_listHeader)), m_listHeader(HeaderViewController(nullptr, &m_listController, &m_listController)), m_listStackViewController(StackViewController(&m_tabViewController, &m_listHeader)), @@ -32,8 +31,4 @@ Context * App::localContext() { return &m_xContext; } -Preferences * App::preferences() { - return m_preferences; -} - } diff --git a/apps/graph/app.h b/apps/graph/app.h index 80bfa74ad..6b17e2068 100644 --- a/apps/graph/app.h +++ b/apps/graph/app.h @@ -8,20 +8,17 @@ #include "list/list_controller.h" #include "values/values_controller.h" #include "../text_field_delegate_app.h" -#include "../preferences.h" namespace Graph { class App : public TextFieldDelegateApp { public: - App(Container * container, Context * context, Preferences * preferences); + App(Container * container, Context * context); InputViewController * inputViewController(); Context * localContext() override; - Preferences * preferences(); private: FunctionStore m_functionStore; VariableContext m_xContext; - Preferences * m_preferences; ListController m_listController; HeaderViewController m_listHeader; StackViewController m_listStackViewController; diff --git a/apps/graph/graph/graph_controller.cpp b/apps/graph/graph/graph_controller.cpp index 27339ab4f..7f7c0abde 100644 --- a/apps/graph/graph/graph_controller.cpp +++ b/apps/graph/graph/graph_controller.cpp @@ -1,5 +1,6 @@ #include "graph_controller.h" #include "../app.h" +#include "../../apps_container.h" #include #include #include @@ -110,11 +111,12 @@ bool GraphController::handleEnter() { void GraphController::reloadBannerView() { App * myApp = (App *)app(); + AppsContainer * myContainer = (AppsContainer *)myApp->container(); char buffer[k_maxNumberOfCharacters+Float::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)]; const char * legend = "x = "; int legendLength = strlen(legend); strlcpy(buffer, legend, legendLength+1); - Float(m_cursor.x()).convertFloatToText(buffer+ legendLength, Float::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, myApp->preferences()->displayMode()); + Float(m_cursor.x()).convertFloatToText(buffer+ legendLength, Float::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, myContainer->preferences()->displayMode()); m_bannerView.setLegendAtIndex(buffer, 0); legend = "00(x) = "; @@ -122,7 +124,7 @@ void GraphController::reloadBannerView() { strlcpy(buffer, legend, legendLength+1); Function * f = m_functionStore->activeFunctionAtIndex(m_indexFunctionSelectedByCursor); buffer[1] = f->name()[0]; - Float(m_cursor.y()).convertFloatToText(buffer+legendLength, Float::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, myApp->preferences()->displayMode()); + Float(m_cursor.y()).convertFloatToText(buffer+legendLength, Float::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, myContainer->preferences()->displayMode()); m_bannerView.setLegendAtIndex(buffer+1, 1); if (m_bannerView.displayDerivative()) { @@ -130,7 +132,7 @@ void GraphController::reloadBannerView() { buffer[1] = '\''; App * graphApp = (Graph::App *)app(); float y = f->approximateDerivative(m_cursor.x(), graphApp->localContext()); - Float(y).convertFloatToText(buffer + legendLength, Float::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, myApp->preferences()->displayMode()); + Float(y).convertFloatToText(buffer + legendLength, Float::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, myContainer->preferences()->displayMode()); m_bannerView.setLegendAtIndex(buffer, 2); } } diff --git a/apps/graph/values/values_controller.cpp b/apps/graph/values/values_controller.cpp index bf2465200..b743ff113 100644 --- a/apps/graph/values/values_controller.cpp +++ b/apps/graph/values/values_controller.cpp @@ -122,8 +122,8 @@ int ValuesController::numberOfColumns() { } void ValuesController::willDisplayCellAtLocation(TableViewCell * cell, int i, int j) { - App * graphApp = (Graph::App *)app(); - willDisplayCellAtLocationWithDisplayMode(cell, i, j, graphApp->preferences()->displayMode()); + AppsContainer * myContainer = (AppsContainer *)app()->container(); + willDisplayCellAtLocationWithDisplayMode(cell, i, j, myContainer->preferences()->displayMode()); if (cellAtLocationIsEditable(i, j)) { return; } @@ -165,11 +165,12 @@ void ValuesController::willDisplayCellAtLocation(TableViewCell * cell, int i, in // The cell is a value cell EvenOddBufferTextCell * myValueCell = (EvenOddBufferTextCell *)cell; Function * function = functionAtColumn(i); + App * graphApp = (Graph::App *)app(); float x = m_interval.element(j-1); if (isDerivativeColumn(i)) { - Float(function->approximateDerivative(x, graphApp->localContext())).convertFloatToText(buffer, Float::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, graphApp->preferences()->displayMode()); + Float(function->approximateDerivative(x, graphApp->localContext())).convertFloatToText(buffer, Float::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, myContainer->preferences()->displayMode()); } else { - Float(function->evaluateAtAbscissa(x, graphApp->localContext())).convertFloatToText(buffer, Float::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, graphApp->preferences()->displayMode()); + Float(function->evaluateAtAbscissa(x, graphApp->localContext())).convertFloatToText(buffer, Float::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, myContainer->preferences()->displayMode()); } myValueCell->setText(buffer); }