6663b6c9
adorian
projet complet av...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
#include "histogram_parameter_controller.h"
#include "app.h"
#include <assert.h>
#include <cmath>
using namespace Shared;
namespace Statistics {
HistogramParameterController::HistogramParameterController(Responder * parentResponder, Store * store) :
FloatParameterController(parentResponder),
m_cells{},
m_store(store)
{
}
const char * HistogramParameterController::title() {
return I18n::translate(I18n::Message::HistogramSet);
}
int HistogramParameterController::numberOfRows() {
return 1+k_numberOfCells;
}
void HistogramParameterController::willDisplayCellForIndex(HighlightCell * cell, int index) {
if (index == numberOfRows()-1) {
return;
}
MessageTableCellWithEditableText * myCell = (MessageTableCellWithEditableText *)cell;
I18n::Message labels[k_numberOfCells] = {I18n::Message::RectangleWidth, I18n::Message::BarStart};
myCell->setMessage(labels[index]);
FloatParameterController::willDisplayCellForIndex(cell, index);
}
double HistogramParameterController::parameterAtIndex(int index) {
assert(index >= 0 && index < k_numberOfCells);
if (index == 0) {
return m_store->barWidth();
}
return m_store->firstDrawnBarAbscissa();
}
bool HistogramParameterController::setParameterAtIndex(int parameterIndex, double f) {
assert(parameterIndex >= 0 && parameterIndex < k_numberOfCells);
if (parameterIndex == 0) {
double newNumberOfBars = std::ceil((m_store->maxValue() - m_store->minValue())/f);
if (f <= 0.0f || newNumberOfBars > Store::k_maxNumberOfBars || m_store->firstDrawnBarAbscissa() > m_store->maxValue()+f) {
app()->displayWarning(I18n::Message::ForbiddenValue);
return false;
}
m_store->setBarWidth(f);
} else {
double newNumberOfBars = ceilf((m_store->maxValue() - f)/m_store->barWidth());
if (newNumberOfBars > Store::k_maxNumberOfBars || f > m_store->maxValue()+m_store->barWidth()) {
app()->displayWarning(I18n::Message::ForbiddenValue);
return false;
}
m_store->setFirstDrawnBarAbscissa(f);
}
return true;
}
HighlightCell * HistogramParameterController::reusableParameterCell(int index, int type) {
assert(index >= 0 && index < k_numberOfCells);
return m_cells[index];
}
int HistogramParameterController::reusableParameterCellCount(int type) {
return k_numberOfCells;
}
View * HistogramParameterController::loadView() {
SelectableTableView * tableView = (SelectableTableView *)FloatParameterController::loadView();
for (int i = 0; i < k_numberOfCells; i++) {
m_cells[i] = new MessageTableCellWithEditableText(tableView, this, m_draftTextBuffer, I18n::Message::Default);
}
return tableView;
}
void HistogramParameterController::unloadView(View * view) {
for (int i = 0; i < k_numberOfCells; i++) {
delete m_cells[i];
m_cells[i] = nullptr;
}
FloatParameterController::unloadView(view);
}
}
|