diff --git a/apps/graph/values/values_controller.cpp b/apps/graph/values/values_controller.cpp index 5df51b57c..7730a4916 100644 --- a/apps/graph/values/values_controller.cpp +++ b/apps/graph/values/values_controller.cpp @@ -23,8 +23,7 @@ ValuesController::ValuesController(Responder * parentResponder, InputEventHandle } bool ValuesController::handleEvent(Ion::Events::Event event) { - if ((event == Ion::Events::OK || event == Ion::Events::EXE) && selectedRow() == 0 - && selectedColumn()>0 && isDerivativeColumn(selectedColumn())) { + if ((event == Ion::Events::OK || event == Ion::Events::EXE) && typeAtLocation(selectedColumn(), selectedRow()) == 1 && isDerivativeColumn(selectedColumn())) { configureDerivativeFunction(); return true; } @@ -34,13 +33,13 @@ bool ValuesController::handleEvent(Ion::Events::Event event) { void ValuesController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) { Shared::ValuesController::willDisplayCellAtLocation(cell, i, j); // The cell is the abscissa title cell: - if (j == 0 && i == 0) { + if (typeAtLocation(i,j) == 0) { EvenOddMessageTextCell * mytitleCell = (EvenOddMessageTextCell *)cell; mytitleCell->setMessage(I18n::Message::X); return; } // The cell is a function title cell: - if (j == 0 && i > 0) { + if (typeAtLocation(i,j) == 1) { Shared::BufferFunctionTitleCell * myFunctionCell = (Shared::BufferFunctionTitleCell *)cell; const size_t bufferNameSize = Shared::Function::k_maxNameWithArgumentSize + 1; char bufferName[bufferNameSize]; @@ -70,7 +69,7 @@ IntervalParameterController * ValuesController::intervalParameterController() { } Ion::Storage::Record ValuesController::recordAtColumn(int i) { - assert(i > 0); + assert(typeAtLocation(i, 0) == 1); int index = 1; for (int k = 0; k < functionStore()->numberOfDefinedModels(); k++) { Ion::Storage::Record record = functionStore()->definedRecordAtIndex(k); @@ -93,7 +92,7 @@ Ion::Storage::Record ValuesController::recordAtColumn(int i) { } bool ValuesController::isDerivativeColumn(int i) { - assert(i >= 1); + assert(typeAtLocation(i, 0) == 1); int index = 1; for (int k = 0; k < functionStore()->numberOfDefinedModels(); k++) { ExpiringPointer f = functionStore()->modelForRecord(functionStore()->definedRecordAtIndex(k)); diff --git a/apps/regression/store_controller.cpp b/apps/regression/store_controller.cpp index 5d237dee0..786b79bd7 100644 --- a/apps/regression/store_controller.cpp +++ b/apps/regression/store_controller.cpp @@ -36,7 +36,7 @@ bool StoreController::fillColumnWithFormula(Expression formula) { void StoreController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) { ::StoreController::willDisplayCellAtLocation(cell, i, j); - if (cellAtLocationIsEditable(i, j)) { + if (typeAtLocation(i, j) != k_titleCellType) { return; } Shared::StoreTitleCell * mytitleCell = static_cast(cell); diff --git a/apps/sequence/values/values_controller.cpp b/apps/sequence/values/values_controller.cpp index 5bb6a3880..6fee9bd80 100644 --- a/apps/sequence/values/values_controller.cpp +++ b/apps/sequence/values/values_controller.cpp @@ -23,13 +23,13 @@ ValuesController::ValuesController(Responder * parentResponder,InputEventHandler void ValuesController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) { Shared::ValuesController::willDisplayCellAtLocation(cell, i, j); // The cell is the abscissa title cell: - if (j == 0 && i == 0) { + if (typeAtLocation(i,j) == 0) { EvenOddMessageTextCell * mytitleCell = (EvenOddMessageTextCell *)cell; mytitleCell->setMessage(I18n::Message::N); return; } // The cell is a function title cell: - if (j == 0 && i > 0) { + if (typeAtLocation(i,j) == 1) { SequenceTitleCell * myCell = (SequenceTitleCell *)cell; Sequence * sequence = functionStore()->modelForRecord(recordAtColumn(i)); myCell->setLayout(sequence->nameLayout()); diff --git a/apps/shared/store_controller.cpp b/apps/shared/store_controller.cpp index 4a9143535..3a99ec424 100644 --- a/apps/shared/store_controller.cpp +++ b/apps/shared/store_controller.cpp @@ -153,7 +153,7 @@ int StoreController::typeAtLocation(int i, int j) { void StoreController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) { // Handle the separator - if (cellAtLocationIsEditable(i, j)) { + if (typeAtLocation(i, j) == k_editableCellType) { bool shouldHaveLeftSeparator = i % DoublePairStore::k_numberOfColumnsPerSeries == 0; static_cast(cell)->setSeparatorLeft(shouldHaveLeftSeparator); } @@ -170,7 +170,7 @@ void StoreController::willDisplayCellAtLocation(HighlightCell * cell, int i, int } return; } - if (cellAtLocationIsEditable(i, j)) { + if (typeAtLocation(i, j) == k_editableCellType) { static_cast(cell)->setHide(false); } willDisplayCellAtLocationWithDisplayMode(cell, i, j, Preferences::PrintFloatMode::Decimal); @@ -220,10 +220,7 @@ Responder * StoreController::tabController() const { } bool StoreController::cellAtLocationIsEditable(int columnIndex, int rowIndex) { - if (rowIndex > 0) { - return true; - } - return false; + return typeAtLocation(columnIndex, rowIndex) == k_editableCellType; } bool StoreController::setDataAtLocation(double floatBody, int columnIndex, int rowIndex) { diff --git a/apps/shared/store_controller.h b/apps/shared/store_controller.h index 11fd68a0f..d5c0de1df 100644 --- a/apps/shared/store_controller.h +++ b/apps/shared/store_controller.h @@ -75,7 +75,6 @@ protected: }; Responder * tabController() const override; - bool cellAtLocationIsEditable(int columnIndex, int rowIndex) override; bool setDataAtLocation(double floatBody, int columnIndex, int rowIndex) override; double dataAtLocation(int columnIndex, int rowIndex) override; virtual HighlightCell * titleCells(int index) = 0; @@ -88,6 +87,7 @@ private: SelectableTableView * selectableTableView() override { return m_contentView.dataView(); } + bool cellAtLocationIsEditable(int columnIndex, int rowIndex) override; int numberOfElementsInColumn(int columnIndex) override; int maxNumberOfElements() const override { return DoublePairStore::k_maxNumberOfPairs; diff --git a/apps/shared/values_controller.cpp b/apps/shared/values_controller.cpp index 0aec8826a..53779c755 100644 --- a/apps/shared/values_controller.cpp +++ b/apps/shared/values_controller.cpp @@ -104,7 +104,7 @@ bool ValuesController::handleEvent(Ion::Events::Event event) { return header()->handleEvent(event); } if ((event == Ion::Events::OK || event == Ion::Events::EXE) && selectedRow() == 0) { - if (selectedColumn() == 0) { + if (typeAtLocation(selectedColumn(), 0) == 0) { configureAbscissa(); return true; } @@ -146,7 +146,7 @@ Button * ValuesController::buttonAtIndex(int index, ButtonRowController::Positio void ValuesController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) { willDisplayCellAtLocationWithDisplayMode(cell, i, j, Preferences::sharedPreferences()->displayMode()); // The cell is not a title cell and not editable - if (j > 0 && i > 0) { + if (typeAtLocation(i,j) == 3) { constexpr int precision = Preferences::LargeNumberOfSignificantDigits; char buffer[PrintFloat::bufferSizeForFloatsWithPrecision(precision)]; // Special case: last row @@ -254,7 +254,7 @@ void ValuesController::viewDidDisappear() { } Ion::Storage::Record ValuesController::recordAtColumn(int i) { - assert(i > 0); + assert(typeAtLocation(i, 0) == 1); return functionStore()->activeRecordAtIndex(i-1); } @@ -286,10 +286,7 @@ void ValuesController::configureFunction() { } bool ValuesController::cellAtLocationIsEditable(int columnIndex, int rowIndex) { - if (rowIndex > 0 && columnIndex == 0) { - return true; - } - return false; + return typeAtLocation(columnIndex, rowIndex) == 2; } bool ValuesController::setDataAtLocation(double floatBody, int columnIndex, int rowIndex) { diff --git a/apps/statistics/store_controller.cpp b/apps/statistics/store_controller.cpp index 9dac9c3fe..5a4c93237 100644 --- a/apps/statistics/store_controller.cpp +++ b/apps/statistics/store_controller.cpp @@ -39,7 +39,7 @@ bool StoreController::fillColumnWithFormula(Expression formula) { void StoreController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) { Shared::StoreController::willDisplayCellAtLocation(cell, i, j); - if (cellAtLocationIsEditable(i, j)) { + if (typeAtLocation(i, j) != k_titleCellType) { return; } Shared::StoreTitleCell * mytitleCell = static_cast(cell);