[apps/graph] Replace multiple pointers to evaluate context by

app()->evaluateContext()

Change-Id: I21035aa357e9d2f2c471ad5751bed59cf05cebf3
This commit is contained in:
Émilie Feral
2016-11-04 17:13:38 +01:00
parent 65465897d3
commit f4a95cb43f
8 changed files with 38 additions and 17 deletions

View File

@@ -10,8 +10,8 @@ App::App(::Context * context) :
m_evaluateContext(EvaluateContext(context)),
m_listController(ListController(nullptr, &m_functionStore)),
m_listStackViewController(StackViewController(&m_tabViewController, &m_listController)),
m_graphController(GraphController(nullptr, &m_functionStore, &m_evaluateContext)),
m_valuesController(nullptr, &m_functionStore, &m_evaluateContext),
m_graphController(GraphController(nullptr, &m_functionStore)),
m_valuesController(nullptr, &m_functionStore),
m_valuesStackViewController(StackViewController(&m_tabViewController, &m_valuesController)),
m_tabViewController(&m_inputViewController, &m_listStackViewController, &m_graphController, &m_valuesStackViewController),
m_inputViewController(&m_modalViewController, &m_tabViewController, this)
@@ -26,4 +26,8 @@ Context * App::globalContext() {
return m_globalContext;
}
Context * App::evaluateContext() {
return &m_evaluateContext;
}
}

View File

@@ -16,6 +16,7 @@ public:
App(::Context * context);
InputViewController * inputViewController();
Context * globalContext();
Context * evaluateContext();
private:
FunctionStore m_functionStore;
Context * m_globalContext;

View File

