-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
77 lines (67 loc) · 1.7 KB
/
mainwindow.cpp
File metadata and controls
77 lines (67 loc) · 1.7 KB
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
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->top_panel->setMinimumWidth(388);
ui->top_panel->setMinimumHeight(233);
plot = new QwtPlot(ui->top_panel);
}
MainWindow::~MainWindow()
{
this->stop_button_clicked();
if (plot)
delete plot;
delete ui;
}
void MainWindow::play_button_clicked()
{
if (!curve)
{
curve = new QwtPlotCurve();
curve->setStyle(QwtPlotCurve::CurveStyle::Dots);
curve->setPen(QColor(Qt::blue), 5);
curve->attach(plot);
thr = new QThread(this);
ng = new number_generator(curve);
ng->moveToThread(thr);
connect(this, &MainWindow::ask_to_start_generation, ng, &number_generator::start_number_generation);
connect(this, &MainWindow::ask_to_pause_generation, ng, &number_generator::pause_number_generation);
connect(ng, &number_generator::ask_to_replot, this, &MainWindow::perform_replot);
thr->start();
}
emit this->ask_to_start_generation();
}
void MainWindow::pause_button_clicked()
{
emit this->ask_to_pause_generation();
}
void MainWindow::stop_button_clicked()
{
if (!thr)
return;
ng->deleteLater();
ng = nullptr;
thr->terminate();
thr->wait();
delete thr;
thr = nullptr;
delete curve;
curve = nullptr;
plot->replot();
}
void MainWindow::perform_replot()
{
plot->replot();
}
void MainWindow::resizeEvent(QResizeEvent *e)
{
e->accept();
if (plot != nullptr)
{
plot->setFixedWidth(ui->top_panel->width());
plot->setFixedHeight(ui->top_panel->height());
}
}