[apps/statistics] Forbid negative sizes and round float sizes

Change-Id: I4db9777bea04f70b86da97f940ef5cbe669e41d9
This commit is contained in:
Émilie Feral
2017-03-24 10:36:31 +01:00
parent 85b27c372d
commit 128af56396
8 changed files with 23 additions and 6 deletions

View File

@@ -22,7 +22,10 @@ bool EditableCellTableViewController::textFieldDidFinishEditing(TextField * text
app()->displayWarning(I18n::Message::UndefinedValue);
return false;
}
setDataAtLocation(floatBody, m_selectableTableView.selectedColumn(), m_selectableTableView.selectedRow());
if (!setDataAtLocation(floatBody, m_selectableTableView.selectedColumn(), m_selectableTableView.selectedRow())) {
app()->displayWarning(I18n::Message::ForbiddenValue);
return false;
}
willDisplayCellAtLocation(m_selectableTableView.cellAtLocation(m_selectableTableView.selectedColumn(), m_selectableTableView.selectedRow()), m_selectableTableView.selectedColumn(), m_selectableTableView.selectedRow());
m_selectableTableView.reloadData();
m_selectableTableView.selectCellAtLocation(m_selectableTableView.selectedColumn(), m_selectableTableView.selectedRow()+1);

View File

@@ -27,7 +27,7 @@ private:
TextFieldDelegateApp * textFieldDelegateApp() override;
static constexpr KDCoordinate k_cellHeight = 20;
virtual bool cellAtLocationIsEditable(int columnIndex, int rowIndex) = 0;
virtual void setDataAtLocation(float floatBody, int columnIndex, int rowIndex) = 0;
virtual bool setDataAtLocation(float floatBody, int columnIndex, int rowIndex) = 0;
virtual float dataAtLocation(int columnIndex, int rowIndex) = 0;
virtual int numberOfElements() = 0;
virtual int maxNumberOfElements() const = 0;

View File

@@ -112,8 +112,9 @@ bool StoreController::cellAtLocationIsEditable(int columnIndex, int rowIndex) {
return false;
}
void StoreController::setDataAtLocation(float floatBody, int columnIndex, int rowIndex) {
bool StoreController::setDataAtLocation(float floatBody, int columnIndex, int rowIndex) {
m_store->set(floatBody, columnIndex, rowIndex-1);
return true;
}
float StoreController::dataAtLocation(int columnIndex, int rowIndex) {

View File

@@ -28,7 +28,7 @@ protected:
constexpr static int k_numberOfTitleCells = 2;
Responder * tabController() const override;
bool cellAtLocationIsEditable(int columnIndex, int rowIndex) override;
void setDataAtLocation(float floatBody, int columnIndex, int rowIndex) override;
bool setDataAtLocation(float floatBody, int columnIndex, int rowIndex) override;
float dataAtLocation(int columnIndex, int rowIndex) override;
int numberOfElements() override;
int maxNumberOfElements() const override;

View File

@@ -260,8 +260,9 @@ bool ValuesController::cellAtLocationIsEditable(int columnIndex, int rowIndex) {
return false;
}
void ValuesController::setDataAtLocation(float floatBody, int columnIndex, int rowIndex) {
bool ValuesController::setDataAtLocation(float floatBody, int columnIndex, int rowIndex) {
m_interval.setElement(rowIndex-1, floatBody);
return true;
}
float ValuesController::dataAtLocation(int columnIndex, int rowIndex) {

View File

@@ -47,7 +47,7 @@ private:
void configureAbscissa();
void configureFunction();
bool cellAtLocationIsEditable(int columnIndex, int rowIndex) override;
void setDataAtLocation(float floatBody, int columnIndex, int rowIndex) override;
bool setDataAtLocation(float floatBody, int columnIndex, int rowIndex) override;
float dataAtLocation(int columnIndex, int rowIndex) override;
int numberOfElements() override;
int maxNumberOfElements() const override;

View File

@@ -32,4 +32,15 @@ HighlightCell * StoreController::titleCells(int index) {
return &m_titleCells[index];
}
bool StoreController::setDataAtLocation(float floatBody, int columnIndex, int rowIndex) {
if (columnIndex == 1) {
if (floatBody < 0) {
return false;
}
m_store->set(roundf(floatBody), columnIndex, rowIndex-1);
return true;
}
return Shared::StoreController::setDataAtLocation(floatBody, columnIndex, rowIndex);
}
}

View File

@@ -12,6 +12,7 @@ public:
StoreController(Responder * parentResponder, Store * store, ButtonRowController * header);
void willDisplayCellAtLocation(HighlightCell * cell, int i, int j) override;
private:
bool setDataAtLocation(float floatBody, int columnIndex, int rowIndex) override;
HighlightCell * titleCells(int index) override;
EvenOddMessageTextCell m_titleCells[k_numberOfTitleCells];
};