From 266482ef99783b7002e09be59bf44c24d6da57d4 Mon Sep 17 00:00:00 2001 From: Ruben Dashyan Date: Thu, 5 Mar 2020 17:30:16 +0100 Subject: [PATCH] [apps/calculation] Additional outputs for Unit --- apps/calculation/Makefile | 1 + .../unit_list_controller.cpp | 32 +++++++++++++++++++ .../additional_outputs/unit_list_controller.h | 22 +++++++++++++ apps/calculation/calculation.cpp | 5 +-- apps/calculation/history_controller.cpp | 5 ++- apps/calculation/history_controller.h | 2 ++ 6 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 apps/calculation/additional_outputs/unit_list_controller.cpp create mode 100644 apps/calculation/additional_outputs/unit_list_controller.h diff --git a/apps/calculation/Makefile b/apps/calculation/Makefile index ef4c9d36d..a2de2432c 100644 --- a/apps/calculation/Makefile +++ b/apps/calculation/Makefile @@ -21,6 +21,7 @@ app_calculation_src = $(addprefix apps/calculation/,\ additional_outputs/trigonometry_graph_cell.cpp \ additional_outputs/trigonometry_list_controller.cpp \ additional_outputs/trigonometry_model.cpp \ + additional_outputs/unit_list_controller.cpp \ app.cpp \ edit_expression_controller.cpp \ expression_field.cpp \ diff --git a/apps/calculation/additional_outputs/unit_list_controller.cpp b/apps/calculation/additional_outputs/unit_list_controller.cpp new file mode 100644 index 000000000..fe4e61d84 --- /dev/null +++ b/apps/calculation/additional_outputs/unit_list_controller.cpp @@ -0,0 +1,32 @@ +#include "unit_list_controller.h" +#include "../app.h" +#include "../../shared/poincare_helpers.h" + +namespace Calculation { + +int UnitListController::numberOfRows() const { //FIXME + return 2; +} + +void UnitListController::computeLayoutAtIndex(int index) { //FIXME + Poincare::Expression expressionAtIndex; + if (index == 0) { + expressionAtIndex = m_expression; + } else { + assert(index == 1); + Poincare::ExpressionNode::ReductionContext reductionContext( + App::app()->localContext(), + Poincare::Preferences::sharedPreferences()->complexFormat(), + Poincare::Preferences::sharedPreferences()->angleUnit(), + Poincare::ExpressionNode::ReductionTarget::SystemForApproximation, + Poincare::ExpressionNode::SymbolicComputation::ReplaceAllSymbolsWithDefinitionsOrUndefined); + expressionAtIndex = m_expression.reduce(reductionContext); + } + m_layouts[index] = Shared::PoincareHelpers::CreateLayout(expressionAtIndex); +} + +I18n::Message UnitListController::messageAtIndex(int index) { + return (I18n::Message)0; +} + +} diff --git a/apps/calculation/additional_outputs/unit_list_controller.h b/apps/calculation/additional_outputs/unit_list_controller.h new file mode 100644 index 000000000..1e9d168bd --- /dev/null +++ b/apps/calculation/additional_outputs/unit_list_controller.h @@ -0,0 +1,22 @@ +#ifndef CALCULATION_ADDITIONAL_OUTPUTS_UNIT_LIST_CONTROLLER_H +#define CALCULATION_ADDITIONAL_OUTPUTS_UNIT_LIST_CONTROLLER_H + +#include "expressions_list_controller.h" + +namespace Calculation { + +class UnitListController : public ExpressionsListController { +public: + UnitListController(EditExpressionController * editExpressionController) : + ExpressionsListController(editExpressionController) {} + + //ListViewDataSource + int numberOfRows() const override; +private: + void computeLayoutAtIndex(int index) override; + I18n::Message messageAtIndex(int index) override; +}; + +} + +#endif diff --git a/apps/calculation/calculation.cpp b/apps/calculation/calculation.cpp index fe3f09f2f..3393e9f2e 100644 --- a/apps/calculation/calculation.cpp +++ b/apps/calculation/calculation.cpp @@ -250,8 +250,9 @@ Calculation::AdditionalInformationType Calculation::additionalInformationType(Co if (input().isDefinedCosineOrSine(context, complexFormat, preferences->angleUnit()) || o.isDefinedCosineOrSine(context, complexFormat, preferences->angleUnit())) { return AdditionalInformationType::Trigonometry; } - - // TODO: return AdditionalInformationType::Unit + if (o.hasUnit()) { + return AdditionalInformationType::Unit; + } if (o.isBasedIntegerCappedBy(k_maximalIntegerWithAdditionalInformation)) { return AdditionalInformationType::Integer; } diff --git a/apps/calculation/history_controller.cpp b/apps/calculation/history_controller.cpp index cafa5c4cd..694374f02 100644 --- a/apps/calculation/history_controller.cpp +++ b/apps/calculation/history_controller.cpp @@ -15,7 +15,8 @@ HistoryController::HistoryController(EditExpressionController * editExpressionCo m_complexController(editExpressionController), m_integerController(editExpressionController), m_rationalController(editExpressionController), - m_trigonometryController(editExpressionController) + m_trigonometryController(editExpressionController), + m_unitController(editExpressionController) { for (int i = 0; i < k_maxNumberOfDisplayedRows; i++) { m_calculationHistory[i].setParentResponder(&m_selectableTableView); @@ -106,6 +107,8 @@ bool HistoryController::handleEvent(Ion::Events::Event event) { vc = &m_integerController; } else if (additionalInfoType == Calculation::AdditionalInformationType::Rational) { vc = &m_rationalController; + } else if (additionalInfoType == Calculation::AdditionalInformationType::Unit) { + vc = &m_unitController; } if (vc) { vc->setExpression(e); diff --git a/apps/calculation/history_controller.h b/apps/calculation/history_controller.h index 606637edb..2cb20840a 100644 --- a/apps/calculation/history_controller.h +++ b/apps/calculation/history_controller.h @@ -9,6 +9,7 @@ #include "additional_outputs/integer_list_controller.h" #include "additional_outputs/rational_list_controller.h" #include "additional_outputs/trigonometry_list_controller.h" +#include "additional_outputs/unit_list_controller.h" namespace Calculation { @@ -45,6 +46,7 @@ private: IntegerListController m_integerController; RationalListController m_rationalController; TrigonometryListController m_trigonometryController; + UnitListController m_unitController; }; }