Blame view

build3/apps/statistics/box_controller.cpp 2.74 KB
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
89
90
91
  #include "box_controller.h"
  #include "app.h"
  #include "../apps_container.h"
  
  using namespace Poincare;
  
  namespace Statistics {
  
  BoxController::BoxController(Responder * parentResponder, ButtonRowController * header, Store * store, BoxView::Quantile * selectedQuantile) :
    ViewController(parentResponder),
    ButtonRowDelegate(header, nullptr),
    m_boxBannerView(),
    m_view(store, &m_boxBannerView, selectedQuantile),
    m_store(store)
  {
  }
  
  const char * BoxController::title() {
    return I18n::translate(I18n::Message::BoxTab);
  }
  
  View * BoxController::view() {
    return &m_view;
  }
  
  bool BoxController::handleEvent(Ion::Events::Event event) {
    if (event == Ion::Events::Up) {
      m_view.selectMainView(false);
      app()->setFirstResponder(tabController());
      return true;
    }
    if (event == Ion::Events::Left || event == Ion::Events::Right) {
      int nextSelectedQuantile = event == Ion::Events::Left ? (int)m_view.selectedQuantile()-1 : (int)m_view.selectedQuantile()+1;
      if (m_view.selectQuantile(nextSelectedQuantile)) {
        reloadBannerView();
        return true;
      }
      return false;
    }
    return false;
  }
  
  void BoxController::didBecomeFirstResponder() {
    m_view.selectMainView(true);
    m_view.reload();
  }
  
  bool BoxController::isEmpty() const {
    if (m_store->sumOfColumn(1) == 0) {
      return true;
    }
    return false;
  }
  
  I18n::Message BoxController::emptyMessage() {
    return I18n::Message::NoDataToPlot;
  }
  
  Responder * BoxController::defaultController() {
    return tabController();
  }
  
  Responder * BoxController::tabController() const {
    return (parentResponder()->parentResponder()->parentResponder());
  }
  
  void BoxController::reloadBannerView() {
    I18n::Message calculationName[5] = {I18n::Message::Minimum, I18n::Message::FirstQuartile, I18n::Message::Median, I18n::Message::ThirdQuartile, I18n::Message::Maximum};
    m_boxBannerView.setMessageAtIndex(calculationName[(int)m_view.selectedQuantile()], 0);
    char buffer[PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
    CalculPointer calculationMethods[5] = {&Store::minValue, &Store::firstQuartile, &Store::median, &Store::thirdQuartile,
      &Store::maxValue};
    double calculation = (m_store->*calculationMethods[(int)m_view.selectedQuantile()])();
    Complex<double>::convertFloatToText(calculation, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
    m_boxBannerView.setLegendAtIndex(buffer, 1);
  }
  
  void BoxController::viewWillAppear() {
    m_view.selectMainView(true);
    reloadBannerView();
    m_view.reload();
  }
  
  void BoxController::willExitResponderChain(Responder * nextFirstResponder) {
    if (nextFirstResponder == tabController()) {
      m_view.selectMainView(false);
      m_view.reload();
    }
  }
  
  }