From fe20ad7968a7c4d51ffd4d46d7905a59867032a7 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 28 May 2022 18:44:32 +0300 Subject: Autocommit at 28.05.2022 @ 18:44 --- src/Models/CellFormula.cpp | 6 +++++- src/Models/CellFormula.h | 1 + src/Models/CellString.cpp | 9 +++++++-- src/Models/CellString.h | 1 + 4 files changed, 14 insertions(+), 3 deletions(-) (limited to 'src/Models') diff --git a/src/Models/CellFormula.cpp b/src/Models/CellFormula.cpp index 71e4e29..21de3ec 100644 --- a/src/Models/CellFormula.cpp +++ b/src/Models/CellFormula.cpp @@ -2,8 +2,12 @@ #include "CellDouble.h" #include +CellFormula::CellFormula(const char* str) : referencedCells(), formula(), rawFormula() { + parseAndSetValue(str); +} + double CellFormula::calculate(unsigned index) { - double lval = CellDouble(formula[index].left->getValue()).getNumeralValue(); + double lval = formula[index].left->getNumeralValue(); switch(formula[index].right) { case plus: return lval + calculate(index++); diff --git a/src/Models/CellFormula.h b/src/Models/CellFormula.h index 5838b38..688f805 100644 --- a/src/Models/CellFormula.h +++ b/src/Models/CellFormula.h @@ -23,6 +23,7 @@ class CellFormula : public Cell { public: CellFormula() = default; + CellFormula(const char* str); double getNumeralValue() override; String getValueForPrint() override; diff --git a/src/Models/CellString.cpp b/src/Models/CellString.cpp index ffc760c..20eacf4 100644 --- a/src/Models/CellString.cpp +++ b/src/Models/CellString.cpp @@ -1,7 +1,12 @@ #include "CellString.h" +#include -String CellString::getNumeralValue() { - return value; +CellString::CellString(const char* str) { + value = String(str); +} + +double CellString::getNumeralValue() { + return atof(value.get_cstr()); } String CellString::getValueForPrint() { diff --git a/src/Models/CellString.h b/src/Models/CellString.h index ee581e8..f15e904 100644 --- a/src/Models/CellString.h +++ b/src/Models/CellString.h @@ -8,6 +8,7 @@ class CellString : public Cell { public: CellString() = default; + CellString(const char* str); double getNumeralValue() override; String getValueForPrint() override; -- cgit v1.3.1-26-gb76a