[apps/*/expression_model_list_controller] Refactor modelStore()

Its return type is covariant. Get the ExpressionModelStore from the App.
This commit is contained in:
Ruben Dashyan
2019-09-06 17:21:31 +02:00
committed by LeaNumworks
parent e80aaa649d
commit 413397652c
9 changed files with 26 additions and 14 deletions

View File

@@ -118,7 +118,7 @@ bool ListController::textFieldDidAbortEditing(TextField * textField) {
// Put the name column back to normal size
computeTitlesColumnWidth();
selectableTableView()->reloadData();
ExpiringPointer<Function> function = modelStore()->modelForRecord(modelStore()->recordAtIndex(selectedRow()));
ExpiringPointer<CartesianFunction> function = modelStore()->modelForRecord(modelStore()->recordAtIndex(selectedRow()));
setFunctionNameInTextField(function, textField);
m_selectableTableView.selectedCell()->setHighlighted(true);
Container::activeApp()->setFirstResponder(&m_selectableTableView);
@@ -165,7 +165,7 @@ void ListController::willDisplayTitleCellAtIndex(HighlightCell * cell, int j) {
titleCell->setBaseline(baseline(j));
if (!titleCell->isEditing()) {
// Set name and color if the name is not being edited
ExpiringPointer<Function> function = modelStore()->modelForRecord(modelStore()->recordAtIndex(j));
ExpiringPointer<CartesianFunction> function = modelStore()->modelForRecord(modelStore()->recordAtIndex(j));
setFunctionNameInTextField(function, titleCell->textField());
KDColor functionNameColor = function->isActive() ? function->color() : Palette::GreyDark;
titleCell->setColor(functionNameColor);
@@ -177,16 +177,20 @@ void ListController::willDisplayExpressionCellAtIndex(HighlightCell * cell, int
assert(j >= 0 && j < modelStore()->numberOfModels());
Shared::FunctionListController::willDisplayExpressionCellAtIndex(cell, j);
FunctionExpressionCell * myCell = (FunctionExpressionCell *)cell;
ExpiringPointer<Function> f = modelStore()->modelForRecord(modelStore()->recordAtIndex(j));
ExpiringPointer<CartesianFunction> f = modelStore()->modelForRecord(modelStore()->recordAtIndex(j));
KDColor textColor = f->isActive() ? KDColorBlack : Palette::GreyDark;
myCell->setTextColor(textColor);
}
void ListController::setFunctionNameInTextField(ExpiringPointer<Function> function, TextField * textField) {
void ListController::setFunctionNameInTextField(ExpiringPointer<CartesianFunction> function, TextField * textField) {
assert(textField != nullptr);
char bufferName[BufferTextView::k_maxNumberOfChar];
function->nameWithArgument(bufferName, BufferTextView::k_maxNumberOfChar);
textField->setText(bufferName);
}
CartesianFunctionStore * ListController::modelStore() {
return App::app()->functionStore();
}
}

View File

@@ -29,7 +29,8 @@ private:
HighlightCell * expressionCells(int index) override;
void willDisplayTitleCellAtIndex(HighlightCell * cell, int j) override;
void willDisplayExpressionCellAtIndex(HighlightCell * cell, int j) override;
void setFunctionNameInTextField(Shared::ExpiringPointer<Shared::Function> function, TextField * textField);
void setFunctionNameInTextField(Shared::ExpiringPointer<Shared::CartesianFunction> function, TextField * textField);
CartesianFunctionStore * modelStore() override;
TextFieldFunctionTitleCell m_functionTitleCells[k_maxNumberOfDisplayableRows];
Shared::FunctionExpressionCell m_expressionCells[k_maxNumberOfDisplayableRows];
ListParameterController m_parameterController;

View File

@@ -291,4 +291,8 @@ bool ListController::removeModelRow(Ion::Storage::Record record) {
return true;
}
SequenceStore * ListController::modelStore() {
return App::app()->functionStore();
}
}

View File

@@ -40,7 +40,7 @@ private:
void reinitSelectedExpression(Shared::ExpiringPointer<Shared::ExpressionModelHandle> model) override;
void editExpression(Ion::Events::Event event) override;
bool removeModelRow(Ion::Storage::Record record) override;
SequenceStore * modelStore() override { return static_cast<SequenceStore *>(Shared::FunctionListController::modelStore()); }
SequenceStore * modelStore() override;
constexpr static int k_maxNumberOfRows = 3*MaxNumberOfSequences;
SequenceTitleCell m_sequenceTitleCells[k_maxNumberOfRows];
Shared::FunctionExpressionCell m_expressionCells[k_maxNumberOfRows];

View File

@@ -248,10 +248,6 @@ TabViewController * FunctionListController::tabController() const {
return static_cast<TabViewController *>(parentResponder()->parentResponder()->parentResponder()->parentResponder());
}
FunctionStore * FunctionListController::modelStore() {
return FunctionApp::app()->functionStore();
}
InputViewController * FunctionListController::inputController() {
return FunctionApp::app()->inputViewController();
}

View File

@@ -53,7 +53,6 @@ protected:
StackViewController * stackController() const;
void configureFunction(Ion::Storage::Record record);
void computeTitlesColumnWidth(bool forceMax = false);
FunctionStore * modelStore() override;
KDCoordinate baseline(int j);
void resetMemoizationForIndex(int index) override;
void shiftMemoization(bool newCellIsUnder) override;

View File

@@ -32,6 +32,12 @@ public:
static App * app() {
return static_cast<App *>(Container::activeApp());
}
Snapshot * snapshot() {
return static_cast<Snapshot *>(::App::snapshot());
}
EquationStore * equationStore() {
return snapshot()->equationStore();
}
InputViewController * inputViewController() { return &m_inputViewController; }
ViewController * solutionsControllerStack() { return &m_alternateEmptyViewController; }
ViewController * intervalController() { return &m_intervalController; }

View File

@@ -10,7 +10,6 @@ namespace Solver {
ListController::ListController(Responder * parentResponder, EquationStore * equationStore, ButtonRowController * footer) :
ExpressionModelListController(parentResponder, I18n::Message::AddEquation),
ButtonRowDelegate(nullptr, footer),
m_equationStore(equationStore),
m_equationListView(this),
m_expressionCells{},
m_resolveButton(this, equationStore->numberOfDefinedModels() > 1 ? I18n::Message::ResolveSystem : I18n::Message::ResolveEquation, Invocation([](void * context, void * sender) {
@@ -221,6 +220,10 @@ void ListController::reloadBrace() {
m_equationListView.setBraceStyle(braceStyle);
}
EquationStore * ListController::modelStore() {
return App::app()->equationStore();
}
SelectableTableView * ListController::selectableTableView() {
return m_equationListView.selectableTableView();
}

View File

@@ -51,13 +51,12 @@ private:
void addEmptyModel() override;
bool removeModelRow(Ion::Storage::Record record) override;
void reloadBrace();
EquationStore * modelStore() override { return m_equationStore; }
EquationStore * modelStore() override;
StackViewController * stackController() const;
InputViewController * inputController() override;
// ListViewDataSource
KDCoordinate notMemoizedCumulatedHeightFromIndex(int j) override { return ListViewDataSource::cumulatedHeightFromIndex(j); }
int notMemoizedIndexFromCumulatedHeight(KDCoordinate offsetY) override { return ListViewDataSource::indexFromCumulatedHeight(offsetY); }
EquationStore * m_equationStore;
EquationListView m_equationListView;
EvenOddExpressionCell m_expressionCells[k_maxNumberOfRows];
Button m_resolveButton;