-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
89 lines (60 loc) · 1.87 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "worker.h"
#include <QDebug>
#include <QThreadPool>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this);
}
MainWindow::~MainWindow() {
emit sendStopThreads();
delete ui;
qDebug() << "UI destroyed";
}
void MainWindow::on_start_clicked() {
// change buttons state
ui->threadsDone->setValue(0);
ui->start->setEnabled(false);
ui->pause->setEnabled(true);
ui->stop->setEnabled(true);
// Set maximum threads
QThreadPool::globalInstance()->setMaxThreadCount(ui->maxThreads->value());
Worker *work = new Worker(ui->threads->value());
connect(work, SIGNAL(incrThreadDone()), this, SLOT(incrThreadDoneChange()));
connect(this, SIGNAL(sendPause()), work, SLOT(pauseThreads()));
connect(this, SIGNAL(sendResume()), work, SLOT(resumeThreads()));
connect(this, SIGNAL(sendStopThreads()), work, SLOT(stopThreads()));
connect(work, SIGNAL(finished()), this, SLOT(threadFinished()));
work->start();
}
void MainWindow::on_pause_clicked() {
qDebug() << "Set pause";
// change buttons state
ui->pause->setEnabled(false);
ui->resume->setEnabled(true);
emit sendPause();
}
void MainWindow::threadFinished() {
qDebug() << "All threads done";
// change buttons state
ui->start->setEnabled(true);
ui->pause->setEnabled(false);
ui->resume->setEnabled(false);
ui->stop->setEnabled(false);
}
void MainWindow::on_resume_clicked() {
qDebug() << "Resume `s";
ui->pause->setEnabled(true);
ui->resume->setEnabled(false);
emit sendResume();
}
void MainWindow::on_stop_clicked() {
// change buttons state
ui->resume->setEnabled(false);
ui->start->setEnabled(false);
ui->pause->setEnabled(false);
ui->stop->setEnabled(false);
emit sendStopThreads();
}
void MainWindow::incrThreadDoneChange() { ui->threadsDone->stepUp(); }