-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainView.h
59 lines (45 loc) · 1.3 KB
/
MainView.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
59
#ifndef MainView_H
#define MainView_H
#include <QChartView>
#include <QLineSeries>
#include <QtWidgets>
class MainView : public QBoxLayout
{
Q_OBJECT
public:
using openFileCallback_t = std::function<void(void)>;
MainView()
: QBoxLayout(QBoxLayout::Direction::TopToBottom)
{
createUI();
}
void setOpenFileCallback(const openFileCallback_t& callback) { openFileCallback = callback; }
void update(const std::vector<QLineSeries*>& series)
{
QChart* c = chartView->chart();
c->removeAllSeries();
for (auto s : series) {
c->addSeries(s);
}
}
private slots:
void openFileClicked() { openFileCallback(); }
private:
QChartView* chartView{ nullptr };
openFileCallback_t openFileCallback{ nullptr };
void createUI()
{
QPushButton* button = new QPushButton("Open file");
connect(button, SIGNAL(clicked()), this, SLOT(openFileClicked()));
QChart* chart = new QChart();
chart->legend()->hide();
chart->createDefaultAxes();
chart->setTitle("Chart");
chartView = new QChartView();
chartView->setChart(chart);
chartView->setRenderHint(QPainter::Antialiasing);
this->addWidget(chartView);
this->addWidget(button);
}
};
#endif