[apps] Get rid of App casts

This commit is contained in:
Romain Goyet
2019-06-03 15:40:54 +02:00
committed by EmilieNumworks
parent eaa4758367
commit 21907fb89a
35 changed files with 96 additions and 91 deletions

View File

@@ -39,6 +39,10 @@ private:
EditExpressionController m_editExpressionController;
};
inline App * app() {
return static_cast<App *>(::app());
}
}
#endif

View File

@@ -109,11 +109,11 @@ void EditExpressionController::layoutFieldDidChangeSize(::LayoutField * layoutFi
}
TextFieldDelegateApp * EditExpressionController::textFieldDelegateApp() {
return (App *)app();
return app();
}
ExpressionFieldDelegateApp * EditExpressionController::expressionFieldDelegateApp() {
return (App *)app();
return app();
}
void EditExpressionController::reloadView() {
@@ -126,14 +126,13 @@ void EditExpressionController::reloadView() {
bool EditExpressionController::inputViewDidReceiveEvent(Ion::Events::Event event, bool shouldDuplicateLastCalculation) {
if (shouldDuplicateLastCalculation && m_cacheBuffer[0] != 0) {
App * calculationApp = (App *)app();
/* The input text store in m_cacheBuffer might have beed correct the first
* time but then be too long when replacing ans in another context */
if (!calculationApp->isAcceptableText(m_cacheBuffer)) {
calculationApp->displayWarning(I18n::Message::SyntaxError);
if (!app()->isAcceptableText(m_cacheBuffer)) {
app()->displayWarning(I18n::Message::SyntaxError);
return true;
}
m_calculationStore->push(m_cacheBuffer, calculationApp->localContext());
m_calculationStore->push(m_cacheBuffer, app()->localContext());
m_historyController->reload();
((ContentView *)view())->mainView()->scrollToCell(0, m_historyController->numberOfRows()-1);
return true;
@@ -151,14 +150,13 @@ bool EditExpressionController::inputViewDidReceiveEvent(Ion::Events::Event event
bool EditExpressionController::inputViewDidFinishEditing(const char * text, Layout layoutR) {
App * calculationApp = (App *)app();
if (layoutR.isUninitialized()) {
assert(text);
strlcpy(m_cacheBuffer, text, k_cacheBufferSize);
} else {
layoutR.serializeParsedExpression(m_cacheBuffer, k_cacheBufferSize);
}
m_calculationStore->push(m_cacheBuffer, calculationApp->localContext());
m_calculationStore->push(m_cacheBuffer, app()->localContext());
m_historyController->reload();
((ContentView *)view())->mainView()->scrollToCell(0, m_historyController->numberOfRows()-1);
((ContentView *)view())->expressionField()->setEditing(true, true);

View File

@@ -151,8 +151,7 @@ KDCoordinate HistoryController::rowHeight(int j) {
return 0;
}
Calculation * calculation = m_calculationStore->calculationAtIndex(j);
App * calculationApp = (App *)app();
return calculation->height(calculationApp->localContext(), j == selectedRow() && selectedSubviewType() == SubviewType::Output) + 4 * Metric::CommonSmallMargin;
return calculation->height(app()->localContext(), j == selectedRow() && selectedSubviewType() == SubviewType::Output) + 4 * Metric::CommonSmallMargin;
}
int HistoryController::typeAtLocation(int i, int j) {

View File

@@ -75,8 +75,7 @@ void HistoryViewCell::reloadScroll() {
}
void HistoryViewCell::reloadOutputSelection() {
App * calculationApp = (App *)app();
Calculation::DisplayOutput display = m_calculation.displayOutput(calculationApp->localContext());
Calculation::DisplayOutput display = m_calculation.displayOutput(app()->localContext());
/* Select the right output according to the calculation display output. This
* will reload the scroll to display the selected output. */
if (display == Calculation::DisplayOutput::ExactAndApproximate) {
@@ -140,8 +139,7 @@ void HistoryViewCell::setCalculation(Calculation * calculation, bool expanded) {
// Memoization
m_calculation = *calculation;
m_calculationExpanded = expanded;
App * calculationApp = (App *)app();
Calculation::DisplayOutput display = calculation->displayOutput(calculationApp->localContext());
Calculation::DisplayOutput display = calculation->displayOutput(app()->localContext());
m_inputView.setLayout(calculation->createInputLayout());
/* Both output expressions have to be updated at the same time. Otherwise,
* when updating one layout, if the second one still points to a deleted
@@ -151,13 +149,13 @@ void HistoryViewCell::setCalculation(Calculation * calculation, bool expanded) {
if (display == Calculation::DisplayOutput::ExactOnly) {
rightOutputLayout = calculation->createExactOutputLayout();
} else {
rightOutputLayout = calculation->createApproximateOutputLayout(calculationApp->localContext());
rightOutputLayout = calculation->createApproximateOutputLayout(app()->localContext());
if (display == Calculation::DisplayOutput::ExactAndApproximate || (display == Calculation::DisplayOutput::ExactAndApproximateToggle && expanded)) {
leftOutputLayout = calculation->createExactOutputLayout();
}
}
m_scrollableOutputView.setLayouts(rightOutputLayout, leftOutputLayout);
I18n::Message equalMessage = calculation->exactAndApproximateDisplayedOutputsAreEqual(calculationApp->localContext()) == Calculation::EqualSign::Equal ? I18n::Message::Equal : I18n::Message::AlmostEqual;
I18n::Message equalMessage = calculation->exactAndApproximateDisplayedOutputsAreEqual(app()->localContext()) == Calculation::EqualSign::Equal ? I18n::Message::Equal : I18n::Message::AlmostEqual;
m_scrollableOutputView.setEqualMessage(equalMessage);
/* The displayed input and outputs have changed. We need to re-layout the cell

View File

@@ -84,6 +84,10 @@ private:
VariableBoxController m_variableBoxController;
};
inline App * app() {
return static_cast<App *>(::app());
}
}
#endif

View File

@@ -57,7 +57,7 @@ bool ConsoleController::loadPythonEnvironment() {
/* We load functions and variables names in the variable box before running
* any other python code to avoid failling to load functions and variables
* due to memory exhaustion. */
static_cast<App *>(app())->variableBoxController()->loadFunctionsAndVariables();
app()->variableBoxController()->loadFunctionsAndVariables();
return true;
}
@@ -290,7 +290,7 @@ bool ConsoleController::textFieldDidReceiveEvent(TextField * textField, Ion::Eve
return true;
}
}
return static_cast<App *>(app())->textInputDidReceiveEvent(textField, event);
return app()->textInputDidReceiveEvent(textField, event);
}
bool ConsoleController::textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) {

View File

@@ -58,7 +58,7 @@ bool EditorController::textAreaDidReceiveEvent(TextArea * textArea, Ion::Events:
saveScript();
return false;
}
if (static_cast<App *>(app())->textInputDidReceiveEvent(textArea, event)) {
if (app()->textInputDidReceiveEvent(textArea, event)) {
return true;
}
if (event == Ion::Events::EXE) {
@@ -109,13 +109,13 @@ bool EditorController::textAreaDidReceiveEvent(TextArea * textArea, Ion::Events:
}
VariableBoxController * EditorController::variableBoxForInputEventHandler(InputEventHandler * textInput) {
VariableBoxController * varBox = static_cast<App *>(app())->variableBoxController();
VariableBoxController * varBox = app()->variableBoxController();
varBox->loadFunctionsAndVariables();
return varBox;
}
InputEventHandlerDelegateApp * EditorController::inputEventHandlerDelegateApp() {
return static_cast<App *>(app());
return app();
}
StackViewController * EditorController::stackController() {

View File

@@ -36,7 +36,7 @@ MenuController::MenuController(Responder * parentResponder, App * pythonDelegate
}
ConsoleController * MenuController::consoleController() {
return static_cast<App *>(app())->consoleController();
return app()->consoleController();
}
StackViewController * MenuController::stackViewController() {

View File

@@ -33,7 +33,7 @@ void VariableBoxController::didEnterResponderChain(Responder * previousFirstResp
* environment where Python has already been inited. This way, we do not
* deinit Python when leaving the VariableBoxController, so we do not lose the
* environment that was loaded when entering the VariableBoxController. */
assert(static_cast<App *>(app())->pythonIsInited());
assert(app()->pythonIsInited());
}
static bool shouldAddObject(const char * name, int maxLength) {

View File

@@ -52,6 +52,10 @@ private:
InputViewController m_inputViewController;
};
inline App * app() {
return static_cast<App *>(::app());
}
}
#endif

View File

@@ -45,16 +45,14 @@ void CalculationGraphController::reloadBannerView() {
}
Expression::Coordinate2D CalculationGraphController::computeNewPointOfInteresetFromAbscissa(double start, int direction) {
App * myApp = static_cast<App *>(app());
double step = m_graphRange->xGridUnit()/10.0;
step = direction < 0 ? -step : step;
double max = direction > 0 ? m_graphRange->xMax() : m_graphRange->xMin();
return computeNewPointOfInterest(start, step, max, myApp->localContext());
return computeNewPointOfInterest(start, step, max, app()->localContext());
}
CartesianFunctionStore * CalculationGraphController::functionStore() const {
App * a = static_cast<App *>(app());
return a->functionStore();
return app()->functionStore();
}
bool CalculationGraphController::handleLeftRightEvent(Ion::Events::Event event) {

View File

@@ -7,7 +7,7 @@ namespace Graph {
static inline float maxFloat(float x, float y) { return x > y ? x : y; }
GraphController::GraphController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, CartesianFunctionStore * functionStore, Shared::InteractiveCurveViewRange * curveViewRange, CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Poincare::Preferences::AngleUnit * angleUnitVersion, ButtonRowController * header) :
GraphController::GraphController(Responder * parentResponder, ::InputEventHandlerDelegate * inputEventHandlerDelegate, CartesianFunctionStore * functionStore, Shared::InteractiveCurveViewRange * curveViewRange, CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Poincare::Preferences::AngleUnit * angleUnitVersion, ButtonRowController * header) :
FunctionGraphController(parentResponder, inputEventHandlerDelegate, header, curveViewRange, &m_view, cursor, indexFunctionSelectedByCursor, modelVersion, rangeVersion, angleUnitVersion),
m_bannerView(this, inputEventHandlerDelegate, this),
m_view(functionStore, curveViewRange, m_cursor, &m_bannerView, &m_cursorView),
@@ -43,10 +43,9 @@ void GraphController::setDisplayDerivativeInBanner(bool displayDerivative) {
float GraphController::interestingXHalfRange() const {
float characteristicRange = 0.0f;
TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app();
for (int i = 0; i < functionStore()->numberOfActiveFunctions(); i++) {
ExpiringPointer<CartesianFunction> f = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(i));
float fRange = f->expressionReduced(myApp->localContext()).characteristicXRange(*(myApp->localContext()), Poincare::Preferences::sharedPreferences()->angleUnit());
float fRange = f->expressionReduced(app()->localContext()).characteristicXRange(*(app()->localContext()), Poincare::Preferences::sharedPreferences()->angleUnit());
if (!std::isnan(fRange)) {
characteristicRange = maxFloat(fRange, characteristicRange);
}
@@ -74,14 +73,12 @@ void GraphController::reloadBannerView() {
return;
}
Ion::Storage::Record record = functionStore()->activeRecordAtIndex(indexFunctionSelectedByCursor());
App * myApp = static_cast<App *>(app());
reloadDerivativeInBannerViewForCursorOnFunction(m_cursor, record, myApp);
reloadDerivativeInBannerViewForCursorOnFunction(m_cursor, record, app());
}
bool GraphController::moveCursorHorizontally(int direction) {
Ion::Storage::Record record = functionStore()->activeRecordAtIndex(indexFunctionSelectedByCursor());
App * myApp = static_cast<App *>(app());
return privateMoveCursorHorizontally(m_cursor, direction, m_graphRange, k_numberOfCursorStepsInGradUnit, record, myApp);
return privateMoveCursorHorizontally(m_cursor, direction, m_graphRange, k_numberOfCursorStepsInGradUnit, record, app());
}
InteractiveCurveViewRange * GraphController::interactiveCurveViewRange() {

View File

@@ -15,7 +15,7 @@ namespace Graph {
class GraphController : public Shared::FunctionGraphController, public GraphControllerHelper {
public:
GraphController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, CartesianFunctionStore * functionStore, Shared::InteractiveCurveViewRange * curveViewRange, Shared::CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Poincare::Preferences::AngleUnit * angleUnitVersion, ButtonRowController * header);
GraphController(Responder * parentResponder, ::InputEventHandlerDelegate * inputEventHandlerDelegate, CartesianFunctionStore * functionStore, Shared::InteractiveCurveViewRange * curveViewRange, Shared::CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Poincare::Preferences::AngleUnit * angleUnitVersion, ButtonRowController * header);
I18n::Message emptyMessage() override;
void viewWillAppear() override;
bool displayDerivativeInBanner() const;

View File

@@ -43,8 +43,7 @@ bool TangentGraphController::textFieldDidFinishEditing(TextField * textField, co
if (textFieldDelegateApp()->hasUndefinedValue(text, floatBody)) {
return false;
}
App * myApp = static_cast<App *>(app());
ExpiringPointer<CartesianFunction> function = myApp->functionStore()->modelForRecord(m_record);
ExpiringPointer<CartesianFunction> function = app()->functionStore()->modelForRecord(m_record);
double y = function->evaluateAtAbscissa(floatBody, textFieldDelegateApp()->localContext());
m_cursor->moveTo(floatBody, y);
interactiveCurveViewRange()->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio);
@@ -62,29 +61,27 @@ void TangentGraphController::reloadBannerView() {
if (m_record.isNull()) {
return;
}
App * myApp = static_cast<App *>(app());
FunctionBannerDelegate::reloadBannerViewForCursorOnFunction(m_cursor, m_record, myApp->functionStore(), CartesianFunction::Symbol());
GraphControllerHelper::reloadDerivativeInBannerViewForCursorOnFunction(m_cursor, m_record, myApp);
FunctionBannerDelegate::reloadBannerViewForCursorOnFunction(m_cursor, m_record, app()->functionStore(), CartesianFunction::Symbol());
GraphControllerHelper::reloadDerivativeInBannerViewForCursorOnFunction(m_cursor, m_record, app());
constexpr size_t bufferSize = FunctionBannerDelegate::k_maxNumberOfCharacters+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits);
char buffer[bufferSize];
const char * legend = "a=";
int legendLength = strlcpy(buffer, legend, bufferSize);
ExpiringPointer<CartesianFunction> function = myApp->functionStore()->modelForRecord(m_record);
double y = function->approximateDerivative(m_cursor->x(), myApp->localContext());
ExpiringPointer<CartesianFunction> function = app()->functionStore()->modelForRecord(m_record);
double y = function->approximateDerivative(m_cursor->x(), app()->localContext());
PoincareHelpers::ConvertFloatToText<double>(y, buffer + legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits);
m_bannerView->aView()->setText(buffer);
legend = "b=";
legendLength = strlcpy(buffer, legend, bufferSize);
y = -y*m_cursor->x()+function->evaluateAtAbscissa(m_cursor->x(), myApp->localContext());
y = -y*m_cursor->x()+function->evaluateAtAbscissa(m_cursor->x(), app()->localContext());
PoincareHelpers::ConvertFloatToText<double>(y, buffer + legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits);
m_bannerView->bView()->setText(buffer);
m_bannerView->reload();
}
bool TangentGraphController::moveCursorHorizontally(int direction) {
App * myApp = static_cast<App *>(app());
return privateMoveCursorHorizontally(m_cursor, direction, m_graphRange, k_numberOfCursorStepsInGradUnit, m_record, myApp);
return privateMoveCursorHorizontally(m_cursor, direction, m_graphRange, k_numberOfCursorStepsInGradUnit, m_record, app());
}
bool TangentGraphController::handleEnter() {

View File

@@ -189,4 +189,8 @@ void ListController::setFunctionNameInTextField(ExpiringPointer<Function> functi
textField->setText(bufferName);
}
Shared::TextFieldDelegateApp * ListController::textFieldDelegateApp() {
return app();
}
}

View File

@@ -29,9 +29,7 @@ private:
HighlightCell * expressionCells(int index) override;
void willDisplayTitleCellAtIndex(HighlightCell * cell, int j) override;
void willDisplayExpressionCellAtIndex(HighlightCell * cell, int j) override;
Shared::TextFieldDelegateApp * textFieldDelegateApp() override {
return static_cast<Shared::TextFieldDelegateApp *>(app());
}
Shared::TextFieldDelegateApp * textFieldDelegateApp() override;
void setFunctionNameInTextField(Shared::ExpiringPointer<Shared::Function> function, TextField * textField);
TextFieldFunctionTitleCell m_functionTitleCells[k_maxNumberOfDisplayableRows];
Shared::FunctionExpressionCell m_expressionCells[k_maxNumberOfDisplayableRows];

View File

@@ -82,8 +82,7 @@ KDCoordinate DerivativeParameterController::cellHeight() {
}
CartesianFunctionStore * DerivativeParameterController::functionStore() {
App * a = static_cast<App *>(app());
return a->functionStore();
return app()->functionStore();
}
}

View File

@@ -70,8 +70,7 @@ void FunctionParameterController::willDisplayCellForIndex(HighlightCell * cell,
}
ExpiringPointer<CartesianFunction> FunctionParameterController::function() {
App * a = static_cast<App *>(app());
return a->functionStore()->modelForRecord(m_record);
return app()->functionStore()->modelForRecord(m_record);
}
}

View File

@@ -1,6 +1,7 @@
#include "values_controller.h"
#include <assert.h>
#include "../../constant.h"
#include "../app.h"
using namespace Shared;
using namespace Poincare;
@@ -142,15 +143,14 @@ FunctionParameterController * ValuesController::functionParameterController() {
}
double ValuesController::evaluationOfAbscissaAtColumn(double abscissa, int columnIndex) {
TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app();
bool isDerivative = isDerivativeColumn(columnIndex);
/* isDerivativeColumn uses expiring pointers, so "function" must be created
* after the isDerivativeColumn call, else it will expire. */
Shared::ExpiringPointer<CartesianFunction> function = functionStore()->modelForRecord(recordAtColumn(columnIndex));
if (isDerivative) {
return function->approximateDerivative(abscissa, myApp->localContext());
return function->approximateDerivative(abscissa, app()->localContext());
}
return function->evaluateAtAbscissa(abscissa, myApp->localContext());
return function->evaluateAtAbscissa(abscissa, app()->localContext());
}
void ValuesController::updateNumberOfColumns() {

View File

@@ -63,7 +63,7 @@ private:
StackViewController m_stackViewController;
};
App * app() {
inline App * app() {
return static_cast<App *>(::app());
}

View File

@@ -57,6 +57,10 @@ private:
RegressionController m_regressionController;
};
inline App * app() {
return static_cast<App *>(::app());
}
}
#endif

View File

@@ -42,7 +42,7 @@ void GraphOptionsController::viewWillAppear() {
bool GraphOptionsController::handleEvent(Ion::Events::Event event) {
if (event == Ion::Events::OK || event == Ion::Events::EXE || event == Ion::Events::Right) {
if (selectedRow() == numberOfRows() -1) {
RegressionController * regressionController = static_cast<Regression::App *>(app())->regressionController();
RegressionController * regressionController = app()->regressionController();
regressionController->setSeries(m_graphController->selectedSeriesIndex());
StackViewController * stack = static_cast<StackViewController *>(parentResponder());
stack->push(regressionController);

View File

@@ -20,7 +20,7 @@ void StoreParameterController::viewWillAppear() {
bool StoreParameterController::handleEvent(Ion::Events::Event event) {
if ((event == Ion::Events::OK || event == Ion::Events::EXE || event == Ion::Events::Right) && selectedRow() == numberOfRows() - 1) {
RegressionController * regressionController = static_cast<Regression::App *>(app())->regressionController();
RegressionController * regressionController = app()->regressionController();
regressionController->setSeries(m_series);
StackViewController * stack = static_cast<StackViewController *>(parentResponder());
stack->push(regressionController);

View File

@@ -58,6 +58,10 @@ private:
InputViewController m_inputViewController;
};
inline App * app() {
return static_cast<App *>(::app());
}
}
#endif

View File

@@ -1,6 +1,7 @@
#include "graph_controller.h"
#include <cmath>
#include <limits.h>
#include "../app.h"
using namespace Shared;
using namespace Poincare;
@@ -10,7 +11,7 @@ namespace Sequence {
static inline int minInt(int x, int y) { return (x < y ? x : y); }
static inline int maxInt(int x, int y) { return (x > y ? x : y); }
GraphController::GraphController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, SequenceStore * sequenceStore, CurveViewRange * graphRange, CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Preferences::AngleUnit * angleUnitVersion, ButtonRowController * header) :
GraphController::GraphController(Responder * parentResponder, ::InputEventHandlerDelegate * inputEventHandlerDelegate, SequenceStore * sequenceStore, CurveViewRange * graphRange, CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Preferences::AngleUnit * angleUnitVersion, ButtonRowController * header) :
FunctionGraphController(parentResponder, inputEventHandlerDelegate, header, graphRange, &m_view, cursor, indexFunctionSelectedByCursor, modelVersion, rangeVersion, angleUnitVersion),
m_bannerView(this, inputEventHandlerDelegate, this),
m_view(sequenceStore, graphRange, m_cursor, &m_bannerView, &m_cursorView),
@@ -95,8 +96,7 @@ bool GraphController::moveCursorHorizontally(int direction) {
return false;
}
Sequence * s = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(indexFunctionSelectedByCursor()));
TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app();
double y = s->evaluateAtAbscissa(x, myApp->localContext());
double y = s->evaluateAtAbscissa(x, app()->localContext());
m_cursor->moveTo(x, y);
return true;
}

View File

@@ -14,7 +14,7 @@ namespace Sequence {
class GraphController final : public Shared::FunctionGraphController {
public:
GraphController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, SequenceStore * sequenceStore, CurveViewRange * graphRange, Shared::CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Poincare::Preferences::AngleUnit * angleUnitVersion, ButtonRowController * header);
GraphController(Responder * parentResponder, ::InputEventHandlerDelegate * inputEventHandlerDelegate, SequenceStore * sequenceStore, CurveViewRange * graphRange, Shared::CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Poincare::Preferences::AngleUnit * angleUnitVersion, ButtonRowController * header);
I18n::Message emptyMessage() override;
void viewWillAppear() override;
TermSumController * termSumController() { return &m_termSumController; }

View File

@@ -107,10 +107,9 @@ void ListController::editExpression(int sequenceDefinition, Ion::Events::Event e
// Replace UCodePointUnknownN with 'n'
replaceUnknownSymbolWithReadableSymbol(initialText);
}
App * myApp = (App *)app();
InputViewController * inputController = myApp->inputViewController();
InputViewController * inputController = app()->inputViewController();
// Invalidate the sequences context cache
static_cast<App *>(app())->localContext()->resetCache();
app()->localContext()->resetCache();
switch (sequenceDefinition) {
case 0:
inputController->edit(this, event, this, initialText,
@@ -160,15 +159,15 @@ bool ListController::editInitialConditionOfSelectedRecordWithText(const char * t
}
TextFieldDelegateApp * ListController::textFieldDelegateApp() {
return (App *)app();
return app();
}
ExpressionFieldDelegateApp * ListController::expressionFieldDelegateApp() {
return (App *)app();
return app();
}
InputEventHandlerDelegateApp * ListController::inputEventHandlerDelegateApp() {
return (App *)app();
return app();
}
ListParameterController * ListController::parameterController() {
@@ -280,7 +279,7 @@ void ListController::editExpression(Ion::Events::Event event) {
void ListController::reinitSelectedExpression(ExpiringPointer<ExpressionModelHandle> model) {
// Invalidate the sequences context cache
static_cast<App *>(app())->localContext()->resetCache();
app()->localContext()->resetCache();
Sequence * sequence = static_cast<Sequence *>(model.pointer());
switch (sequenceDefinitionForRow(selectedRow())) {
case 1:
@@ -308,7 +307,7 @@ void ListController::reinitSelectedExpression(ExpiringPointer<ExpressionModelHan
bool ListController::removeModelRow(Ion::Storage::Record record) {
Shared::FunctionListController::removeModelRow(record);
// Invalidate the sequences context cache
static_cast<App *>(app())->localContext()->resetCache();
app()->localContext()->resetCache();
return true;
}

View File

@@ -56,7 +56,7 @@ bool ListParameterController::handleEvent(Ion::Events::Event event) {
#else
if (selectedRowIndex == 2+hasAdditionalRow) {
#endif
static_cast<App *>(app())->localContext()->resetCache();
app()->localContext()->resetCache();
return handleEnterOnRow(selectedRowIndex-hasAdditionalRow-1);
}
}
@@ -82,7 +82,7 @@ bool ListParameterController::textFieldDidFinishEditing(TextField * textField, c
}
sequence()->setInitialRank(index);
// Invalidate sequence context cache when changing sequence type
static_cast<App *>(app())->localContext()->resetCache();
app()->localContext()->resetCache();
m_selectableTableView.reloadCellAtLocation(0, selectedRow());
m_selectableTableView.handleEvent(event);
return true;
@@ -149,7 +149,7 @@ void ListParameterController::willDisplayCellForIndex(HighlightCell * cell, int
}
TextFieldDelegateApp * ListParameterController::textFieldDelegateApp() {
return (TextFieldDelegateApp *)app();
return app();
}
int ListParameterController::totalNumberOfCells() const {

View File

@@ -60,7 +60,7 @@ bool TypeParameterController::handleEvent(Ion::Events::Event event) {
m_listController->selectPreviousNewSequenceCell();
sequence()->setType(sequenceType);
// Invalidate sequence context cache when changing sequence type
static_cast<App *>(app())->localContext()->resetCache();
app()->localContext()->resetCache();
// Reset the first index if the new type is "Explicit"
if (sequenceType == Sequence::Type::Explicit) {
sequence()->setInitialRank(0);
@@ -135,8 +135,7 @@ void TypeParameterController::setRecord(Ion::Storage::Record record) {
}
SequenceStore * TypeParameterController::sequenceStore() {
App * a = static_cast<App *>(app());
return a->functionStore();
return app()->functionStore();
}
StackViewController * TypeParameterController::stackController() const {

View File

@@ -25,7 +25,7 @@ private:
StackViewController m_stackViewController;
};
App * app() {
inline App * app() {
return static_cast<App *>(::app());
}

View File

@@ -45,6 +45,10 @@ private:
InputViewController m_inputViewController;
};
inline App * app() {
return static_cast<App *>(::app());
}
}
#endif

View File

@@ -103,9 +103,8 @@ bool IntervalController::textFieldDidFinishEditing(TextField * textField, const
void IntervalController::buttonAction() {
StackViewController * stack = stackController();
App * solverApp = static_cast<App *>(app());
m_equationStore->approximateSolve(solverApp->localContext());
stack->push(solverApp->solutionsControllerStack(), KDColorWhite, Palette::SubTab, Palette::SubTab);
m_equationStore->approximateSolve(app()->localContext());
stack->push(app()->solutionsControllerStack(), KDColorWhite, Palette::SubTab, Palette::SubTab);
}
}

View File

@@ -175,7 +175,7 @@ void ListController::resolveEquations() {
app()->displayWarning(I18n::Message::EnterEquation);
return;
}
EquationStore::Error e = m_equationStore->exactSolve(static_cast<App *>(app())->localContext());
EquationStore::Error e = m_equationStore->exactSolve(app()->localContext());
switch (e) {
case EquationStore::Error::EquationUndefined:
app()->displayWarning(I18n::Message::UndefinedEquation);
@@ -192,16 +192,14 @@ void ListController::resolveEquations() {
case EquationStore::Error::RequireApproximateSolution:
{
StackViewController * stack = stackController();
App * solverApp = static_cast<App *>(app());
stack->push(solverApp->intervalController(), KDColorWhite, Palette::PurpleBright, Palette::PurpleBright);
stack->push(app()->intervalController(), KDColorWhite, Palette::PurpleBright, Palette::PurpleBright);
return;
}
default:
{
assert(e == EquationStore::Error::NoError);
StackViewController * stack = stackController();
App * solverApp = static_cast<App *>(app());
stack->push(solverApp->solutionsControllerStack(), KDColorWhite, Palette::PurpleBright, Palette::PurpleBright);
stack->push(app()->solutionsControllerStack(), KDColorWhite, Palette::PurpleBright, Palette::PurpleBright);
}
}
}
@@ -231,11 +229,11 @@ SelectableTableView * ListController::selectableTableView() {
}
Shared::TextFieldDelegateApp * ListController::textFieldDelegateApp() {
return static_cast<App *>(app());
return app();
}
Shared::ExpressionFieldDelegateApp * ListController::expressionFieldDelegateApp() {
return static_cast<App *>(app());
return app();
}
StackViewController * ListController::stackController() const {
@@ -243,7 +241,7 @@ StackViewController * ListController::stackController() const {
}
InputViewController * ListController::inputController() {
return static_cast<App *>(app())->inputViewController();
return app()->inputViewController();
}
}

View File

@@ -105,11 +105,10 @@ View * SolutionsController::view() {
void SolutionsController::viewWillAppear() {
ViewController::viewWillAppear();
App * solverApp = static_cast<App *>(app());
bool requireWarning = false;
if (m_equationStore->type() == EquationStore::Type::Monovariable) {
m_contentView.setWarningMessages(I18n::Message::OnlyFirstSolutionsDisplayed0, I18n::Message::OnlyFirstSolutionsDisplayed1);
requireWarning = m_equationStore->haveMoreApproximationSolutions(solverApp->localContext());
requireWarning = m_equationStore->haveMoreApproximationSolutions(app()->localContext());
} else if (m_equationStore->type() == EquationStore::Type::PolynomialMonovariable && m_equationStore->numberOfSolutions() == 1) {
assert(Preferences::sharedPreferences()->complexFormat() == Preferences::ComplexFormat::Real);
m_contentView.setWarningMessages(I18n::Message::PolynomeHasNoRealSolution0, I18n::Message::PolynomeHasNoRealSolution1);

View File

@@ -47,7 +47,7 @@ private:
static Container * s_sharedContainer;
};
App * app() {
inline App * app() {
return Container::sharedContainer()->activeApp();
}