[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.
This commit is contained in:
Ruben Dashyan
2019-09-04 15:50:20 +02:00
parent 1b169e0836
commit f70fb98a23
2 changed files with 35 additions and 7 deletions

View File

@@ -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<Shared::CartesianFunction::PlotType>(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<IntervalParameterSelectorController *>(this)->numberOfRows());
return static_cast<Shared::CartesianFunction::PlotType>(j);
int rowCount = 0;
int plotTypeIndex = 0;
Shared::CartesianFunction::PlotType plotType;
while (plotTypeIndex < Shared::CartesianFunction::k_numberOfPlotTypes) {
plotType = static_cast<Shared::CartesianFunction::PlotType>(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) {

View File

@@ -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;
};