@@ -1,17 +1,26 @@
#include "graph_controller.h"
#include "../app.h"
#include <assert.h>
namespace Graph {
GraphController::GraphController(Responder * parentResponder, FunctionStore * functionStore, EvaluateContext * evaluateContext) :
GraphController::GraphController(Responder * parentResponder, FunctionStore * functionStore) :
HeaderViewController(parentResponder, &m_view),
m_view(GraphView(functionStore, evaluateContext)),
m_view(GraphView(functionStore)),
m_headerSelected(false),
m_windowButton(Button(this, "Fenetre", Invocation([](void * context, void * sender) {}, this))),
m_displayButton(this, "Affichage", Invocation([](void * context, void * sender) {}, this))
{
}
View * GraphController::view() {
if (m_view.context() == nullptr) {
App * graphApp = (Graph::App *)app();
m_view.setContext(graphApp->evaluateContext());
}
return HeaderViewController::view();
}
const char * GraphController::title() const {
return "Graphique";
}

View File

@@ -4,14 +4,13 @@
#include <escher.h>
#include "graph_view.h"
#include "../function_store.h"
#include "../evaluate_context.h"
namespace Graph {
class GraphController : public HeaderViewController {
public:
GraphController(Responder * parentResponder, FunctionStore * functionStore, EvaluateContext * evaluateContext);
GraphController(Responder * parentResponder, FunctionStore * functionStore);
const char * title() const override;
View * view() override;
bool handleEvent(Ion::Events::Event event) override;
void didBecomeFirstResponder() override;

View File

@@ -9,7 +9,7 @@ constexpr KDColor kSecondaryGridColor = KDColor(0xEEEEEE);
constexpr int kNumberOfMainGridLines = 5;
constexpr int kNumberOfSecondaryGridLines = 4;
GraphView::GraphView(FunctionStore * functionStore, EvaluateContext * evaluateContext) :
GraphView::GraphView(FunctionStore * functionStore) :
#if GRAPH_VIEW_IS_TILED
TiledView(),
#else
@@ -22,7 +22,7 @@ GraphView::GraphView(FunctionStore * functionStore, EvaluateContext * evaluateCo
m_yMin(-2.0f),
m_yMax(2.0f),
m_functionStore(functionStore),
m_evaluateContext(evaluateContext)
m_evaluateContext(nullptr)
{
}
@@ -34,6 +34,14 @@ View * GraphView::subviewAtIndex(int index) {
return &m_cursorView;
}
void GraphView::setContext(Context * context) {
m_evaluateContext = (EvaluateContext *)context;
}
Context * GraphView::context() const {
return m_evaluateContext;
}
void GraphView::moveCursorRight() {
KDPoint offset = KDPoint(2,0);
m_cursorPosition = m_cursorPosition.translatedBy(offset);

View File

@@ -18,7 +18,7 @@ class GraphView : public
#endif
{
public:
GraphView(FunctionStore * functionStore, EvaluateContext * evaluateContext);
GraphView(FunctionStore * functionStore);
#if GRAPH_VIEW_IS_TILED
KDColor * tile() const override;
@@ -30,6 +30,8 @@ public:
// void drawRect(KDRect rect) const override;
void moveCursorRight();
void setContext(Context * evaluateContext);
Context * context() const;
private:
int numberOfSubviews() const override;
View * subviewAtIndex(int index) override;

View File

@@ -47,11 +47,10 @@ ValuesController::ContentView::TableState ValuesController::ContentView::tableSt
/* Value Controller */
ValuesController::ValuesController(Responder * parentResponder, FunctionStore * functionStore, EvaluateContext * evaluateContext) :
ValuesController::ValuesController(Responder * parentResponder, FunctionStore * functionStore) :
HeaderViewController(parentResponder, &m_contentView),
m_selectableTableView(SelectableTableView(this, this, k_topMargin, k_rightMargin, k_bottomMargin, k_leftMargin)),
m_functionStore(functionStore),
m_evaluateContext(evaluateContext),
m_parameterController(ValuesParameterController(this, &m_interval)),
m_abscissaParameterController(AbscissaParameterController(this, &m_parameterController)),
m_functionParameterController(FunctionParameterController(this)),
@@ -384,10 +383,11 @@ void ValuesController::willDisplayCellAtLocation(TableViewCell * cell, int i, in
}
Function * function = functionAtColumn(i);
float x = m_interval.element(j-1);
App * graphApp = (Graph::App *)app();
if (isDerivativeColumn(i)) {
Float(function->approximateDerivative(x, m_evaluateContext)).convertFloatToText(buffer, Constant::FloatBufferSizeInScientificMode, Constant::NumberOfDigitsInMantissaForDerivativeNumberInScientificMode);
Float(function->approximateDerivative(x, (EvaluateContext *)graphApp->evaluateContext())).convertFloatToText(buffer, Constant::FloatBufferSizeInScientificMode, Constant::NumberOfDigitsInMantissaForDerivativeNumberInScientificMode);
} else {
Float(function->evaluateAtAbscissa(x, m_evaluateContext)).convertFloatToText(buffer, Constant::FloatBufferSizeInScientificMode, Constant::NumberOfDigitsInMantissaInScientificMode);
Float(function->evaluateAtAbscissa(x, (EvaluateContext *)graphApp->evaluateContext())).convertFloatToText(buffer, Constant::FloatBufferSizeInScientificMode, Constant::NumberOfDigitsInMantissaInScientificMode);
}
myValueCell->setText(buffer);
}

View File

@@ -3,7 +3,6 @@
#include <escher.h>
#include "../function_store.h"
#include "../evaluate_context.h"
#include "../function_title_cell.h"
#include "value_cell.h"
#include "title_cell.h"
@@ -17,7 +16,7 @@ namespace Graph {
class ValuesController : public HeaderViewController, public TableViewDataSource {
public:
ValuesController(Responder * parentResponder, FunctionStore * functionStore, EvaluateContext * evaluateContext);
ValuesController(Responder * parentResponder, FunctionStore * functionStore);
int activeRow();
int activeColumn();
@@ -88,7 +87,6 @@ private:
FunctionTitleCell m_functionTitleCells[k_maxNumberOfFunctions];
ValueCell m_floatCells[k_maxNumberOfCells];
FunctionStore * m_functionStore;
EvaluateContext * m_evaluateContext;
Interval m_interval;
ValuesParameterController m_parameterController;
AbscissaParameterController m_abscissaParameterController;