@@ -1,82 +1,84 @@
|
|
1 |
#include <QProgressBar>
|
2 |
|
3 |
#include "GoldbachModel.h"
|
4 |
#include "MainWindow.h"
|
5 |
#include "ui_MainWindow.h"
|
6 |
|
7 |
MainWindow::MainWindow(QWidget *parent)
|
8 |
: QMainWindow(parent)
|
9 |
, ui(new Ui::MainWindow)
|
10 |
{
|
11 |
ui->setupUi(this);
|
12 |
|
13 |
this->progressBar = new QProgressBar();
|
14 |
this->ui->statusBar->addPermanentWidget(progressBar);
|
15 |
this->ui->statusBar->showMessage(tr("Ready"));
|
16 |
}
|
17 |
|
18 |
MainWindow::~MainWindow()
|
19 |
{
|
20 |
delete ui;
|
21 |
}
|
22 |
|
23 |
#include <iostream>
|
24 |
void MainWindow::on_lineEditNumber_textEdited(const QString &arg1)
|
25 |
{
|
26 |
// std::cout << qPrintable(arg1) << std::endl;
|
27 |
bool enable = arg1.trimmed().length() > 0;
|
28 |
this->ui->pushButtonCalculate->setEnabled(enable);
|
29 |
}
|
30 |
|
31 |
void MainWindow::on_pushButtonStop_clicked()
|
32 |
{
|
33 |
-
|
|
|
34 |
}
|
35 |
|
36 |
void MainWindow::on_pushButtonCalculate_clicked()
|
37 |
{
|
38 |
bool isValid = true;
|
39 |
const QString& text = this->ui->lineEditNumber->text();
|
40 |
|
41 |
long long int number = text.toLongLong(&isValid);
|
42 |
|
43 |
if ( isValid )
|
44 |
{
|
45 |
// this->ui->plainTextEditResults->clear();
|
46 |
if ( this->model )
|
47 |
this->model->deleteLater();
|
48 |
|
49 |
this->model = new GoldbachModel(this);
|
50 |
this->ui->listViewResults->setModel(model);
|
51 |
|
52 |
this->progressBar->reset();
|
53 |
|
54 |
this->ui->pushButtonCalculate->setEnabled(false);
|
55 |
this->ui->pushButtonStop->setEnabled(true);
|
56 |
ui->statusBar->showMessage( tr("Calculating...") );
|
57 |
|
58 |
this->time.start();
|
59 |
|
60 |
this->connect(this->model, &GoldbachModel::calculationDone, this, &MainWindow::calculationDone);
|
|
|
61 |
|
62 |
this->model->calculate(number);
|
63 |
}
|
64 |
else
|
65 |
{
|
66 |
ui->statusBar->showMessage( tr("Invalid number: %1").arg(text) );
|
67 |
}
|
68 |
}
|
69 |
|
70 |
void MainWindow::calculationDone(long long sumCount)
|
71 |
{
|
72 |
double seconds = this->time.elapsed() / 1000.0;
|
73 |
ui->statusBar->showMessage( tr("%1 sums found in %2 seconds").arg(sumCount).arg(seconds) );
|
74 |
|
75 |
this->ui->pushButtonCalculate->setEnabled(true);
|
76 |
this->ui->pushButtonStop->setEnabled(false);
|
77 |
}
|
78 |
|
79 |
void MainWindow::updateProgressBar(int percent)
|
80 |
{
|
81 |
this->progressBar->setValue(percent);
|
82 |
}
|
1 |
#include <QProgressBar>
|
2 |
|
3 |
#include "GoldbachModel.h"
|
4 |
#include "MainWindow.h"
|
5 |
#include "ui_MainWindow.h"
|
6 |
|
7 |
MainWindow::MainWindow(QWidget *parent)
|
8 |
: QMainWindow(parent)
|
9 |
, ui(new Ui::MainWindow)
|
10 |
{
|
11 |
ui->setupUi(this);
|
12 |
|
13 |
this->progressBar = new QProgressBar();
|
14 |
this->ui->statusBar->addPermanentWidget(progressBar);
|
15 |
this->ui->statusBar->showMessage(tr("Ready"));
|
16 |
}
|
17 |
|
18 |
MainWindow::~MainWindow()
|
19 |
{
|
20 |
delete ui;
|
21 |
}
|
22 |
|
23 |
#include <iostream>
|
24 |
void MainWindow::on_lineEditNumber_textEdited(const QString &arg1)
|
25 |
{
|
26 |
// std::cout << qPrintable(arg1) << std::endl;
|
27 |
bool enable = arg1.trimmed().length() > 0;
|
28 |
this->ui->pushButtonCalculate->setEnabled(enable);
|
29 |
}
|
30 |
|
31 |
void MainWindow::on_pushButtonStop_clicked()
|
32 |
{
|
33 |
+
Q_ASSERT(this->model);
|
34 |
+
this->model->stop();
|
35 |
}
|
36 |
|
37 |
void MainWindow::on_pushButtonCalculate_clicked()
|
38 |
{
|
39 |
bool isValid = true;
|
40 |
const QString& text = this->ui->lineEditNumber->text();
|
41 |
|
42 |
long long int number = text.toLongLong(&isValid);
|
43 |
|
44 |
if ( isValid )
|
45 |
{
|
46 |
// this->ui->plainTextEditResults->clear();
|
47 |
if ( this->model )
|
48 |
this->model->deleteLater();
|
49 |
|
50 |
this->model = new GoldbachModel(this);
|
51 |
this->ui->listViewResults->setModel(model);
|
52 |
|
53 |
this->progressBar->reset();
|
54 |
|
55 |
this->ui->pushButtonCalculate->setEnabled(false);
|
56 |
this->ui->pushButtonStop->setEnabled(true);
|
57 |
ui->statusBar->showMessage( tr("Calculating...") );
|
58 |
|
59 |
this->time.start();
|
60 |
|
61 |
this->connect(this->model, &GoldbachModel::calculationDone, this, &MainWindow::calculationDone);
|
62 |
+
this->connect(this->model, &GoldbachModel::progressUpdated, this, &MainWindow::updateProgressBar);
|
63 |
|
64 |
this->model->calculate(number);
|
65 |
}
|
66 |
else
|
67 |
{
|
68 |
ui->statusBar->showMessage( tr("Invalid number: %1").arg(text) );
|
69 |
}
|
70 |
}
|
71 |
|
72 |
void MainWindow::calculationDone(long long sumCount)
|
73 |
{
|
74 |
double seconds = this->time.elapsed() / 1000.0;
|
75 |
ui->statusBar->showMessage( tr("%1 sums found in %2 seconds").arg(sumCount).arg(seconds) );
|
76 |
|
77 |
this->ui->pushButtonCalculate->setEnabled(true);
|
78 |
this->ui->pushButtonStop->setEnabled(false);
|
79 |
}
|
80 |
|
81 |
void MainWindow::updateProgressBar(int percent)
|
82 |
{
|
83 |
this->progressBar->setValue(percent);
|
84 |
}
|