From af3d1456e0afbf047b105bbf743b151db08caf12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Thu, 5 Sep 2019 10:24:40 +0200 Subject: [PATCH] [apps/graph] Hideable cells in values controller --- apps/graph/values/values_controller.cpp | 35 ++++++++++++++++--- apps/graph/values/values_controller.h | 3 +- apps/shared/Makefile | 1 + .../hideable_even_odd_buffer_text_cell.cpp | 20 +++++++++++ .../hideable_even_odd_buffer_text_cell.h | 22 ++++++++++++ apps/shared/interval.cpp | 9 ++--- apps/shared/values_controller.h | 2 +- 7 files changed, 81 insertions(+), 11 deletions(-) create mode 100644 apps/shared/hideable_even_odd_buffer_text_cell.cpp create mode 100644 apps/shared/hideable_even_odd_buffer_text_cell.h diff --git a/apps/graph/values/values_controller.cpp b/apps/graph/values/values_controller.cpp index e5caaf444..ebf9d27c2 100644 --- a/apps/graph/values/values_controller.cpp +++ b/apps/graph/values/values_controller.cpp @@ -32,8 +32,36 @@ ValuesController::ValuesController(Responder * parentResponder, InputEventHandle } void ValuesController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) { - Shared::ValuesController::willDisplayCellAtLocation(cell, i, j); + // Handle hidden cells int typeAtLoc = typeAtLocation(i,j); + if (typeAtLoc == k_editableValueCellType) { + StoreCell * storeCell = (StoreCell *)cell; + storeCell->setSeparatorLeft(i > 0); + } + + const int numberOfElementsInCol = numberOfElementsInColumn(i); + if (j == numberOfElementsInCol+1) { + if (typeAtLoc == k_notEditableValueCellType) { + Shared::HideableEvenOddBufferTextCell * myCell = static_cast(cell); + myCell->setText(""); + } else if (typeAtLoc == k_editableValueCellType) { + StoreCell * myCell = static_cast(cell); + myCell->editableTextCell()->textField()->setText(""); + } + return; + } + if (j > numberOfElementsInCol + 1) { + if (typeAtLoc == k_notEditableValueCellType) { + Shared::HideableEvenOddBufferTextCell * myCell = static_cast(cell); + myCell->setHide(true); + } else if (typeAtLoc == k_editableValueCellType) { + StoreCell * myCell = static_cast(cell); + myCell->setHide(true); + } + return; + } + + Shared::ValuesController::willDisplayCellAtLocation(cell, i, j); if (typeAtLoc == k_abscissaTitleCellType) { AbscissaTitleCell * myTitleCell = (AbscissaTitleCell *)cell; Ion::Storage::Record record = recordAtColumn(i+1); @@ -58,10 +86,7 @@ void ValuesController::willDisplayCellAtLocation(HighlightCell * cell, int i, in myFunctionCell->setColor(function->color()); return; } - if (typeAtLoc == k_editableValueCellType) { - StoreCell * storeCell = (StoreCell *)cell; - storeCell->setSeparatorLeft(i > 0); - } + } int ValuesController::typeAtLocation(int i, int j) { diff --git a/apps/graph/values/values_controller.h b/apps/graph/values/values_controller.h index 6728f72da..6146cf859 100644 --- a/apps/graph/values/values_controller.h +++ b/apps/graph/values/values_controller.h @@ -3,6 +3,7 @@ #include "../cartesian_function_store.h" #include "../../shared/buffer_function_title_cell.h" +#include "../../shared/hideable_even_odd_buffer_text_cell.h" #include "../../shared/values_controller.h" #include "../../shared/interval_parameter_controller.h" #include "../../shared/store_cell.h" @@ -54,7 +55,7 @@ private: int m_numberOfColumnsForType[Shared::CartesianFunction::k_numberOfPlotTypes]; Shared::BufferFunctionTitleCell m_functionTitleCells[k_maxNumberOfFunctions]; - EvenOddBufferTextCell m_floatCells[k_maxNumberOfCells]; + Shared::HideableEvenOddBufferTextCell m_floatCells[k_maxNumberOfCells]; AbscissaTitleCell m_abscissaTitleCells[Shared::CartesianFunction::k_numberOfPlotTypes]; Shared::StoreCell m_abscissaCells[k_maxNumberOfAbscissaCells]; FunctionParameterController m_functionParameterController; diff --git a/apps/shared/Makefile b/apps/shared/Makefile index 6a8c4fc5c..6497254aa 100644 --- a/apps/shared/Makefile +++ b/apps/shared/Makefile @@ -37,6 +37,7 @@ app_shared_src = $(addprefix apps/shared/,\ function_store.cpp \ function_title_cell.cpp \ go_to_parameter_controller.cpp \ + hideable_even_odd_buffer_text_cell.cpp \ hideable_even_odd_cell.cpp \ hideable_even_odd_editable_text_cell.cpp \ initialisation_parameter_controller.cpp \ diff --git a/apps/shared/hideable_even_odd_buffer_text_cell.cpp b/apps/shared/hideable_even_odd_buffer_text_cell.cpp new file mode 100644 index 000000000..7a2357bba --- /dev/null +++ b/apps/shared/hideable_even_odd_buffer_text_cell.cpp @@ -0,0 +1,20 @@ +#include "hideable_even_odd_buffer_text_cell.h" + +namespace Shared { + +KDColor HideableEvenOddBufferTextCell::backgroundColor() const { + if (hidden()) { + return hideColor(); + } + return EvenOddBufferTextCell::backgroundColor(); +} + +void HideableEvenOddBufferTextCell::setHide(bool hide) { + if (hidden() != hide) { + Hideable::setHide(hide); + m_bufferTextView.setBackgroundColor(backgroundColor()); + reloadCell(); + } +} + +} diff --git a/apps/shared/hideable_even_odd_buffer_text_cell.h b/apps/shared/hideable_even_odd_buffer_text_cell.h new file mode 100644 index 000000000..4585c6538 --- /dev/null +++ b/apps/shared/hideable_even_odd_buffer_text_cell.h @@ -0,0 +1,22 @@ +#ifndef APPS_SHARED_HIDEABLE_EVEN_ODD_BUFFER_TEXT_CELL_H +#define APPS_SHARED_HIDEABLE_EVEN_ODD_BUFFER_TEXT_CELL_H + +#include +#include +#include "hideable.h" + +namespace Shared { + +class HideableEvenOddBufferTextCell : public EvenOddBufferTextCell, public Hideable { +public: + HideableEvenOddBufferTextCell() : + EvenOddBufferTextCell(), + Hideable() + {} + KDColor backgroundColor() const override; + void setHide(bool hide) override; +}; + +} + +#endif diff --git a/apps/shared/interval.cpp b/apps/shared/interval.cpp index a5a53c33d..4754feb3d 100644 --- a/apps/shared/interval.cpp +++ b/apps/shared/interval.cpp @@ -15,11 +15,12 @@ int Interval::numberOfElements() { } void Interval::deleteElementAtIndex(int index) { - m_numberOfElements--; - for (int k = index; k < m_numberOfElements; k++) { + assert(!m_needCompute); + assert(m_numberOfElements > 0); + for (int k = index; k < m_numberOfElements-1; k++) { m_intervalBuffer[k] = m_intervalBuffer[k+1]; } - m_intervalBuffer[m_numberOfElements] = 0.0f; + m_numberOfElements--; } double Interval::element(int i) { @@ -70,7 +71,7 @@ void Interval::computeElements() { if (!m_needCompute) { return; } - if ( m_start > m_end) { + if (m_start > m_end) { m_numberOfElements = 0; } else { m_numberOfElements = m_step > 0 ? 1 + (m_end - m_start)/m_step : k_maxNumberOfElements; diff --git a/apps/shared/values_controller.h b/apps/shared/values_controller.h index a3c4b9af2..23b6bc45d 100644 --- a/apps/shared/values_controller.h +++ b/apps/shared/values_controller.h @@ -55,6 +55,7 @@ protected: virtual void updateNumberOfColumns(); virtual FunctionStore * functionStore() const; virtual Ion::Storage::Record recordAtColumn(int i); + int numberOfElementsInColumn(int columnIndex) override; int m_numberOfColumns; bool m_numberOfColumnsNeedUpdate; private: @@ -62,7 +63,6 @@ private: SelectableTableView * selectableTableView() override { return &m_selectableTableView; } bool cellAtLocationIsEditable(int columnIndex, int rowIndex) override; double dataAtLocation(int columnIndex, int rowIndex) override; - int numberOfElementsInColumn(int columnIndex) override; virtual Interval * intervalAtColumn(int columnIndex) = 0; int maxNumberOfElements() const override { return Interval::k_maxNumberOfElements;