[apps] Replace app() by textFieldDelegateApp() in TextFieldDelegates

This commit is contained in:
Ruben Dashyan
2019-07-18 18:14:33 +02:00
committed by EmilieNumworks
parent 28f713e905
commit 3e992a3560
13 changed files with 35 additions and 32 deletions

View File

@@ -69,7 +69,7 @@ bool EditExpressionController::textFieldDidReceiveEvent(::TextField * textField,
if (inputViewDidReceiveEvent(event, shouldDuplicateLastCalculation)) {
return true;
}
return app()->textFieldDidReceiveEvent(textField, event);
return textFieldDelegateApp()->textFieldDidReceiveEvent(textField, event);
}
bool EditExpressionController::textFieldDidFinishEditing(::TextField * textField, const char * text, Ion::Events::Event event) {
@@ -120,10 +120,11 @@ bool EditExpressionController::inputViewDidReceiveEvent(Ion::Events::Event event
if (shouldDuplicateLastCalculation && m_cacheBuffer[0] != 0) {
/* 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 (!app()->isAcceptableText(m_cacheBuffer)) {
Shared::TextFieldDelegateApp * myApp = textFieldDelegateApp();
if (!myApp->isAcceptableText(m_cacheBuffer)) {
return true;
}
m_calculationStore->push(m_cacheBuffer, app()->localContext());
m_calculationStore->push(m_cacheBuffer, myApp->localContext());
m_historyController->reload();
((ContentView *)view())->mainView()->scrollToCell(0, m_historyController->numberOfRows()-1);
return true;
@@ -147,7 +148,7 @@ bool EditExpressionController::inputViewDidFinishEditing(const char * text, Layo
} else {
layoutR.serializeParsedExpression(m_cacheBuffer, k_cacheBufferSize);
}
m_calculationStore->push(m_cacheBuffer, app()->localContext());
m_calculationStore->push(m_cacheBuffer, textFieldDelegateApp()->localContext());
m_historyController->reload();
((ContentView *)view())->mainView()->scrollToCell(0, m_historyController->numberOfRows()-1);
((ContentView *)view())->expressionField()->setEditing(true, true);

View File

@@ -48,7 +48,7 @@ Expression::Coordinate2D CalculationGraphController::computeNewPointOfInteresetF
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, app()->localContext());
return computeNewPointOfInterest(start, step, max, textFieldDelegateApp()->localContext());
}
CartesianFunctionStore * CalculationGraphController::functionStore() const {

View File

@@ -43,9 +43,10 @@ void GraphController::setDisplayDerivativeInBanner(bool displayDerivative) {
float GraphController::interestingXHalfRange() const {
float characteristicRange = 0.0f;
Poincare::Context * context = textFieldDelegateApp()->localContext();
for (int i = 0; i < functionStore()->numberOfActiveFunctions(); i++) {
ExpiringPointer<CartesianFunction> f = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(i));
float fRange = f->expressionReduced(app()->localContext()).characteristicXRange(*(app()->localContext()), Poincare::Preferences::sharedPreferences()->angleUnit());
float fRange = f->expressionReduced(context).characteristicXRange(*context, Poincare::Preferences::sharedPreferences()->angleUnit());
if (!std::isnan(fRange)) {
characteristicRange = maxFloat(fRange, characteristicRange);
}

View File

@@ -33,18 +33,19 @@ void TangentGraphController::viewWillAppear() {
void TangentGraphController::didBecomeFirstResponder() {
if (curveView()->isMainViewSelected()) {
m_bannerView->abscissaValue()->setParentResponder(this);
m_bannerView->abscissaValue()->setDelegates(app(), this);
m_bannerView->abscissaValue()->setDelegates(textFieldDelegateApp(), this);
app()->setFirstResponder(m_bannerView->abscissaValue());
}
}
bool TangentGraphController::textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) {
Shared::TextFieldDelegateApp * myApp = textFieldDelegateApp();
double floatBody;
if (app()->hasUndefinedValue(text, floatBody)) {
if (myApp->hasUndefinedValue(text, floatBody)) {
return false;
}
ExpiringPointer<CartesianFunction> function = app()->functionStore()->modelForRecord(m_record);
double y = function->evaluateAtAbscissa(floatBody, app()->localContext());
double y = function->evaluateAtAbscissa(floatBody, myApp->localContext());
m_cursor->moveTo(floatBody, y);
interactiveCurveViewRange()->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio);
reloadBannerView();
@@ -65,16 +66,18 @@ void TangentGraphController::reloadBannerView() {
GraphControllerHelper::reloadDerivativeInBannerViewForCursorOnFunction(m_cursor, m_record);
constexpr size_t bufferSize = FunctionBannerDelegate::k_maxNumberOfCharacters+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits);
char buffer[bufferSize];
Poincare::Context * context = textFieldDelegateApp()->localContext();
const char * legend = "a=";
int legendLength = strlcpy(buffer, legend, bufferSize);
ExpiringPointer<CartesianFunction> function = app()->functionStore()->modelForRecord(m_record);
double y = function->approximateDerivative(m_cursor->x(), app()->localContext());
double y = function->approximateDerivative(m_cursor->x(), context);
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(), app()->localContext());
y = -y*m_cursor->x()+function->evaluateAtAbscissa(m_cursor->x(), context);
PoincareHelpers::ConvertFloatToText<double>(y, buffer + legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits);
m_bannerView->bView()->setText(buffer);
m_bannerView->reload();

View File

@@ -147,10 +147,11 @@ double ValuesController::evaluationOfAbscissaAtColumn(double abscissa, int colum
/* 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));
Poincare::Context * context = textFieldDelegateApp()->localContext();
if (isDerivative) {
return function->approximateDerivative(abscissa, app()->localContext());
return function->approximateDerivative(abscissa, context);
}
return function->evaluateAtAbscissa(abscissa, app()->localContext());
return function->evaluateAtAbscissa(abscissa, context);
}
void ValuesController::updateNumberOfColumns() {

View File

@@ -211,7 +211,7 @@ bool CalculationController::textFieldShouldFinishEditing(TextField * textField,
bool CalculationController::textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) {
double floatBody;
if (app()->hasUndefinedValue(text, floatBody)) {
if (textFieldDelegateApp()->hasUndefinedValue(text, floatBody)) {
return false;
}
if (m_calculation->type() != Calculation::Type::FiniteIntegral && selectedColumn() == 2) {

View File

@@ -61,12 +61,13 @@ float GraphController::interestingXHalfRange() const {
}
bool GraphController::textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) {
Shared::TextFieldDelegateApp * myApp = textFieldDelegateApp();
double floatBody;
if (app()->hasUndefinedValue(text, floatBody)) {
if (myApp->hasUndefinedValue(text, floatBody)) {
return false;
}
floatBody = std::fmax(0, std::round(floatBody));
double y = yValue(selectedCurveIndex(), floatBody, app()->localContext());
double y = yValue(selectedCurveIndex(), floatBody, myApp->localContext());
m_cursor->moveTo(floatBody, y);
interactiveCurveViewRange()->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio);
reloadBannerView();
@@ -96,7 +97,7 @@ bool GraphController::moveCursorHorizontally(int direction) {
return false;
}
Sequence * s = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(indexFunctionSelectedByCursor()));
double y = s->evaluateAtAbscissa(x, app()->localContext());
double y = s->evaluateAtAbscissa(x, textFieldDelegateApp()->localContext());
m_cursor->moveTo(x, y);
return true;
}

View File

@@ -72,7 +72,7 @@ bool ListParameterController::textFieldDidFinishEditing(TextField * textField, c
/* -1 to take into account a double recursive sequence, which has
* SecondIndex = FirstIndex + 1 */
double floatBody;
if (app()->hasUndefinedValue(text, floatBody)) {
if (textFieldDelegateApp()->hasUndefinedValue(text, floatBody)) {
return false;
}
int index = std::round(floatBody);

View File

@@ -78,7 +78,7 @@ bool DisplayModeController::textFieldShouldFinishEditing(TextField * textField,
bool DisplayModeController::textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) {
double floatBody;
if (app()->hasUndefinedValue(text, floatBody)) {
if (textFieldDelegateApp()->hasUndefinedValue(text, floatBody)) {
return false;
}
if (floatBody < 1) {

View File

@@ -42,8 +42,7 @@ void FunctionGraphController::viewWillAppear() {
functionGraphView()->setAreaHighlight(NAN,NAN);
if (functionGraphView()->context() == nullptr) {
FunctionApp * myApp = static_cast<FunctionApp *>(app());
functionGraphView()->setContext(myApp->localContext());
functionGraphView()->setContext(textFieldDelegateApp()->localContext());
}
Preferences::AngleUnit newAngleUnitVersion = Preferences::sharedPreferences()->angleUnit();
if (*m_angleUnitVersion != newAngleUnitVersion) {
@@ -74,7 +73,7 @@ void FunctionGraphController::reloadBannerView() {
}
InteractiveCurveViewRangeDelegate::Range FunctionGraphController::computeYRange(InteractiveCurveViewRange * interactiveCurveViewRange) {
FunctionApp * myApp = static_cast<FunctionApp *>(app());
Poincare::Context * context = textFieldDelegateApp()->localContext();
float min = FLT_MAX;
float max = -FLT_MAX;
float xMin = interactiveCurveViewRange->xMin();
@@ -87,13 +86,12 @@ InteractiveCurveViewRangeDelegate::Range FunctionGraphController::computeYRange(
}
for (int i=0; i<functionStore()->numberOfActiveFunctions(); i++) {
ExpiringPointer<Function> f = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(i));
float y = 0.0f;
float res = curveView()->resolution();
/* Scan x-range from the middle to the extrema in order to get balanced
* y-range for even functions (y = 1/x). */
for (int j = -res/2; j <= res/2; j++) {
float x = (xMin+xMax)/2.0+(xMax-xMin)*j/res;
y = f->evaluateAtAbscissa(x, myApp->localContext());
float y = f->evaluateAtAbscissa(x, context);
if (!std::isnan(y) && !std::isinf(y)) {
min = min < y ? min : y;
max = max > y ? max : y;
@@ -116,12 +114,12 @@ FunctionStore * FunctionGraphController::functionStore() const {
void FunctionGraphController::initCursorParameters() {
double x = defaultCursorAbscissa();
FunctionApp * myApp = static_cast<FunctionApp *>(app());
Poincare::Context * context = textFieldDelegateApp()->localContext();
int functionIndex = 0;
double y = 0;
do {
ExpiringPointer<Function> firstFunction = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(functionIndex++));
y = firstFunction->evaluateAtAbscissa(x, myApp->localContext());
y = firstFunction->evaluateAtAbscissa(x, context);
} while ((std::isnan(y) || std::isinf(y)) && functionIndex < functionStore()->numberOfActiveFunctions());
m_cursor->moveTo(x, y);
functionIndex = (std::isnan(y) || std::isinf(y)) ? 0 : functionIndex - 1;
@@ -133,8 +131,7 @@ void FunctionGraphController::initCursorParameters() {
bool FunctionGraphController::moveCursorVertically(int direction) {
int currentActiveFunctionIndex = indexFunctionSelectedByCursor();
Poincare::Context * context = static_cast<FunctionApp *>(app())->localContext();
Poincare::Context * context = textFieldDelegateApp()->localContext();
int nextActiveFunctionIndex = InteractiveCurveViewController::closestCurveIndexVertically(direction > 0, currentActiveFunctionIndex, context);
if (nextActiveFunctionIndex < 0) {
return false;

View File

@@ -327,8 +327,7 @@ int ValuesController::maxNumberOfElements() const {
double ValuesController::evaluationOfAbscissaAtColumn(double abscissa, int columnIndex) {
ExpiringPointer<Function> function = functionStore()->modelForRecord(recordAtColumn(columnIndex));
TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app();
return function->evaluateAtAbscissa(abscissa, myApp->localContext());
return function->evaluateAtAbscissa(abscissa, textFieldDelegateApp()->localContext());
}
void ValuesController::updateNumberOfColumns() {

View File

@@ -103,7 +103,7 @@ bool IntervalController::textFieldDidFinishEditing(TextField * textField, const
void IntervalController::buttonAction() {
StackViewController * stack = stackController();
m_equationStore->approximateSolve(app()->localContext());
m_equationStore->approximateSolve(textFieldDelegateApp()->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(app()->localContext());
EquationStore::Error e = m_equationStore->exactSolve(textFieldDelegateApp()->localContext());
switch (e) {
case EquationStore::Error::EquationUndefined:
app()->displayWarning(I18n::Message::UndefinedEquation);