[apps/calculation] Evaluate calculations in the context including ANS

Change-Id: I9442885551d928d2c1a32bae1324eb6c45af3c94
This commit is contained in:
Émilie Feral
2016-11-03 17:20:01 +01:00
parent 99af9b8692
commit f5272cb0cf
4 changed files with 10 additions and 2 deletions

View File

@@ -6,6 +6,7 @@ namespace Calculation {
App::App(Context * context) :
::App(&m_editExpressionController, "Calcul", ImageStore::CalculationIcon),
m_globalContext(context),
m_evaluateContext(EvaluateContext(context, &m_calculationStore)),
m_calculationStore(CalculationStore()),
m_historyController(HistoryController(&m_editExpressionController, &m_calculationStore)),
m_editExpressionController(EditExpressionController(&m_modalViewController, &m_historyController, &m_calculationStore, this))
@@ -16,4 +17,8 @@ Context * App::globalContext() {
return m_globalContext;
}
Context * App::evaluateContext() {
return &m_evaluateContext;
}
}

View File

@@ -2,6 +2,7 @@
#define CALCULATION_APP_H
#include "edit_expression_controller.h"
#include "evaluate_context.h"
#include "history_controller.h"
#include "../expression_text_field_delegate.h"
#include <escher.h>
@@ -12,8 +13,10 @@ class App : public ::App, public ExpressionTextFieldDelegate {
public:
App(Context * context);
Context * globalContext();
Context * evaluateContext();
private:
Context * m_globalContext;
EvaluateContext m_evaluateContext;
CalculationStore m_calculationStore;
HistoryController m_historyController;
EditExpressionController m_editExpressionController;

View File

@@ -74,7 +74,7 @@ bool EditExpressionController::handleEvent(Ion::Events::Event event) {
{
Calculation calculation = Calculation();
App * calculationApp = (App *)app();
calculation.setContent(textBody(), calculationApp->globalContext());
calculation.setContent(textBody(), calculationApp->evaluateContext());
m_calculationStore->push(&calculation);
m_historyController->reload();
m_contentView.mainView()->scrollToCell(0, m_historyController->numberOfRows()-1);

View File

@@ -69,7 +69,7 @@ bool HistoryController::handleEvent(Ion::Events::Event event) {
char buffer[Constant::FloatBufferSizeInScientificMode];
Float(calculation->evaluation()).convertFloatToText(buffer, Constant::FloatBufferSizeInScientificMode, Constant::NumberOfDigitsInMantissaInScientificMode);
App * calculationApp = (App *)app();
newCalculation.setContent(buffer, calculationApp->globalContext());
newCalculation.setContent(buffer, calculationApp->evaluateContext());
}
m_selectableTableView.deselectTable();
m_calculationStore->push(&newCalculation);