mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps] Put the method preference in container instead of in every app
Change-Id: Ib390952a6559aa847c99e3ca74c4f6995a07e909
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,19 +5,16 @@
|
||||
#include "local_context.h"
|
||||
#include "history_controller.h"
|
||||
#include "../text_field_delegate_app.h"
|
||||
#include "../preferences.h"
|
||||
#include <escher.h>
|
||||
|
||||
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;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "edit_expression_controller.h"
|
||||
#include "app.h"
|
||||
#include "../apps_container.h"
|
||||
#include <assert.h>
|
||||
|
||||
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("");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "history_controller.h"
|
||||
#include "app.h"
|
||||
#include "../apps_container.h"
|
||||
#include <assert.h>
|
||||
|
||||
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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "graph_controller.h"
|
||||
#include "../app.h"
|
||||
#include "../../apps_container.h"
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user