From f70fb98a239ee46902b92e2d997565ba97cfadba Mon Sep 17 00:00:00 2001 From: Ruben Dashyan Date: Wed, 4 Sep 2019 15:50:20 +0200 Subject: [PATCH] [apps/graph/values/interval_parameter_selector_controller] Hide irrelevant rows Hide those rows corresponding to plot types, not used by any function in the store. --- ...interval_parameter_selector_controller.cpp | 38 ++++++++++++++++--- .../interval_parameter_selector_controller.h | 4 +- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/apps/graph/values/interval_parameter_selector_controller.cpp b/apps/graph/values/interval_parameter_selector_controller.cpp index 53e0d9283..7430555f3 100644 --- a/apps/graph/values/interval_parameter_selector_controller.cpp +++ b/apps/graph/values/interval_parameter_selector_controller.cpp @@ -16,6 +16,13 @@ const char * IntervalParameterSelectorController::title() { return I18n::translate(I18n::Message::IntervalSet); } +void IntervalParameterSelectorController::viewDidDisappear() { + /* Deselect the table properly because it needs to be relayouted the next time + * it appears: the number of rows might change according to the plot type. */ + m_selectableTableView.deselectTable(false); + m_selectableTableView.setFrame(KDRectZero); +} + void IntervalParameterSelectorController::didBecomeFirstResponder() { if (selectedRow() < 0) { selectCellAtLocation(0, 0); @@ -37,8 +44,17 @@ bool IntervalParameterSelectorController::handleEvent(Ion::Events::Event event) } int IntervalParameterSelectorController::numberOfRows() { - return MaxNumberOfRows; -}; + int rowCount = 0; + int plotTypeIndex = 0; + Shared::CartesianFunction::PlotType plotType; + while (plotTypeIndex < Shared::CartesianFunction::k_numberOfPlotTypes) { + plotType = static_cast(plotTypeIndex); + bool plotTypeIsShown = App::app()->functionStore()->numberOfActiveFunctionsOfType(plotType) > 0; + rowCount += plotTypeIsShown; + plotTypeIndex++; + } + return rowCount; +} HighlightCell * IntervalParameterSelectorController::reusableCell(int index) { assert(0 <= index && index < reusableCellCount()); @@ -46,7 +62,7 @@ HighlightCell * IntervalParameterSelectorController::reusableCell(int index) { } int IntervalParameterSelectorController::reusableCellCount() { - return MaxNumberOfRows; + return Shared::CartesianFunction::k_numberOfPlotTypes; } void IntervalParameterSelectorController::willDisplayCellForIndex(HighlightCell * cell, int index) { @@ -56,8 +72,20 @@ void IntervalParameterSelectorController::willDisplayCellForIndex(HighlightCell } Shared::CartesianFunction::PlotType IntervalParameterSelectorController::plotTypeAtRow(int j) const { - assert(0 <= j && j < const_cast(this)->numberOfRows()); - return static_cast(j); + int rowCount = 0; + int plotTypeIndex = 0; + Shared::CartesianFunction::PlotType plotType; + while (plotTypeIndex < Shared::CartesianFunction::k_numberOfPlotTypes) { + plotType = static_cast(plotTypeIndex); + bool plotTypeIsShown = App::app()->functionStore()->numberOfActiveFunctionsOfType(plotType) > 0; + if (plotTypeIsShown && rowCount == j) { + break; + } + rowCount += plotTypeIsShown; + plotTypeIndex++; + } + assert(rowCount == j); + return plotType; } I18n::Message IntervalParameterSelectorController::messageForType(Shared::CartesianFunction::PlotType plotType) { diff --git a/apps/graph/values/interval_parameter_selector_controller.h b/apps/graph/values/interval_parameter_selector_controller.h index e52f94ad5..20d28a511 100644 --- a/apps/graph/values/interval_parameter_selector_controller.h +++ b/apps/graph/values/interval_parameter_selector_controller.h @@ -11,6 +11,7 @@ public: IntervalParameterSelectorController(); const char * title() override; View * view() override { return &m_selectableTableView; } + void viewDidDisappear() override; bool handleEvent(Ion::Events::Event event) override; void didBecomeFirstResponder() override; int numberOfRows() override; @@ -19,10 +20,9 @@ public: HighlightCell * reusableCell(int index) override; void willDisplayCellForIndex(HighlightCell * cell, int index) override; private: - static constexpr int MaxNumberOfRows = Shared::CartesianFunction::k_numberOfPlotTypes; Shared::CartesianFunction::PlotType plotTypeAtRow(int j) const; I18n::Message messageForType(Shared::CartesianFunction::PlotType plotType); - MessageTableCellWithChevron m_intervalParameterCell[MaxNumberOfRows]; + MessageTableCellWithChevron m_intervalParameterCell[Shared::CartesianFunction::k_numberOfPlotTypes]; SelectableTableView m_selectableTableView; };