-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
106 lines (85 loc) · 3.1 KB
/
mainwindow.cpp
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <QtCharts>
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
, serial(this)
{
ui->setupUi(this);
createMenu();
createDocks();
createPlot();
fileMenu->addAction("Save", measurementDock, &MeasurementDock::save);
connectObjects();
serial.openPort();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::createDocks() {
createControlDock();
createMeasurementDock();
createTerminalDock();
}
void MainWindow::createControlDock() {
controlDock = new ControlDock(this);
addDockWidget(Qt::RightDockWidgetArea, controlDock);
viewMenu->addAction(controlDock->toggleViewAction());
}
void MainWindow::createMeasurementDock() {
measurementDock = new MeasurementDock(this);
addDockWidget(Qt::BottomDockWidgetArea, measurementDock);
viewMenu->addAction(measurementDock->toggleViewAction());
}
void MainWindow::createTerminalDock() {
terminalDock = new TerminalDock(this);
addDockWidget(Qt::BottomDockWidgetArea, terminalDock);
viewMenu->addAction(terminalDock->toggleViewAction());
}
void MainWindow::createMenu() {
viewMenu = menuBar()->addMenu("View");
fileMenu = menuBar()->addMenu("File");
}
void MainWindow::createPlot() {
chart = new QChart();
chart->legend()->hide();
xAxis = new QValueAxis();
yAxis = new QValueAxis();
chart->addAxis(xAxis, Qt::AlignBottom);
chart->addAxis(yAxis, Qt::AlignLeft);
QChartView *chartView = new QChartView(chart);
chartView->setRenderHint(QPainter::Antialiasing);
setCentralWidget(chartView);
}
void MainWindow::connectObjects() {
connect(&serial, &SerialPort::newRawIncomingPacket, terminalDock, &TerminalDock::rawIncomingPacket);
connect(&serial, &SerialPort::newRawOutgoingPacket, terminalDock, &TerminalDock::rawOutgoingPacket);
connect(terminalDock, &TerminalDock::sendRaw, &serial, &SerialPort::sendRawText);
connect(&serial, &SerialPort::newPacket, controlDock, &ControlDock::onPacketReceived);
connect(controlDock, &ControlDock::sendPacket, &serial, &SerialPort::sendPacket);
connect(&serial, &SerialPort::newPacket, measurementDock, &MeasurementDock::onPacketReceived);
connect(measurementDock, &MeasurementDock::sendPacket, &serial, &SerialPort::sendPacket);
connect(measurementDock, &MeasurementDock::removeSeries, this, &MainWindow::removeSeries);
connect(measurementDock, &MeasurementDock::addSeries, this, &MainWindow::addSeries);
connect(measurementDock, &MeasurementDock::setAxes, this, &MainWindow::setAxes);
}
void MainWindow::removeSeries(QList<QAbstractSeries *> series) {
foreach (QAbstractSeries *s, series) {
chart->removeSeries(s);
}
}
void MainWindow::addSeries(QList<QAbstractSeries *> series) {
foreach (QAbstractSeries *s, series) {
chart->addSeries(s);
s->attachAxis(xAxis);
s->attachAxis(yAxis);
}
}
void MainWindow::setAxes(AxesRange range) {
xAxis->setMin(range.minX);
xAxis->setMax(range.maxX);
yAxis->setMin(range.minY);
yAxis->setMax(range.maxY);
}