-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainViewController.h
58 lines (50 loc) · 1.56 KB
/
MainViewController.h
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
#ifndef MainViewController_H
#define MainViewController_H
#include "MainModel.h"
#include "MainView.h"
#include <QtWidgets>
class MainViewController
{
public:
void setView(MainView* mainView)
{
view = mainView;
if (view != nullptr) {
mainView->setOpenFileCallback([this]() {
const auto filepath{ QFileDialog::getOpenFileName(nullptr, "Open Data File", "", "Data Files (*.csv)") };
processFileChange(filepath.toStdString());
});
}
}
private:
void processFileChange(std::string filepath)
{
model.update(filepath);
if (view != nullptr) {
auto series(createLineSeries(model.getDataProvider().table()));
auto seriesAlgo(createLineSeries(model.getRollingAverage()));
series.insert(end(series), begin(seriesAlgo), end(seriesAlgo));
view->update(series);
}
}
std::vector<QLineSeries*> createLineSeries(const MainModel::DataProvider_t::DataTable_t& data)
{
std::vector<QLineSeries*> res;
transform(cbegin(data), cend(data), back_inserter(res), [this](const auto& v) { return createLineSeries(v); });
return res;
}
QLineSeries* createLineSeries(const MainModel::DataProvider_t::DataColumn_t& data)
{
QLineSeries* series = new QLineSeries();
int count = 0;
for (const auto c : data) {
series->append(count, c);
count++;
}
return series;
}
private:
MainModel model;
MainView* view{ nullptr };
};
#endif