mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[Stat+Reg] Allowing lists of values to be sorted
Change-Id: I181bb55443bf87356d127eb6c56ff6140806fdea
This commit is contained in:
committed by
Émilie Feral
parent
018dd91ca1
commit
09e39ad890
@@ -1,5 +1,6 @@
|
||||
#include "store_parameter_controller.h"
|
||||
#include "store_controller.h"
|
||||
#include <poincare/helpers.h>
|
||||
#include <assert.h>
|
||||
|
||||
namespace Shared {
|
||||
@@ -9,61 +10,87 @@ StoreParameterController::StoreParameterController(Responder * parentResponder,
|
||||
m_store(store),
|
||||
m_series(0),
|
||||
m_selectableTableView(this, this, this),
|
||||
m_deleteColumn(I18n::Message::ClearColumn),
|
||||
m_fillWithFormula(I18n::Message::FillWithFormula),
|
||||
#if COPY_IMPORT_LIST
|
||||
m_copyColumn(I18n::Message::CopyColumnInList),
|
||||
m_importList(I18n::Message::ImportList),
|
||||
#endif
|
||||
m_cells{I18n::Message::ClearColumn, I18n::Message::FillWithFormula},
|
||||
m_storeController(storeController),
|
||||
m_xColumnSelected(true)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void StoreParameterController::willDisplayCellForIndex(HighlightCell * cell, int index) {
|
||||
MessageTableCellWithEditableText * myCell = static_cast<MessageTableCellWithEditableText *>(cell);
|
||||
assert(index >= 0 && index < k_totalNumberOfCell);
|
||||
if (index == 2) {
|
||||
myCell->setMessage(sortMessage());
|
||||
}
|
||||
ListViewDataSource::willDisplayCellForIndex(cell, index);
|
||||
}
|
||||
|
||||
const char * StoreParameterController::title() {
|
||||
return I18n::translate(I18n::Message::ColumnOptions);
|
||||
}
|
||||
|
||||
void StoreParameterController::viewWillAppear() {
|
||||
m_selectableTableView.reloadData();
|
||||
}
|
||||
|
||||
void StoreParameterController::didBecomeFirstResponder() {
|
||||
selectCellAtLocation(0, 0);
|
||||
Container::activeApp()->setFirstResponder(&m_selectableTableView);
|
||||
}
|
||||
|
||||
bool StoreParameterController::handleEvent(Ion::Events::Event event) {
|
||||
if (event == Ion::Events::OK || event == Ion::Events::EXE) {
|
||||
switch (selectedRow()) {
|
||||
case 0:
|
||||
{
|
||||
if (m_xColumnSelected) {
|
||||
m_store->deleteAllPairsOfSeries(m_series);
|
||||
} else {
|
||||
m_store->resetColumn(m_series, !m_xColumnSelected);
|
||||
}
|
||||
StackViewController * stack = ((StackViewController *)parentResponder());
|
||||
stack->pop();
|
||||
return true;
|
||||
if (event != Ion::Events::OK && event != Ion::Events::EXE) {
|
||||
return false;
|
||||
}
|
||||
switch (selectedRow()) {
|
||||
case 0:
|
||||
{
|
||||
if (m_xColumnSelected) {
|
||||
m_store->deleteAllPairsOfSeries(m_series);
|
||||
} else {
|
||||
m_store->resetColumn(m_series, !m_xColumnSelected);
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
m_storeController->displayFormulaInput();
|
||||
StackViewController * stack = ((StackViewController *)parentResponder());
|
||||
stack->pop();
|
||||
return true;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
m_storeController->displayFormulaInput();
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
Poincare::Helpers::Swap swapRows = [](int i, int j, void * context, int numberOfElements) {
|
||||
double * contextI = (static_cast<double*>(context) + i);
|
||||
double * contextJ = (static_cast<double*>(context) + j);
|
||||
double * contextIOtherColumn = (static_cast<double*>(context) + DoublePairStore::k_maxNumberOfPairs + i);
|
||||
double * contextJOtherColumn = (static_cast<double*>(context) + DoublePairStore::k_maxNumberOfPairs + j);
|
||||
double temp1 = *contextI;
|
||||
double temp2 = *contextIOtherColumn;
|
||||
*contextI = *contextJ;
|
||||
*contextIOtherColumn = *contextJOtherColumn;
|
||||
*contextJ = temp1;
|
||||
*contextJOtherColumn = temp2;
|
||||
};
|
||||
Poincare::Helpers::Compare compareX = [](int a, int b, void * context, int numberOfElements)->bool{
|
||||
double * contextA = (static_cast<double*>(context) + a);
|
||||
double * contextB = (static_cast<double*>(context) + b);
|
||||
return *contextA > *contextB;
|
||||
};
|
||||
Poincare::Helpers::Compare compareY = [](int a, int b, void * context, int numberOfElements)->bool{
|
||||
double * contextAOtherColumn = (static_cast<double*>(context) + DoublePairStore::k_maxNumberOfPairs + a);
|
||||
double * contextBOtherColumn = (static_cast<double*>(context) + DoublePairStore::k_maxNumberOfPairs + b);
|
||||
return *contextAOtherColumn > *contextBOtherColumn;
|
||||
};
|
||||
if (m_xColumnSelected) {
|
||||
Poincare::Helpers::Sort(swapRows, compareX, (m_store->data() + m_series), m_store->numberOfPairsOfSeries(m_series));
|
||||
} else {
|
||||
Poincare::Helpers::Sort(swapRows, compareY, (m_store->data() + m_series), m_store->numberOfPairsOfSeries(m_series));
|
||||
}
|
||||
|
||||
#if COPY_IMPORT_LIST
|
||||
/* TODO: implement copy column and import list */
|
||||
case 2:
|
||||
return true;
|
||||
case 3:
|
||||
return true;
|
||||
#endif
|
||||
default:
|
||||
assert(false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
assert(selectedRow() >= 0 && selectedRow() <= 2);
|
||||
StackViewController * stack = static_cast<StackViewController *>(parentResponder());
|
||||
stack->pop();
|
||||
return true;
|
||||
}
|
||||
|
||||
KDCoordinate StoreParameterController::cumulatedHeightFromIndex(int j) {
|
||||
@@ -88,8 +115,7 @@ HighlightCell * StoreParameterController::reusableCell(int index, int type) {
|
||||
assert(type == k_standardCellType);
|
||||
assert(index >= 0);
|
||||
assert(index < k_totalNumberOfCell);
|
||||
HighlightCell * cells[] = {&m_deleteColumn, &m_fillWithFormula};// {&m_deleteColumn, &m_fillWithFormula, &m_copyColumn, &m_importList};
|
||||
return cells[index];
|
||||
return &m_cells[index];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user