[apps/graph] ValuesController: factorize code to hide the cells

This commit is contained in:
Émilie Feral
2019-09-24 16:29:32 +02:00
committed by LeaNumworks
parent b91ea42286
commit 6a983a5bdf
5 changed files with 23 additions and 20 deletions

View File

@@ -41,6 +41,16 @@ ValuesController::ValuesController(Responder * parentResponder, InputEventHandle
m_selectableTableView.setDelegate(this);
}
Shared::Hideable * ValuesController::hideableCellFromType(HighlightCell * cell, int type) {
if (type == k_notEditableValueCellType) {
Shared::HideableEvenOddBufferTextCell * myCell = static_cast<Shared::HideableEvenOddBufferTextCell *>(cell);
return static_cast<Shared::Hideable *>(myCell);
}
assert(type == k_editableValueCellType);
Shared::StoreCell * myCell = static_cast<Shared::StoreCell *>(cell);
return static_cast<Shared::Hideable *>(myCell);
}
void ValuesController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) {
// Handle hidden cells
int typeAtLoc = typeAtLocation(i,j);
@@ -51,38 +61,27 @@ void ValuesController::willDisplayCellAtLocation(HighlightCell * cell, int i, in
const int numberOfElementsInCol = numberOfElementsInColumn(i);
if (j > numberOfElementsInCol + 1) {
if (typeAtLoc == k_notEditableValueCellType) {
Shared::HideableEvenOddBufferTextCell * myCell = static_cast<Shared::HideableEvenOddBufferTextCell *>(cell);
myCell->setHide(true);
myCell->setText("");
} else if (typeAtLoc == k_editableValueCellType) {
StoreCell * myCell = static_cast<StoreCell *>(cell);
myCell->editableTextCell()->textField()->setText("");
myCell->setHide(true);
if (typeAtLoc == k_notEditableValueCellType || typeAtLoc == k_editableValueCellType) {
Shared::Hideable * hideableCell = hideableCellFromType(cell, typeAtLoc);
hideableCell->setHide(true);
hideableCell->reinit();
}
return;
} else {
if (typeAtLoc == k_notEditableValueCellType) {
Shared::Hideable * myCell = static_cast<Shared::Hideable *>(static_cast<Shared::HideableEvenOddBufferTextCell *>(cell));
myCell->setHide(false);
} else if (typeAtLoc == k_editableValueCellType) {
StoreCell * myCell = static_cast<StoreCell *>(cell);
myCell->setHide(false);
if (typeAtLoc == k_notEditableValueCellType || typeAtLoc == k_editableValueCellType) {
hideableCellFromType(cell, typeAtLoc)->setHide(false);
}
}
if (j == numberOfElementsInCol+1) {
static_cast<EvenOddCell *>(cell)->setEven(j%2 == 0);
if (typeAtLoc == k_notEditableValueCellType) {
Shared::HideableEvenOddBufferTextCell * myCell = static_cast<Shared::HideableEvenOddBufferTextCell *>(cell);
myCell->setText("");
} else if (typeAtLoc == k_editableValueCellType) {
StoreCell * myCell = static_cast<StoreCell *>(cell);
myCell->editableTextCell()->textField()->setText("");
if (typeAtLoc == k_notEditableValueCellType || typeAtLoc == k_editableValueCellType) {
hideableCellFromType(cell, typeAtLoc)->reinit();
}
return;
}
Shared::ValuesController::willDisplayCellAtLocation(cell, i, j);
if (typeAtLoc == k_abscissaTitleCellType) {
AbscissaTitleCell * myTitleCell = (AbscissaTitleCell *)cell;
myTitleCell->setMessage(valuesParameterMessageAtColumn(i));

View File

@@ -48,6 +48,7 @@ private:
int maxNumberOfCells() override;
int maxNumberOfFunctions() override;
double evaluationOfAbscissaAtColumn(double abscissa, int columnIndex) override;
Shared::Hideable * hideableCellFromType(HighlightCell * cell, int type);
ContinuousFunctionStore * functionStore() const override { return static_cast<ContinuousFunctionStore *>(Shared::ValuesController::functionStore()); }
Shared::BufferFunctionTitleCell * functionTitleCells(int j) override;
EvenOddBufferTextCell * floatCells(int j) override;

View File

@@ -13,6 +13,7 @@ public:
static KDColor hideColor() { return Palette::WallScreenDark; }
bool hidden() const { return m_hide; }
virtual void setHide(bool hide) { m_hide = hide; }
virtual void reinit() {}
private:
bool m_hide;
};

View File

@@ -15,6 +15,7 @@ public:
{}
KDColor backgroundColor() const override;
void setHide(bool hide) override;
void reinit() override { setText(""); }
};
}

View File

@@ -15,6 +15,7 @@ public:
{}
KDColor backgroundColor() const override;
void setHide(bool hide) override;
void reinit() override { editableTextCell()->textField()->setText(""); }
};
}