@@ -1,84 +1,87 @@
|
|
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 |
}
|
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 ( number < 4 || number == 5 )
|
45 |
+
isValid = false;
|
46 |
+
|
47 |
if ( isValid )
|
48 |
{
|
49 |
// this->ui->plainTextEditResults->clear();
|
50 |
if ( this->model )
|
51 |
this->model->deleteLater();
|
52 |
|
53 |
this->model = new GoldbachModel(this);
|
54 |
this->ui->listViewResults->setModel(model);
|
55 |
|
56 |
this->progressBar->reset();
|
57 |
|
58 |
this->ui->pushButtonCalculate->setEnabled(false);
|
59 |
this->ui->pushButtonStop->setEnabled(true);
|
60 |
ui->statusBar->showMessage( tr("Calculating...") );
|
61 |
|
62 |
this->time.start();
|
63 |
|
64 |
this->connect(this->model, &GoldbachModel::calculationDone, this, &MainWindow::calculationDone);
|
65 |
this->connect(this->model, &GoldbachModel::progressUpdated, this, &MainWindow::updateProgressBar);
|
66 |
|
67 |
this->model->calculate(number);
|
68 |
}
|
69 |
else
|
70 |
{
|
71 |
ui->statusBar->showMessage( tr("Invalid number: %1").arg(text) );
|
72 |
}
|
73 |
}
|
74 |
|
75 |
void MainWindow::calculationDone(long long sumCount)
|
76 |
{
|
77 |
double seconds = this->time.elapsed() / 1000.0;
|
78 |
ui->statusBar->showMessage( tr("%1 sums found in %2 seconds").arg(sumCount).arg(seconds) );
|
79 |
|
80 |
this->ui->pushButtonCalculate->setEnabled(true);
|
81 |
this->ui->pushButtonStop->setEnabled(false);
|
82 |
}
|
83 |
|
84 |
void MainWindow::updateProgressBar(int percent)
|
85 |
{
|
86 |
this->progressBar->setValue(percent);
|
87 |
}
|