Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Models / CellFormula.cpp
diff options
context:
space:
mode:
Commit8cd7e44980107a3e205f67834eaea20927c6a0fe (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-05-30 15:52:23 +0300
Committer
 Syndamia <kamen@syndamia.com>
2022-05-30 15:52:23 +0300
Files012f3d4fdd2aaae7575579405f61efe7f85a7dc7 /src/Models/CellFormula.cpp
FMI-OOP-P2_Tables-8cd7e44980107a3e205f67834eaea20927c6a0fe.tar
FMI-OOP-P2_Tables-8cd7e44980107a3e205f67834eaea20927c6a0fe.tar.gz
FMI-OOP-P2_Tables-8cd7e44980107a3e205f67834eaea20927c6a0fe.zip
Parent7571a449b3f90e3f723488f167c25a3d095e0093 (diff)
Started work on making edit work with cells, referenced by formulas
1 files changed, 8 insertions, 7 deletions
-rw-r--r--src/Models/CellFormula.cpp15
diff --git a/src/Models/CellFormula.cpp b/src/Models/CellFormula.cpp
index 1ebc6d6..b3203bc 100644
--- a/src/Models/CellFormula.cpp
+++ b/src/Models/CellFormula.cpp
@@ -13,7 +13,8 @@ double pow(double x, unsigned y) {
}
double CellFormula::calculate(unsigned index) {
- double lval = formula[index].left->getNumeralValue();
+ CellLoc& c = formula[index].left;
+ double lval = (c.firstInd == -1) ? localCells[c.secondInd]->getNumeralValue() : tableCells[c.firstInd][c.secondInd].getNumeralValue();
while (formula[index].right < 0) {
switch (-formula[index++].right) {
@@ -66,21 +67,21 @@ String CellFormula::getValueForPrint() {
void CellFormula::parseAndSetValue(const char* str) {
rawFormula = String(str);
- Cell* cellToAdd;
+ CellLoc cellToAdd;
char currOp;
while (*str != '\0') {
str++;
while (*str == ' ') str++;
if (*str == 'R') {
- unsigned row = atoi(++str);
+ int row = atoi(++str);
while (*str != 'C') str++;
- unsigned col = atoi(++str);
+ int col = atoi(++str);
while (*str != ' ' && *str != '\0') str++;
while (*str == ' ') str++;
currOp = *str;
- cellToAdd = (*tableCells)[row][col];
+ cellToAdd = {row, col};
}
else {
double val = atof(str);
@@ -88,7 +89,7 @@ void CellFormula::parseAndSetValue(const char* str) {
currOp = *str;
localCells.add(CellDouble(val));
- cellToAdd = &localCells[localCells.get_count() - 1];
+ cellToAdd = {-1, (int)(localCells.get_count() - 1)};
}
if (currOp == '^') currOp *= -1;
@@ -100,7 +101,7 @@ void CellFormula::parseAndSetValue(const char* str) {
if (currOp == '-') {
formula.add({cellToAdd, '+'});
localCells.add(CellDouble(-1.0));
- formula.add({&localCells[localCells.get_count() - 1], '*' * -1});
+ formula.add({{-1, (int)(localCells.get_count() - 1)}, '*' * -1});
}
else formula.add({cellToAdd, currOp});
}